akhauriyash/Code-Regression huggingface dataset:
package main
import(
  "fmt"
)
func gdc(p int, q int) int{
  if p==0||q==0{
    return p+q
  }else if p>q{
    return gdc(p%q, q)
  }else{
    return gdc(p, q%p)
  }
}
func main(){
  var n, i, x, temp, tmp int
  fmt.Scan(&n, &x)
  a:=make([]int, n)
  b:=make([]int, n)
  for i=0;i<n;i++{
    fmt.Scan(&a[i])
    b[i]=a[i]-x
    if b[i]<0{
      b[i]*=-1
    }
    }
  temp=b[0]
  for i=0;i<n;i++{
    tmp=b[i]
    temp=gdc(temp, tmp)
  }
  fmt.Println(temp)
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod=2019;
//head

ll modpow(ll a, ll b) {
    if(b == 0) return 1;
    if(b == 1) return a % mod;
    ll p1 = modpow(a, b/2);
    if(b&1) {
        return ((p1 * p1 % mod) * a) % mod;
    } else {
        return (p1 * p1) % mod;
    }
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    string s;
    cin >> s;
    reverse(all(s));
    int curr = 0;
    int ans = 0;
    vector<int> cnt(2019, 0);
    cnt[0] = 1;
    for(int i = 0; i < s.size(); i++) {
        curr += (s[i] - 48)*modpow(10, i);
        curr %= mod;
        ans += cnt[curr];
        cnt[curr]++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int x; cin >> x;
  int count = 0, tmp, mn = 100001;
  bool flag;
  for(int j=x; j<1000001; ++j) {
    flag = true;
    for(int i=3; i<j; ++i) {
      if (j%i == 0) {
        flag = false;
        break;
      }
    } 
    //cout << j << endl;
    if (flag == true) {
      tmp = j;
      cout << tmp << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
x = input().split()
n, k = int(x[0]), int(x[1])
x = input().split()
l = [int(i) for i in x]
l = sorted(l)
x = set(l)
diff = len(x) - k
cnt_dic = {}
cnt =0
if diff <= 0:
    print(0)
else:
    same=1
    for i in range(1, n):
        if l[i] == l[i-1]:
            same += 1
        else:
            cnt_dic[l[i-1]] = same
            same = 1
    cnt_dic[l[n-1]] = same
    #print(cnt_dic)
    res = sorted(cnt_dic.items(), key = lambda kv:(kv[1], kv[0]))
    #print(res)
    sum = 0
    for i in range(diff):
        sum += res[i][1]
    print(sum)

Measured memory_bytes: 62976
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
int N;
const int Nmax = 1e5;
int A[Nmax];


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

    vector<ll> v;
    v.push_back(0);
    for(int i=0; i<N; i++) v.push_back(A[i]);
    v.push_back(0);

    ll sum = 0;
    for(int i=0; i<v.size()-1; i++) sum += abs(v[i]-v[i+1]);

    for(int i=1; i<v.size()-1; i++){
        cout << sum - abs(v[i-1]-v[i]) - abs(v[i]-v[i+1]) + abs(v[i-1]-v[i+1]) << endl;
    }

    return 0;
}

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

typedef struct{
    //***軸は半時計周り***
    int X[4];//top front btm back
    int Y[4];//front right back left
    int Z[4];//top left btm right
}Dice;

void init_dice(Dice *d, int arr[]){
    //top
    d->X[0] = arr[0];
    d->Z[0] = arr[0];
    //front
    d->X[1] = arr[1];
    d->Y[0] = arr[1];
    //right
    d->Y[1] = arr[2];
    d->Z[3] = arr[2];
    //left
    d->Y[3] = arr[3];
    d->Z[1] = arr[3];
    //back
    d->X[3] = arr[4];
    d->Y[2] = arr[4];
    //bottom
    d->X[2] = arr[5];
    d->Z[2] = arr[5];
}

int rotate_X(int X[], int Y[], int Z[], int n){ //n : how many loops?
    //North : n=1
    //South : n=3
    int tmp, i, j;
    for(i = 0; i < n; i++){
        for(j = 0; j < 3; j++){
            tmp = X[j + 1];
            X[j + 1] = X[j];
            X[j] = tmp;
        }
    }
    Z[0] = X[0];
    Y[0] = X[1];
    Z[2] = X[2];
    Y[2] = X[3];
}

int rotate_Y(int X[], int Y[], int Z[], int n){ //n : how many loops?
    //Left : n=1
    //Right : n=3
    int tmp, i, j;
    for(i = 0; i < n; i++){
        for(j = 0; j < 3; j++){
            tmp = Y[j + 1];
            Y[j + 1] = Y[j];
            Y[j] = tmp;
        }
    }
    X[1] = Y[0];
    Z[3] = Y[1];
    X[3] = Y[2];
    Z[1] = Y[3];
}

int rotate_Z(int X[], int Y[], int Z[], int n){ //n : how many loops?
    //East : n=1
    //West : n=3
    int tmp, i, j;
    for(i = 0; i < n; i++){
        for(j = 0; j < 3; j++){
            tmp = Z[j + 1];
            Z[j + 1] = Z[j];
            Z[j] = tmp;
        }
    }

    //sync
    X[0] = Z[0]; //top
    Y[3] = Z[1]; //left
    X[2] = Z[2]; //btm
    Y[1] = Z[3]; //right
}

void find_top(Dice *d, int ptn){
    int i;
    if(d->X[0] == ptn)return;
    for(i = 0; i < 3; i++){
        rotate_X(d->X, d->Y, d->Z, 1);
        if(d->X[0] == ptn){
            return;
        }
    }
    for(i = 0; i < 3; i++){
        rotate_Z(d->X, d->Y, d->Z, 1);
        if(d->X[0] == ptn){
            return;
        }
    }
    printf("NOT FOUND\n");
}

void find_front(Dice *d, int ptn){
    int i;
    if(d->Y[0] == ptn)return;
    for(i = 0; i < 3; i++){
        rotate_Y(d->X, d->Y, d->Z, 1);
        if(d->Y[0] == ptn){
            return;
        }
    }
    printf("NOT FOUND\n");
}

int main(){
    Dice d, *p = &d;
    int i, tmp[6];

    for(i = 0; i < 6; i++){
        scanf("%d", &tmp[i]);
        getchar();
    }

    init_dice(p, tmp);

    int n, top, front;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        getchar();
        scanf("%d %d", &top, &front);
        find_top(p, top);
        find_front(p, front);
        printf("%d\n", d.Y[1]);
    }

    // printf("%d\n", d.X[0]);
}



Measured memory_bytes: 2116
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
#define ll long long
typedef vector<int> vi;
//macros
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
int mod = 1e9+7;
/////////////////////////////////////////////////////////////SEGMENT  TREES////////////////////////////////////////////////
// const int N = 100000;  
// int n;
// int tree[2 * N]; 

// void build( int arr[])  
// {   
//     for (int i=0; i<n; i++) // insert leaf nodes in tree     
//         tree[n+i] = arr[i]; 
       
//     for (int i = n - 1; i > 0; --i) // build the tree by calculating parents add function here      
//         tree[i] = tree[i<<1] + tree[i<<1 | 1];     
// } 

// void updateTreeNode(int p, int value)  
// {   
//     tree[p+n] = value; 
//     p = p+n;

//     for (int i=p; i > 1; i >>= 1) 
//         tree[i>>1] = tree[i] + tree[i^1]; 
// } 
  
// // function to get sum on interval [l, r) 
// int query(int l, int r)  
// {  
//     int res = 0; 
      
//     // loop to find the sum in the range 
//     for (l += n, r += n; l < r; l >>= 1, r >>= 1) 
//     { 
//         if (l&1)  
//             res += tree[l++]; 
      
//         if (r&1)  
//             res += tree[--r]; 
//     } 
      
//     return res; 
// }

/////////////////////////////////////////////////////**********************/////////////////////////////////////////////////

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

void solution(){
	int n;
	cin >> n;
	vector<int> nums(n);
	for(int& x : nums){
		cin >> x; 
	}
	vector<int> dp(n,0);
	for(int i=1;i<n;i++){
		dp[i] = min(dp[i-1]+abs(nums[i] - nums[i-1]),(i-2 >=0 ? (dp[i-2]+abs(nums[i] - nums[i-2])) : INT_MAX));
	}
	cout << dp[n-1] << endl;
	return;
}
 
 
// void solution(){ //read a whole line from the input, possibly containing spaces
// 	string s;
// 	getline(cin,s);
// }
int main(){
	
    fio; // fast input output
    int t;
    t = 1;
    // cin >> t;
    while(t--){
    	// cout << "Case #" << t  << ": ";
        solution();
    }
    return 0;
};

Measured memory_bytes: 3864
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_V = 100010;

int main() {
    ll n;
    cin >> n;
    ll m = n/2;

    vl x0(MAX_V);
    vl x1(MAX_V); 
    rep(i, n) {
        ll v;
        cin >> v;
        if(i%2 == 0) {
            x0[v]++;
        }
        else {
            x1[v]++;
        }
    }

    vector<P> p0(MAX_V);
    vector<P> p1(MAX_V);
    rep(i, MAX_V) {
        p0[i] = make_pair(x0[i], i);
        p1[i] = make_pair(x1[i], i);
    }
    sort(rall(p0));
    sort(rall(p1));

    if(p0[0].second != p1[0].second) {
        out(n - (p0[0].first + p1[0].first));
    }
    else {
        ll y = n - (p0[0].first + p1[1].first);
        ll z = n - (p0[1].first + p1[0].first);
        out(min(y, z));
    }
    
    re0;
}

Measured memory_bytes: 4992
#include <stdio.h>
int main(){
	int i,a[26]={0};
	char w;
	
	while (scanf("%c",&w)!=EOF){
		if (w>='a'&&w<='z'){
			a[w-'a']++;
		}else if (w>='A'&&w<='Z'){
			a[w-'A']++;
		    
		}
	}
	for (i=0;i<26;i++){
		printf("%c : %d\n",i+'a',a[i]);	
	}
	return 0;
}



Measured memory_bytes: 2040
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <tuple>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <list>

using namespace std;


#define INF pow(10, 9)
// typedef priority_queue<tuple<int,int,int>, vector< tuple<int, int, int> >, greater< tuple<int, int, int> > > PQ;

typedef long long int ll;




int main(void)
{

    int tmp_d;
    cin >> tmp_d;
    const int N = tmp_d;
    int Array[N];
    ll Sum = 0;
    ll mod = pow(10, 9) + 7;
    for(int i=0; i<N; i++)
    {
        cin >> Array[i];
        Sum = (Sum+Array[i])%mod;
    }

    ll Total = 0;
    for(int i=0; i<N-1; i++)
    {
        Sum = (Sum-Array[i])%mod;
        if(Sum<0) Sum += mod;
        Total = (Total+Array[i] * Sum) % mod;
    }

    cout << Total << endl;






    return 0;
}


Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(b>=c)puts("delicious");
	else if(c-b<=a)puts("safe");
	else puts("dangerous");
	return 0;
}

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

int main(void)
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int kuriage = 0;
		int sum[200] = {};
		string a, b;
		bool f = true;
		cin >> a >> b;
		int sizea = a.size(), sizeb = b.size();
		if (sizea > 80 || sizeb > 80) f = false;
		else
			for (int j = 0; j < max(sizea, sizeb); j++)
			{
				if (sizea > j && sizeb > j) sum[j] = (a[sizea - j - 1] - '0') + (b[sizeb - j - 1] - '0') + kuriage;
				else if (sizea > j) sum[j] = (a[sizea - j - 1] - '0') + kuriage;
				else if (sizeb > j) sum[j] = (b[sizeb - j - 1] - '0') + kuriage;
				kuriage = 0;
				if (sum[j] > 9)
				{
					kuriage++;
					sum[j] -= 10;
				}
			}
			sum[max(sizea, sizeb)] = kuriage;
			int count = max(sizea, sizeb);
			while (sum[count] == 0 && count > 0) count--;
			if (count >= 80 || f == false) cout << "overflow" << endl;
			else
			{
				for (int j = count; j >= 0; j--)
					cout << sum[j];
				cout << endl;
			}
	}
	return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

int main(){
    int N; cin >> N;
    int h[100];
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
    int cnt=0;
    for(int i=0;i<N;i++){
        while(h[i]>0){
            int r;
            for(r=i+1;r<N;r++){
                if(h[r]==0) break;
            }
            for(int j=i;j<r;j++) h[j]--;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();
		int dx, dy;
		dx = tx - sx;
		dy = ty - sy;
		for (int i = 0; i < dx; i++) {
			System.out.print("R");
		}
		for (int i = 0; i < dy; i++) {
			System.out.print("U");
		}
		for (int i = 0; i < dx; i++) {
			System.out.print("L");
		}
		for (int i = 0; i < dy; i++) {
			System.out.print("D");
		}

		System.out.print("D");
		for (int i = 0; i <= dx; i++) {
			System.out.print("R");
		}
		for (int i = 0; i <= dy; i++) {
			System.out.print("U");
		}
		System.out.print("LU");
		for (int i = 0; i <= dx; i++) {
			System.out.print("L");
		}
		for (int i = 0; i <= dy; i++) {
			System.out.print("D");
		}
		System.out.print("R");
	}

}


Measured memory_bytes: 23492
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n; i++){
    if(n%i == 0){
      res.push_back(i);
      if(i != n/i) res.push_back(n/i);
    }
  }
  return res;
}

