akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 1000005
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    ll N, M;
    cin >> N >> M;
    ll p[100001], y[100001];
    ll i, j;
    vector<P> G[100001];
    P id[100001];
    
    for(i=0; i<M; i++) {
        cin >> p[i] >> y[i];
        p[i]--;
        G[p[i]].push_back({y[i], i});
    }
    
    for(i=0; i<N; i++) {
        sort(G[i].begin(), G[i].end());
    }
    
    for(i=0; i<N; i++) {
        for(j=0; j<G[i].size(); j++) {
            id[G[i][j].second]={i, j};
        }
    }
    
    for(i=0; i<M; i++) {
        printf("%06lld%06lld\n", id[i].first+1, id[i].second+1);
    }
    
}


Measured memory_bytes: 10112
#include<stdio.h>

int gcd(int ,int );

int main(){

  int x,y,n;
  
  scanf("%d %d",&x,&y);
  n=gcd(x,y);

  printf("%d\n",n);

  return 0;
}

int gcd(x,y){
  int n,x1,y1;

  if(x>y){
    y1=y;
    x1=x;
  }else if(x<y){
    y1=x;
    x1=y;
  }

  while(y1>0){
    n=x1%y1;
    x1=y1;
    y1=n;
  }

  return x1;

}



Measured memory_bytes: 2124
L, R = map(int, input().split())

minimam = 2019
for i in range(L, min(R, L+2019)):
    for j in range(i+1, min(R+1, L+2019)):
        if (i*j) % 2019 < minimam:
            minimam = (i*j) % 2019

print(minimam)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  	cin>>n;
  	int i=0;
  	int count=0;
  	while(i<360){
		i=i+n;
  		if(i>360){
          i=i-360;
        }
      	count++;
     
    }
  cout<<count<<endl;
}

Measured memory_bytes: 3564
program making_triangle
  implicit none
  integer :: n, l(100) = 0, i, j, k, m = 0
  read(*,*) n
  read(*,*) l(1:n)
  do i = 1, n - 2
    do j = i + 1, n - 1
      if (l(j) == l(i)) cycle
      do k = j + 1, n
        if (l(k) == l(i)) cycle
        if (l(k) == l(j)) cycle
        if (l(i) >= l(j) + l(k)) cycle
        if (l(j) >= l(k) + l(i)) cycle
        if (l(k) >= l(i) + l(j)) cycle
        m = m + 1
      end do
    end do
  end do
  write(*,'(i0)') m
end program making_triangle

Measured memory_bytes: 2868
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			int[][] height = new int[201][201];
			int[][] top = new int[201][201];
			for(int i=0;i<n;i++) {
				int t = sc.nextInt();
				int f = sc.nextInt();
				int x = 100;
				int y = 100;
				Dice d = new Dice(t, f);
				ROLL: while(true) {
					int dir = -1;
					int max = -1;
					if (d.right  >= 4 && height[x][y] > height[x+1][y]) {
						if (d.right > max) {
							max = d.right;
							dir = 0;
						}
					}
					if (d.back  >= 4 && height[x][y] > height[x][y+1]) {
						if (d.back > max) {
							max = d.back;
							dir = 1;
						}
					}
					if (d.left  >= 4 && height[x][y] > height[x-1][y]) {
						if (d.left > max) {
							max = d.left;
							dir = 2;
						}
					}
					if (d.front  >= 4 && height[x][y] > height[x][y-1]) {
						if (d.front > max) {
							max = d.front;
							dir = 3;
						}
					}
					switch (dir) {
					case 0:
						d.rollRight();
						x++;
						break;
					case 1:
						d.rollBack();
						y++;
						break;
					case 2:
						d.rollLeft();
						x--;
						break;
					case 3:
						d.rollFront();
						y--;
						break;
					default:
						break ROLL;
					}
				}
				height[x][y]++;
				top[x][y] = d.top;
			}
			int[] ans = new int[7];
			for(int i=0;i<=200;i++) {
				for(int j=0;j<=200;j++) {
					ans[top[i][j]]++;
				}
			}
			System.out.print(ans[1]);
			for(int i=2;i<=6;i++) {
				System.out.print(" " + ans[i]);
			}
			System.out.println();
		}
	}

}
class Dice {
	int[][] d = {{-1,3,5,2,4,-1},{4,-1,1,6,-1,3},{2,6,-1,-1,1,5},{5,1,-1,-1,6,2},{3,-1,6,1,-1,4},{-1,4,2,5,3,-1}};
	int top,bottom,front,back,right,left;
	public Dice(int top,int front) {
		this.top = top;
		this.front = front;
		this.right = d[top-1][front-1];
		this.bottom = 7 - top;
		this.back = 7 - front;
		this.left = 7 - right;
	}
	public void rollRight() {
		int temp = top;
		top = left;
		left = bottom;
		bottom = right;
		right = temp;
	}
	public void rollLeft() {
		rollRight();
		rollRight();
		rollRight();
	}
	public void rollFront() {
		int temp = top;
		top = back;
		back = bottom;
		bottom = front;
		front = temp;
	}
	public void rollBack() {
		rollFront();
		rollFront();
		rollFront();
	}
}

