akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vs a;

void dfs(string s,int I){
	if(s.size()==n){
		a.push_back(s);
		return;
	}
	for(int j=0;j<=I;j++){
		dfs(s+(char)('a'+j),I+(I==j?1:0));
	}
}

int main(){
	cin>>n;
	dfs("",0);
	for(auto i:a) cout<<i<<endl;
}

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

int main() {
  int K,A,B; cin >>K >>A >>B;
  int i=1,kyori=0;
  while (kyori<B) {
    kyori=i*K;
    if (A<=kyori && kyori<=B) {
      cout <<"OK" <<endl;
      return 0;
    }
    i++;
  }
  cout <<"NG" <<endl;
  return 0;
}


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

int main() {
  int n; cin >>n;
  int ans;
  for (int i=n; i<1000; i++){
    if (i/100==i/10%10 && i/100==i%10){
      ans = i; break;
    }
  }

  cout <<ans;
  cout <<endl;
}


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

vector<vector<vector<ll>>> ki(0, vector<vector<ll>>(0, vector<ll>(2)));
vector<ll> it(0);
vector<ll> d(0);
ll k;
ll kei(ll a, ll sum){
    it.at(a) = 1;
    rep(i, ki.at(a).size()){
        if(it.at(ki.at(a).at(i).at(0)) == 0){
            d.at(ki.at(a).at(i).at(0)) = sum + ki.at(a).at(i).at(1);
            kei(ki.at(a).at(i).at(0), sum + ki.at(a).at(i).at(1));
        }
    }
    return 0;
}

int main(){
    ll n, in0, in1, in2;
    cin >> n;
    vector<vector<ll>> kiin((n-1)*2, vector<ll>(3));
    rep(i, n-1){
        cin >> in0 >> in1 >> in2;
        kiin.at(i*2) = {in0-1, in1-1, in2};
        kiin.at(i*2+1) = {in1-1, in0-1, in2};
    }
    sort(kiin.begin(), kiin.end());
//    rep(i, (n-1)*2) cout << ki.at(i).at(0) << ' ' << ki.at(i).at(1) << ' ' << ki.at(i).at(2) << endl;

    rep(i, n){
        ki.push_back({});
        it.push_back(0);
        d.push_back(-1);
    }
    rep(i, (n-1)*2){
        ki.at(kiin.at(i).at(0)).push_back({kiin.at(i).at(1), kiin.at(i).at(2)});
    }

/*    rep(i, n){
        cout << i << endl;
        rep(j, ki.at(i).size()) cout << ki.at(i).at(j).at(0) << ' ' << ki.at(i).at(j).at(1) << endl;
    }*/

    ll q;
    cin >> q >> k;
    d.at(k-1) = 0;
    kei(k-1, 0);
    vector<ll> a(q);
    vector<ll> b(q);
//    rep(i, n) cout << d.at(i) << endl;


    rep(i, q){
        cin >> a.at(i) >> b.at(i);
    }
    rep(i, q){
        cout << d.at(a.at(i)-1) + d.at(b.at(i)-1) << endl;
    }
    return 0;
}

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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  long a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max({a * c, a * d, b * c, b * d}) << "\n";
}

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

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true;string res = "{"; for (const auto &x : v) {if (!first) {res += ", ";} first = false; res += to_string(x);} res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB") {
      cout << "No";
    }
    else {
      cout << "Yes";
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n, 0);
    for (int& e : x) {
        cin >> e;
    }

    ll sum = 0;
    for (int i = 0; i < n; i++) {
        int distance = min(x[i], abs(x[i] - k));
        sum += distance * 2ll;
    }
    cout << sum << "\n";
    return 0;
}

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> pll;
typedef vector<int> vi;
typedef vector<long long int> vl;
#define pb push_back
#define mp make_pair

ll expm(ll x, ll y, ll mod){
	ll ans = 1;
	while(y>0){
		if(y%2==1) ans*=x, ans%=mod, y--;
		else x*=x, x%=mod, y/=2;
	}
	return ans%mod;
}

ll exp(ll x, ll y){
	return expm(x,y,LLONG_MAX);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);

	int n;
	cin >> n;
	vector<int> h(n);
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}

	vector<int> dp(n,0);
	for(int i = n-2; i >= 0; i--){
		int short_jump_cost = dp[i + 1] + abs(h[i + 1] - h[i]);
		int long_jump_cost = short_jump_cost + 1;
		
		if(i + 2 < n) 
			long_jump_cost = dp[i + 2] + abs(h[i + 2] - h[i]);
		
		dp[i] = min(short_jump_cost, long_jump_cost);
	}

	cout << dp[0] << endl;
	return 0;
}



