akhauriyash/Code-Regression huggingface dataset:
import sys


def I(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LMI(): return list(map(int, sys.stdin.readline().split()))


MOD = 10 ** 9 + 7

s = 'abcdefghijklmnop'
N = I()

for c1 in range(1):
    if N == 1:
        print(s[c1])
        continue
    for c2 in range(2):
        if N == 2:
            print(s[c1]+s[c2])
            continue
        for c3 in range(max(c1, c2) + 2):
            if N == 3:
                print(s[c1] + s[c2] + s[c3])
                continue
            for c4 in range(max(c1, c2, c3) + 2):
                if N == 4:
                    print(s[c1] + s[c2] + s[c3] + s[c4])
                    continue
                for c5 in range(max(c1, c2, c3, c4) + 2):
                    if N == 5:
                        print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] )
                        continue
                    for c6 in range(max(c1, c2, c3, c4, c5) + 2):
                        if N == 6:
                            print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6])
                            continue
                        for c7 in range(max(c1, c2, c3, c4, c5, c6) + 2):
                            if N == 7:
                                print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6] + s[c7] )
                                continue
                            for c8 in range(max(c1, c2, c3, c4, c5, c6, c7) + 2):
                                if N == 8:
                                    print(s[c1] + s[c2] + s[c3] + s[c4] + s[c5] + s[c6] + s[c7] + s[c8])
                                    continue
                                for c9 in range(max(c1, c2, c3, c4, c5, c6, c7, c8) + 2):
                                    if N == 9:
                                        print(s[c1]+s[c2]+s[c3]+s[c4]+s[c5]+s[c6]+s[c7]+s[c8]+s[c9])
                                        continue
                                    for c10 in range(max(c1, c2, c3, c4, c5, c6, c7, c8, c9) + 2):
                                        print(s[c1]+s[c2]+s[c3]+s[c4]+s[c5]+s[c6]+s[c7]+s[c8]+s[c9]+s[c10])