Measured memory_bytes: 58180
import sys
input=sys.stdin.readline
n,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n-1)]
l2=[list(map(int,input().split())) for i in range(q)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)
L4=[0 for i in range(n)]
for i in range(q):
  L4[l2[i][0]-1]+=l2[i][1]
distance=[0 for i in range(n)]
distance[0]=L4[0]

L=[0]
L2=[]
L22=[-1]*n
L3=[]
while len(L2)!=n and len(L)!=0:
  for j in range(len(L)):
    L22[L[j]]=1
    for k in range(len(connection[L[j]])):
      if L22[connection[L[j]][k]]==-1:
        distance[connection[L[j]][k]]=distance[L[j]]+L4[connection[L[j]][k]]
        L3.append(connection[L[j]][k])
  L=L3
  L3=[]
for i in range(len(distance)):
  print(distance[i])

Measured memory_bytes: 129832
#include <cstdio>
using namespace std;
int main(int argc, char *argv[]) {
    int a, b;
    scanf("%d%d", &a,&b);
    if (a > 8 || b > 8) {
        printf(":(\n"); 
    }
    else {
        printf("Yay!\n"); 
    }
    return 0;
}

Measured memory_bytes: 128
/*
 	安部NANA先輩大好き

 */
#include<bits/stdc++.h>

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e9 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
typedef vector<int> vi;
typedef pair<int,int> pii;
vector<pii> vii;

bool used[2000006],use[2000006];
int x[2000006];

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k,m=0;
    stack<int> que;
    cin >> k >> n;
    m=n;
    if(n>1)m *= pow(n-1,k-1);
    cout << m << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a;
	int b;
	int d;
	int r;
	double f;

	scanf("%d %d", &a, &b);

	d = a/b;
	r = a%b;
	double c = b;
	f = a/c;

	printf("%d %d %f\n", d,r,f);

	return 0;
}




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

using namespace std;