Measured memory_bytes: 3988
#include <iostream>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  double inv_sum = 0;
  for (int i = 0; i < N; ++i) {
    int A;
    cin >> A;
    inv_sum += 1.0 / A;
  }
  cout << 1.0 / inv_sum << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
   int n;
   cin >>n;
   VI b(n+3);
   rep(i,n-1){
       cin >> b.at(i);
   }
    ll sum=0;
   for(int i=0;i<=n-1;i++){
    if(i==0){
        sum+=b.at(i);
    }
    else if(i==n-1){
        sum+=b.at(n-2);
    }
    else{
        sum+=min(b.at(i-1),b.at(i));
    }
   }
   cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    bool prime[50100] = {true, true, false};
    int p[20000], j = 2;
    rep(i,50100){
        if(!prime[i]){
            p[j++] = i;
            for(int j = i + i; j < 50100; j+=i){
                prime[j] = true;
            }
        }
    }

    int n;
    while(cin >> n){
        int i = 2;
        while(true){
            if(p[i] < n && p[i + 1] > n){
                cout << p[i] << ' ' << p[i + 1] << endl;
                break;
            }else if(p[i] == n){
                cout << p[i - 1] << ' ' << p[i + 1] << endl;
                break;
            }else if(p[i + 1] == n){
                cout << p[i] << ' ' << p[i + 2] << endl;
                break;
            }
            i++;
        }
    }
}

Measured memory_bytes: 1244
#include <stdio.h>
 
int main()
{
  int a[4];
  scanf("%d%d",&a[0],&a[1]);
  if ((a[0] + a[1]) % 3 != 0 && a[0] % 3 != 0 && a[1] % 3 != 0)
  	printf("Impossible");
  else
    printf("Possible");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);++i)
#define reps(i,n) for(int i = 1;i <= (n);++i)
using namespace std;
int main(){
  int n,a;
  cin >> n >> a;
  cout << n * n - a << '\n';
  return 0;
}

Measured memory_bytes: 256
n=int(input())
s=input()
cnt=0
r=[""]*(2*n)
d={"B":1,"W":0}
for i in range(2*n):
    if d[s[i]]^cnt%2:
        cnt+=1
        r[i]="L"
    else:
        cnt-=1
        r[i]="R"
    if cnt<=-1 or cnt>=n+1:print(0);exit()
if cnt!=0:print(0);exit()
ans=1
mod=10**9+7
for i in range(1,n+1):
    ans*=i
    ans%=mod
lcnt=0
for i in range(2*n):
    if r[i]=="L":
        lcnt+=1
    if r[i]=="R":
        ans*=lcnt
        ans%=mod
        lcnt-=1
print(ans)


Measured memory_bytes: 4968
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int x;
		int y;
		int w, h;
		int[][] u;
		int[][] d;
		int[][] l;
		int[][] r;
		int[][] dist;
		int[][] flag;
		int t;

		while(true){
			t = 0;
			w = sc.nextInt();
			h = sc.nextInt();
			if(w == 0 && h == 0)
				break;

			u = new int[h][w];
			d = new int[h][w];
			l = new int[h][w];
			r = new int[h][w];
			dist = new int[h][w];
			flag = new int[h][w];

			for(int i = 0; i < h; i++){
				l[i][0] = 1;
				r[i][w-1] = 1;
			}
			for(int j = 0; j < w; j++){
				u[0][j] = 1;
				d[h-1][j] = 1;
			}
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w-1; j++){
					r[i][j] = sc.nextInt();
					l[i][j+1] = r[i][j];
				}
				if(i == h - 1)
					continue;
				for(int j = 0; j < w; j++){
					d[i][j] = sc.nextInt();
					u[i+1][j] = d[i][j];
				}
			}

			Queue xQueue = new Queue(w * h);
			Queue yQueue = new Queue(w * h);

			xQueue.enqueue(0);
			yQueue.enqueue(0);
			dist[0][0] = 1;

			while(!xQueue.isEmpty()){
				x = xQueue.dequeue();
				y = yQueue.dequeue();
				if(x == h-1 && y == w-1){
					System.out.println(dist[x][y]);
					t = 1;
					break;
				}
				if(d[x][y] == 0 && flag[x+1][y] == 0){
					xQueue.enqueue(x+1);
					yQueue.enqueue(y);
					dist[x+1][y] = dist[x][y] + 1;
					flag[x+1][y] = 1;
				}
				if(r[x][y] == 0 && flag[x][y+1] == 0){
					xQueue.enqueue(x);
					yQueue.enqueue(y+1);
					dist[x][y+1] = dist[x][y] + 1;
					flag[x][y+1] = 1;
				}
				if(u[x][y] == 0 && flag[x-1][y] == 0){
					xQueue.enqueue(x-1);
					yQueue.enqueue(y);
					dist[x-1][y] = dist[x][y] + 1;
					flag[x-1][y] = 1;
				}
				if(l[x][y] == 0 && flag[x][y-1] == 0){
					xQueue.enqueue(x);
					yQueue.enqueue(y-1);
					dist[x][y-1] = dist[x][y] + 1;
					flag[x][y-1] = 1;
				}
			}
			if(t == 0)
				System.out.println(0);
		}
	}
}
class Queue{
	int SIZE;
	int head = 0;
	int tail = 0;
	int[] val;

