akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

struct saikoro{

    int Size[6] = {0};
    int up, down;
    int south, east, west, north;
    int next_up, next_down, next_south, next_east, next_west, next_north;
public : 
    saikoro(){  //初期化
        up = Size[0];
        south = Size[1];
        east = Size[2];
        west = Size[3];
        north = Size[4];
        down = Size[5];

        next_up = 0;
        next_south = 0;
        next_north = 0;
        next_east = 0;
        next_west = 0;
        next_down = 0;
    }

    void init(){  //再初期化
        up = Size[0];
        south = Size[1];
        east = Size[2];
        west = Size[3];
        north = Size[4];
        down = Size[5];
    }
    int gettop(){ return up; }
    void change(char ch){
        if(ch == 'S'){
        next_up = north;
        next_south = up;
        next_north = down;
        next_down = south;

        up = next_up;
        south = next_south;
        north = next_north;
        down = next_down;
        } else if(ch == 'N'){
        next_up = south;
        next_south = down;
        next_north = up;
        next_down = north; 

        up = next_up;
        south = next_south;
        north = next_north;
        down = next_down;
        } else if(ch == 'E'){
        next_up = west;
        next_east = up;
        next_west = down;
        next_down = east; 

        up = next_up;
        east = next_east;
        west = next_west;
        down = next_down;
        } else if(ch == 'W'){       
        next_up = east;
        next_east = down;
        next_west = up;
        next_down = west; 

        up = next_up;
        east = next_east;
        west = next_west;
        down = next_down;
        }
    }
};

int main(){

    saikoro S;
    for(int i=0; i<6; i++){
        scanf("%d", &S.Size[i]);
    }
    S.init();

    int n;
    scanf("%d", &n);

    for(int i=0; i<n; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        if(a == S.north) S.change('S');
        if(a == S.south) S.change('N');
        if(a == S.west) S.change('E');
        if(a == S.east) S.change('W');
        if(a == S.down) {
            S.change('N');
            S.change('N');
        }

        if(b == S.north) printf("%d\n", S.west);
        if(b == S.west) printf("%d\n", S.south);
        if(b == S.south) printf("%d\n", S.east);
        if(b == S.east) printf("%d\n", S.north);
    }
    return 0;
}


Measured memory_bytes: 2600
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#ifdef RUBICK
#include "dbg.h"
#endif

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;

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

    vector<string> arr(n);
    for (auto& row : arr)
        cin >> row;

    sort(begin(arr), end(arr));

    for (auto row : arr)
        cout << row;
    cout << '\n';

    return 0;
}



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

