akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<iomanip>

#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define MOD 1000000007

using namespace std;
using ll=long long int;

int main(){
    int N;
    cin >> N;
    int n_k = N;
    int s=0;
    while(N!=0){
        s+=N%10;
        N/=10;
    }
    if(n_k%s==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define modulo 1000000007
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main(){
	fast_io;
	ll n;
	cin>>n;
	ll a[n];
	ll dp[n]={0};
	for (int i = 0; i < n; ++i){
		cin>>a[i];
	}
	dp[1]=abs(a[1]-a[0]);
	for (int i = 2; i < n+1; ++i){
		dp[i]=min(dp[i-2]+abs(a[i-2]-a[i]),dp[i-1]+abs(a[i-1]-a[i]));
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>


void swap(int *x, int *y)
{
  int tmp;

  tmp = *x;
  *x = *y;
  *y = tmp;
 
}


void insertionSort(int *A, int N)
{
  int i,j;
  int v;
  for(i=1; i<N; i++) {
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;

    for(j=0; j<N-1; j++)
      printf("%d ", A[j]);
    printf("%d\n", A[N-1]);
  }
}


int main(void)
{
  int A[100], N, i;
  
  scanf("%d",&N);
  for(i=0;i<N;i++) {
    scanf("%d", &A[i]);//配列読み込み
  }    

  for(i=0; i<N-1; i++)
    printf("%d ", A[i]);
  printf("%d\n", A[N-1]);

  insertionSort(A, N);

  return 0;
}

  



Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <list>
#include <numeric>
#include <math.h>
#include <cstdlib>
#include <queue>
#include <iterator>
#include <limits>
#include <string>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <stack>
#include <memory>
#include <deque>
#include <string_view>
#include <random>
#include <chrono>
#include <cstring>

using namespace std;

static int my_speed_up = []() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }();
using ll = long long; using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T> using vv = vector<vector<T>>;
template<class T> using vvv = vector<vector<vector<T>>>;
template<class T> using vvvv = vector<vector<vector<vector<T>>>>;
#define for_b(i, b) for (int i = 0; i < ll(b); ++i)
#define for_ab(i, a, b) for (int i = a; i < ll(b); ++i)
#define what_is(x) cout << #x << " = " << x << endl;
#define what_are(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl;
#define pad(x) for_b(i, x) cout << "  ";
#define show_1d(___x) cout << #___x << " = "; for (auto& ___num : ___x) cout << ___num << ", "; cout << endl;
#define show_2d(___x) cout << #___x << endl; for (auto& ___row : ___x) { for (auto ___num : ___row) cout << ___num << ", "; cout << endl; }
#define show_3d(___x) cout << #___x << endl; for (auto& ___row : ___x) { for (auto& ___row2 : ___row) { for (auto ___num : ___row2) cout << ___num << ", "; cout << endl; }cout << endl; }


int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    
    x = abs(x);
    
    ll cnt =  x / d;
    
    if (cnt > k)
    {
        ll res = x - (k * d);
        cout << res << endl;
    }
    else
    {
        ll res = x - (cnt * d);
        k -= cnt;
        if (k % 2 == 0)
            cout << res << endl;
        else
            cout << abs(res - d) << endl;
    }
        
    return 0;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
	char S[5];
	while(scanf("%s",S)) {
		if(strcmp(S,"0000")==0) break;
		int ans=0;
		bool NG=0;
		while(strcmp(S,"6174")) {
			sort(S,S+4);
			NG=1;
			for(int i=0;i<3;i++) {
				if(S[i]!=S[i+1]) NG=0;
			}
			if(NG) break;
			int a=0,b=0,c=1;
			for(int i=0;i<4;i++) {
				a+=(S[i]-'0')*c;
				b+=(S[3-i]-'0')*c;
				c*=10;
			}
			int k=a-b;
			for(int i=3;i>=0;i--) {
				S[i]=(k%10+'0');
				k/=10;
			}
			ans++;
		}
		if(NG) printf("NA\n"); else printf("%d\n",ans);
	}
}

Measured memory_bytes: 996
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while (true) {
    N /= K;
    ans++;
    if (N==0) break;
  }

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

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp

#include <iostream>
#include <algorithm>
using namespace std;
//int n,counter = 0;
//int a[n];

int main(){
  int n,counter = 0;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  bool flag = true;
  while(flag){
    flag = false;
    for(int i=n-1; i>0; i--){
      if(a[i] < a[i-1]){
        swap(a[i], a[i-1]);
        counter++;
        flag = true;
      }
    }
  }
    for(int i=0; i<n-1; i++){
    cout  << a[i] << " ";
  }
  cout << a[n-1] << endl;
  cout << counter << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e10;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double



////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,x;
signed main(){
  cin>>n>>x;
  if(x == 1 || x == 2*n-1){
    cout << "No" << endl;return 0;
  }
  cout << "Yes" << endl;
  if(n == 2){
    cout << 1 << endl << 2 << endl << 3 << endl;return 0;
  }
  queue<int> que;
  repd(i,1,2*n)if(!(x != 2 && x-2 <= i && i <= x+1) && !(x == 2 && 1 <= i && i <= 4))que.push(i);
  if(x != 2){
    int ind = 1;
    repd(i,1,2*n){
      if(n-1 <= i && i <= n+2){
        cout << x-2 << endl << x+1 << endl << x << endl << x-1 << endl;
        i += 3;
      }else{
        cout << que.front() << endl;que.pop();
      }
    }
  }if(x == 2){
    int ind = 1;
    repd(i,1,2*n){
      if(n-1 <= i && i <= n+2){
        cout << 3 << endl << 1 << endl << 2 << endl << 4 << endl;
        i += 3;
      }else{
        cout << que.front() << endl;que.pop();
      }
    }
  }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    int e;
    cin >> e;
    if (i > 0) d[i] = d[i-1]+e;
    else d[i] = e;
  }
  
  set<int> s;
  s.insert(d[K-1]);
  for (int i = 0; i < N-K; i++) {
    s.insert(d[i+K]-d[i]);
  }
  
  int pos = *rbegin(s);
  cout << (pos+K)/2;
  if ((pos+K)%2 != 0) cout << ".5";
  cout << endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long N,M;
    cin >> N >> M;
    if (N >= M/2){
        cout << M/2 << endl;
        return 0;
    }
    else {
        cout << N + (M-N*2)/4 << endl;
    }
}

Measured memory_bytes: 3636
a,b,c,d,s,x,y;main(n){for(scanf("%d",&n);d<n;){
scanf("%d",&x);
if(x==y)a=b,b=c,c=d;
else y=x;
if(s<++d-a)s=d-a;
}s=!printf("%d\n",s);}

Measured memory_bytes: 600
N=int(input())
a_list=list(map(int,input().split()))
a_list.sort(reverse=True)
Asum=0
Bsum=0
for i in range(N):
    if i%2==0:
        Asum+=a_list[i]
    else:
        Bsum+=a_list[i]
print(Asum-Bsum)

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

int main() {
  for(int i = 1; i <= 9; ++i) {
    for(int j = 1; j <= 9; ++j) {
      cout << i << "x" << j << "=" << i*j << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

long long n;

long long f(int d)
{
  long long t = n;
  long long r = 0;
  long long c = 10;
  int b = 1;
  while (d) {
    if (d & b) {
      r += t % c;
      t /= c;
      d /= b*2;
      c = 10;
      b = 1;
    } else {
      c *= 10;
      b *= 2;
    }
  }
  r += t;
  return r;
}

int main()
{
  double dn;
  scanf("%lf",&dn);
//  printf("%lf\n",dn);
  n = (long long)dn;
//  printf("%lld\n",n);
  
  //桁数取得
  int d = 1;
  if (n!=0) {
    long long t = n;
    for ( ; t >= 10 ; d++ )
      t /= 10;
  }
//  printf("digit=%d\n",d);

  // pow(2,桁-1)
  int x = 1;
  for ( int i = 0 ; i < d-1 ; i++ )
    x*= 2;
//  printf("max=%d\n",x);

  long long a = n;
  for ( int i = 1 ; i < x ; i++ )
    a += f(i);

  printf("%lld\n",a);

}


Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli N;
	cin >> N;
	lli ans = 0;
	for (int i = 1; i <= N; i++) {
		if ((int)log10(i) % 2 == 0)
			ans++;
	}

	COUT(ans);


	return 0;
}

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

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var n = vals[0];
        var a = vals[1];
        var b = vals[2];

        var max = Math.Min(a, b);
        var min = Math.Max(0, a + b - n);

        Console.WriteLine($"{max} {min}");
    }
}

Measured memory_bytes: 13396
#include <stdio.h>

int main(void){
    int a, b, d, r;
    double f;
    scanf("%d %d",&a,&b);
    d = a/b;
    r = a%b;
    f = (double)a/b;
    printf("%d %d %f\n", d, r, f);
    return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n, T;
    cin >> n >> T;
    
    int ans = -1;
    
    for (int i = 0; i < n; ++i) {
        int c, t;
        cin >> c >> t;
        
        if (t <= T) {
            if (ans == -1 || ans > c) {
                ans = c;
            }
        }
    }
    
    if (ans == -1) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N, T;
    cin >> N >> T;
    int ans = INT_MAX;
    for (int i = 0; i < N; i++) {
        int c, t;
        cin >> c >> t;
        if (t <= T) {
            ans = min(c, ans);
        }
    }
    if (ans == INT_MAX) {
        puts("TLE");
    }
    else {
        cout << ans << endl;
    }
}

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

//freopen("file_name.in", "r", stdin);
//freopen("file_name.out", "w", stdout);

#define fr(i,n) for(int i=0;i<n;i++)
#define frr(i,a,b) for(int i =a;i<=b;i++)

typedef long long ll;

#define eb emplace_back

#define all(v) (v).begin(),(v).end()

#define fi first
#define se second
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

//-DBL_MAX
//__builtin_popcountll(ll x) - __builtin_popcount(int x)

#define prin(a) cout << #a << " = " << (a) << endl
#define prinv(v) {cout << #v << " = "; for(auto it : v) cout << it << " "; cout << endl;}
#define ppal(a)  cout << #a << endl

const int N = 1e5+10;

ll dp[N];
ll h[N];

int main(){
    ll n;
    cin >> n;
    fr(i,n) scanf("%lld", h+i);
    
    for(int i = n-2;i>=0;i--){
        ll &ans = dp[i];
        ans = abs(h[i]-h[i+1])+dp[i+1];
        if(i+2<n) ans = min(ans,abs(h[i]-h[i+2])+dp[i+2]);
    }   
    
    cout << dp[0] << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int a,b,c,s1,s2,s3;
    scanf("%d%d%d",&a,&b,&c);
    s1=a+b;
    s2=a+c;
    s3=b+c;
    if(s1<=s2&&s1<=s3)
        printf("%d\n",s1);
    else if(s2<=s1&&s2<=s3)
        printf("%d\n",s2);
    else if(s3<=s1&&s3<=s2)
        printf("%d\n",s3);
    return 0;
}

Measured memory_bytes: 1696
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;

int N;
string S;
int W[300002], E[300002];

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

    rep(i,N){
        if(S[i]=='W') W[i+1]++;
        else E[i+1]++;
        W[i+2]=W[i+1];
        E[i+2]=E[i+1];
    }

    int ans=1001001001;
    rep(i,N){
        int x=(W[i])+(E[N+1]-E[i+1]);
        ans=min(ans,x);
    }

    cout<<ans<<endl;
}

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

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())