int main(void)
{
    ll N;cin>>N;
    vector<ll> res;
    res = divisor(N);
    sort(res.begin(), res.end());
    ll a = res[res.size()/2];
    int ans=1;
    while(a>=10){
      a /= 10; ans++;
    }

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


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
	 int dp[100001];
	int x;
	scanf("%d",&x);
	
	
		dp[0]=1;
	
	
	for(int i=1;i<=x;i++){
		if(i >= 100 && (dp[i-100] == 1 || dp[i-101]==1||dp[i-102]==1|| dp[i-103]==1||dp[i-104]==1||dp[i-105]==1))dp[i]=1;
		else dp[i]=0;
	}
 
	printf("%d\n",dp[x]);
	return 0;
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = 1
for a in A:
    ans *= a
    if ans>10**18:
        print(-1)
        exit()

if ans>10**18:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 21916
import math

n = int(input())
#a, b, c, d = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = input()
#list = list(s)

table2 = sorted(table, key=lambda x:(x[1]))
sum = 0
flag = 0


for i in range(n) :
    sum += table2[i][0]
    if (sum > table2[i][1]) :
        flag = 1


if (flag == 0) :
    print("Yes")
else :
    print("No")

Measured memory_bytes: 42824
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n;
vector<int> graf[100010];
ll res[100010][2];
bool mark[100010][2];
ll modul = 1000000007;

ll resi(int cvor, int boja, int predak)
{
	if(mark[cvor][boja])
		return res[cvor][boja];
	mark[cvor][boja]=true;
	ll ret=1;
	if(boja==0) //bela	
	{
		for(int i=0;i<graf[cvor].size();i++)
			if(graf[cvor][i]!=predak)
				ret=(ret*(resi(graf[cvor][i],1,cvor)+resi(graf[cvor][i],0,cvor)))%modul;
	}
	else //crna
	{
		for(int i=0;i<graf[cvor].size();i++)
			if(graf[cvor][i]!=predak)
				ret=(ret*resi(graf[cvor][i],0,cvor))%modul;
	}
	res[cvor][boja]=ret;
	return ret;
}

int main()
{
	ios::sync_with_stdio(false);	
	cin.tie(0);
	
	cin>>n;
	int u,v;
	for(int i=0;i<n-1;i++)
	{
		cin>>u>>v;
		graf[u].push_back(v);
		graf[v].push_back(u);
	}
	
	cout<<(resi(1,1,0)+resi(1,0,0))%modul;
	
	return 0;
}


Measured memory_bytes: 15872
// 2717 ???????????????
import java.util.Scanner;
class Main{
    
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int S =sc.nextInt();
        int h=S/3600;
        int m=S%3600/60;
        int s=S%3600%60;
        System.out.println(h+":"+m+":"+s);
        
    }
}