Measured memory_bytes: 64856
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  int idx = 0;
  int sum = 0;

  while(true){
    idx++;
    sum += idx;
    if(sum==n){
        cout << "Yes" << endl;
        vector<vector<int>> v(idx + 1,vector<int>(0));
        int first = 1;
        REP(j, idx + 1)
        {
          int num = idx  - j;
          REP(k,num){
            v[j].push_back(first);
            v[j + k + 1].push_back(first);
            first++;
          }
        }
        cout << idx + 1 << endl;
        REP(j, idx + 1)
        {
          cout << v[j].size() << " ";
          REP(k,v[j].size()){
            cout << v[j][k];
            if(k!=v[j].size()-1){
              cout << " ";
            }
          }
          cout << endl;
        }
        break;
    }
    else
    {
      if(sum>n){
        cout << "No" << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;

char ans[105][105];

int main() {
	int n, m;
	scanf("%d %d", &n, &m);

	for(int i = 0; i <= m + 1; i++) {
		ans[0][i] = '#';
		ans[n + 1][i] = '#';
	}
	for(int i = 1; i <= n; i++) {
		ans[i][0] = '#';
		for(int j = 1; j <= m; j++) {
			scanf(" %c", &ans[i][j]);
		}
		ans[i][m + 1] = '#';
	}

	for(int i = 0; i <= n + 1; i++) {
		for(int j = 0; j <= m + 1; j++) {
			printf("%c", ans[i][j]);
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

struct point{
    double x;
    double y;
};

int n;
point points[300];

double getDist2(point a, point b){
    return pow(a.x - b.x ,2) + pow(a.y - b.y, 2);
}

double getDist(point a, point b){
    return sqrt(getDist2(a, b));
}

int findMaxCover(){
    int ans = 1;
    int count;
    int sign[2] = {-1, 1};
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            point a, b;
            a = points[i];
            b = points[j];
            if (getDist2(a, b) > 4.0) {
                continue;
            }
            point m;
            m.x = (a.x + b.x) / 2.0;
            m.y = (a.y + b.y) / 2.0;
            double v, u, d, e;
            d = getDist(a, b);
            v = (a.y - b.y) / d;
            u = (a.x - b.x) / d;
            d = getDist(a, b);
            e = sqrt(1 - d * d / 4);
            for (int k = 0; k < 2; k++) {
                count = 0;
                double p = m.x - e * v * sign[k];
                double q = m.y + e * u * sign[k];
                for (int l = 0; l < n; l++) {
                    point t;
                    t.x = p;
                    t.y = q;
                    if (l == i || l == j) {
                        count++;
                        continue;
                    }
                    if (getDist2(t, points[l]) <= 1.0) {
                        count++;
                    }
                }
                ans = max(ans, count);
            }
        }
    }
    return ans;
}

int main()
{
    while (true) {
        cin >> n;
        if (n == 0) {
            break;
        }
        for (int i = 0; i < n; i++) {
            cin >> points[i].x >> points[i].y;
        }
        cout << findMaxCover() << endl;
        
    }

    return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string S; cin >> S;
    OUT(S.substr(0,3))

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <sstream>

using namespace std;

string IntToString(int number) {
	stringstream ss;
	ss << number;
	return ss.str();
}

int main(void) {
	int in;
	int omori[] = {512,256,128,64,32,16,8,4,2,1};
	int i;
	string ret;

	while(true) {
		cin >> in;
		if(cin.eof()) { break; }
		ret = "";
		for(i = 0; i < 10; i++) {
			if(omori[i] <= in) {
				in -= omori[i];
				ret = IntToString(omori[i]) + ((ret=="")?(""):(" ")) + ret;
			}
			if(in == 0) { break; }
		}
		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 0
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n = ni()
    ans = 0
    for i in range(1, n+1):
        ans += i * (n - i + 1)
    for _ in range(n-1):
        u, v = nm()
        if u > v:
            u, v = v, u
        ans -= u * (n - v + 1)
    print(ans)
    return

solve()


Measured memory_bytes: 9096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

string S;

int rec(string s, char c, int n) {
    bool f = true;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != c) {
            f = false;
            break;
        }
    }
    if (f) return n;

    string new_s = "";
    for (int i = 0; i < s.length() - 1; i++) {
        if (s[i] == c || s[i+1] == c) {
            new_s += c;
        }
        else {
            new_s += s[i];
        }
    }

    return rec(new_s, c, n+1);
}

int main() {
    cin >> S;

    int alpha[26];
    memset(alpha, 0, sizeof(alpha));
    for (int i = 0; i < S.length(); i++) {
        alpha[S[i] - 'a']++;
    }
    
    int ans = 1.0e9;
    for (int i = 0; i < 26; i++) {
        if (alpha[i] > 0) {
            ans = min(ans, rec(S, (char)(i + 'a'), 0));
        }
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define NMAX 100005

ll t[4*NMAX], a[NMAX];
ll n, e, T;
void upd(int i, int s, int e, int indx, ll val){
	if(s == e){
		t[i] = val;
		return;
	}
	int m = (s + e)/2;
	if(indx <= m) upd(i*2, s, m, indx, val);
	else upd(i*2+1, m+1, e, indx, val);
	t[i] = min(t[i*2], t[i*2+1]);
}

ll query(int i, int s, int e, int l, int r){
	if(s >= l & e <= r){
		return t[i];
	}
	if(s > r || e < l) return LONG_LONG_MAX;
	int m = (s + e)/2;
	return min(query(i*2, s, m, l, r), query(i*2+1, m+1, e, l, r));
}

int main(){
	cin>>n>>e>>T;
	for(int i = 0; i < n; i++) cin>>a[i];
	ll dp[n+1]; dp[n] = 0; dp[n-1] = T; upd(1, 0, n-1, n-1, 2*a[n-1]);
	for(int i = n-2; i >= 0; i--){
		dp[i] = dp[i+1] + T;
		ll sv = (T + 2LL*a[i] + 1)/2LL;
		int indx = lower_bound(a + i, a + n, sv) - a;
		//cout<<"INDX: "<<i<<" "<<indx<<endl;
		if(indx-1 >= i) dp[i] = min(dp[i], dp[indx] + max(2*(a[indx-1]-a[i]), T));
		if(indx < n) dp[i] = min(dp[i], query(1, 0, n-1, indx, n-1) - 2*a[i]);
		upd(1, 0, n-1, i, dp[i+1] + 2*a[i]);
		//cout<<"UPD : "<<i<<" : "<<dp[i+1] + 2*a[i]<<endl;
		//cout<<"DP "<<i<<" "<<dp[i]<<endl;
		//dp[i] = min(dp[i], dp[indx+1] + max(2*(a[indx]-a[i]), T));
	}
	cout<<dp[0] + e<<endl;
}


Measured memory_bytes: 3840
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>

using namespace std;
using P = pair<int, int>;

int w, h, m;
string map[20];
int d[20][20][20][20];
P dirty[20];
int diri[] = {-1, 0, 1, 0};
int dirj[] = {0, -1, 0, 1};

void bfs(int si, int sj) {
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            d[si][sj][i][j] = -1;
        }
    }
    d[si][sj][si][sj] = 0;

    queue<P> q;
    q.push(make_pair(si, sj));

    while (!q.empty()) {
        P p = q.front();
        q.pop();
        int i = p.first;
        int j = p.second;
        int cost = d[si][sj][i][j];
        for (int k = 0; k < 4; ++k) {
            int ni = i + diri[k];
            int nj = j + dirj[k];
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (map[ni][nj] == 'x') continue;
            //cout << ni << nj << " "<<d[si][sj][ni][nj]<< endl;
            if (d[si][sj][ni][nj] != -1) continue;
            d[si][sj][ni][nj] = cost + 1;
            q.push(make_pair(ni, nj));
        }
    }
    // for (int i = 0; i < h; ++i) {
    //     for (int j = 0; j < w; ++j) {
    //         cout << d[si][sj][i][j] << "  ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;
}

void solve() {
    for (int i = 0; i < h; ++i) {
        cin >> map[i];
    }

    m = 0;
    int ri, rj;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (map[i][j] == '*') {
                dirty[m] = make_pair(i, j);
                m++;
                bfs(i, j);
            } else if (map[i][j] == 'o') {
                ri = i;
                rj = j;
                bfs(i, j);
            }
        }
    }

    sort(dirty, dirty + m);

    int mincost = 4000;
    do {
        int cost = 0;
        int i = ri;
        int j = rj;
        for (int k = 0; k < m; ++k) {
            int toi = dirty[k].first;
            int toj = dirty[k].second;
            cost += d[i][j][toi][toj];
            if (d[i][j][toi][toj] == -1) {
                mincost = -1;
                break;
            }
            i = toi;
            j = toj;
        }
        mincost = min(cost, mincost);
    } while (next_permutation(dirty, dirty + m));

    cout << mincost << endl;
}

int main() {
    while (1) {
        cin >> w >> h;
        if (w == 0) break;
        solve();
    }
}


Measured memory_bytes: 3756
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

fact :: Int -> Int
fact 1 = 1
fact i = i * fact (i - 1) `mod` 1000000007

main :: IO ()
main = print =<< fact . fst . fromJust . B.readInt <$> B.getLine


Measured memory_bytes: 2044
# ENV[Z = 'RUBY_THREAD_VM_STACK_SIZE'] || exec( { Z => '50000000' },'ruby',$0)
# readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
# gets.split.map(&:to_i)
s = gets.chomp!
matched = /(hi)+/.match(s)
if matched && matched[0] == s
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main() {
  map<string,int> mp;
  int N;
  cin >> N;
  mp["AC"] = 0;
  mp["WA"] = 0;
  mp["TLE"] = 0;
  mp["RE"] = 0; 
  rep(i,N) {
	string s;
	cin >> s;
	mp[s]++;
  }
  printf("AC x %d\n",mp["AC"]);
  printf("WA x %d\n",mp["WA"]);
  printf("TLE x %d\n",mp["TLE"]);
  printf("RE x %d\n",mp["RE"]);
}



Measured memory_bytes: 3264
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        Array.Sort(a);

        long sum = 0;
        for (int i = 1; i < a.Length; i += 2)
        {
            var s = a[i] + a[i - 1];
            if (s > 0)
                sum += s;
            else
                sum -= s;
        }
        if (n % 2 == 1)
            sum += a[a.Length - 1];
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 27868
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        List<Long> enemyList = new ArrayList<>();
        for(int i=0;i<N;i++){
                enemyList.add(Long.parseLong(sc.next()));
        }
        int res = enemyList.size() - K >= 0 ? enemyList.size() - K : 0;
        Collections.sort(enemyList);
        List<Long> resList = enemyList.subList(0,res);
        long total = resList.stream().reduce(0L,(s1,s2) -> s1 + s2);
        System.out.println(total);
    }
}


Measured memory_bytes: 67152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() 
{
    COMinit();
    const ll mod = 1e9 + 7;
    ll S;
    cin >> S;
    if (S < 3) {
        cout << 0 << endl;
        return 0;
    }
    const ll maxLength = S / 3;
    ll count = 0;
    for (auto i = 1; i <= maxLength; ++i) {
        auto m = S - 2 * i;
        if (i == 1) {
            count += 1;
        }
        else {
            count += COM(m-1, i-1);
        }
        count %= mod;
    }
    cout << count << endl;
}

Measured memory_bytes: 15604
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  string S;
  cin >> S;

  int max = 0, count = 0;
  bool b = false;
  for (char ch : S) {
    if (!b) {
      count = 0;
    }
    if (ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T') {
      count++;
      if (count > max) {
        max = count;
      }
      b = true;
    } else {
      b = false;
    }
  }
  cout << max << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int N;
    set<ll> A;
    ll a;
    cin>>N;
    rep(i,N){
        cin>>a;
        if(A.find(a)==A.end()){
            A.insert(a);
        }else{
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int M, N, K;
vector<int> u, v;

int L[30];

int main()
{
    cin >> N;
    int sum = 0, m = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
        sum += L[i];
        m = max(m, L[i]);
    }
    sum -= m;
    if (sum > m)
        puts("Yes");
    else
        puts("No");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007

int n;
char s[222222][11];

main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%s", s[i]);
    }
    qsort(s, n, sizeof(s[0]), strcmp);
    int ans = 1;
    for (int i = 1; i < n; i++)
    {
        ans += 1 - !strcmp(s[i - 1], s[i]);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 5740
import java.io.*;
import java.util.*;
import java.util.Stack;
import java.util.regex.Pattern;


public class Main {

	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long)(1e9+7);
	public static void main(String[] args) {
		 FastReader sc = new FastReader();
		 int n = sc.nextInt();
		 int k = sc.nextInt();
		 int[] v = new int[n];
		 for(int i=0;i<n;++i) v[i] = sc.nextInt();
		 long ans = 0;
		 
		 for(int it = 0;it<=Math.min(n, k);++it){
			 
		        for(int a=0;a<=it;++a){
		            int b = it - a;
		    TreeMap<Integer,Integer> map = new TreeMap<>();
		            
		 
		            for(int i=0;i<a;++i) add(map,v[i]);
		            for(int i=0;i<b;++i) add(map,v[n-1-i]);
		 
		            int rem = k - it;
		 
		            long temp = 0;
		            for(int key : map.keySet()) temp+=key*map.get(key)*1L;
		         //   out.println("temp : "+temp);
		            for (int x: map.keySet()){
		            	for(int i=0;i<map.get(x);++i)
		                if (rem-- > 0 && x < 0) temp -= x;
		            }
		 
		            ans = Math.max(ans, temp);
		        }
		    }
		 
		    out.println(ans);
		 
		
		 
		 out.close();
		 
	}
	private static void add(TreeMap<Integer, Integer> map, int i) {
		// TODO Auto-generated method stub
		if(map.containsKey(i)) map.put(i, map.get(i)+1);
		else map.put(i, 1);
		
	}
	private static void delete(TreeMap<Integer, Integer> map, int i) {
		if(map.containsKey(i)) {
			if(map.get(i) == 1) map.remove(i);
			else map.put(i, map.get(i)-1);
		}
		
	}
}		 





Measured memory_bytes: 27644
#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

typedef pair<int,int> pii;

bool isok(vector<pii> &ord,set<pii> &S,int n,int k){
  rep(i,ord.size()){
    pii tmp=make_pair((ord[i].first+k)%n,(ord[i].second+k)%n);
    if (tmp.first > tmp.second)swap(tmp.first,tmp.second);
    if (S.find(tmp) == S.end())S.insert(tmp);
    else return false;
  }
  return true;
}

bool solve(int n,int k){
  vector<pii> ord;
  set<pii> S;
  vector<int> tmp;
  for(int i=0;i<n/2;i++){
    tmp.push_back(i);
    tmp.push_back(n-1-i);
  }
  if (n%2 == 1)tmp.push_back(n/2);
  rep(i,tmp.size()-1){
    ord.push_back(make_pair(tmp[i],tmp[i+1]));
  }
  rep(i,k){
    if (!isok(ord,S,n,i))return false;
  }
  rep(i,k){
    if (i)printf("\n");
    rep(j,ord.size()){
      //cout << (ord[j].first+i)%n+1 <<" " << (ord[j].second+i)%n+1 << endl;
      printf("%d %d\n",(ord[j].first+i)%n+1,(ord[j].second+i)%n+1);
    }
  }
  return true;
}


main(){
  int n,k;
  while(cin>>n>>k && n){
    if (!solve(n,k))cout << -1 << endl;
  }
  return false;
}

Measured memory_bytes: 0
n = gets.to_i
i = 1

loop do
  x = i
  if (x % 3 == 0) then
    printf " %d", i
  else
    loop do
      if (x % 10 == 3 ) 
        printf " %d", i
        break
      end
      x /= 10
      break if x == 0
    end
  end
  i += 1
  break if (i > n)
end

puts


Measured memory_bytes: 6872
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<pii> cnt;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    cnt.push_back(make_pair(a, 1));
  }
  for (int i = 0; i < M; i++) {
    int b, c;
    cin >> b >> c;
    cnt.push_back(make_pair(c, b));
  }
  sort(cnt.begin(), cnt.end());
  reverse(cnt.begin(), cnt.end());
  ll res = 0;
  for (int i = 0; i < cnt.size(); i++) {
    int n = cnt[i].first, c = cnt[i].second;
    if (N - c >= 0) {
      res += 1LL * n * c;
      N -= c;
    } else {
      res += 1LL * n * N;
      break;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 2420
using System;

class AOJ{
  public static void Main(string[] args)
  {
    int[] n = new int[10];

    for(int i=0; i<10; i++)
      n[i] = int.Parse(Console.ReadLine());

    Array.Sort(n);

    for(int i=0; i<3; i++)
      Console.WriteLine(n[9-i]);
  }
}

Measured memory_bytes: 9284
#include<bits/stdc++.h>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define pii pair<int,int>
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define mp make_pair

#define INF (ll)1e18


ll N,Q;
ll A[5050];
vector<ll> tuv[5050];
vector<ll> dp1[5050], dp2[5050];

ll i, j, k, ans;

ll minn(ll a,ll b){
    return a < b ? a : b;
}

void dfs(ll a,ll p){
    dp1[a].push_back(A[a] > 0 ? A[a] : INF);
    dp2[a].push_back(A[a]);
    ll i, j, k;
    fornum(i,0,tuv[a].size()){
        ll b = tuv[a][i];
        if(b==p){
            continue;
        }
        dfs(b, a);
        ll an = dp1[a].size();
        ll bn = dp1[b].size();
        vector<ll> ndp1(an + bn,INF),ndp2(an + bn,INF);
        fornum(j,0,an){
            fornum(k,0,bn){
                if(dp1[a][j]!=INF&&dp1[b][k]!=INF){
                    ndp1[j + k] = minn(ndp1[j + k], dp1[a][j] + dp1[b][k]);
                }
                if(dp2[a][j]!=INF&&dp2[b][k]!=INF){
                    ndp2[j + k] = minn(ndp2[j + k], dp2[a][j] + dp2[b][k]);
                }
                if(dp1[b][k]!=INF||dp2[b][k]<0){
                    ndp1[j + k + 1] = minn(ndp1[j + k + 1], dp1[a][j]);
                    ndp2[j + k + 1] = minn(ndp2[j + k + 1], dp2[a][j]);
                }
            }
        }
        dp1[a] = ndp1;
        dp2[a] = ndp2;
    }
    /*
    printf("%lld:\n", a);
    fornum(i,0,dp1[a].size()){
        printf("%lld,%lld,%lld\n", i, dp1[a][i], dp2[a][i]);
    }
    */
}


int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &A[i+1]);
    }
    fornum(i,1,N){
        ll u, v;
        scanf("%lld%lld", &u, &v);
        tuv[u].push_back(v);
        tuv[v].push_back(u);
    }
    dfs(1, 0);
    fornum(i,0,N){
        fornum(j,0,N){
        }
    }
    fornum(i,0,dp1[1].size()){
        //printf("%lld,%lld,%lld\n", i, dp1[1][i], dp2[1][i]);
        if(dp1[1][i]<INF||dp2[1][i]<0){
            printf("%lld", i);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 164480
N = int(input())
S = input()

alphabet = "abcdefghijklmnopqrstuvwxyz"

ans = 0
for i in range(N):
        ans_tmp = 0
        for c in alphabet:
                if (c in S[:i]) and (c in S[i:]):
                        ans_tmp += 1
        if ans < ans_tmp:
                ans = ans_tmp

print(ans)

Measured memory_bytes: 3060
X = int(input())
happiness = 0
while X > 0:
    if X >= 500:
        temp = int(X / 500)
        X = X - (500 * temp)
        happiness = 1000 * temp
    else:
        temp = int(X / 5)
        X = X - (500 * temp)
        happiness = happiness + (5 * temp)
        break
print(happiness)

Measured memory_bytes: 2940
N, M = map(int,input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]

for i in range(N-M+1):
    A_new = A[i:i+M]
    for j in range(N-M+1):
        A_new_new = list(map(lambda n:n[j:j+M], A_new))
        if A_new_new == B:
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 3060
class Combination:
    def __init__(self, n_max, mod=10 ** 9 + 7):
        # O(n_max + log(mod))
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max + 1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod - 2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    # "n 要素" は区別できる n 要素
    # "k グループ" はちょうど k グループ

    def __call__(self, n, r):  # self.C と同じ
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def nCr(self, n, r):
        if not 0 <= r <= n:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod


def resolve():
    def route(a, b):
        dx = b[0] - a[0]
        dy = b[1] - a[1]
        if dx < 0 or dy < 0:
            return 0
        return cmb.nCr(dx+dy, dx)


    MOD = 10 ** 9 + 7
    H, W, N = map(int, input().split())
    wall = []
    for _ in range(N):
        r, c = map(lambda x:int(x)-1, input().split())
        wall.append((r, c))
    # スタート位置
    wall.append((0, 0))
    wall.sort()

    cmb = Combination((H + W) + 1)
    dp = [[0] * 2 for _ in range(N + 1)]
    dp[0][0] = 1

    for i in range(1, N+1):
        for j in range(0, i):
            dp[i][0] += dp[j][1] * route(wall[j], wall[i]) % MOD
            dp[i][0] %= MOD
            dp[i][1] += dp[j][0] * route(wall[j], wall[i]) % MOD
            dp[i][1] %= MOD

    goal = (H-1, W-1)
    ng = 0
    for i in range(1, N+1):
        ng -= dp[i][0] * route(wall[i], goal) % MOD
        ng += dp[i][1] * route(wall[i], goal) % MOD
        ng %= MOD

    # 全体 - ng
    all = cmb.nCr(H+W-2, H-1)
    ans = (all - ng + MOD) % MOD
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 102256
#include <stdio.h>

typedef struct{
    char name[11];
    int t;
    int prev;
    int next;
}QUEUE;

int main(void){
    int i;
    
    int n,q;
    scanf("%d %d",&n,&q);
    
    QUEUE Q[n];
    for(i=0;i<n;i++){
        scanf("%s %d",Q[i].name,&Q[i].t);
        if(i==0)Q[i].prev=n-1;
        else Q[i].prev=i-1;
        if(i==n-1)Q[i].next=0;
        else Q[i].next=i+1;
    }
    
    int count=0;
    i=0;
    int tmp,k=0;
    while(i!=-1&&k!=n){
        if(Q[i].t<=q){
            count=count+Q[i].t;
            printf("%s %d\n",Q[i].name,count);
            tmp=i;
            i=Q[tmp].next;
            Q[tmp].t=0;
            Q[Q[tmp].prev].next=Q[tmp].next;
            Q[Q[tmp].next].prev=Q[tmp].prev;
            Q[tmp].next=-1;
            Q[tmp].prev=-1;
            k++;
        }else{
            count=count+q;
            Q[i].t=Q[i].t-q;
            i=Q[i].next;
        }
    }
}



Measured memory_bytes: 2872
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		while (true)
		{
			try
			{
				int a[] = new int[4];
				for (int i = 0; i < 4; i++)
				{
					a[i] = sc.nextInt();
				}
				
				int hit = 0;
				int blow = 0;
				for (int i = 0; i < 4; i++)
				{
					int b = sc.nextInt();
					if (a[i] == b) hit++;
					else
					{
						for (int j = 0; j < 4; j++)
						{
							if (a[j] == b) blow++;
						}
					}
				}
				System.out.println(Integer.toString(hit) + " " + Integer.toString(blow));
			}
			catch (Exception e)
			{
				break;
			}
		}
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define ITR(i,x) for(auto i=(x).begin();i!=(x).end();++i)
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int mod = 1000000007;

bool square(ll a){ll n=(ll)sqrt(a);return a==n*n;}
int digitsum(ll N,int a);//a進数におけるNの各桁の和、計算量はloga(N)
ll mpow(ll x, ll n);
ll inv_mod(ll a){return mpow(a,mod-2);}
int gcd(int x,int y){return y ? gcd(y,x%y) : x;};//xとyの最大公約数
int lcm(int x,int y){return x*y/gcd(x,y);}//xとyの最小公倍数

int main(){
    int H,W;
    cin>>H>>W;
    int c[10][10];
    vector<vector<ll>> dist(10,vector<ll>(10));
    REP(i,10) REP(j,10) cin>>dist[i][j];
    REP(k,10) REP(i,10) REP(j,10){
        if(dist[i][j]>dist[i][k]+dist[k][j]){
            dist[i][j]=dist[i][k]+dist[k][j];
        }
    }
    int ans=0;
    vector<vector<int>> A(H,vector<int>(W));
    REP(i,H) REP(j,W){ 
        cin>>A[i][j];
        if(A[i][j]==-1) continue;
        ans+=dist[A[i][j]][1];
    }
    cout<<ans<<endl;
    
}

int digitsum(ll N,int a){
    if(N==0) return 0;
    int ret=0;
    ret+=digitsum(N/a,a)+N%a;
    return ret;
}
ll mpow(ll x, ll n){ //x^n(mod division) ←普通にpow(x,n)では溢れてしまうため，随時mod計算 2分累乗法だから早い
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}
/*
class Factorial{//階乗とその逆元を求めて計算に利用するクラス
private:
    vector<ll> fac;
public:
    
    Factorial(ll N){
        fac.push_back(1);
        for(int i=0;i<N;i++) fac.push_back(fac[i]*(i+1)%mod);
    }

    ll fact(ll a){return fac[a];}
    ll ifact(ll a){return inv_mod(fac[a]);}

    ll cmb(ll a,ll b){
        if(a==0&&b==0) return 1;
        if(a<b||a<0) return 0;
        ll tmp =ifact(a-b)*ifact(b)%mod;
        return tmp*fac[a]%mod;
    }
};
*/

/*
class UnionFind{//UnionFind木
 private:
    vector<int> Parent;
 public:
    UnionFind(int N){
        for(int i=0;i<N;i++) Parent.push_back(-1);
    }

    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A]=root(Parent[A]);
    }

    int size(int A){
        return -Parent[root(A)];
    }

    bool connect(int A,int B){
        A=root(A);
        B=root(B);
        if(A==B) return false;
        if(size(A)<size(B)) swap(A,B);
        Parent[A]-=Parent[B];
        Parent[B]=A;
    }
};
*/

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

//matp G(N);
void graphmake(ll E,matp &G){
  rep(i,E){
    ll a,b,c;
    cin >> a >> b >> c;
    G.at(a-1).push_back(P(b-1,c));
    G.at(b-1).push_back(P(a-1,c));//有向なら消す
  }
}
//vec d(N);
void dijkstra(ll s,vec &d, matp &G,ll V){
  priority_queue<P,vector<P>,greater<P>> que;
  rep(i,V) d.at(i)=INF;
  d.at(s)=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    ll v=p.second;
    if(d.at(v)<p.first) continue;
    rep(i,G.at(v).size()){
      P e=G.at(v).at(i);
      if(d.at(e.first)>d.at(v)+e.second){
        d.at(e.first)=d.at(v)+e.second;
        que.push(P(d.at(e.first),e.first));
      }
    }
  }
}


int main(){
  ll A,B,C;
  cin >> A >> B >> C;
  if(A%2==0||B%2==0||C%2==0){
    cout << 0 << endl;
  }else{
    if(A>B){
      swap(A,B);
    }
    if(B>C){
      swap(B,C);
    }
    if(A>B){
      swap(A,B);
    }
    cout << A*B << endl;
  }
}
  

Measured memory_bytes: 3576
import itertools
h, w, k = [int(i) for i in input().split()]
choco = ([input() for j in range(h)])
ans = float("inf")

for i in itertools.product([0,1], repeat=h-1):
    list_yoko = []
    list_temp = []
    list_temp.append(0)
    for j in range(h-1):
        if i[j] == 1:
            list_yoko.append(list_temp)
            list_temp = []
            list_temp.append(j+1)
        else:
            list_temp.append(j+1)
    else:
        list_yoko.append(list_temp)


    count = 0
    count_list = [0 for _ in range(len(list_yoko))]

    for j in range(w):
        count_list_ = [0 for _ in range(len(list_yoko))]

        for m in range(len(list_yoko)):
            for l in list_yoko[m]:
                count_list_[m] += int(choco[l][j])

        if max(count_list) > k :
            count = float("inf")

        else:
            if max([count_list[_] + count_list_[_] for _ in range(len(list_yoko))]) > k:
                count += 1
                count_list = count_list_[:]

            else:
                count_list = [count_list[_] + count_list_[_] for _ in range(len(list_yoko))]

    ans = min(count+sum(i), ans)

print(ans)


Measured memory_bytes: 61528
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
int n; cin>>n;
  string s; cin>>s;
  int r=0;
  int b=0;
  for(int i=0;i<n;i++){
    if(s[i]=='R') r++;
    else b++;
}
  if(r>b){cout<<"Yes"<<endl;}
  else cout<<"No"<<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++)
        cin >> s[i];
    
    sort(s.begin(), s.end());
    
    int ans = 1;
    for (int i = 1; i < n; i++) {
        if (s[i] != s[i-1])
            ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 9544
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	rep(i, N) cin >> a[i];

	int cnt = 0;
	int res = 1;
	rep(i, N) {
		if(res == a[i])
			res++;
		else
			cnt++;
	}

	if(cnt == N)
		cout << -1 << endl;
	else
		cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std ;
int main () {
	int n ;
	cin >> n ;
	n %= 10 ;
	if (n == 3){
		cout << "bon" ;
	}
	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9){
		cout << "hon" ;
	}
	if (n == 0 || n == 1 || n == 8 || n == 6) {
		cout << "pon" ;
	}
	return 0 ;
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	long long n;
	cin >> n;
	vector<long long> a(n);
	long long all=0;
	for(long long i=0;i<n;i++)
	{
		cin >> a[i];
		all+=a[i];
	}
	long long cnt=0;
	long long ans=0;
	for(long long i=0;i<n;i++)
	{
		cnt+=a[i];
		if(cnt>=all/2)
		{
			long long bef=cnt-a[i];
			ans=abs(cnt-(all-cnt));
			long long tmp=abs((all-bef)-bef);
			if(tmp<ans)
				ans=tmp;
			break;
		}
	}
	cout << ans << endl;

	




}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<limits>

using namespace std;

int main(void) {
	int N, M;
	cin >> N >> M;

	vector<int> a(N);
	vector<int> b(N);
	vector<int> c(M);
	vector<int> d(M);

	for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
	for (int i = 0; i < M; i++) cin >> c[i] >> d[i];

	for (int i = 0; i < N; i++) {
		int n = 0;
		for (int j = 1; j < M; j++) {
			if (abs(a[i] - c[n]) + abs(b[i] - d[n]) > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				n = j;
			}
		}
		cout << n + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
    int S;
    cin >> S;
    int a,b,c;
    a=S%10;
    b=(S-a)%100/10;
    c=(S-b*10)%1000/100;
    cout << a+b+c << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
  ll N,K; cin>>N>>K;

  vector<ll> x(N);
  for(ll i=0;i<N;i++)cin>>x[i];

  ll pc=0,mc=0,zc=0;
  ll pind=-1,mind=-1;

  for(ll i=0;i<N;i++){
    if(x[i]>0){
      pc++;
      if(pind==-1){
        pind = i;
      }
    }
    else if(x[i]==0)
    {
      zc++;
    }
    else{
      mc++;
      mind = i;
    }
    
  }

  ll num = K-zc;
  ll mii =10000000000;
  if(num==0){
    cout<<0<<endl;
    return 0;
  }

  for(ll i=0;i<=num;i++){
    ll r = i;
    ll l = num-i;
    if(r>pc||l>mc)
    continue;

    ll hidari = x[mind-(l-1)];
    ll migi = x[pind+(r-1)];
    hidari *=(-1);

    ll tar = min((migi+hidari*2),(migi*2+hidari));

    if(r==0){
      tar = hidari;
    }
     if(l==0){
      tar = migi;
    }

    mii = min(tar,mii);

  }




cout<<mii<<endl;


}








Measured memory_bytes: 1024
#include <iostream>

char convert(int m, int f, int r){
    if(m == -1 or f == -1) return 'F';
    if(m + f >= 80) return 'A';
    if(m + f >= 65) return 'B';
    if(m + f >= 50) return 'C';
    if(m + f >= 30) return (r >= 50) ? 'C' : 'D';
    return 'F';
}

int main(void){
    char ptr[101]; int p = 0;
    while(true){
        int m, f, r; scanf("%d%d%d", &m, &f, &r);
        if(m == -1 and f == -1 and r == -1) break;
        ptr[p++] = convert(m, f, r);
        ptr[p++] = '\n';
    }
    ptr[p] = '\0';
    printf("%s", ptr);
    return 0;
}


Measured memory_bytes: 3204
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	long long  n, a, b; cin >> n >> a >> b;
	long long  ans = ((n / (a + b)) * a) + min(a, n % (a + b));
	cout << ans;

	return 0;
}

Measured memory_bytes: 3192
#include<cstdio>
#include<algorithm>
#define rep(i,a) for(int i=0;i<(a);++i)

const int MAX_D = 200, MAX_N = 200;

int D, N;
int T[MAX_D], A[MAX_N], B[MAX_N], C[MAX_N];

int dp[MAX_D][MAX_N];

bool safe( int d, int k )
{ return A[k] <= T[d] && T[d] <= B[k]; }

int main()
{
	scanf( "%d%d", &D, &N );
	rep( i, D )
		scanf( "%d", T+i );
	rep( i, N )
		scanf( "%d%d%d", A+i, B+i, C+i );

	rep( i, D-1 ) rep( j, N ) if( safe(i,j) ) rep( k, N ) if( safe(i+1,k) )
		dp[i+1][k] = std::max( dp[i+1][k], dp[i][j]+abs(C[k]-C[j]) );

	printf( "%d\n", *std::max_element( dp[D-1], dp[D-1]+N ) );

	return 0;
}

Measured memory_bytes: 1172
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String s = sc.next();
        if(s.length() <= k){
            System.out.println(s);
        }else{
            System.out.println(s.substring(0, k) + "...");
        }
    }
}