int main() {
  int N , M;
  cin >> N >> M;	//N個の都市と、M本の道路
  
  vector <int> A(50) , B(50);	//入力が１行につき２つあるので、AB２つの配列を用意する
  
  for(int i = 0; i < M; i++)
  {
    cin >> A.at(i) >> B.at(i);	//AB配列に入力値を入れていく
  }
  
  vector <int> count(50);
  for(int i = 0; i < N; i++)
  {
    count.at(i) = 0;			//カウント用の配列を作り一旦値を0にしておく。
  }
  
  for(int i = 0; i < M; i++)
  {
    count.at(A.at(i) - 1) +=  1;	//カウント変数の0を1本目の道路のカウントとするため-1
    count.at(B.at(i) - 1) +=  1;	//判別してカウントしていく
  }
  
  for(int i = 0; i < N; i++)
  {
    cout << count.at(i) << endl;
  }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_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 || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    ll N,M; cin >> N >> M;
    if (M % N == 0){
        cout << M/N << endl;
        return 0;
    }
    ll mx = 0;
    for (ll i = 1; i*N <= M; i++){
        ll tmp = M-i*N;
        if (tmp % i == 0){
            mx = max(i,mx);
        }
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <bitset>
using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    int a[N];
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    long long min = LLONG_MAX;
    int bit = 1 << N;
    for(int i = 0; i < bit; i++) {
        long long sum = 0;
        int base = 0;
        int count = 0;
        int flag = 0;
        for(int j = 0; j < N; j++) {
            if((i & (1<<j)) != 0) {
                if(base == 0) {
                    base = a[j];
                } else if(base < a[j]) {
                    base += a[j];
                } else {
                    sum += (base+1)-a[j];
                    base += 1;
                }
                count += 1;
            } else {
                if(base < a[j]) {
                    base = a[j];
                    count += 1;
                }
            }
            if(count == K) {
                flag = 1;
                break;
            }
        }
        if(flag == 1 && sum < min) {
            min = sum;
            //cout << bitset<8>(i) << endl;
        }
    }
    cout << min << endl;
    return 0;
}

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

int main() {
  ll a, b, c, x, y; cin >> a >> b >> c >> x >> y;
  
  if (a + b <= c * 2)
    cout << a * x + b * y << endl;
  else {
    if (x > y)
      cout << min(a, c * 2) * (x - y) + 2 * c * y << endl;
    else
      cout << min(b, c * 2) * (y - x) + 2 * c * x << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
use std::io;

fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().split(' ').flat_map(str::parse).collect()
}

fn main() {
    let l1 = read::<i32>();

    let a = l1.get(0).unwrap();
    let b = l1.get(1).unwrap();

    let cmp = if a > b {
        ">"
    } else if a < b {
        "<"
    } else {
        "=="
    };

    println!("a {} b", cmp);
}



Measured memory_bytes: 5024
def roll(i):
    global u, s, e, w, n, d
    if i == 'N':
        u, s, n, d = s, d, u, n
    elif i == 'E':
        u, e, w, d = w, u, d, e
    elif i == 'S':
        u, s, n, d = n, u, d, s
    elif i == 'W':
        u, e, w, d = e, d, u, w

u, s, e, w, n, d = input().split()
q = int(input())
for i in range(q):
    u1, s1 = input().split()
    if u1 == u:
        pass
    elif u1 == s:
        roll('N')
    elif u1 == e:
        roll('W')
    elif u1 == w:
        roll('E')
    elif u1 == n:
        roll('S')
    elif u1 == d:
        roll('N')
        roll('N')
    if s1 == s:
        print(e)
    elif s1 == e:
        print(n)
    elif s1 == n:
        print(w)
    elif s1 == w:
        print(s)

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

long long f(long long k,long long o){
  long long co=1;
    co=k/o;
  return co;
}
    

int main(){
  long long n;
  cin >> n;
  long long ans=0;
  if(n%2!=0){
    ans=0;
  }else{
    long long i=10;
    long long k=n;
    long long j=1;
    long long o=10;
    while(o<=n){
      ans=ans+f(k,o);
      o=o*5;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);
	for (int i = 0; i < N; i++)
	{
		cin >> x[i] >> y[i] >> h[i];
	}

  int MAX = 100;
  
for(int posY = 0; posY <= MAX; posY++)
{
    for(int posX = 0; posX <= MAX; posX++)
    {
      int needH = -1;
    

      for(int i = 0; i < N; i++){
        if(h.at(i) > 0){
          int tmp = h.at(i) + abs(posY - y.at(i)) + abs(posX - x.at(i));
          if (needH == -1){
            needH = tmp;
          }else{
            if(needH != tmp){
              needH = -2;
              break;
            }
          }
        }
      }
        if(needH == -2) continue;


  for(int i = 0; i < N; i++){
    if(h.at(i) == 0){
      int dist = abs(posY - y.at(i)) + abs(posX - x.at(i));
      if(needH > dist){
        needH = -2;
        break;
      }
    }
  }
  if(needH == -2) continue;
  cout << posX << ' ' << posY << ' ' << needH << endl;   
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int t, x;
    cin >> t >> x;
    cout << (double)t/(double)x << endl;
    return 0;
}

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

int main(void) {
	string S, T;
	cin >> S;
	cin >> T;
	int count = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i]) {
			count++;
		}
	}
	cout << count << endl;

}

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

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld",&n);

        for(i=1;i<=n;i++)
        {
            scanf("%lld",&a);  v.push_back(a);
        }

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

        vector<long long>::iterator it;

        for(i=0;i<=n-3;i++)
        {
            for(j=i+1;j<=n-2;j++)
            {

                fr=v[i]+v[j];

                it=lower_bound(v.begin(),v.end(),fr); sc=it-v.begin();  sc--; ans=ans+max(0LL,sc-j);

            }

        }




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






    return 0;
}





Measured memory_bytes: 3820
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  string s;
  cin >> s;

  map<char, int> num;
  map<char, vector<int> > pos;
  vector<int> vec;

  int dist;

  REP(i, s.size()){
    char c = s[i];
    if(num.count(c) == 0){
      pos[c].push_back(i);
      num[c] = 1;
    }
    else{
      pos[c].push_back(i);
      vec = pos[c];
      if(!(vec[vec.size()-1] == vec[vec.size()-2]+1 || vec[vec.size()-1] == vec[vec.size()-2]+2)) continue;
      for(int j=0;j<vec.size();j++){
        for(int k=j+1;k<vec.size();k++){
          dist = vec[k]-vec[j]+1;
          if(dist/2 < k-j+1){
            cout << vec[j]+1 << " " << vec[k]+1 << endl;
            return 0;
          }
        }
      }
    }
  }

  cout << "-1 -1" << endl;
  return 0;
}


Measured memory_bytes: 1404
#include<stdio.h>
#define MAX 10000000

int S[MAX], T[MAX];
int n;

int binarySearch(int key){
  int left = 0;
  int right = n;

  while(left < right){
      int mid = (left + right)/2;
      if(S[mid] == key){
          return mid;
      }else if(key < S[mid]){
          right = mid;
      }else{
          left = mid + 1;
      }
   
  }
     return -1;
}