	Queue(int iSIZE){
		SIZE = iSIZE;
		val = new int[SIZE];
	}

	int next(int index){
		return (index+1)%SIZE;
	}

	boolean isEmpty(){
		return (head == tail);
	}

	boolean enqueue(int data){
		if(next(tail) == head)
			return false;
		else{
			val[tail] = data;
			tail = next(tail);
			return true;
		}
	}

	int dequeue(){
		int data;
		if(isEmpty()){
			data = -1;
		}else{
			data = val[head];
			head = next(head);
		}
		return data;
	}
}

Measured memory_bytes: 65100
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define dl double
#define mod 1000000007
#define sz 300005

using namespace std;

int main()
{
    char str[5];

    scanf("%s",str);

    if(str[0]=='9'||str[1]=='9')
        printf("Yes\n");

    else
        printf("No\n");

    return (0);
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;

void bfs(int start, int n, vector<vector<int>> &a) {
	int INF = 10000000;
	vector<int> d(n, INF);
	queue<int> q;
	d[start] = 0;
	q.push(start);
	while (q.size() != 0) {
		int u = q.front();
		q.pop();
		for (int i = 0; i < n; i++) {
			if (a[u][i] == 0)
				continue;
			if (d[i] != INF)
				continue;
			d[i] = d[u] + 1;
			q.push(i);
		}
	}
	for (int i = 0; i < n; i++) {
		if (d[i] == INF) {
			cout << i + 1 << " -1" << endl;
		}
		else {
			cout << i + 1 << " " << d[i] << endl;
		}
	}
}
int main()
{
	int n;
	vector<vector<int>> a;
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		a[i].resize(n);
	}
	for (int i = 0; i < n; i++) {
		int temp, k;
		cin >> temp >> k;
		for (int j = 0; j < k; j++) {
			int temp2;
			cin >> temp2;
			a[temp - 1][temp2 - 1] = 1;
		}
	}

	bfs(0, n, a);

	return 0;
}



Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        while (true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0)
                break;
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}



Measured memory_bytes: 34688
A, B, C, K = map(int, input().split(' '))

arieru_max = 0
selected = 0

# 1の枚数がK以下
if A <= K:
    arieru_max += A
    selected += A

    if B <= (K - A):
        selected += B

        if C <= (K - A - B):
            arieru_max -= C
        else:
            arieru_max -= (K - A - B)

# 1の枚数がKを超える
else:
    arieru_max = K

print(arieru_max)


Measured memory_bytes: 9180
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		int a[];
		int friendA[];
		int friendB[];
		int count;

		n = sc.nextInt();
		m = sc.nextInt();
		while (n + m != 0) {
			a = new int[n];
			a[0] = 1;
			for (int i = 1; i < n; i++) {
				a[i] = 0;
			}
			friendA = new int[m];
			friendB = new int[m];
			for (int i = 0; i < m; i++) {
				friendA[i] = sc.nextInt();
				friendB[i] = sc.nextInt();
				if (friendA[i] == 1) {
					a[friendB[i] - 1] = 2;
				}
			}
			for (int i = 0; i < m; i++) {
				if (a[friendA[i] - 1] == 2 && a[friendB[i] - 1] == 0) {
					a[friendB[i] - 1] = 3;
				} else if (a[friendB[i] - 1] == 2 && a[friendA[i] - 1] == 0) {
					a[friendA[i] - 1] = 3;
				}
			}
			count = -1;
			for (int i = 0; i < n; i++) {
				if (a[i] != 0) {
					count++;
				}
			}
			System.out.println(count);
			n = sc.nextInt();
			m = sc.nextInt();
		}
	}
}

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

 using namespace std;

 int main() {
   int N;

   cin >> N;

   vector<string> W(N);

   for (int i = 0; i < N; i++) cin >> W.at(i);

   string ans = "Yes";

   for (int i = 0; i < N - 1; i++) {
     if (W.at(i).back() != W.at(i + 1).front()) {
       ans = "No";
       break;
     }
     for (int j = i + 1; j < N; j++) {
       if (W.at(i) == W.at(j)) {
         ans = "No";
         break;
       }
     }
     if (ans == "No") break;
   }

   cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by Sohail on 9/7/2019.
 */

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer x = sc.nextInt();
        Integer res = x*x*x;
        System.out.println(res);
    }
}