Measured memory_bytes: 17228
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    PII x1,x2;
    R(x1.F,x1.S);
    R(x2.F,x2.S);
    int dx=x2.F-x1.F;
    int dy=x2.S-x1.S;
    tie(dx,dy)=MP(-dy,dx);
    PII x3=MP(x2.F+dx,x2.S+dy);
    tie(dx,dy)=MP(-dy,dx);
    PII x4=MP(x3.F+dx,x3.S+dy);
    W(x3,x4);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
dp = [0 for _ in range(N)]
dp[N-2] = abs(H[N-1]-H[N-2])
for i in range(N-3,-1,-1):
    dp[i] = abs(H[i+1]-H[i])+dp[i+1]
    if i+2<N:
        dp[i] = min(dp[i],abs(H[i+2]-H[i])+dp[i+2])
print(dp[0])

Measured memory_bytes: 52720
#include <stdio.h>
#define MAX 500000

void maxHeapify(int);
void swap(int *a,int *b);

int H,A[MAX+1];

int main(){
  int i;

  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }

  for(i=H/2;i>=1;i--){
    maxHeapify(i);
  }

  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}

void maxHeapify(int i){
  int left,right,max;
  left=2*i;
  right=2*i+1;

  
  if(left<=H && A[left]>A[i]){
    max=left;
  }else max=i;

  if(right<=H && A[right]>A[max]){
    max=right;
  }

  if(max!=i){
    swap(&A[i],&A[max]);
    maxHeapify(max);
  }
}