int main(void) {
    int A, B, m;
    cin >> A >> B >> m;

    vector<int> a(A);
    vector<int> b(B);

    for (int i = 0; i < A; i++) cin >> a[i];
    for (int j = 0; j < B; j++) cin >> b[j];

    vector<int> ans;

    for (int i = 0; i < m; i++) {
        int x, y, c;
        cin >> x >> y >> c;

        ans.push_back(a[x - 1] + b[y - 1] - c);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(ans.begin(), ans.end());

    cout << min(ans[0], a[0] + b[0]) << endl;

    return 0;
}


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

int main(void){
  int N, D;
  cin >> N >> D;
  if(N % ( 2 * D + 1) == 0) cout << N / (2 * D + 1);
  else cout << N / (2 * D + 1) + 1;
  
 return 0;
  
}

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

int main()
{
	double val;

	while ( cin >> val, val > 0 ) {
		val *= 16;
		if ( fabs(val - (int)val) < 1e-6 ) {
			int dat = val;
			for ( int i = 11; i >= 0; i-- ) {
				cout << ((dat & (1 << i)) >> i);
				if ( i == 4 ) cout << ".";
			}
			cout << endl;
		} else {
			cout << "NA" << endl;
		}
	}

	return ( 0 );
}



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

int main( void )
{
    int N;
    while ( cin >> N && N ) {
        int W, H;
        cin >> W >> H;
        bool G[H][W];
        memset( G, false, sizeof(G) );
        for ( int i = 0; i < N; i++ ) {
            int x, y;
            cin >> x >> y;
            x--;
            y--;
            G[y][x] = true;
        }
        int S, T;
        cin >> S >> T;
        int answer = 0;
        for ( int i = 0; i + T - 1 < H; i++ ) {
            for ( int j = 0; j + S - 1 < W; j++ ) {
                int sum = 0;
                for ( int k = 0; k < T; k++) {
                    for ( int l = 0; l < S; l++ ) {
                        if ( G[i+k][j+l] ) sum++;
                    }
                }
                answer = max( sum, answer );
            }
        }
        cout << answer << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
double z, f[320][33], t;
int n, c, a[9];
int main() {
	cin >> n >> c;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	do {
		memset(f, 0, sizeof f);
		f[n * a[n - 1]][0] = 1;
		for (int i = 0; i < n * c; i++) {
			for (int j = i; j <= n * c; j++) {
				for (int k = 0; k < (1 << (n - 1)); k++) {
					if (i % n && (k >> (i % n - 1) & 1) == 0) {
						f[min(max(j, i + n * a[i % n - 1]), n * c)][k | (1 << (i % n - 1))] += f[j][k];
					}
				}
			}
		}
		z += f[n * c][(1 << (n - 1)) - 1];
		t++;
	} while (next_permutation(a, a + n - 1));
	printf("%.15f\n", z / t / pow(c, n - 1));
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
 int N,k;
 int final_cost=0;
 cin>>N>>k;
 int arr[N];
 for(int i=0;i<N;i++)
 {
     cin>>arr[i];
 }
 int size=sizeof(arr)/sizeof(arr[0]);
 sort(arr,arr+size); 
 
 
 for(int j=0;j<k;j++)
 {
     final_cost+=arr[j];
 }
 cout<<final_cost;
  return 0;
}

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

int main() {
    string days[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    for(int i = 0; i < 7; i++) {
        if(s == days[i]) {
            cout << 7 - i << endl;
            break;
        }
    }
    return 0;
}

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

int main( ){
  int X;
  cin>>X;
  if (X%7==1){cout<<"fri"<<endl;
  }else if (X%7==2){cout<<"sat"<<endl;
    }else if (X%7==3){cout<<"sun"<<endl;
    }else if (X%7==4){cout<<"mon"<<endl;
    }else if (X%7==5){cout<<"tue"<<endl;
    }else if (X%7==6){cout<<"wed"<<endl;
    }else if (X%7==0){cout<<"thu"<<endl;
    }
  return 0;
}



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

void score_print(vector<int> ar)
{
    for (int i=0; i<ar.size(); ++i) {
        if (ar[i] > 0) printf("Yes\n");
        else printf("No\n");
    }
}
int main()
{
    int n, k, q, A;
    vector<int> score;
    scanf("%d%d%d", &n, &k, &q);
    for (int i=0; i<n; ++i) score.push_back(k-q);
    for (int i=0; i<q; ++i) {
        scanf("%d", &A);
        score[A-1]++;
    }

    score_print(score);
    return 0;
}


Measured memory_bytes: 1528
import sys
sys.setrecursionlimit(pow(10, 8))

S = [6, 3, 1, 4, 2, 5]
H, W = map(int, input().split())
X = []
for i in range(H):
    X.append(input().strip())

def migi(S):
    return [S[1], S[2], S[3], S[0], S[4], S[5]]
def hidari(S):
    return [S[3], S[0], S[1], S[2], S[4], S[5]]
def sita(S):
    return [S[4], S[1], S[5], S[3], S[2], S[0]]
def ue(S):
    return [S[5], S[1], S[4], S[3], S[0], S[2]]

vs = set()

def dfs(x, y, s):
    if (x, y) == (H-1, W-1):
        return True
    vs.add((x, y))
    f = False
    if x+1 < H and (x+1, y) not in vs:
        ns = sita(s)
        if str(ns[0]) == X[x+1][y]:
            f = f|dfs(x+1, y, ns)
    if y+1 < W and (x, y+1) not in vs:
        ns = migi(s)
        if str(ns[0]) == X[x][y+1]:
            f = f|dfs(x, y+1, ns)
    if x-1 >= 0 and (x-1, y) not in vs:
        ns = ue(s)
        if str(ns[0]) == X[x-1][y]:
            f = f|dfs(x-1, y, ns)
    if y-1 >= 0 and (x, y-1) not in vs:
        ns = hidari(s)
        if str(ns[0]) == X[x][y-1]:
            f = f|dfs(x, y-1, ns)
    return f
if dfs(0, 0, S):
    print("YES")
else:
    print("NO")



Measured memory_bytes: 11760
// C++(GCC 9.2.1)
// 解き直し.
// https://img.atcoder.jp/abc173/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    LL N, u, v, uv = 0;
    scanf("%lld", &N);
    rep(i, (int)(N - 1)){
        scanf("%lld %lld", &u, &v);
        
        // 大小関係を考慮.
        if(u > v) swap(u, v);
        
        // 辺の出現数をカウント.
        // 辺 uv は, u * (N - v + 1)回分, 頂点集合 S に含まれるはず.
        uv += u * (N - v + 1);
    }
    
    // 2. 部分グラフの連結成分の個数の総和.
    // -> 頂点集合 S におけるすべての頂点の出現数の総和は, 
    // 1, 4, 10, 20, 35, 56, ... と 増加するので, N * (N + 1) * (N + 2) / 6 で 計算されるはず.
    LL ans = N * (N + 1) * (N + 2) / 6 - uv;
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;

}

Measured memory_bytes: 3844
import numpy as np

n, m, x = map(int, input().split())

books = []
prices = []
for _ in range(n):
    a = list(map(int, input().split()))
    c = a.pop(0)
    prices.append(c)
    books.append(a)

books = np.array(books)

ans = 10 ** 7
for i in range(2 ** n):
    sel = np.zeros(m)
    price = 0

    for j in range(n):
        if (i >> j) & 1:
            sel += books[j]
            price += prices[j]
    if (sel >= x).all() and price < ans:
        ans = price

if ans == 10 ** 7:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 27196
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 2019, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    string s;
    ll ans = 0;
    cin >> s;
    vector<ll> dp(N);
    for (char c : s)
    {
        vector<ll> d(N);
        for (ll j = 0; j < N; j++)
            d[(j * 10 + c - '0') % 2019] += dp[j];
        d[c - '0']++;
        dp = d;
        ans += dp[0];
    }
    cout << ans;
}

Measured memory_bytes: 3748
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

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 in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)



int main() {
	
	ll h, w,ans=0;
	in(h);
	in(w);
	vector<string> s(h);
	vector<vll> x(h, vll(w, 0)), y(h, vll(w, 0));
	rep(i, 0, h) {
		in(s[i]);
	}

	rep(i, 0, h) {
		ll tmp = -1;
		rep(j, 0, w) {
			if (s[i][j] == '.' && tmp < 0) {
				tmp = j;
			}
			else if (s[i][j] != '.' && tmp >= 0) {
				rep(k, tmp, j) {
					x[i][k] = j - tmp;
				}
				tmp = -1;
			}
		}
		if (tmp >= 0) {
			rep(k, tmp, w) {
				x[i][k] = w - tmp;
			}
		}
	}

	rep(j, 0, w) {
		ll tmp = -1;
		rep(i, 0, h) {
			if (s[i][j] == '.' && tmp < 0) {
				tmp = i;
			}
			else if (s[i][j] != '.' && tmp >= 0) {
				rep(k, tmp, i) {
					y[k][j] = i - tmp;
				}
				tmp = -1;
			}
		}
		if (tmp >= 0) {
			rep(k, tmp, h) {
				y[k][j] = h - tmp;
			}
		}
	}

	rep(i, 0, h) {
		rep(j, 0, w) {
			ans = max(ans, x[i][j] + y[i][j]-1);
		}
	}

	outn(ans);

	return 0;
}


Measured memory_bytes: 67072
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define int long long
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
struct Node{
    int x;
    int y;
}a[200005];
int n,x,y;
ll ans;
ll f[1000005],tag[1000005];
bool cmp(Node x,Node y){
    return x.x<y.x;
}
int work(int s){
    int l=1,r=n,sum=-1;
    while(l<=r){
        int mid=(l+r)>>1;
        if(a[mid].x<=s)l=mid+1,sum=mid;
        else r=mid-1;
    }
    return sum;
}
void pushup(int c){
    f[c]=max(f[c<<1],f[c<<1|1]);
}
void build(int c,int l,int r){
    if(l==r){
        f[c]=a[l].y;
        return;
    }
    int mid=(l+r)>>1;
    build(c<<1,l,mid);
    build(c<<1|1,mid+1,r);
    pushup(c);
}
void pushdown(int c){
    f[c<<1]+=tag[c];
    f[c<<1|1]+=tag[c];
    tag[c<<1]+=tag[c];
    tag[c<<1|1]+=tag[c];
    tag[c]=0;
}
void add(int x,int y,int l,int r,int c,int k){
    if(x<=l&&y>=r){
        f[c]+=k;
        tag[c]+=k;
        return;
    }
    pushdown(c);
    int mid=(l+r)>>1;
    if(x<=mid)add(x,y,l,mid,c<<1,k);
    if(y>mid)add(x,y,mid+1,r,c<<1|1,k);
    pushup(c);
}
int query(int x,int y,int l,int r,int c){
    if(x<=l&&y>=r)return f[c];
    pushdown(c);
    int mid=(l+r)>>1,sum=1<<31;
    if(x<=mid)sum=max(sum,query(x,y,l,mid,c<<1));
    if(y>mid)sum=max(sum,query(x,y,mid+1,r,c<<1|1));
    return sum;
}
signed main(){
	in(n);in(x);in(y);
    for(int i=1;i<=n;i++)in(a[i].x),in(a[i].y);
    sort(a+1,a+1+n,cmp);
    build(1,1,n);
    int i=1;
    while(i<=n){
        int s=a[i].x+x*2;
        int id=work(s);
        int g=query(i,i,1,n,1);
        int ci=(g+y-1)/y;
        ans+=ci;
        add(i,id,1,n,1,-(ci*y));
        int l=i,r=id,sum=i;
        while(l<=r){
            int mid=(l+r)>>1;
            if(query(i,mid,1,n,1)<=0)l=mid+1,sum=mid;
            else r=mid-1;
        }
        i=sum+1;
    }
    printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

int main()
{	
	int n;
	cin >> n;
	vector<long> cost(n + 2, 0);
	vector<long> v(n + 2, 0);
	v[n] = 2e9;
	cost[n] = 2e9;
	for (int i = 0; i < n; i++) {
		int h;
		cin >> h;
		v[i] = h;
	}

	for (int i = n - 2; i >= 0; i--) {
		cost[i] = min(cost[i + 1] + abs(v[i] - v[i + 1]), cost[i + 2] + abs(v[i] - v[i + 2]) );
	}

	cout << cost[0] << endl;

	return 0;
}


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

int main()
{
    string S;
    cin >> S;
    if (S.substr(0, 4).find("YAKI") != -1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
n = gets.chomp.to_i
c_str = gets.chomp

r_count = c_str.each_char.count {|c| c == "R" }
w_count = n - r_count

# 全部一色に変える場合の回数
min = [r_count, w_count].min

# 文字列の間に仕切りを1つ入れて, それより左の赤白の数, 右の赤白の数を管理
left = {red: 0, white: 0}
right = {red: r_count, white: w_count}
0.upto(c_str.length-1) do |i|
  if c_str[i] == "R"
    left[:red] += 1
    right[:red] -= 1
  else
    left[:white] += 1
    right[:white] -= 1
  end
  # left[:whilte]=0, right[:red]=0 にするような操作の回数を求める
  # leftにある白とrightにある赤を入れ替える操作を限界まで行って ... (*)
  # leftに残っている白の数 もしくは rightに残っている赤の数を数えるイメージ
  # (*)の操作を行うと必ず (left[:white] == 0 || right[:red] == 0) はtrueになる
  tmp = [left[:white], right[:red]].min + (left[:white] - right[:red]).abs
  min = tmp if tmp < min
end

puts min


Measured memory_bytes: 14676
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	vector<pair<int, int> > a;
	while (true) {
		int p, s;
		char mudaisyo;
		cin >> p >> mudaisyo >> s;
		if (p == s&&s == 0) { break; }
		a.push_back(make_pair(s, p));
	}
	Sort(a);
	Reverse(a);
	int t;
	
	while (cin >> t) {
		int last = 0;
		for (int i = 0; i < a.size() - 1; i++)
		{
			if (a[i].second == t) {
				cout << last + 1 << endl;
				break;
			}
			if (a[i].first != a[i + 1].first) {
				last ++;
			}
			if (i == a.size() - 2) {
				cout << last+1 << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3020
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int a,b; cin>>a>>b;
    cout<<max({a+b, a*b, a-b})<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    unsigned long long a[5000]={0},c=0,p,o,u;
    rep(i,n){
      scanf("%d%d%d",&p,&o,&u);
      a[p]+=o*u;
      if(a[p]>=1000000){cout<<p<<endl;c++;}
    }
    if(!c)cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 3192
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
ll u(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll d(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
ll f(ll a){
  return a*(a+1)/2;
}
int main(void){
  char s[100001];
  scanf("%s",s);
  int a[2]={0,0};
  FOR(strlen(s))a[s[i]-'0']++;
  PRN(min(a[0],a[1])*2);
  return 0;
}


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

signed main()
{
  cout << fixed << setprecision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;

  int ans = 0;

  for (int i = 0; i < n; ++i) {
    int h;
    cin >> h;
    if (h >= k) ++ans;
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N = 60;
int n,X,d,tot;
struct Tree{int val,id; ll cost; int friend operator <(const Tree &a,const Tree &b){return a.val * b.cost > b.val * a.cost;}} a[N];
int head[N]; ll f[N * N * N];
struct node{int nex,to;} e[N << 1];
void add(int f,int t) {e[++ tot].nex = head[f]; e[tot].to = t; head[f] = tot;}
void dfs(int now)
{
	a[now].val = 1; a[now].id = now;
	for(int i = head[now],to;i;i = e[i].nex)
	{
		to = e[i].to; dfs(to);
		a[now].val += a[to].val;
		a[now].cost += a[to].cost;
	}
}
int main()
{
	n = read(); X = read(); d = read(); a[1].cost = read();
	for(int i = 2;i <= n;i ++) a[i].cost = read(),add(read(),i);
	dfs(1); int mx = n * n * n,L = min(n,d); memset(f,0x3f,sizeof(f)); f[0] = 0;
	for(int i = 1,w,x;i <= n;i ++)
	{
		x = L;
		for(int j = 0;1 << j <= x;j ++)
		{
			w = a[i].val * (1 << j); ll v = a[i].cost * (1 << j);
			for(int k = mx;k >= w;k --) f[k] = min(f[k],f[k - w] + v);
			x -= 1 << j;
		}
		if(x)
		{
			w = a[i].val * x; ll v = a[i].cost * x;
			for(int j = mx;j >= w;j --) f[j] = min(f[j],f[j - w] + v);
		}
	}
	sort(a + 1,a + 1 + n); while(a[n].id != 1) n --; ll ans = 0;
	for(int i = 0;i <= mx;i ++)
	{
		if(f[i] > X) continue;
		ll w = i,v = f[i];
		for(int j = 1;j < n;j ++)
		{
			ll c = min((ll)d - L,(X - v) / a[j].cost);
			w += c * a[j].val; v += c * a[j].cost;
		}
		ll c = (X - v) / a[n].cost;
		w += c * a[n].val; v += c * a[n].cost;
		ans = max(ans,w);
	}
	cout << ans << "\n";
	return 0;
}
/*
3 100 1
15
10 1
20 1
*/

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1) {
        a-=d;
        c-=b;
        if(c<=0) {cout << "Yes" << endl; return 0;}
        if(a<=0) {cout << "No" << endl; return 0;}
    }
    
    return 0;
}

Measured memory_bytes: 3580
//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: 1160
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []

    t = [10,50,100,500]

    while True:
        n = I()
        if n == 0:
            break
        a = LI()
        sm = [0] * 4
        sm[0] = t[0] * a[0]
        for i in range(1,4):
            sm[i] = sm[i-1] + t[i] * a[i]

        tr = []
        for i in range(3,-1,-1):
            if i == 0 and n > 0:
                tr.append('{} {}'.format(t[i], n//t[i]))
                break
            tn = n - sm[i-1]
            c = (tn + t[i] - 1) // t[i]
            n -= t[i] * c
            if c > 0:
                tr.append('{} {}'.format(t[i], c))
        if len(rr) > 0:
            rr.append('')
        rr += tr[::-1]



    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9356
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vpiipi vector<piipi>
#define pb push_back
#define pob pop_back
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
#define mod 1000000007
// #define mod 163577857 
// #define mod 998244353
#define rep(i,n) for (int i = 0; i < n; i++)
#define repp(i,a,b) for(int i = a ; i<b ; i++)
#define reppr(i,a,b) for(int i = a-1 ; i>=b ; i--)
#define repr(i,n) for (int i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprec(x) cout << fixed << setprecision(x);
#define REVERSE(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()
 
//GCD and LCM
    int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }
    int lcm (int a, int b) { return a / gcd(a, b) * b; }
 
//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }
 
//Modular Inverse
    int inverse(int a) 
    { 
       return powmod(a,mod-2); 
    }

//Binomial Coefficients
    int fact[500010], factinv[500010] , coefficientflag = 0;
    void Util_nCr()
    {
        fact[0] = 1 , factinv[0] = 1;
        repp(i,1,500010)
        {
            fact[i] = (fact[i-1] * i)%mod;
            factinv[i] = (factinv[i-1] * inverse(i))%mod;
        }
    }
    int nCr(int n , int r)
    {
        if(!coefficientflag) coefficientflag = 1 , Util_nCr();             
        return ((fact[n] * inverse(fact[n-r]) % mod * inverse(fact[r]))%mod) ;
    }

void solve();
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    // cin >> t; 
    while(t--)
        solve();
} 

void solve()            
{
    string s;
    cin >> s;
    int ans = 0;
    int l = s.length();
    rep(i,l)
    {
        if(i==0)
        {
            if(s[i]=='?')
                ans++ , s[i] = 'D';
            else if(s[i]=='D')
                ans++;
        }
        else
        {
            if(s[i]=='?')
            {
                ans++ , s[i] = 'D';
                if(s[i-1]=='P')
                    ans++;
            }
            else if(s[i]=='D')
            {
                ans++;
                if(s[i-1]=='P')
                    ans++;
            }
        }
    }    
    cout << s << endl;
}

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

int rec(int a, int b){
  if(b == 0) return a;
  return rec(b, a%b);
}

int main(){
  string A, B; cin >> A >> B;
  string res = "EQUAL";
  if(A.size() > B.size()) res = "GREATER";
  else if(A.size() < B.size()) res = "LESS";
  else{
    for(int i = 0; i < A.size(); i++){
      if(A[i] > B[i]){
        res = "GREATER";
        break;
      }
      if(A[i] < B[i]){
        res = "LESS";
        break;
      }
    }
  }
  cout << res << endl;
}


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

int main(void){
  int count=0;
  while(1){
  cin >> count;
  if(count == 0) break;
  else{
    int maxkan,maxkyori=-1,kan=0,kyori1=0,kyori2=0;
    for(int i=0;i<count;i++){
      cin >> kan >> kyori1 >> kyori2;
       if(maxkyori < kyori1+kyori2){
         maxkan = kan;
         maxkyori = kyori1+kyori2;
       }
    }
    cout << maxkan << " " << maxkyori << endl;
   } 
  }
}

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

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            // 文字列配列の入力
            int[] kotae = new int[4] { 0,0,0,0};

            for (int i = 0; i < n; i++)
            {
                switch (Console.ReadLine())
                {
                    case "AC":
                        kotae[0]++;
                        break;
                    case "WA":
                        kotae[1]++;
                        break;
                    case "TLE":
                        kotae[2]++;
                        break;
                    case "RE":
                        kotae[3]++;
                        break;
                    default:
                        break;
                }
            }

            Console.WriteLine($@"AC x {kotae[0]}");
            Console.WriteLine($@"WA x {kotae[1]}");
            Console.WriteLine($@"TLE x {kotae[2]}");
            Console.WriteLine($@"RE x {kotae[3]}");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 30620
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    odd_count = 0
    for aa in a:
        if aa % 2 == 1:
            odd_count += 1

    if odd_count % 2 == 1:
        print('NO')
    else:
        print('YES')


Measured memory_bytes: 14112
import sys

def findset(x,element):
    if(x != element[x]):
        element[x] = findset(element[x],element)
    return element[x]

def union(x,y,rank,element):
    link(findset(x,element),findset(y,element),rank,element)

def link(x,y,rank,element):
    if(rank[x] > rank[y]):
        element[y] = x
    else:
        element[x] = y
        if(rank[x] == rank[y]):
            rank[y]+=1

n,q = map(int, input().split());

element = [i for i in range(n)]
rank = [0 for i in range(n)]

for i in range(q):
    query,x,y = map(int, input().split());
    if(query == 0):
        union(x,y,rank,element)
    else :
        if(findset(x,element) == findset(y,element)):
            print(1)
        else:
            print(0)


Measured memory_bytes: 6036
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	Scanner in = new Scanner(System.in);
	int[] points;
	int[][][] schedule;
	int N, ans;

	void simulateDate(boolean[] hersSche, int startMan, int res) {
		for (int i = startMan; i < N; i++) {
			boolean[] temp = Arrays.copyOf(hersSche, 23);
			nextMan: for (int j = 0; j < schedule[i].length; j++) {
				int start = schedule[i][j][0];
				int end = schedule[i][j][1];
				for (int k = start; k < end; k++) {
					if (hersSche[k]) {
						break nextMan;
					} else {
						temp[k] = true;
					}
				}
				if (j == schedule[i].length - 1) 
					simulateDate(temp, i + 1, res + points[i]);
			}
		}
		ans = (res > ans) ? res : ans;
	}

	public void run() {
		while (true) {
			N = in.nextInt();
			if (N == 0)
				break;
			ans = -1;
			boolean[] hersSche = new boolean[23];
			schedule = new int[N][][];
			points = new int[N];
			Arrays.fill(hersSche, false);
			for (int i = 0; i < N; i++) {
				int scheNum = in.nextInt();
				points[i] = in.nextInt();
				schedule[i] = new int[scheNum][2];
				for (int k = 0; k < scheNum; k++) {
					schedule[i][k][0] = in.nextInt();
					schedule[i][k][1] = in.nextInt();
				}
			}
			simulateDate(hersSche, 0, 0);
			System.out.println(ans);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 61588
import java.util.Scanner;

//Dessert Witch
public class Main{

	char[][] s;
	int[][] d = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	
	int[] put(int i, int j, char c){
		int[] r = new int[8];
		char foe = c=='o'?'x':'o';
		for(int k=0;k<8;k++){
			int ni = i+d[k][0], nj = j+d[k][1], len = 0;
			while(0<=ni&&ni<8&&0<=nj&&nj<8){
				if(s[ni][nj]==foe){
					len++; ni+=d[k][0]; nj+=d[k][1];
				}
				else if(s[ni][nj]==c){
					r[k] = len; break;
				}
				else break;
			}
		}
		return r;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		s = new char[8][];
		for(int i=0;i<8;i++)s[i]=sc.next().toCharArray();
		for(;;){
			boolean f1 = false, f2 = false;
			int pi = -1, pj = -1, max = 0;
			for(int i=0;i<8;i++)for(int j=0;j<8;j++){
				if(s[i][j]!='.')continue;
				int[] r = put(i, j, 'o');
				int c = 0;
				for(int x:r)c+=x;
				if(max<c){
					max = c; pi = i; pj = j;
				}
			}
			if(max==0)f1 = true;
			else{
				s[pi][pj] = 'o';
				int[] r = put(pi, pj, 'o');
				for(int k=0;k<8;k++){
					if(r[k]==0)continue;
					int ni = pi+d[k][0], nj = pj+d[k][1];
					while(0<=ni&&ni<8&&0<=nj&&nj<8&&s[ni][nj]=='x'){
						s[ni][nj] = 'o'; ni+=d[k][0]; nj+=d[k][1];
					}
				}
			}
			max = 0;
			for(int i=7;i>=0;i--)for(int j=7;j>=0;j--){
				if(s[i][j]!='.')continue;
				int[] r = put(i, j, 'x');
				int c = 0;
				for(int x:r)c+=x;
				if(max<c){
					max = c; pi = i; pj = j;
				}
			}
			if(max==0)f2 = true;
			else{
				s[pi][pj] = 'x';
				int[] r = put(pi, pj, 'x');
				for(int k=0;k<8;k++){
					if(r[k]==0)continue;
					int ni = pi+d[k][0], nj = pj+d[k][1];
					while(0<=ni&&ni<8&&0<=nj&&nj<8&&s[ni][nj]=='o'){
						s[ni][nj] = 'x'; ni+=d[k][0]; nj+=d[k][1];
					}
				}
			}
			if(f1&&f2)break;
		}
		for(int i=0;i<8;i++)System.out.println(new String(s[i]));
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

int n,k;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	k=rd();
	if (k==1) { puts("1");puts("1");return 0; }
	printf("%d\n",n=(k+3)/4*2);
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<n;j++)
		{
			int hh=(i+j)%n;
			if (i%2==1) hh+=n;
			if (hh>=k) hh-=n;
			printf("%d ",hh+1);
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
long long dp[100005];
int K;
long long f(int n, vector<int>&V){
	if(n == V.size() - 1) return 0;
	if(dp[n] != -1) return dp[n];
	long long ans = LLONG_MAX;
	for(int i=n+1, k = 0; i<V.size() && k < K;k++, i++)
		ans = min(ans, abs(V[n] - V[i]) + f(i, V));
	
	return dp[n] = ans;
}
int main() {
	int n;
	cin >> n >> K;
	memset(dp, -1, sizeof(dp));
	vector<int> V(n);
	for(int i=0; i<n;i++) cin >> V[i];
	cout << f(0, V);
	return 0;
}

Measured memory_bytes: 10752
#include <stdio.h>
 int main(void){
  int a,b,n,x,i;
 
  for(;;){
    i=0;
    scanf("%d%d",&n,&x);
    if(n+x == 0) break;
 
    for(a=1;a<=n;a++)
      for(b=a+1;b<=n;b++)
        if(b < x-a-b && x-a-b <= n)
          i++;
 
    printf("%d\n", i);
  }
 
  return 0;
}


Measured memory_bytes: 2068
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main()
{
	int i,j,x=0,N, L[200],L_longer,longer=0;

	scanf("%d", &N);

	for (i = 0; i < N * 2; i++)
		scanf("%d",&L[i]);

	for (i = 0; i < N * 2; i++)
	{
		for (j = 0; j < N * 2; j++)
		{
			if (longer < L[j])
			{
				longer = L[j];
				L_longer = j;
			}
		}
		if (i%2==1)
			x += L[L_longer];

		L[L_longer] = 0;
		longer = 0;
	}

	printf("%d", x);

	return 0;
}

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

int main(void)
{
    char str[15];
    scanf("%s", str);
    int ans = 100000000;
    for (int i = 0; i < strlen(str) - 2; i++)
    {
        int t = (str[i] - '0') * 100 + (str[i + 1] - '0') * 10 + (str[i + 2] - '0');
        if (ans > abs(t - 753))
            ans = abs(t - 753);
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>
#include <complex>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

bool is_prime(int n) {
  int max_n = (int)sqrt(n) + 1;
  FOR(i, 2, max_n) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main(){
  int M = 55555 + 1;
  int in(n);
  vector<int> primes;
  FOR(i, 2, M) {
    if(is_prime(i) and i % 5 == 1) {
      primes.push_back(i);
      if(--n == 0) break;
    }
  }
  for(auto itr = primes.begin(); itr != primes.end() - 1; itr++) {
    cout << *itr << " ";
  }
  out(*(primes.end() - 1));
}


Measured memory_bytes: 256
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/
#include<bits/stdc++.h>
#define mod 1000000007
#define modc 998244353
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define deb(x) cout << #x << " " << x << endl;
#define deb2(x,y) cout << #x << " " << x << " " <<  #y << " " << y << endl
#define deb3(x,y,z) cout << #x << " " << x << " " << #y << " " << y << " " << #z << " "  << z << endl;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using namespace std;
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
bool perfectSq(T n)
{
	if(sqrt(n) == floor(sqrt(n)))
		return true;
	else
		false;
}
void solve()
{
	ll i,j;
	ll sum = 0,prod = 1;
	string s;
	cin >> s;
	map<int,int>b;
	int n = s.length();
	int prev = 0,rem;
	b[0]++;
	for(i=n-1;i>=0;i--)
	{
		rem =  (((s[i]-'0')%2019)*(prod%2019)+prev)%2019;
	//	deb2(rem,i);
		sum+=b[rem];
		b[rem]++;
		prev = rem;
		prod*=10;
		prod%=2019;
	}
	cout << sum << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
	{
		solve();
	}
}


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

int main()
{
    int x,a[1000];
    int i,j,s;
    while(cin>>x)
    {
        s=0;
        if(x<4){cout<<"1"<<endl;break;}
        for( i=x/2;i>0;i--){
            for( j=x/2;j>1;j--){
                a[i]=pow(i,j);
                if(a[i]<=x){
                    s=max(s,a[i]);
                    //cout<<"s:"<<s<<" "<<endl;
                }
            }
        }
        cout<<s<<endl;
    }
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#ABC125C
import sys

n=int(input())

v=[]
c=[]
tmp = input().split()
tmp2 = input().split()
hoge = list(map(lambda a: int(a), tmp))
fuga = list(map(lambda a: int(a), tmp2))

sum=0
for i in range(0,n):
	v.append(hoge[i])
	c.append(fuga[i])
	if(v[i]>c[i]):
		sum+= v[i]-c[i]

print(sum)

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
 ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
    ll ans  = n * (mi+ma) /2;
    return ans;
}
ll kw(ll k,ll n){
    
    ll ans  =0;
    ll mi,ma;
    mi= wa(k,0,k-1);
    
    ma = wa(k,n-k+1,n);
    
    return (ma-mi +1)%modd;
}

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

    map<string, int> mp;

    REP(i,n){
        string s;
        cin >> s;

        mp[s] ++;
    }

    int m=0;

    for(auto x:mp){
        m = max(m,x.second);
    }

    for(auto x:mp){
        if(m == x.second){
            cout << x.first << endl;
        }
    }
    
}





Measured memory_bytes: 25216
import java.util.Scanner;

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

        int a, b, c, x;
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        x = sc.nextInt();

        int ans = 0;
        int t = 0;

        for(int i = 0; i <= a; i++){
            for(int j = 0; j <= b; j++){
                t = (x - (500*i + 100*j)) / 50;
                if(t >= 0 && t <= c) ans++;
            }
        }

        System.out.println(ans);

        sc.close();
    }
}

Measured memory_bytes: 22740