Measured memory_bytes: 21460
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * (3) for _ in range(n + 1)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[i][k])
                
ans = 0                
for i in range(3):
  ans = max(ans, dp[n][i])
print(ans)

Measured memory_bytes: 47344
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // write your code here
        //dream dreamer erase eraser
        int H;
        int W;
        String[] sList;
        try (Scanner sc = new Scanner(System.in)) {
            H = sc.nextInt();
            W = sc.nextInt();
            sList = new String[H];
            for (int i = 0; i < H; i++) {
                sList[i] = sc.next();
            }
        }
        long dp[][] = new long[H + 2][W + 2];

        for (int i = 1; i <= H; i++) {
            char[] c = sList[i - 1].toCharArray();
            for (int j = 1; j <= W; j++) {
                if (c[j - 1] == '#') {
                    //爆弾
                    dp[i][j] = Long.MIN_VALUE;
                } else {
                    //空きマス
                    dp[i][j] = 0;
                }
            }
        }

        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if (dp[i][j] < 0) {
                    //周りに足しこむ
                    addSurroundMass(dp, i, j);
                }
            }
        }

        for (int i = 1; i <= H; i++) {
            char[] c = sList[i - 1].toCharArray();
            for (int j = 1; j <= W; j++) {
                if (c[j - 1] == '#') {
                    System.out.print("#");
                } else {
                    //空きマス
                    System.out.print(dp[i][j]);
                }
            }
            System.out.println("");
        }
        return;
    }

    private static void addSurroundMass(long[][] dp, int i, int j) {
        dp[i - 1][j] += 1;
        dp[i - 1][j - 1] += 1;
        dp[i][j - 1] += 1;
        dp[i + 1][j - 1] += 1;
        dp[i + 1][j] += 1;
        dp[i + 1][j + 1] += 1;
        dp[i][j + 1] += 1;
        dp[i - 1][j + 1] += 1;
    }
}


Measured memory_bytes: 22740
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;


int main(){
  int N; cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
    a[i]--;
  }
  int num = 0;
  int count = 1;
  while(count < N){
    num = a[num];
    if(num == 1){
      cout << count << endl;
      return 0;
    }
    count++;
  }
  cout << -1 << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main()
{
	int n, m;
	while(~scanf("%d %d", &n, &m))
	{
		if(m%2==0)
			printf("%d\n", n+(m/2));
		else
			printf("%d\n", n+(m/2)+1);
	}
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());

            var answer = x - a;
            Console.WriteLine(answer % b);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w",stdout);
    #endif
    int n,k;
    cin>>n>>k;
    set<int> s;
    while(k--){
        int d;
        cin>>d;
        while(d--){
            int temp;
            cin>>temp;
            s.insert(temp);

        }
    }

    // cout<<"F: "<<s.size();

    cout<<( max(0, n -(int)s.size()) )<<endl;
}

Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef vector<vector<int>> Graph;
void add_edge(Graph& g, int from, int to, bool isDirected) {
	g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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

	ll n,m; cin >> n >> m;

	vector<ll> a(n), b(m);
	rep(i,n) cin >> a[i];
	rep(i,m) cin >> b[i];

	for(auto a : convolution(a,b)) cout << a << " "; cout << endl;
}




Measured memory_bytes: 27304
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL <class T = int> inline T IN() { T x; cin >> x; return x; }
TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }
TPL<TNM T> vector<T> make_v(size_t a) { return vector<T>(a); }
TPL<TNM T, TNM... Ts> auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }

TPL<TNM T> using vec2 = decltype(make_v<T>(0, 0));
TPL<TNM T> using vec3 = decltype(make_v<T>(0, 0, 0));
TPL<TNM T> using vec4 = decltype(make_v<T>(0, 0, 0, 0));
TPL<TNM T> using vec5 = decltype(make_v<T>(0, 0, 0, 0, 0));