int main(void){
  int i, q, a;
  int count = 0;

  scanf("%d\n", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &S[i]);
  }
  scanf("%d\n", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &T[i]);
  }

  for (i = 0; i < q; i++) {
    a = binarySearch(T[i]);
    if(a >= 0){
      count++;
    }
  }
  printf("%d\n", count);

  return 0;
}



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

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

  if (N == 1 || N == 2 || N == 3 || N == 5 || N == 6 || N == 9 || N == 10 || N == 13 || N == 17) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (void)
{
    intmax_t N, p[20];
    intmax_t ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &p[i]);
    }

    for (size_t i = 1; i < (N - 1); i++) {
        if ((p[i - 1] > p[i]) && (p[i - 1] > p[i + 1]) && (p[i] >= p[i + 1])) {
            ans++;
        } else if ((p[i + 1] > p[i]) && (p[i + 1] > p[i - 1]) && (p[i] >= p[i - 1])) {
            ans++;
        }
    }

    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
char a[maxn][maxn], b[maxn][maxn];
int main(){
  int n, m; cin >> n >> m;
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> a[i][j];
  for(int i = 0; i < m; i++) for(int j = 0; j < m; j++) cin >> b[i][j];
  for(int i = 0; i <= n - m; i++) for(int j = 0; j <= n - m; j++){
  	bool bad = false;
    for(int k = 0; k < m; k++) for(int l = 0; l < m; l++){
    	bad |= a[i + k][j + l] != b[k][l];
    }
    if(!bad){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<fstream>
#include<vector>
#include<initializer_list>
#include<string>
using namespace std;
  int main(){
  string S;
  string T;
  string U;
  int A;
  int B;
 
cin >> S ;
cin >> T;
cin >>A;
cin >>B;
cin >>U;
  if (U==S)
  {cout << A-1 <<" " << B << endl; }

  else if(U==T)
  {cout << A <<" " << B-1 << endl;}}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  string s,t;
  cin>>n>>s>>t;
  vector<char> x(2*n);
  for(int i=0;i<2*n;i++){
    if(i%2==0){
      x[i]=s[i/2];
    }
    else{
      x[i]=t[(i-1)/2];
    }
  }
  for(int i=0;i<2*n;i++){
    cout<<x[i];
  }
  
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N,M;
char A[51][51];
char B[51][51];
int main(){
	cin>>N>>M;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cin>>A[i][j];
		}
	}
	int ans;
	for(int i=0;i<M;i++){
		for(int j=0;j<M;j++){
			cin>>B[i][j];
		}
	}
	for(int i=0;i<N-M+1;i++){
		for(int j=0;j<N-M+1;j++){
			if(A[i][j]==B[0][0]){
				ans=1;
				for(int k=0;k<M;k++){
					for(int v=0;v<M;v++){
						if(A[i+k][j+v]!=B[k][v]){
							ans=0;
						}
					}
				}
				if(ans==1){
					cout<<"Yes"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"No"<<endl;

	return 0;
}


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

int main(){
  int A, B; cin >> A >> B;
  if(A >= 13){
    cout << B;
  }
  else if(A >= 6){
    cout << B / 2;
  }
  else cout << 0;
  return 0;
}

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

int main()
{
	int k;
	cin >> k;
	vector<ll> A(k);
	for(int i =0;i<k;i++)
	{cin >> A[i];}
	reverse(A.begin(),A.end());
	ll mn = 2;
	ll mx = 2;
	for(int i = 0;i<k;i++)
	{
		mn = mn%A[i]==0?mn:(mn/A[i]+1)*A[i];
		mx = (mx/A[i]+1)*A[i]-1;
		//cout<<mn<<endl;
	}
	if(mn<mx)
	cout<<mn<<' '<<mx<<endl;
	else
		cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
#define fin(name) freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
typedef pair<int, int> pii;
typedef long long LL;
const double PI = acos(-1.0);

int main(void)
{
    string s, t;
    int i, j;
    while (cin >> s >> t)
    {
        if (s.size() < t.size())
            puts("UNRESTORABLE");
        else
        {
            int la = s.size(), lb = t.size();
            string ans = "";
            for (i = 0; i < la - lb + 1; ++i)
            {
                string temp = s.substr(0, i);
                for (j = 0; j < i; ++j)
                    if (temp[j] == '?')
                        temp[j] = 'a';
                int flag = 1;
                for (j = 0; j < lb; ++j)
                {
                    if (s[i + j] == t[j])
                    {
                        temp += t[j];
                        continue;
                    }
                    else if (s[i + j] == '?')
                    {
                        temp += t[j];
                    }
                    else
                    {
                        temp = "";
                        flag = 0;
                        break;
                    }
                }
                if (!flag)
                    continue;
                else
                {
                    for (j = i + lb; j < la; ++j)
                        temp += (s[j] == '?' ? 'a' : s[j]);
                }
                if (ans == "" || strcmp(temp.c_str(), ans.c_str()) < 0)
                    ans = temp;
            }
            puts(ans.size() ? ans.c_str() : "UNRESTORABLE");
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
using pii = pair<int, int>; using vi = vector<int>; using vl = vector<ll>;

signed main() {
    int s, w;
    cin>>s>>w;
    cout<< ((w>=s) ? "unsafe" : "safe");
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
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;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
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;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
//最初に設定する.
ll MOD=998244353;
const int  MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];  void modcinit() { 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 modc(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; }
int main( ){
    modcinit();
    ll N,M;
    ll K;
    cin>>N>>M>>K;
    ll ans=0;
    rep(i,0,K+1){
       ll add=(((M*modc(N-1,i)%MOD+MOD)%MOD*modpow(M-1,N-1-i,MOD)%MOD)+MOD)%MOD;
       ans+=add;
       ans=(ans%MOD+MOD)%MOD;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 15564
package main

import "fmt"

var (
	N          int
	S          string
	rs, gs, bs []int
)

func main() {
	fmt.Scan(&N, &S)
	rs = make([]int, 0, N)
	gs = make([]int, 0, N)
	bs = make([]int, 0, N)

	for i, c := range S {
		if c == 'R' {
			rs = append(rs, i)
		}
		if c == 'G' {
			gs = append(gs, i)
		}
		if c == 'B' {
			bs = append(bs, i)
		}
	}

	runes := []rune(S)
	ans := len(rs) * len(gs) * len(bs)
	for _, r := range rs {
		for _, g := range gs {
			k1 := max(r, g) + abs(r-g)
			k2 := min(r, g) - abs(r-g)
			if k1 > 0 && k1 < N && runes[k1] == 'B' {
				ans--
			}
			if k2 > 0 && k2 < N && runes[k2] == 'B' {
				ans--
			}
			if (r-g)%2 == 0 && runes[(r+g)/2] == 'B' {
				ans--
			}
		}
	}
	fmt.Println(ans)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func search(i int, c rune) int {
	var x, y []int
	if c == 'R' {
		x, y = gs, bs
	} else if c == 'G' {
		x, y = rs, bs
	} else {
		x, y = rs, gs
	}
	ans := 0
	for _, j := range x {
		for _, k := range y {
			if j <= i || k <= i {
				continue
			}
			if max(j, k)-min(j, k) != min(j, k)-i {
				ans++
			}
		}
	}
	return ans
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 1880
#include <iostream>
#include <math.h>

#define PI 3.14159265358979

using namespace std;

int main(){
  int theta,x,theta_sum;
  double x_sum,y_sum;
  x_sum =0;
  scanf("%d,%d",&x,&theta);
  y_sum = (double)x,theta_sum =(double)theta;
  while(1){
    scanf("%d,%d",&x,&theta);
    if(x == 0 && theta == 0) break;
    x_sum += (double)x * sin(double(theta_sum * PI / 180.00));
    y_sum += (double)x * cos(double(theta_sum * PI / 180.00));
    theta_sum += theta;
  }

  cout << (int)x_sum << endl << (int)y_sum << endl;

  return 0;

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 1000000007

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  sort(A.begin(),A.end());
  if(N%2==0){
    bool flag=true;
    ll ans=1;
    for(int i=0;i<N/2;i++){
      if(A.at(2*i)!=2*i+1||A.at(2*i+1)!=2*i+1){
        flag=false;
        break;
      }
      ans*=2;
      ans%=MOD;
    }
    if(flag){
      cout<<ans<<endl;
    }else{
      cout<<0<<endl;
    }
  }else{
    bool flag=true;
    ll ans=1;
    if(A.at(0)!=0){
      flag=false;
    }
    for(int i=0;i<(N-1)/2;i++){
      if(A.at(2*i+1)!=2*(i+1)||A.at(2*i+2)!=2*(i+1)){
        flag=false;
        break;
      }
      ans*=2;
      ans%=MOD;
    }
    if(flag){
      cout<<ans<<endl;
    }else{
      cout<<0<<endl;
    }
  }
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int n,a[100010],maxx,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	maxx=1;
	for(int i=n-1;i>=0;--i)
	{
		if(a[i]<a[i+1])
			maxx=1;
		else maxx++;
		ans=max(ans,maxx);
	}
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int sum = 0;
    rep(i,n){
        sum += s[i]-'0';
        sum%=9;
    }
    if(sum%9==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3696
from collections import*
from bisect import*
p=[1]
for _ in range(30):p+=p[-1]*2,
n,*a=map(int,open(0).read().split())
d=Counter(a)
c=0
for b in sorted(a)[::-1]:
  if d[b]<1:continue
  d[b]-=1
  x=p[bisect(p,b)]-b
  if d[x]:
    d[x]-=1
    c+=1
print(c)

Measured memory_bytes: 33712
data = input()

if data[0]=="R" and data[1]=="R" and data[2]=="R":
    print(3)
elif (data[0]=="R" and data[1]=="R") or (data[1]=="R" and data[2]=="R"):
    print(2)
elif data[0]=="R" or data[1]=="R" or data[2]=="R":
    print(1)
else:
    print(0)

Measured memory_bytes: 9060
#include <iostream>

using namespace std;

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

  int cnt=0;

  for(int i=1; i<n; ++i){
    for(int j=n-1; j>=i; --j){
      if(a[j] < a[j-1]){
	swap(a[j] , a[j-1]);
	++cnt;
      }
    }
  }

  for(int i=0; i<n; ++i){
    cout << a[i];
    if(i<n-1)
      cout<<" ";
  }
  cout << endl << cnt << endl;
  


  return 0;
}



Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int P = 2019;
        final char[] str = in.nextLine().toCharArray();
        final int N = str.length;
        final int[] digits = new int[N];
        for (int i = 0; i < N; i++) {
            digits[i] = Character.getNumericValue(str[i]);
        }
        final int[] remainders = new int[P];
        remainders[0] = 1;
        int suffix = 0;
        int shift = 1;
        long ans = 0;
        for (int pos = N - 1; pos >= 0; pos--) {
            suffix = (suffix + shift * digits[pos]) % P;
            ans += remainders[suffix];
            remainders[suffix]++;
            shift = (shift * 10) % P;
        }
        System.out.println(ans);
    }
}


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

int main(){
    double W,H,x,y;
    cin >> W >> H >> x >> y;

    double m = (W*H)/2;
    bool c = false;
    if(W/2 == x && H/2 == y) c = true;
    cout << m << " " << c << "\n"; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    bool flag=true;
    for(int i=0;;i++)
    {
        if(i%2==0)
        c-=b;
        else a-=d;
        if(c<=0)
        {flag=true;break;}
        else if(a<=0)
        {flag=false;break;}
    }
    if(flag)cout<<"Yes\n";
    else cout<<"No";
  }  
  return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>

using namespace std;

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

	long long int k;
	cin >> k;

	vector<pair<int, int> >a;

	for (int i = 0; i < n; i++) {
		int ai, bi;
		cin >> ai >> bi;
		pair<int, int>ci = make_pair(ai, bi);
		a.push_back(ci);
	}
	sort(a.begin(), a.end());

	long long int total = 0;
	int i = 0;
	while(total<k) {
		total += a[i].second;
		i++;
	}
	cout << a[i - 1].first << endl;

	return 0;

}


Measured memory_bytes: 1400
#include<iostream>
using namespace std;
     
int main(void){
	int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    if(a + b > c + d){
      cout << "Left" << endl;
    }else if( a + b == c + d){
      cout << "Balanced" << endl;
    }else{
      cout << "Right" << endl;
    }
}

Measured memory_bytes: 3648
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c;
    
    cin >> a >> b >> c;
    if (a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if(b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if(b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if(c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
    else 
        cout << c << " " << b << " " << a << endl;
        
}      


Measured memory_bytes: 3092
#include <iostream>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[1000][1000];
ll x[200000] = {};
ll y[200000] = {};
ll x2[200000] = {};
ll y2[200000] = {};

int main() {
	ll h, w, v; cin >> h >> w;
	rep(i, 0, h)rep(j, 0, w) {
		cin >> v;
		a[i][j] = v % 2;
	}

	ll cnt = 0;
	rep(i, 0, h) {
		rep(j, 0, w - 1) {
			if (a[i][j] % 2) {
				a[i][j]--;
				a[i][j + 1]++;

				y[cnt] = i + 1;
				x[cnt] = j + 1;
				y2[cnt] = i + 1;
				x2[cnt] = j + 2;
				cnt++;
			}
		}
		if (i != h - 1) {
			if (a[i][w - 1] % 2) {
				a[i][w - 1]--;
				a[i + 1][w - 1]++;

				y[cnt] = i + 1;
				x[cnt] = w;
				y2[cnt] = i + 2;
				x2[cnt] = w;
				cnt++;
			}
		}
	}

	printf("%d\n", cnt);
	rep(i, 0, cnt) {
		printf("%d %d %d %d\n", y[i], x[i], y2[i], x2[i]);
	}

	return 0;
}

Measured memory_bytes: 11776
#include <iostream>
#include <cmath>
using namespace std;
 
int main(){
	int Q;
	cin >> Q;
	while (Q --){
		long long a, b;
		cin >> a >> b;
		if (a > b)
			swap(a, b);
		if (a + 1 >= b)
			cout << 2 * a - 2 << endl;
		else{
			long long c = sqrt(a * b + 0.5);
			while (c * c >= a * b)
				-- c;
			if (c * (c + 1) >= a * b)
				cout << 2 * c - 2 << endl;
			else
				cout << 2 * c - 1 << endl;
		}
	}
}

Measured memory_bytes: 256
# include <iostream>
# include <cmath>

using namespace std;

int main()
{
    int n, a[110], s = 0, m = 0;
    cin >> n;

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

    int ans = 5000000;

    for(int i = 0; i < n; i++) {
        m += a[i];
        int x = abs(s - 2 * m);
        ans = min(ans, x);
    }
    cout << ans;
}



Measured memory_bytes: 256
/**
 *    author:  math2do
 *    created: 03.05.2020 20:39:17 IST
**/

#include <bits/stdc++.h>

using namespace std;

template <typename T>
class graph {
 public:
  struct edge {
    int from;
    int to;
    T cost;
  };
 
  vector<edge> edges;
  vector<vector<int>> g;
  int n;
 
  graph(int _n) : n(_n) {
    g.resize(n);
  }
 
  virtual int add(int from, int to, T cost) = 0;
};

template <typename T>
class forest : public graph<T> {
 public:
  using graph<T>::edges;
  using graph<T>::g;
  using graph<T>::n;
 
  forest(int _n) : graph<T>(_n) {
  }
 
  int add(int from, int to, T cost = 1) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    int id = (int) edges.size();
    assert(id < n - 1);
    g[from].push_back(id);
    g[to].push_back(id);
    edges.push_back({from, to, cost});
    return id;
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  forest <int> g(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g.add(x, y);
  }
  vector <int> tail(n, 0);
  vector <int> ans(n, 1);
  vector <bool> seen(g.n, false);
  function<void(int, int)> dfs = [&](int u, int len) {
    seen[u] = true;
    auto b = tail.begin();
    auto e = tail.begin() + len;
    auto it = lower_bound(b, e, arr[u]);
    int pos = -1;
    int val = -1;
    if (it == tail.begin() + len) {
      tail[len++] = arr[u];
    } else {
      pos = it - b;
      val = tail[pos];
      tail[pos] = arr[u];
    }
    ans[u] = max(ans[u], len);
    for (int id : g.g[u]) {
      int v = g.edges[id].from ^ g.edges[id].to ^ u;
      if (!seen[v]) {
        dfs(v, len);
      }
    }
    if (pos != -1) {
      tail[pos] = val;
    } 
  };
  tail[0] = arr[0];
  int len = 1;
  seen[0] = true;
  for (int id : g.g[0]) {
    int v = g.edges[id].from ^ g.edges[id].to ^ 0;
    dfs(v, len);
  } 
  for (int v : ans) {
    cout << v << '\n';
  } 
  return 0;
}


Measured memory_bytes: 38980
n, q, s, t = gets.split.map(&:to_i)
a = (0..n).map { gets.to_i }
temp = 0
height_diff = []
(1..n).each do |i|
    d = a[i] - a[i-1]
    height_diff << d
    temp -= (d > 0 ? s * d : t * d)
end
q.times do
    l, r, x = gets.split.map(&:to_i)
    d = height_diff[l-1]
    temp += (d > 0 ? s * d : t * d)
    height_diff[l-1] += x
    d = height_diff[l-1]
    temp -= (d > 0 ? s * d : t * d)
    if r < n
        d = height_diff[r]
        temp += (d > 0 ? s * d : t * d)
        height_diff[r] -= x
        d = height_diff[r]
        temp -= (d > 0 ? s * d : t * d)
    end
    p temp
end


Measured memory_bytes: 10132
n = int(input())
A = [[0] * 10 for i in range(10)]

for i in range(1, n+1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    A[a][b] += 1

ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += A[i][j] * A[j][i]
print(ans)

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

int main()
{
    int64_t h, w;
    cin >> h >> w;
    if (h == 1 || w == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    int64_t s = h * w;
    cout << (s + 1) / 2 << endl;
}

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

#define ll long long
#define ld long double
#define ull unsigned long long

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"

using namespace std;

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

    int n;
    cin >> n;

    vector<int> cnt(26, INT_MAX);

    for (int i = 0; i < n; ++i)
    {
        string s;
        cin >> s;
        vector<int> cur_cnt(26);
        for (char c : s)
            ++cur_cnt[c - 'a'];

        for (int j = 0; j < 26; ++j)
            cnt[j] = min(cnt[j], cur_cnt[j]);
    }

    for (int i = 0; i < 26; ++i)
        for (int j = 0; j < cnt[i]; ++j)
        {
            char tmp = 'a' + i;
            cout << tmp;
        }

    cout << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b="CODEFESTIVAL2016";
int s;
int main()
{
	cin>>a;
	for(int i=0;i<16;i++)
	{
		if(a[i]!=b[i]) s++;
	}
	cout<<s;

	return 0;
}

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

int main()
{
	int n; cin >> n;
	int d[n]; for (int i = 0; i < n; i++) { cin >> d[i]; }
	
	int ans = 0;

	for (int i = 0; i <= n - 2; i++) {
		for (int j = i + 1; j <= n - 1; j++) {
			ans += d[i] * d[j];
		}	
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            while(true) {
                int n = Integer.parseInt(sc.nextLine());
                if(n==0) break;
                int [] kouho = new int[26];
                int [] sokuhou = new int[26];
                String[] vote = new String[n];
                for(int i=0;i<26;i++) {
                    kouho[i] = 0;
                }
                vote = sc.nextLine().split(" ");
                boolean flag = true;
                loop:for(int i=1;i<=n;i++) {
                    int d = vote[i-1].charAt(0) - 'A';
                    kouho[d] += 1;
                    for(int j=0;j<26;j++) {
                        sokuhou[j] = kouho[j];
                    }
                    Arrays.sort(sokuhou);
                    if(sokuhou[24]+(n-i)<sokuhou[25]) {
                        int k=0;
                        for(k=0;k<26;k++) {
                            if(kouho[k] == sokuhou[25]) break;
                        }
                        System.out.printf("%c %d", k +'A',i);
                        System.out.println();
                        flag = false;
                        break loop;
                    }
                }
                if(flag) System.out.println("TIE");
            }
 
        }   
    }
}


Measured memory_bytes: 52512
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int a[2];
  int ans = 0;
  for(int i = 0; i < 3; i++){
    cin >> a[i];
  }
  sort(a, a + 3);
  ans = a[2] - a[1];
  if((a[1] - a[0])%2 == 0){
    ans += (a[1] - a[0])/2;
  }
  if((a[1] - a[0])%2 != 0){
    ans += 1 + (a[1] + 1 - a[0])/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
program checker
  implicit none
  integer :: n, k, x, y, m, t
  integer :: i, j, g(0:4000,0:4000)
  character(1) :: c
  g = 0
  read(*,*) n, k
  do i = 1, n
    read(*,*) x, y, c
    if (c.eq."W") y = y + k
    x = mod(x,2*k)+1
    y = mod(y,2*k)+1
    g(x,y) = g(x,y) + 1
    g(x,y+2*k) = g(x,y+2*k) + 1
    g(x+2*k,y) = g(x+2*k,y) + 1
    g(x+2*k,y+2*k) = g(x+2*k,y+2*k) + 1
  end do
  do i = 1, 4*k
    do j = 1, 4*k
      g(i,j) = g(i,j) + g(i,j-1)
    end do
  end do
  do j = 1, 4*k
    do i = 1, 4*k
      g(i,j) = g(i,j) + g(i-1,j)
    end do
  end do
  m = 0
  do x = 0, 2*k
    i = x + k
    do y = 0, 2*k
      j = y + k
      t = g(i+k,j+k) + 2*g(i,j) + g(i-k,j-k) &
      & - (g(i+k,j) + g(i,j+k) + g(i,j-k) + g(i-k,j))
      if (m.lt.t) m = t
    end do
  end do
  write(*,'(i0)') m
  stop
end program checker

Measured memory_bytes: 62720
N = int(input())
res = 'Yes'
A = [[0 for j in range(2)] for i in range(N)]
for i in range(N):
  A[i][0], A[i][1] = map(int, input().split(' '))
A.sort(key=lambda x: x[1])
A.append([0, 0])
total = 0
i = 0
while i < N:
  while True:
    total += A[i][0]
    if A[i][1] != A[i + 1][1]:
      break
    i += 1
  if A[i][1] < total:
    res = 'No'
    break
  i += 1
print(res)

Measured memory_bytes: 41240
# -*- coding: utf-8 -*-
import sys


def get_num():
    return int(input())


def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


def get_numbers():
    return map(int, input().split())

n = get_num()
v = list(get_numbers())
c = list(get_numbers())

ans = 0
for x, y in zip(v, c):
    if x - y > 0:
        ans += (x - y)

print(ans)

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

int main(){
int n; cin >>n;
long long a[n];
bool tan = false;
int count = 0;
long long ans =1;
long long inf = 1e18;
for(int i=0;i<n;i++){
  cin >>a[i];
  if(a[i]==0) tan = true;
}

if(tan) cout << 0 <<endl;
else{
  for(int i=0;i<n;i++){
    if(a[i] >inf/ans) break;
    else {
      ans = ans*a[i];
      count ++;}
  }
  if(count == n) cout << ans <<endl;
  else cout << -1 << endl;
}

return 0;
}


Measured memory_bytes: 4368
/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	static long solve(long n){
		long ans = 1l;
		while(n>0){
			n >>= 1l;
			ans <<= 1l;
		}
		return ans-1l;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		System.out.println(solve(n));
		// your code goes here
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    while (a.at(i) % 2 == 0) {
      a.at(i) /= 2;
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int A = 0;
  int B = 0;
  vector<int> vec(N);
  
  for(int i = 0 ; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

 for(int i = 0 ; i<N; i++){
   if(i % 2 == 0) A += vec.at(i);
   
   else B += vec.at(i);
 }

   cout << A -B << endl;
        
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,flg,t[26][26];
string str[500];
void check(int x,int y){
  //cout<<str[x]<<' '<<str[y]<<endl;
  int v = str[x].size();
  int w = str[y].size();
  for(int i=0;i<min(v,w);i++){
    if(str[x][i]==str[y][i])continue;
    if(t[str[x][i]-'a'][str[y][i]-'a']==-1)flg=0;
    t[str[x][i]-'a'][str[y][i]-'a']=1;
    t[str[y][i]-'a'][str[x][i]-'a']=-1;
    return;
  }
  if(w<v)flg=0;
}
int main(){
  while(cin>>n&&n){

    for(int i=0;i<26;i++)
      for(int j=0;j<26;j++)
	t[i][j]=0;

    flg=1;
    cin>>str[0];
    for(int i=1;i<n;i++){
      cin>>str[i];
      for(int j=i-1;j>=0;j--)check(j,i);
    }
    cout<<(flg?"yes":"no")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1248
#include <iostream>

int main() {
  using namespace std;
  ios_base::sync_with_stdio(false);

  int k, n;
  cin >> k >> n;
  int max = 0;
  
  int a;
  cin >> a;
  int topSpace = a;
  int prev = a;
  
  for (int i=1 ; i<n ; i++) {
    cin >> a;
    if (a - prev > max) max = a - prev;
    prev = a;
  }
  topSpace += k - a;
  if (topSpace > max) max = topSpace;
  cout << k - max;
}


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

int main() {
	int DP[34]={0};
	int x;
	DP[0]=1;

	for(int i=0;i<=29;i++){
		for(int j=1;j<=3;j++)
		DP[i+j]+=DP[i];
	}
	while(true){
		cin >> x;
		if(x==0)
		break;
		cout << (DP[x]+3649)/3650 << endl; 
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iterator>
#include <array>
#include <set>
#include <algorithm>
#include <string>
#include <limits>

using namespace std;

int main()
{
  // skip the first line
  cin.ignore(numeric_limits<streamsize>::max(), '\n');

  constexpr int B = 4, F = 3, R = 10;

  int counts[B][F][R] {0};

  int b, f, r, v;

  while (cin >> b >> f >> r >> v)
    counts[b-1][f-1][r-1] += v;

  for (b = 0; b < B; ++b) {
    for (f = 0; f < F; ++f) {
      for (r = 0; r < R; ++r) {
        cout << " " << counts[b][f][r];
      }
      cout << endl;
    }
    if (b < B-1) {
      for (int hash = 0; hash < 2*R; ++hash) cout << "#";
      cout << endl;
    }
  }
}


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

int main() {
	int N;
	cin >> N;
	vector<ll> a(3 * N + 1);
	for (int i = 1; i <= 3 * N; i++) {
		cin >> a[i];
	}

	vector<ll> dl(N + 1, 0);
	priority_queue<ll, vector<ll>, greater<ll>> quel;
	for (int i = 1; i <= 2 * N; i++) {
		if (i <= N) {
			dl[0] += a[i];
			quel.push(a[i]);
		} else {
			dl[i - N] += dl[i - N - 1] + a[i];
			quel.push(a[i]);
			dl[i - N] -= quel.top();
			quel.pop();
		}
	}

	vector<ll> dr(N + 1, 0);
	priority_queue<ll, vector<ll>> quer;
	for (int i = 3 * N; i > N; i--) {
		if (i > 2 * N) {
			dr[0] += a[i];
			quer.push(a[i]);
		} else {
			int it = 2 * N + 1 - i;
			dr[it] += dr[it - 1] + a[i];
			quer.push(a[i]);
			dr[it] -= quer.top();
			quer.pop();
		}
	}

	ll res = -1e18;
	for (int i = 0; i <= N; i++) {
		res = max(res, dl[i] - dr[N - i]);
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 6516
#include<stdio.h>

int p[5010];
int oya[5010];
int ko[5010][5010],kocnt[5010];
int ans;
void f(int i){
	for(int j=0;j<kocnt[i];j++)if(p[ko[i][j]]==-1){
		p[ko[i][j]]=i;
		p[i]=ko[i][j];
		ans++;
		return;
	}
	if(i==0)return;
	if(p[oya[i]]==-1){
		p[oya[i]]=i;
		p[i]=oya[i];
		ans++;
	}else{
		int t=p[oya[i]];
		p[t]=-1;
		p[oya[i]]=i;
		p[i]=oya[i];
 		if(t<oya[i])f(t);
	}
}

int main(){
	p[0]=-1;
	oya[0]=-1;
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int t;
		scanf("%d",&t);
		oya[i]=t;
		ko[t][kocnt[t]++]=i;
		f(i);
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 11896