Measured memory_bytes: 38680
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 100000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const ll MAXN = 1e18;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int n;
	cin >> n;
	bool ok = false;
	int cnt = 0;
	for(int i=0; i<n; i++){
		int a,b;
		cin >> a >> b;
		if(a == b){
			cnt++;
		}else{
			cnt=0;
		}
		if(cnt>=3){
			ok = true;
		}
	}
	if(ok){
		cout <<"Yes\n";
	}else{
		cout << "No\n";
	}
	return 0;
}
//l,l+1,l+2 ... l+n-1
//^-^

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

long long N, K;

int main() {
    long long r = 1;
    cin >> N >> K;
    for (; r < K && N != 0; N--) {
        r *= 2;
    }
    for (; N != 0; N--) {
        r += K;
    }
    cout << r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <queue>
#include <utility>
#include <cmath>
using namespace std;

int f(int n){
  if(n > 1){
    return n*f(n - 1);
  }
  else return 1;
}

int main()
{
  int N;
  cin >> N;

  vector<pair<int, int> > p(N);

  long double ave = 0;


  for(int i = 0; i < N; i++){
    cin >> p[i].first >> p[i].second;
  }

  int count = 0;

  for(int i = 0; i < N - 1; i++){
    for(int j = i + 1; j < N; j++){
      ave += sqrt((p[i].first - p[j].first)*(p[i].first - p[j].first)
            + (p[i].second - p[j].second)*(p[i].second - p[j].second));
      count++;
    }
  }


  ave = (ave/count)*(N - 1);

  printf("%Lf\n", ave);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, l;
    cin >> n >> l;
    int sum = 0;
    int mn = INF;
    bool flg;
    for( int i = 1; i <= n; ++i ) {
        sum += i + l - 1;
        if( mn > abs( i + l - 1 ) ) { 
            mn = min( mn, abs( i + l - 1 ) );
            if( i + l - 1 >= 0 ) flg = true;
            else flg = false;
        }
    }
    if( !flg ) mn = -mn;
    cout << sum - mn << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    while(cin>>n){
        vi a(n); forn(i,n) cin>>a[i];
        sort(all(a)); reverse(all(a));
        
        ll sum = a[0];
        ll times = n-2;

        fore(i,1,n){
            if(times==0) break;
            sum+=a[i]; --times;
            if(times==0) break;
            sum+=a[i]; --times;
        }

        cout<<sum<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3980