int main(void) {
	ll N;
	cin >> N;
	vll A(N);
	REP(i, N)A[i] = IN();

	FOR(i, 1, N) {
		A[i] += A[i - 1];
	}

	umap<ll, ll> mp;
	REP(i, N) {
		mp[A[i]]++;
	}
	ll ans = 0;
	ans += mp[0];
	for (auto& m : mp) {
		if (m.second < 2)continue;
		ans += m.second* (m.second -1) / 2;
	}
	OUT(ans);
	return 0;
}

Measured memory_bytes: 10056
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

static class CodeJam
{
    static HashSet<long> Divisors(long n)
    {
        var divisors = new HashSet<long> { 1 };
        for (long i = 2; i * i <= n; ++i)
        {
            if (n % i == 0)
            {
                divisors.Add(i);
                while (n % i == 0) { n /= i; }
            }
        }
        if (n > 1) { divisors.Add(n); }
        return divisors;
    }

    static int Solve(long A, long B)
    {
        var d1 = Divisors(A);
        var d2 = Divisors(B);
        return Enumerable.Intersect(d1, d2).Count();
    }

    static void Main(string[] args)
    {
        var V = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        Console.WriteLine(Solve(V[0], V[1]));
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  cin >> n;
  int b[n - 1];
  for(int i = 0; i < n - 1; i++) cin >> b[i];

  int sum = b[0];
  for(int i = 1; i < n - 1; i++){
    sum += min(b[i - 1], b[i]);
  }
  sum += b[n - 2];

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) cout << ", "; else first = false; cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) {
  v = vector<T>(n, x);
}
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i];
}
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s, t;
vector<vector<lli>> dp;
int main() {
  cin >> s >> t;
  lli sn = s.size(), tn = t.size();
  dp = decltype(dp)(sn+1, vector<lli>(tn+1, 0));
  for (lli i=1; i<=sn; ++i) {
    char sc = s[i-1];
    for (lli j=1; j<=tn; ++j) {
      char tc = t[j-1];
      dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      if (tc == sc) dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
    }
  }
  string rs;
  lli i=sn, j=tn;
  while (dp[i][j] > 0) {
    for (; dp[i][j] == dp[i-1][j]; --i);
    for (; dp[i][j] == dp[i][j-1]; --j);
    rs.push_back(s[i-1]);
    --i; --j;
  }
  reverse(begin(rs), end(rs));
  cout << rs << endl;
  return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (int)1e9+7, M = (int)1e5+6;

int main(int argc, char const *argv[])
{
	string s;
	cin >> s;
	int a = 0;
	if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
		cout << 3;
	else if((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R'))
		cout << 2;
	else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
		cout << 1;
	else
		cout << 0;

	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(){
	int K,S;
	scanf("%d %d",&K,&S);

	int x,y,z;
	int xy,num=0;

	for(x=0;x<=K;x++){
		y=0;
		if(x>S)break;
		xy=S-x;
		for(y=0;y<=K;y++){
			if(y>xy)break;
			if(xy-y<=K)num++;
		}
	}
	printf("%d",num);
}

Measured memory_bytes: 128
import java.math.BigInteger;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		long sum = 0;
		long ans = 0;
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			sum += a[i];
		}
		for (int i = N - 1; i >= 0; i--) {
			sum -= a[i];
			BigInteger m = BigInteger.valueOf(a[i]);
			m = m.multiply(BigInteger.valueOf(sum));
			m = m.mod(BigInteger.valueOf(1_000_000_007));
			ans = (ans + m.longValue()) % 1_000_000_007;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 60732
import Foundation

class Scanner {
    static func readInt() -> Int {
        return Int(readLine()!)!
    }
    
    static func readIntArr() -> [Int] {
        return readLine()!.split(separator: " ").map { Int($0)! }
    }
    
    static func readM(_ n: Int) -> [[Int]] {
        var res = [[Int]]()
        for _ in 0..<n {
            res.append(readIntArr())
        }
        return res
    }
    
    static func readUknownIntMat() -> [[Int]] {
        var res = [[Int]]()
        while let line = readLine() {
            res.append(line.split(separator: " ").map { Int($0)! })
        }
        return res
    }
}

let n = Scanner.readInt()
var mat = Scanner.readM(n-1)

var colors = [Int](repeating: 0, count: n)


func solve(_ tree: [[Int]]) -> [Int] {
    var g = [Int: [Int]]()
    for n in tree {
        g[n[0]-1, default: [Int]()].append(n[1]-1)
        g[n[1]-1, default: [Int]()].append(n[0]-1)
    }
    var colors = [Int: [Int: Int]](),
    visited = [Bool](repeating: false, count: n), cols = [Int](repeating: 0, count: n-1)
    visited[0] = true
    
    var mx = 0
    dfs(g, 0, -1, &visited, &colors, &mx)
    
    for (i,n) in tree.enumerated() {
        let dir = colors[n[0]-1, default: [Int: Int]()][n[1]-1, default: 0]
        let rev = colors[n[1]-1, default: [Int: Int]()][n[0]-1, default: 0]
        cols[i] = dir == 0 ? rev : dir
    }
    
    return [mx] + cols
}



func dfs(_ g: [Int: [Int]],
         _ cur: Int,
         _ forbidden: Int,
         _ visited: inout [Bool],
         _ colors: inout [Int: [Int: Int]],
         _ mx: inout Int) {
    var cc = 0
    for c in g[cur, default: [Int]()] {
        guard !visited[c] else {
            continue
        }
        visited[c] = true
        if cc == forbidden {
            cc += 1
        }
        colors[cur, default: [Int: Int]()][c] = (cc+1)
        dfs(g, c, cc, &visited, &colors, &mx)
        cc += 1
    }
    
    mx = max(mx, cc)
}

let res = solve(mat)
for n in res {
    print(n)
}


Measured memory_bytes: 41596
#include <bits/stdc++.h>
using namespace std;
const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=2e5+50;
int n,a[N],nowmx;
inline unsigned int unit() {static unsigned int x=19260817; x^=(x<<13); x^=(x>>17); x^=(x<<5); return x;}
inline int Max(int x,int y) {return (x>y) ? x : y;}
struct node {
	node *lc,*rc;
	unsigned int pri;
	int val,sze,mx,all,tag; 
	node() : lc(NULL),rc(NULL),pri(unit()),sze(0),mx(0),all(1) {}
	inline void upt() {
		mx=Max(Max(rc->mx,lc->mx),val);
		sze=lc->sze+rc->sze+1;
		all=lc->all&rc->all&tag;
	}
} *rt,*nowrt,Pool[N],*pool=Pool,*null=pool;
typedef pair <node*,node*> pii;
inline node* merge(node *x,node *y) {
	if(y==null) return x;
	if(x==null) return y;
	if(x->pri>y->pri) {
		x->rc=merge(x->rc,y);
		x->upt(); return x;
	} else {
		y->lc=merge(x,y->lc);
		y->upt(); return y;
	}
}
inline pii split(node *x,int sze) {
	if(x==null) return pii(null,null);
	if(x->lc->sze>=sze) {
		pii tr=split(x->lc,sze);
		x->lc=tr.second; x->upt();
		return pii(tr.first,x);
	} else {
		pii tr=split(x->rc,sze-x->lc->sze-1);
		x->rc=tr.first; x->upt();
		return pii(x,tr.second);
	}
}
inline void Merge(node *&x,node *y) {
	if(y==null) {return;}
	if(x==null) {x=y; return;}
	node *t=x; while(t->rc!=null) t=t->rc;
	node *t2=y; static node* stk[N]; int top=0;
	while(t2->lc!=null) stk[++top]=t2, t2=t2->lc;
	t2->tag=(t2->val>t->val) ? 1 : 0; t2->upt();
	while(top) stk[top--]->upt();
	x=merge(x,y);
}
inline pii split_val(node *x,int lim) {
	if(x==null) return pii(null,null);
	if(Max(x->val,x->lc->mx)<lim) {
		pii tr=split_val(x->rc,lim);
		x->rc=tr.first; x->upt();
		return pii(x,tr.second); 
	} else {
		pii tr=split_val(x->lc,lim);
		x->lc=tr.second; x->upt();
		return pii(tr.first,x);
	}
}
inline pii split_all(node *x) {
	if(x==null) return pii(null,null);
	if(!(x->lc->all&x->tag)) {
		pii tr=split_all(x->lc);
		x->lc=tr.second; x->upt();
		return pii(tr.first,x); 
	} else {
		pii tr=split_all(x->rc);
		x->rc=tr.first; x->upt();
		return pii(x,tr.second);
	}
}
inline node* find_nxt(int lim) {
	pii tr=split_val(rt,lim);
	pii tr2=split_all(tr.second);
	Merge(nowrt,tr.first);
	rt=tr2.second; 
	return tr2.first;
}
inline node* newnode() {
	node *t=++pool;
	t->lc=t->rc=null;
	return t;
}
node* q[N]; int qt;
int main() {
	n=rd(); rt=null; nowmx=n;
	for(int i=1;i<=n;i++) a[i]=rd();
	for(int i=0;i<=n;i++) {
		node *t=newnode();
		t->val=a[i]; t->sze=1; t->mx=a[i];
		t->all=(i ? (a[i]>a[i-1]) : 1);
		t->tag=t->all; 
		rt=merge(rt,t);
	}
	int step=0;
	while(!rt->all) {
		++step;
		int mxval=1, pos=0;
		qt=0;
		nowrt=null;
		while(mxval<nowmx) 
			mxval=(q[++qt]=find_nxt(mxval))->mx;
		Merge(nowrt,rt); rt=nowrt;
		for(int i=1;i<=qt;i++) Merge(rt,q[i]);
		while(nowmx>3) {
			pii tr=split(rt,nowmx);
			if(tr.second->val==nowmx) rt=tr.first, --nowmx;
			else {rt=merge(tr.first,tr.second); break;}
		}
	}
	cout<<step<<'\n';
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  if(n%1000==0) cout << "0" << endl;
  else cout << 1000-n%1000 << endl;
  return 0;
}

Measured memory_bytes: 3636
import Control.Applicative ((<$>))
import Data.Char (isSpace)
import Data.List (foldl', unfoldr)
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

data Dice = Dice{
                    top    :: Int,
                    front  :: Int,
                    right  :: Int,
                    left   :: Int,
                    back   :: Int,
                    bottom :: Int
                }
                deriving (Show, Eq)

roll :: Dice -> Char -> Dice
roll (Dice top front right left back bottom) dir
    | dir == 'N' = Dice front bottom right left top back
    | dir == 'E' = Dice left front top bottom back right
    | dir == 'W' = Dice right front bottom top back left
    | dir == 'S' = Dice back top right left bottom front
    | otherwise  = Dice top front right left back bottom

rolls :: Dice -> String -> Dice
rolls d s = foldl' roll d s

getL :: (ByteString -> [Int]) -> IO [Int]
getL f = f <$> B.getLine

readIL :: (ByteString -> Maybe (Int, ByteString)) -> (ByteString -> [Int])
readIL f = unfoldr g
    where
        g s = do
            (n, s') <- f s
            return (n, B.dropWhile isSpace s')

main :: IO ()
main = do
    xs <- getL (readIL B.readInt)
    s  <- B.getLine
    print $ solve xs s

solve :: [Int] -> ByteString -> Int
solve xs s = top $ rolls (pasteNumToDice xs) (B.unpack s)

pasteNumToDice :: [Int] -> Dice
pasteNumToDice [a,b,c,d,e,f] = Dice a b c d e f


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    size_t k;
    string s, ss = "";
    cin >> k >> s;
    if(s.size() <= k){ cout << s << endl; return 0; }
    for(size_t i=0;i<k;++i) ss.push_back(s[i]);
    cout << ss << "..." << endl;
    return 0;
}

Measured memory_bytes: 3644
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int[] A = {nextInt(),nextInt(),nextInt()};

		Arrays.sort(A);




		System.out.println(A[1]-A[0]+A[2]-A[1]);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21332
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    stack<char> s;
    // do {

    //     s.push((n) % 26 + 'a' - 1);
    //     n /= 26;
    // } while (n > 0);

    while(n > 0)
    {
        n--;
        s.push((n) % 26 + 'a');
        n /= 26;
    }

    while (!s.empty())
    {
        cout << s.top();
        s.pop();
    }
    cout << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a, b;
    cin >> a >> b;
    vs ans(100, string(100, '#'));
    rep(i, 100)rep(j, 50){
        ans[i][j] = '.';
    }
    a--;
    b--;
    for(int i = 0; i < 100; i += 2){
        if(b == 0) break;
        for(int j = 0; j < 49; j += 2){
            if(b == 0) break;
            ans[i][j] = '#';
            b--;
        }
    }
    for(int i = 0; i < 100; i += 2){
        if(a == 0) break;
        for(int j = 51; j < 100; j += 2){
            if(a == 0) break;
            ans[i][j] = '.';
            a--;
        }
    }
    cout << "100 100" << endl;
    rep(i, 100) cout << ans[i] << endl;
    return 0;
}

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

int main(){

    int d,g;
    cin >> d >> g;
    vector<int> p(d),c(d);

    rep(i,d) cin >> p[i] >> c[i];

    int ans=1e+9;
    for(int b=0;b<(1<<d);b++){
        int s=0;
        int id=0;
        int tans=0;
        for(int i=0;i<d;i++){
            if(b>>i & 1){
                s+=p[i]*100*(i+1)+c[i];
                tans+=p[i];
            }else{
                id=i;
            }
        }
        int t=g-s;
        for(int i=0;i<p[id];i++){
            if(t<=(id+1)*100*i){
                tans+=i;
                t-=(id+1)*100*i;
                break;
            }
        }
        if(t<=0){
            ans=min(ans,tans);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int h, w;
  string s[50];
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (s[y][x] == '#') {
        continue;
      }
      if (s[y][x] == '.') {
        s[y][x] = '0';
      }

      // y=-1
      if (y > 0 && x > 0 && s[y - 1][x - 1] == '#') {
        s[y][x]++;
      }
      if (y > 0 && s[y - 1][x] == '#') {
        s[y][x]++;
      }
      if (y > 0 && x < w && s[y - 1][x + 1] == '#') {
        s[y][x]++;
      }

      // y=0
      if (x > 0 && s[y][x - 1] == '#') {
        s[y][x]++;
      }
      if (x < w && s[y][x + 1] == '#') {
        s[y][x]++;
      }

      // y=1
      if (y < h && x > 0 && s[y + 1][x - 1] == '#') {
        s[y][x]++;
      }
      if (y < h && s[y + 1][x] == '#') {
        s[y][x]++;
      }
      if (y < h && x < w && s[y + 1][x + 1] == '#') {
        s[y][x]++;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << s[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3072
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int N = 1e5+10;

//head

int n, m, q;
int num[N];
int col[N];
int v[N], d[N], c[N];
vi G[N];
void dfs(int v, int d, int c) {
  if(num[v] >= d) return;
  if(col[v] == 0) col[v] = c;
  num[v] = d;
  if(d) for(int x:G[v]) {
    dfs(x, d-1, c);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  memset(num, -1, sizeof(num));
  cin >> q;
  rep(i, q) cin >> v[i] >> d[i] >> c[i];
  for(int i = q-1; i >= 0; i--) {
    dfs(v[i]-1, d[i], c[i]);
  }
  rep(i, n) cout << col[i] << '\n';
}

Measured memory_bytes: 11044
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define INF 1000000000

int main()
{ 
	int t,n,i,x;
	cin >> n >> x >> t;

	if(n%x==0)
		cout << t*(n/x) << endl;
	else
		cout << t*(n/x) + t << endl;
	return 0;
}




Measured memory_bytes: 3544
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 n, a, b;
    std::cin >> n >> a >> b;
    i64 c = n % (a + b);
    std::cout << n / (a + b) * a + std::min(a, n % (a + b)) << std::endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
 		int m = N/2;
      	int i = N%2;
      if(i==0){

    System.out.println(m);
      }else{
    System.out.println(m + 1);
      }
      }
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<int,ii> iii;
typedef pair<int, iii> iiii;
typedef pair<double, ii> dii;
typedef long long ll;
typedef pair<ll, ii> lii;
const int INF = 1000000000;
const double EPS = 1e-9;
#define LSOne(S) (S & (-S))
int mods(int a, int b) { return (b + (a%b)) % b; }

int n, d, ans, dist, sq, x[15][15];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    cin >> n >> d;

    for (int i = 0; i < n; i++)
        for (int j = 0; j < d; j++)
            cin >> x[i][j];

    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            dist = 0;
            for (int k = 0; k < d; k++)
                dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);

            sq = sqrt(dist);
            if (sq * sq == dist) ans++;
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define along long(c) (c).begin(), (c).end()
#define rep(i,a,b) for(long long i=(a);i<(b);++i)
#define per(i,a,b) for(long long i=b-1long long;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[100][2];

int main() {
	clr(dp,0);
	ll n,p;
	cin>>n>>p;
	vector<ll> v;
	rep(i,0,n){
		ll a;
		cin>>a;
		v.pb(a);
	}
	clr(dp,0);
	dp[0][0] = 1;
	rep(i,1,v.sz+1){
		ll a = v[i-1];
		dp[i][0] = dp[i-1][0];
		dp[i][1] = dp[i-1][1];
		if(a%2==0){
			dp[i][0] += dp[i-1][0];
			dp[i][1] += dp[i-1][1];
		}
		else{
			dp[i][1] += dp[i-1][0];
			dp[i][0] += dp[i-1][1];
		}
	}
	printf("%lld\n", dp[v.sz][p]);
	return 0;
}

Measured memory_bytes: 256