using namespace std;

typedef long long ll;
int n, e, t;
ll x[100005];
ll f[100005];
ll mf[100005];

int main() {
    scanf("%d %d %d", &n, &e, &t);
    FO(i,0,n) scanf("%lld", x+i);
    x[n] = e;

    f[n] = 0;
    mf[n] = 1ll<<60;
    for (int i = n-1; i >= 0; i--) {
        f[i] = 1ll<<60;
        int s = i, _e = n-1, b = i;
        while (s <= _e) {
            int m = (s+_e)/2;
            if (2*(x[m]-x[i]) <= t) {
                b = m;
                s = m+1;
            } else {
                _e = m-1;
            }
        }
        f[i] = min(f[i], f[b+1] + t+x[b+1]-x[i]);
        f[i] = min(f[i], mf[b+1] - 3*x[i]);
        mf[i] = min(mf[i+1], f[i+1] + 2*x[i]+x[i+1]);
    }
    printf("%lld\n", x[0]+f[0]);
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

struct Doubling{
    const int ub_log;               // 要素数の二進表記の桁数
    vector<vector<int>> table;      // ダブリングテーブル

    Doubling(int sz, int64_t limit) : ub_log(64 - __builtin_clzll(limit)){
        table.assign(ub_log, vector<int>(sz, -1));
    }

    // k 番目の要素から 1(=2^0) 個先の要素をテーブルに埋める
    void set_next(int k, int x){
        table[0][k] = x;
    }

    // ダブリングテーブルの構築
    void build(){
        for(int k = 0; k + 1 < ub_log; ++k){
            for(int i = 0; i < table[k].size(); ++i){
                if(table[k][i] == -1)   table[k+1][i] = -1;
                else    table[k+1][i] = table[k][table[k][i]];
            }
        }
    }

    // k 番目から t 個先の要素を返す
    int query(int k, int64_t t){
        for(int i = ub_log - 1; i >= 0; --i){
            if((t >> i) & 1)    k = table[i][k];
        }
        return k;
    }
};

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

    int n;
    ll k;
    cin >> n >> k;
    Doubling table(n, k + 1);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        --a;
        table.set_next(i, a);
    }
    table.build();
    int ans = table.query(0, k) + 1;
    cout << ans << endl;
}