void swap(int *a,int *b){
  int temp;

  temp=*a;
  *a=*b;
  *b=temp;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int a, b;
    cin >> a >> b;
    if (a <= b)
    {
        cout << a << endl;
    }
    else
    {
        cout << a - 1 << endl;
    }
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

Measured memory_bytes: 38632
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */

struct UnionFind {
    vector<int> par;
    vector<ll> siz;
    UnionFind(int N) : par(N), siz(N, 1LL) {
        for(int i = 0; i < N; ++i) {
            par[i] = i;
        }
    }
    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        siz[ry] += siz[rx];
        par[rx] = ry;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    ll size(int x) {
        return siz[root(x)];
    }
};

int main() {
    int H, W; cin >> H >> W;
    int c[10][10];
    rep(i, 10)
        rep(j, 10)
            cin >> c[i][j];
    vector<int>mp(10, INF);
    mp[1] = 0;
    for(int i = 0; i < 10; ++i) {
        vector<int> v;
        for(int j = 0;j < 10; ++j) {
            if(j != i)
                v.pb(j);
        }
        do {
            int tmpMP = 0;
            int prev = i;
            for(auto x : v){
                tmpMP += c[prev][x];
                prev = x;
                if(x == 1)break;
            }
            mp[i] = min(mp[i], tmpMP);
        } while(next_permutation(v.begin(), v.end()));
    }
    int A[H][W];
    int ans = 0;
    rep(i, H){
        rep(j, W){
            cin >> A[i][j];
            if(A[i][j] != -1)ans += mp[A[i][j]];}}
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
int main(){
char str[20];
char c;
int i = 0;
memset(str, '\n', 20);
while((c = getchar()) != '\n'){
str[i++] = c;
}
while(i--){
printf("%c", str[i]);
}
printf("\n");
return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int a;
    int b;
    int c;
    int pop;
    cin >> a >> b >> c;

    if (b > c) {
      pop = b;
      b = c;
      c = pop;
      pop = 0;
    }
    
    if (a > b) {
      pop = a;
      a = b;
      b = pop;
      pop = 0;
    }
    
    if (b > c) {
      pop = b;
      b = c;
      c = pop;
      pop = 0;
    }


    cout << a << " " << b << " " << c << endl;

    return 0;
}



Measured memory_bytes: 3016
n = int(input())
ll = [input() for _ in range(n)]

check = 0
i = 0
for i in range(len(ll)-1):
    if ll[i] in ll[i+1:]:
        check = 1
    if ll[i][len(ll[i])-1] != ll[i+1][0]:
        check = 1

if check == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int LLu;

using namespace std;

const int N =  300000+5;
const int MOD = 998244353;
const int INF = 1e9+7;

inline int read() {
    int x = 0,f=1;char ch = getchar();
    for(; ch<'0'||'9'<ch; ch=getchar()) if(ch == '-') f=-1;
    for(; '0'<=ch&&ch<='9'; ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
    return x*f;
}

#define lal puts("****");
#define pb push_back
#define mp make_pair

/********************************************************/
int n,m;
int main(){
    scanf("%d%d",&n,&m);
    printf("%d\n",(n-1)*(m-1));
    return 0;
}


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

int main(void)
{
	int a, b;
	while(cin >> a >> b){
		int max = 1, min = 1;
		for (int i = 2; ; ++i)
		{
			if(a % i == 0 && b % i == 0){
				a /= i;
				b /= i;
				max *= i;
				min *= i;
				i--;
			}
			if(a / i == 0 && b / i == 0){
				break;
			}
		}
		min *= a * b;
		cout << max << " " << min << endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  long long la,lb;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> a >> b;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  if(a > 9 || b > 9) ans = -1;
  else ans = a*b;

  cout << ans << endl;

}

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

int main()
{ 
  int min = 1000;
  string s;
  cin >> s;

  int size = s.size();
  for(int i = 0; i  < size - 2; i++){
    int tmp = atoi((s.substr(i, 3)).c_str());
    if(min > abs(753 - tmp))
      min = abs(753 - tmp);
  }

  cout << min << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

min_a = min(a)
max_a = max(a)
ans_lst = []

for i in range(min_a, max_a + 1):
  sum_ans = 0
  for j in a:
    sum_ans += (i - j) ** 2
  ans_lst.append(sum_ans)
print(min(ans_lst))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000
void CountingSort(int*,int*,int*,int,int);
int main(){
  int *A, *B;
  int C[VMAX+1];
  int n, i, j,max;

  scanf("%d", &n);

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);
  
  for(i=1;i<n+1;i++)
    {
      scanf("%d",&A[i]);
      if(i==1) max = A[i];
      if(max < A[i]) max = A[i];
    }
  CountingSort(A,B,C,n,max);
  for(i=1;i<n;i++)
    {
      printf("%d ",B[i]);
    }
  printf("%d\n",B[i]);
  return 0;
}
void CountingSort(int *A,int *B,int *C,int n,int max){
  int i,j;
  for(i=0;i<=max;i++)
    {
      C[i]=0;
    }
  for(j=1;j<=n;j++)
    {
      C[A[j]]++;
    }
  for(i=1;i<=max;i++)
    {
      C[i]=C[i] + C[i-1];
    }
  for(j=n;j>0;j--)
    {
      B[C[A[j]]] = A[j];
      C[A[j]]--;
    }
}



Measured memory_bytes: 17468
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    private final int N;

    AtCoder(FastScanner sc) {
        N = sc.nextInt();

    }

    void solve(PrintWriter out) {
        String ans = "No";
        for (int i = 1; i <= N; i++) {
            if (N % i == 0 && i < 10 && N / i < 10) {
                ans = "Yes";
            }
        }
        out.println(ans);
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

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

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

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

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

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

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

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

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

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


Measured memory_bytes: 21460
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc042/tasks/abc042_b

int main() {

    int N, L;
    cin >> N >> L;
    string arr[N];

    REP(i, N) {
        cin >> arr[i];
    }

    sort(arr, arr+N);

    REP(i, N) {
        cout << arr[i];
    }

    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			boolean []s=new boolean[13];
			boolean []h=new boolean[13];
			boolean []c=new boolean[13];
			boolean []d=new boolean[13];
			
			int x;
			
			
			for(int a=0;a<n;++a){
				String b = sc.next();
				if(b.equals("S")){
					x=sc.nextInt();
					s[x-1]=true;
				}else if(b.equals("H")){
					x=sc.nextInt();
					h[x-1]=true;
				}else if(b.equals("C")){
					x=sc.nextInt();
					c[x-1]=true;
				}else if(b.equals("D")){
					x=sc.nextInt();
					d[x-1]=true;
				}
			}
			for(int a=1;a<=13;++a){
				if(s[a-1]!=true){
					System.out.println("S "+a);
				}
			}
			for(int a=1;a<=13;++a){
				if(h[a-1]!=true){
					System.out.println("H "+a);
				}
			}
			for(int a=1;a<=13;++a){
				if(c[a-1]!=true){
					System.out.println("C "+a);
				}
			}
			for(int a=1;a<=13;++a){
				if(d[a-1]!=true){
					System.out.println("D "+a);
				}
			}
	}

}

Measured memory_bytes: 26268
def sum_all(x):
  return int(x%10 + (x//10)%10 + (x//100)%10 + (x//1000)%10 + x//10000)
N, A, B = map(int, input().split())
ans_list = []
for i in range(1, N+1):
  if sum_all(i) >= A and sum_all(i) <= B:
    ans_list.append(i)
print(sum(ans_list))

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

int main(void) {
  int x, y;
  cin >> x >> y;
  if(2*x <= y && y <= 4*x && y%2 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
int d;
cin >> d;
vector<int> c(26);
rep(i,26) cin >> c.at(i);
vector<vector<int>> s(d,vector<int>(26));
rep(i,d)rep(j,26) cin >> s.at(i).at(j);

rep(i,d) cout << 20 << endl;
 }


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
using namespace std;

int main()
{
   int t;t=1;
   FAST
   while(t--)
   {
       int a,b,c,d;cin>>a>>b>>c>>d;
       bool ok1,ok2=true;
       while(true)
       {
           c-=b;
           if(c<=0) 
           {
               ok1=false;
               break;
           }
           a-=d;
           if(a<=0)
           {
               ok2=false;
               break;
           }
       }
       cout<<(ok2==false ? "No\n":"Yes\n");
      for(int zz=0;zz<1000;zz++) if(zz%2==0) zz++; 
    for(int zz=0;zz<1000;zz++) if(zz%2==0) zz++; 
    for(int zz=0;zz<1000;zz++) if(zz%2==0) zz++; 
    for(int zz=0;zz<1000;zz++) if(zz%2==0) zz++; 
    for(int zz=0;zz<1000;zz++) if(zz%2==0) zz++; 
    for(int zz=0;zz<1000;zz++) if(zz%2==0) zz++; 
    for(int zz=0;zz<1000;zz++) if(zz%2==0) zz++; 
   }
}


Measured memory_bytes: 3588
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define REP(i, k) for (decltype(k) i = 0; i < k; i++)
#define LOOP(k) REP (ngtkana_is_a_genius, k)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

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

    vec<usize> a(5);
    for (usize& x: a) std::cin >> x;
    for (usize i=0; i<5; i++) {
        if (a.at(i)==0) {
            std::cout << i + 1 << '\n';
        }
    }
}


Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int solve(int w,int h){
    int res = 0;
    vector<vector<char>> masu(h+2,vector<char>(w+2,'#'));
    pii S;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> masu[i][j];
            if(masu[i][j] == '@'){
                masu[i][j] = '.';
                S = {i,j};
            }
        }
    }
    vector<vector<int>> flag(h+2,vector<int>(w+2,0));
    queue<pii> q; q.push(S);
    int dxy[5] = {1,0,-1,0,1};
    while(q.size()){
        int x,y; tie(x,y) = q.front(); q.pop();
        if(masu[x][y] == '#') continue;
        if(flag[x][y] == 1) continue;
        flag[x][y] = 1;
        for(int k = 0; k < 4;k++){
            int nx = x + dxy[k],ny = y + dxy[k+1];
            q.push({nx,ny});
        }
    }
    for(auto& vec:flag) res += accumulate(vec.begin(),vec.end(),0);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int w,h;
    while(cin >> w >> h, w|h){
        cout << solve(w,h) << endl;
    }
    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;


void slove() {
	string s;
	ll n; cin >> n;
	cin >> s;
	ll l = s.size();
	if (n >= l) cout << s;
	else {
		cout << s.substr(0, n) << "...";
	}
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:\\Users\\Fish_Brother\\Desktop\\in", "r", stdin);
	//freopen("C:\\Users\\Fish_Brother\\Desktop\\out", "w", stdout);
#endif
	//int t; cin >> t; while(t--)
	slove();

	return 0;
}

Measured memory_bytes: 3656
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n=gets.to_i
a=get_i

class SegTree
  attr_accessor:node,:n
  def initialize(n)
    @n=1
    @n*=2 while @n<n
    @node=array(2*@n-1,1,0)
  end
  
  def update(i,x)
    i+=@n-1
    @node[i]=x
    while i>0
      i=(i-1)/2
      @node[i]=@node[i*2+1].gcd(@node[i*2+2])
    end
  end

  def find_gcd(s,t,i,l,r)
    return 0 if r<=s or t<=l
    return @node[i] if s<=l and r<=t
    mid=(l+r)/2
    leaf_l=find_gcd(s,t,i*2+1,l,mid)
    leaf_r=find_gcd(s,t,i*2+2,mid,r)
    return leaf_l.gcd(leaf_r)
  end
end
st=SegTree.new(n)
n.times do|i|
  st.update(i,a[i]) 
end

max=1
for i in 0..n-1
  if i.zero?
    l_val=0
    r_val=st.find_gcd(i+1,n,0,0,st.n)
  elsif i==n-1
    l_val=st.find_gcd(0,i,0,0,st.n)
    r_val=0
  else
    l_val=st.find_gcd(0,i,0,0,st.n)
    r_val=st.find_gcd(i+1,n,0,0,st.n) 
  end
  val=l_val.gcd(r_val)
  max=val if max<val
end
puts max

Measured memory_bytes: 11804
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll a, b;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b;

  ll d = b - a + 1;
  ll ans = 0;
  if(a % 2 != 0) {
    ans = a;
    d -= 1;
  }

  if(b % 2 == 0) {
    ans = ans ^ b;
    d -= 1;
  }

  if((d / 2) % 2 == 0) ans = ans ^ 0;
  else ans = ans ^ 1;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int N, K, s, minsum = 0;
	scanf("%d%d", &N, &K);
	/*
		printf("%d %d\n", N, K);
	*/
	for(int i = 0; i < N; i++)
	{
		scanf("%d", &s);
		if(s > K - s)
			minsum += 2 * (K - s);
		else
			minsum += 2 * s;
	}
	printf("%d", minsum);
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main()
{
    int i, n, d, min, max, R_t[200000];
    scanf("%d %d %d", &n, &R_t[0], &R_t[1]);

    min = R_t[0];
    max = R_t[1] - R_t[0];
    if(R_t[0] > R_t[1]) min = R_t[1];

    for(i = 2; i < n; i++){
        scanf("%d", &R_t[i]);
        d = R_t[i] - min;
        if(max < d) max = d;
        if(min > R_t[i]) min = R_t[i];
    }

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

    return 0;
}

Measured memory_bytes: 1804
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

	int A_best[3];
	int B_best[3];

int main(){
	int buf;
	for (int a = 0; a < 10; a++){
		scanf("%d", &buf);
		if (A_best[0] < buf){
			A_best[2] = A_best[1];
			A_best[1] = A_best[0];
			A_best[0] = buf;
			continue;
		}
		if (A_best[1] < buf){
			A_best[2] = A_best[1];
			A_best[1] = buf;
			continue;
		}
		if (A_best[2] < buf){
			A_best[2] = buf;
			continue;
		}
	}
	for (int a = 0; a < 10; a++){
		scanf("%d", &buf);
		if (B_best[0] < buf){
			B_best[2] = B_best[1];
			B_best[1] = B_best[0];
			B_best[0] = buf;
			continue;
		}
		if (B_best[1] < buf){
			B_best[2] = B_best[1];
			B_best[1] = buf;
			continue;
		}
		if (B_best[2] < buf){
			B_best[2] = buf;
			continue;
		}
	}
	printf("%d %d\n", A_best[0] + A_best[1] + A_best[2],
		B_best[0] + B_best[1] + B_best[2]);
	return 0;
}

Measured memory_bytes: 2732
#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
int main(){
  int R;
  cin >> R;
  if(R<1200){
    cout << "ABC" << endl;
  }
  if(1200<=R && R<2800){
    cout << "ARC" << endl;
  }
  if(2800<=R){
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n, m;
    while(cin >> n >> m, n || m) {
        map<string, pii> mp;
        rep(i,0,n) {
            string s; int a, b;
            cin >> s >> a >> b;
            int st = b - a + 1;
            mp[s] = pii(st, b);
        }
        rep(i,0,m) {
            int inp; cin >> inp;
            bool ok = false;
            for(auto x : mp) {
                int s = x.second.first;
                int t = x.second.second;
                if(s <= inp && inp <= t) {
                    int year = inp - s + 1;
                    cout << x.first << " " << year << endl;
                    ok = true;
                    break;
                }
            }
            if(!ok) cout << "Unknown" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3144
package main

import (
	"fmt"
)

func main(){
	var A,B,C,K int
	fmt.Scan(&A,&B,&C,&K)
    if A >= K {
        fmt.Println(K)
        return
    } else if(A+B >= K) {
        fmt.Println(A)
        return
    }else if(A+B+C >= K) {
        fmt.Println(A - (K - A - B))
        return
    }

}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, x, c, d;
  cin >> a >> b >> x;
  if (a % x > 0) {
    c = (a / x + 1) * x;
  } else {
    c = a;
  }
  if (b % x > 0) {
    d = b / x * x;
  } else {
    d = b;
  }
  cout << (d - c) / x + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int dp[50];

int fib(int n){
  if(n==0 || n==1){
    return dp[n]=1;
  }
  if(dp[n]!=-1){
    return dp[n];
  }
  return dp[n]=fib(n-1)+fib(n-2);
}

int main(){
  int n,i;
  for(i=0;i<50;i++) dp[i]=-1;

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}



Measured memory_bytes: 2104