Measured memory_bytes: 50896
import java.util.*;

public class Main {

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long a[];
		a = new long[n];
		long sum = 0;
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sc.next());
			sum += a[i];
		}

		long sum1 = 0;
		long sum2 = sum;
		long result = Math.abs(a[0] - (sum - a[0]));
		for (int i = 0; i < n - 1; i++) {
			sum1 += a[i];
			sum2 -= a[i];
			if (Math.abs(sum1 - sum2) < result) {
				result = Math.abs(sum1 - sum2);
			}
		}

		System.out.println(result);

	}
}


Measured memory_bytes: 60844
#include <iostream>
using namespace std;

int W, H, N;
int X[110], Y[110], A[110];
int AREA[110][110] = {0};

int main() {
    cin >> W >> H >> N;
    for (int i = 0; i < N; ++i) cin >> X[i] >> Y[i] >> A[i];

    for (int i = 0; i < N; ++i) {

        if (A[i] == 1) {
            for (int j = 0; j < X[i]; ++j) {
                for (int k = 0; k < H; ++k) {
                    AREA[j][k] = 1;
                }
            }
        }

        if (A[i] == 2) {
            for (int j = X[i]; j < W; ++j) {
                for (int k = 0; k < H; ++k) {
                    AREA[j][k] = 1;
                }
            }
        }

        if (A[i] == 3) {
            for (int j = 0; j < W; ++j) {
                for (int k = 0; k < Y[i]; ++k) {
                    AREA[j][k] = 1;
                }
            }
        }

        if (A[i] == 4) {
            for (int j = 0; j < W; ++j) {
                for (int k = Y[i]; k < H; ++k) {
                    AREA[j][k] = 1;
                }
            }
        }
    }

    int count = 0;
    for (int i = 0; i < W; ++i) {
        for (int j = 0; j < H; ++j) {
            if (AREA[i][j] == 0) ++count;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
typedef long long ll;
char S[200000];
ll c(ll n,ll a){
    ll ans=1;
    for(ll i=1;i<=a;i++)
        ans *= (n+1-i);
    for(ll i=1;i<=a;i++)
        ans /= i;
    return ans;
}

int main(){
    scanf("%s",S);
    ll length = strlen(S);
    ll keep_mod[200000] = {0};
    ll l_ans = 0,keep=0,keep_tenmod = 1;
    for(ll i=length-1;i>=0;i--){
        keep += (S[i]-'0')*keep_tenmod;
        keep %= 2019;
        keep_tenmod *= 10;
        keep_tenmod %= 2019;
        keep_mod[keep]++;
    } 
    ll ans = keep_mod[0];
    for(ll i=0;i<2019;i++)
        if(keep_mod[i] >= 2) ans += c(keep_mod[i],2);
    printf("%lld",ans);
}



Measured memory_bytes: 3440
let rec floor_sqrt acc acc_x_2_x_r sq_acc_minus_z r sq_r =
  if r = 0 then acc
  else
    let sq_acc_minus_z' = sq_acc_minus_z + acc_x_2_x_r + sq_r in
    ( if sq_acc_minus_z' <= 0 then
        floor_sqrt (acc + r) ((acc_x_2_x_r lsr 1) + sq_r) sq_acc_minus_z'
      else
        floor_sqrt acc (acc_x_2_x_r lsr 1) sq_acc_minus_z) (r lsr 1) (sq_r lsr 2)
let floor_sqrt z = floor_sqrt 0 0 (~-z) (1 lsl 30) (1 lsl 60)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let vs = Array.make n 0 in
  let ws = Array.make n 0 in
  for i = 0 to n - 1 do
    Scanf.scanf "%d %d\n" @@ fun v w ->
      vs.(i) <- v;
      ws.(i) <- w
  done;
  Scanf.scanf "%d\n" @@ fun q ->
    let vls = Array.init q @@ fun _ -> Scanf.scanf "%d %d\n" @@ fun v l -> v, l in
    let maxl = Array.fold_right (fun (_, l) -> max l) vls min_int in
    let n' = min n ((1 lsl 10) - 1) in
    let dp = Bigarray.Array2.create Bigarray.int Bigarray.c_layout (n' + 1) (maxl + 1) in
    Bigarray.Array2.fill (Bigarray.Array2.sub_left dp 0 1) 0;
    for i = 1 to n' do
      let v = Array.unsafe_get vs (i - 1) in
      let w = Array.unsafe_get ws (i - 1) in
      Bigarray.Array2.blit
        (Bigarray.Array2.sub_left dp (i lsr 1) 1)
        (Bigarray.Array2.sub_left dp i 1);
      for j = w to maxl do
        let d = Bigarray.Array2.unsafe_get dp (i lsr 1) j in
        let d' = v + Bigarray.Array2.unsafe_get dp (i lsr 1) (j - w) in
        if d < d' then Bigarray.Array2.unsafe_set dp i j d'
      done
    done;
    let rec solve l i s m =
      if l < 0
      then m
      else if i <= n'
      then max m (s + Bigarray.Array2.unsafe_get dp i l)
      else solve l (i lsr 1) s @@ solve (l - Array.unsafe_get ws (i - 1)) (i lsr 1) (s + Array.unsafe_get vs (i - 1)) m in
    Array.iter (fun (v, l) -> Printf.printf "%d\n" @@ solve l v 0 min_int) vls



Measured memory_bytes: 814100
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int n, m, h, d;

int amida(vector<string> t) {
	int now = m;
	rep(i, 0, d) {
		if (t[i][now] == '1') now++;
		else if (now >= 1 && t[i][now - 1]=='1') now--;
	}
	return now;
}

signed main(){
	while (cin >> n && n) {
		cin >> m >> h >> d;
		m--; h--;
		vector<string> s(d+10), t(d+10);
		rep(i, 0, d) {
			cin >> s[i];
		}
		bool f = false;
		if (amida(s) == h) {
			cout << 0 << endl;
			f = true;
		}
		else {
			rep(i, 0, d) {
				rep(j, 0, n - 1) {
					t = s;
					if (t[i][j] == '0') {
						if (j != 0 && t[i][j - 1] == '1') continue;
						if (j != n - 2 && t[i][j + 1] == '1') continue;
						t[i][j] = '1';
						if (amida(t) == h) {
							f = true;
							cout << i + 1 << " " << j + 1 << endl;
						}
					}
					if (f) i = d + 1;
				}
			}
		}
		if (!f) cout << 1 << endl;
	}
}

Measured memory_bytes: 1224
#include <iostream>

using namespace std;

int main() {
    int p, q, r;
    cin >> p >> q >> r;
    if(p>=q && p>=r) cout << q+r << endl;
    else if(q>=p && q>=r) cout << p+r << endl;
    else if(r>=p && r>=q) cout << p+q << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c; cin >> a >> b >> c;
  int fa = a, fb = b, fc = c;
  int res = 0;
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    int ha = a / 2;
    int hb = b / 2;
    int hc = c / 2;
    a = hb + hc;
    b = ha + hc;
    c = ha + hb;
    if (a == fa && b == fb && c == fc) {
      cout << -1 << endl;
      return 0;
    }
    res++;
  }
  cout << res << endl;
}

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

int main() {
    int N, Y; cin >> N >> Y;
    int res10k = -1, res5k = -1, res1k = -1;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; i+j <= N; j++) {
            int k = N - i - j;
            int total = 10000*i + 5000*j + 1000*k;
            if (total == Y) {
                res10k = i;
                res5k = j;
                res1k = k;
            }
        }
    }
    cout << res10k << " " << res5k << " " << res1k << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0, i_length = (n); i < i_length; i++)
#define MOD 1000000007

int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> a;
	rep(i, n) {
		int x;
		cin >> x;
		a.push_back(make_pair(x, i));
	}

	sort(a.begin(), a.end());

	rep(i, n) {
		if (i == 0) cout << a[i].second + 1;
		else cout << " " << a[i].second + 1;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1780
#include<iostream>
#include<vector>

using namespace std;
int main(){
  int N,M,C;
  cin>>N>>M>>C;
  int *b=new int[M];
  for(int i=0;i<M;i++){
    cin>>b[i];
  }
  vector<vector<int>> a;
  a.resize(N);
  for(int i=0;i<N;i++){
    a[i].resize(M);
    for(int j=0;j<M;j++){
      cin>>a[i][j];
    }
  }
  int count=0;
  for(int i=0;i<N;i++){
    int sum=C;
    for(int j=0;j<M;j++){
      sum+=a[i][j]*b[j];
    }
    if(sum>0)count++;
  }
  cout<<count;
  return 0;
}
  

Measured memory_bytes: 256
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TypeApplications #-}
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import qualified Data.Char as C
import qualified Data.List as L

main :: IO ()
main = readInts >>= output . solve

-- solve :: [Int] -> _
-- solve [x] = fst $ until ((x'<=).snd) (\(n,v) -> (n+1, fromIntegral @Int @Double . floor . (*rate) $ v)) (0, 100.0)
--   where
--     x' = fromIntegral @Int @Double x
--     rate = 1.01 :: Double

solve :: [Int] -> _
solve [x] = fst $ until ((toDouble x <=) . snd) (fork (+1) (toDouble . floor . (*1.01))) (0, 100.0)
  where
    fork f g (v,w) = (f v, g w)
    toDouble = fromIntegral @Int @Double

output :: _ -> IO ()
output = print

-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define mk make_pair
#define ll long long
using namespace std;
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
int n, x, y, m, a[N];
bitset<20000> B;
char s[N]; 
int main() {
	scanf("%s", s + 1);
	m = strlen(s + 1);
	cin >> x >> y;
	B.reset();
	B[10000] = 1;
	n = 1;
	for (int i = 1; i <= m; i++) {
		if (s[i] == 'T') n++;
		else a[n]++;
	}
	//for (int i = 1; i <= n; i++) cout << a[i] << " "; 
	for (int i = 1; i <= n; i += 2) {
		if (i == 1) B = B << a[i];
		else B = (B << a[i]) | (B >> a[i]);
	} 
	if (B[10000 + x] == 0) {
		puts("No");
		return 0;
	}
	B.reset();
	B[10000] = 1;
	for (int i = 2; i <= n; i += 2) {
		B = (B << a[i]) | (B >> a[i]);
	} 
	if (B[10000 + y] == 0) {
		puts("No");
		return 0;
	}
	puts("Yes");
}

Measured memory_bytes: 256
def resolve():
    N, H = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for i in range(N):
        a, b = map(int, input().split())
        A[i] = a
        B[i] = b
    a_max = max(A)

    # a_maxより高い攻撃力を選択(a_maxは何回でも行えるのでそれより低いものは選択しない)
    B = [b for b in B if a_max < b]
    B.sort(reverse=True)

    cnt = 0
    for b in B:
        if H <= 0:
            print(cnt)
            return
        H -= b
        cnt += 1

    cnt += -(-H // a_max)
    print(cnt)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 17624
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main implements Runnable {
	public static void main(String[] args) {
		// long t = System.currentTimeMillis();
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start();
		// System.err.println(System.currentTimeMillis() - t);
	}

	public void run() {
		// 和xで余り0を構成できるか

		Scanner sc = new Scanner();
		int K = sc.nextInt();
		solve(K);
	}

	void solve(int K) {
		int[] f = new int[K];
		Arrays.fill(f, Integer.MAX_VALUE / 3);
		ArrayDeque<Integer> que = new ArrayDeque<>();
		f[1] = 1;
		f[10 % K] = 1;
		que.add(1);
		que.add(10 % K);
		while (!que.isEmpty()) {
			int v = que.poll();
			if (f[10 * v % K] > f[v]) {
				f[10 * v % K] = f[v];
				que.addFirst(10 * v % K);
			}
			if (f[(v + 1) % K] > f[v] + 1) {
				f[(v + 1) % K] = f[v] + 1;
				que.addLast((v + 1) % K);
			}
		}
		System.out.println(f[0]);
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

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

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 27604
package main

import "fmt"

func main() {
	var n, m, h, a, b int
	fmt.Scan(&n, &m)
	type vertex struct {
		h     int
		edges []int
	}
	vertexes := []vertex{}
	for i := 0; i < n; i++ {
		fmt.Scan(&h)
		var v vertex
		v.h = h
		vertexes = append(vertexes, vertex(v))
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&a, &b)
		vertexes[a-1].edges = append(vertexes[a-1].edges, b-1)
		vertexes[b-1].edges = append(vertexes[b-1].edges, a-1)
	}
	count := 0
	for _, vertex := range vertexes {
		highest := true
		for i := 0; i < len(vertex.edges); i++ {
			if vertex.h <= vertexes[vertex.edges[i]].h {
				highest = false
			}
		}
		if highest {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 14760
n = int(input())
li = list(map(int,input().split()))
li.sort(reverse = True)

a,b = 0,0
i = 0
while i<=len(li)-2:
    if li[i] == li[i+1] and a == 0:
        a = li[i]
        i += 2
    elif li[i] == li[i+1]  and a != 0:
        b = li[i]
        break
    elif li[i] != li[i+1]:
        i += 1
print(a*b)

Measured memory_bytes: 14244
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    int a ,b ,c;
    cin >> a >> b >> c;
    
    vector<int> vect{a,b,c};
    sort(vect.begin(), vect.end());
    
    int count = 0;
    for (int i: vect)
    {
        cout << i;
        if (count++ != 2)
        {
            cout << ' ';
        } 
        else
        {
            cout << '\n';
        }
    }
    
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

vvl G(1010);
vl x(1010);

P dfs(ll u, ll p){
    P res = {0,inf};
    vvl dp(2, vl(x[u]+1,linf));
    dp[0][0] = 0;
    for(auto v : G[u]){
        if(v == p) continue;
        P df = dfs(v,u);
        if(df.first == -1) return {-1,-1};
        rep(i,x[u]+1){
            if(i+df.first <= x[u]) chmin(dp[1][i+df.first], dp[0][i]+df.second);
            if(i+df.second <= x[u]) chmin(dp[1][i+df.second], dp[0][i]+df.first);
        }
        swap(dp[1],dp[0]);
        fill(all(dp[1]), linf);
    }
    res.first = x[u];
    rep(i,x[u]+1) chmin(res.second, dp[0][i]);
    if(res.second == inf) return {-1,-1};
    return res;
}

int main(){
    ll n; cin >> n;
    rep(i,n-1){
        ll p; cin >> p; p--;
        G[p].push_back(i+1);
        G[i+1].push_back(p);
    }
    rep(i,n) cin >> x[i];
    if(dfs(0,-1).first == -1) puts("IMPOSSIBLE");
    else puts("POSSIBLE");
}

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

int n, m, f[105][105];
char a[105][105];

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i)
		scanf("%s", a[i]);
	memset(f, 0x3f, sizeof(f));
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j < m; ++j)
		{
			if (i == 1 && j == 0) f[i][j] = (a[i][j] == '#' ? 1 : 0);
			else if (a[i][j] == '#')
			{
				if (i > 1) f[i][j] = std::min(f[i][j], f[i - 1][j] + (a[i - 1][j] == '#' ? 0 : 1));
				if (j > 0) f[i][j] = std::min(f[i][j], f[i][j - 1] + (a[i][j - 1] == '#' ? 0 : 1));
			}
			else
			{
				if (i > 1) f[i][j] = std::min(f[i][j], f[i - 1][j]);
				if (j > 0) f[i][j] = std::min(f[i][j], f[i][j - 1]);
			}
		}
	//for (int i = 1; i <= n; ++i, printf("\n"))
	//	for (int j = 0; j < m; ++j) printf("%d ", f[i][j]);
	printf("%d\n", f[n][m - 1]);
	return 0;
}

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

int main(void) {
    int N;

    cin >> N;

    vector<char> S(N);
    bool four = false;

    for (int i = 0; i < N; i++) {
        cin >> S[i];
        if (S[i] == 'Y') four = true;
    }

    if (four) cout << "Four" << endl;
    else cout << "Three" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

class UnionFind{
public:
    vector<ll> par,num;

    int find(ll v){
        return (par[v]==v)? v: (par[v]=find(par[v]));
    }
    explicit UnionFind(ll N):par(N),num(N,1){
        iota(par.begin(),par.end(),0);
    }
    void unite(ll u,ll v){
        u=find(u),v=find(v);
        if(u==v)return ;
        if(num[u]<num[v])swap(u,v);
        num[u] += num[v];
        par[v] = u;
    }
    bool same(ll u,ll v){
        return find(u) == find(v);
    }
    bool ispar(ll v){
        return v=find(v);
    }
    ll size(ll v){
        return num[find(v)];
    }
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    V<ll> a(m),b(m);
    UnionFind G(n);
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
    }
    ll sum=n*(n-1)/2;
    V<ll> ans;
    for(ll i=m-1;i>=0;i--){
        ans.push_back(sum);
        if(G.find(a[i])==G.find(b[i])){
            G.unite(a[i],b[i]);
        }else{
            sum-=G.size(a[i])*G.size(b[i]);
            G.unite(a[i],b[i]);
        }
    }
    reverse(all(ans));
    for(ll cur:ans) cout<<cur<<'\n';
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

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

using namespace std;

const int MAX_N = 100000, INDEX = 1;

int n, a[MAX_N + 1 + INDEX];
long long ps[MAX_N + INDEX];

bool canAbsorb[MAX_N + 1 + INDEX];

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

    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    a[n + 1] = 0;

    sort(a + INDEX, a + INDEX + n, less<int>());

    ps[0] = 0;
    for (int i = 1; i <= n; i++) {
        ps[i] = ps[i - 1] + a[i];
    }

    canAbsorb[n + 1] = true;
    for (int i = n; i >= 1; i--) {
        canAbsorb[i] = canAbsorb[i + 1] && a[i + 1] <= 2 * ps[i];
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (canAbsorb[i]) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1536
from collections import deque
S=input()
Q=int(input())

X=deque(list(S))
f=1
for _ in range(Q):
    A=list(input().split())
    if A[0]=="1":
        f*=-1
    else:
        if A[1]=="1":
            if f==1:
                X.appendleft(A[2])
            else:
                X.append(A[2])
        else:
            if f==-1:
                X.appendleft(A[2])
            else:
                X.append(A[2])

if f==-1:
    X.reverse()

print("".join(X))

Measured memory_bytes: 8548
#include <iostream>
#include <string>
using namespace std;

string str;

bool find(string s) {
  for(int i = 0; i < s.length(); i++) {
    string a = "";
    for(int j = 0; j < str.length(); j++) {
      a += s[(i+j)%s.length()];
    }
    if(a == str) return true;
  }
  return false;
}

main() {
  int N;
  int cnt;
  cin >> str;
  cin >> N;
  cnt = 0;
  for(int i = 0; i < N; i++) {
    string s;
    cin >> s;
    if(find(s)) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 0
//Created by Aminul on 9/13/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    static long dp[], mod = (long) 1e9 + 7;

    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int s = in.nextInt();
        dp = new long[s + 1];
        Arrays.fill(dp, -1);
        pw.println(solve(s));

        pw.close();
    }

    static long solve(int s) {
        if (s == 0) return 1;
        if(s < 3) return 0;
        if (dp[s] != -1) return dp[s];
        long res = 0;
        for (int i = 3; i <= s; i++) {
            res += solve(s - i);
            if (res >= mod) res -= mod;
        }
        return dp[s] = res;
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

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

int main() {
    int n,r,a,b;
    cin >> n >> r;
    int as[r] = {};
    for(int i = 0;i < n;i++){
        for(int k = 0;k < r;k++){
            int c = 0;
            cin >> c;
            as[k] += c;
            cout << c << " ";
            a += c;
        }
        cout << a << endl;
        a = 0;
    }
    for(int k = 0;k < r;k++){
      cout << as[k] << " ";
      b += as[k];
    }
    cout << b << endl;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
typedef long long ll;
typedef vector<int> vec;
int main(){
  int n,r;
  cin>>n>>r;
  if(n>=10)cout<<r;
  else cout<<r+100*(10-n);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

ll modpow(ll k, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n % 2 == 1) res = res * k % mod;
    k = k * k % mod;
    n /= 2;
  }

  return res;
}

// nCk
ll choose(ll n, ll k, ll mod) {
  ll x = 1, y = 1;

  rep(i, k) {
    x *= (n - i) % mod;
    x %= mod;
    y *= (i + 1) % mod;
    y %= mod;
  }

  return x * modpow(y, mod - 2, mod) % mod;
}

int main() {
  int n, k;
  cin >> n >> k;

  k = min(k, n - 1);
  const int mod = 1000000007;

  ll f[n + 1];
  f[0] = f[1] = 1;
  for (int i = 1; i <= n; ++i) {
    f[i + 1] = f[i] * (i + 1) % mod;
  }

  ll fi[n + 1];
  rep(i, n + 1) { fi[i] = modpow(f[i], mod - 2, mod); }

  auto ch = [&](int a, int b) {
    return ((f[a] * fi[b] % mod) * fi[a - b]) % mod;
  };

  ll ans = 0;
  // rep(i, k + 1) { ans += choose(n, i, mod) * choose(n - 1, i, mod); }
  for (int i = 0; i <= k; ++i) {
    ans += ch(n, i) * ch(n - 1, i) % mod;
    ans %= mod;
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
using pii = pair<int,int>;

int main()
{
	vector<pii>points;
	map<pii,int>color;
	int n;
	cin>>n;
	for(int i=0;i<2*n;i++)
	{
		int x,y;
		cin>>x>>y;
		
		points.pb({x,y});
		if(i<n)
			color[{x,y}]=1;
		else
			color[{x,y}]=-1;

	}
	sort(points.begin(),points.end());
	set<int> ys;
	int matched = 0;
	for(int i=0;i<2*n;i++)
	{
		if(color[points[i]]==1)
			ys.insert(points[i].second);
		else if(color[points[i]]==-1)
		{
			if(ys.size()>0 && *ys.rbegin()<points[i].second)
			{
				matched++;
				ys.erase(*ys.rbegin());
				continue;
			}
			int prev=1e5;
			for(auto x : ys)
			{
				if(x>=points[i].second && prev < points[i].second)
				{
					matched++;
					ys.erase(prev);
					break;
				}
				prev=x;//cout<<prev<<" ";
			}
		
		}
		//cout<<"\n";
	
	}
	/*for(auto x: ys)
		cout<<x<<"\n";*/
	cout<<matched<<"\n";
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
using ll = long long;
int main(){
  ll x,y;
  cin >> x >> y;
  ll ans;
  if((x>0 && y<0)||(x<0 && y>0)){
    ans = abs(abs(y)-abs(x))+1;
  }else if(y == 0){
    if(x<0) ans = abs(x);
    else ans = x+1;
  }else if(x == 0){
    if(y<0) ans = abs(y)+1;
    else ans = y;
  }else if(x < y){
    ans = y-x;
  }else{
    ans = x-y+2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	string S;
	cin >> S;
	if (S[0] >= 'a' && S[0] <= 'z')cout << "a\n";
	else cout << "A\n";
	return 0;
}

Measured memory_bytes: 3028
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

int gcd(int a,int b){
    return b ? gcd(b, a % b) : a;
}
int lcm(int a,int b){
    return b / gcd(a,b) * a;
}


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

    int n; cin >> n;
    vector<int> a(n),b(n);
    for(int i = 0;i < n;i ++) cin >> a.at(i) >> b.at(i);

    int ans = 0;

    for(int i = n-1;i >= 0;i --){
        int c = a.at(i) + ans;
        if(c % b.at(i) == 0) continue;
        else ans += (b.at(i) - c % b.at(i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int X,N; cin >> X >> N;
    set<int> p;
    int min=INF;
    int out=INF;
    for(int i=0;i<N;i++){
        int tmp;
        cin >> tmp;
        p.insert(tmp);
    }
    for(int i=-1;i<=101;i++){
        if(abs(X-i)<=min){
            if(p.count(i)==0){
                if(abs(X-i)!=min){
                    min = abs(X-i);
                    out = i;
                }
            }
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3632