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

using namespace std;

//long long
const long long NN = 210000;
struct so {
	long long x , i;
} s[NN*2];
struct node {
	long long l , r , s;
	node *ll , *rr;
} pool[NN*2] , *t;
long long top;
long long n , row , col;
long long x[NN] , y[NN] , cnt;
bool cmp ( so x1 , so x2 ) {
	return x1.x < x2.x;
}
long long get ( long long xx , long long yy ) {
	if ( xx == 0 ) return yy;
	else {
		if ( yy == col ) {
			return col + xx;
		}
		else {
			if ( xx == row ) {
				return row + col + (col-yy);
			}
			else return row + col + col + (row-xx);
		}
	}
}
void update ( node *id ) {
	id -> s = id -> ll -> s + id -> rr -> s;
}
void buildtree ( node *id , long long l , long long r ) {
	//printf ( "%lld %lld\n" , l , r );
	id -> l = l; id -> r = r;
	if ( l == r ) return ;
	long long mid = (l+r)/2;
	id -> ll = &pool[++top]; id -> rr = &pool[++top];
	buildtree ( id -> ll , l , mid ); buildtree ( id -> rr , mid + 1 , r );
}
void change ( node *id , long long l , long long c ) {
	if ( id -> l == id -> r ) {
		id -> s += c;
		return ;
	}
	long long mid = (id->l+id->r)/2;
	if ( l <= mid ) change ( id -> ll , l , c );
	else change ( id -> rr , l , c );
	update ( id );
}
long long query ( node *id , long long l , long long r ) {
	//printf ( "%lld %lld %lld %lld\n" , id -> l , id -> r , l , r );
	if ( id -> l == l && id -> r == r ) {
		return id -> s;
	}
	long long mid = (id->l+id->r)/2;
	if ( r <= mid ) return query ( id -> ll , l , r );
	else {
		if ( l > mid ) return query ( id -> rr , l , r );
		else return query ( id -> ll , l , mid ) + query ( id -> rr , mid + 1 , r );
	}
}
void work () {
	long long i , k , x1 , y1 , x2 , y2 , tmp;
	scanf ( "%lld%lld%lld" , &row , &col , &n );
	for ( i = 1 ; i <= n ; i++ ) {
		scanf ( "%lld%lld%lld%lld" , &x1 , &y1 , &x2 , &y2 );
		if ( x1 != 0 && x1 != row && y1 != 0 && y1 != col ) continue;
		if ( x2 != 0 && x2 != row && y2 != 0 && y2 != col ) continue;
		x[++cnt] = get ( x1 , y1 ); y[cnt] = get ( x2 , y2 );
		s[cnt*2-1].x = x[cnt]; s[cnt*2-1].i = cnt;
		s[cnt*2].x = y[cnt]; s[cnt*2].i = -cnt;
	}
	sort ( s + 1 , s + 1 + cnt * 2 , cmp );
	k = 0;
	for ( i = 1 ; i <= cnt * 2 ; i++ ) {
		if ( i == 1 || s[i].x != s[i-1].x ) k++;
		if ( s[i].i > 0 ) x[s[i].i] = k;
		else y[-s[i].i] = k;
	}
	//printf ( "%lld\n" , k );
	t = &pool[++top];
	if ( k != 0 ) buildtree ( t , 1 , k );
	for ( i = 1 ; i <= cnt ; i++ ) {
		if ( x[i] > y[i] ) swap ( x[i] , y[i] );
		if ( query ( t , x[i] , y[i] ) != 0 ) {
			printf ( "NO\n" );
			return ;
		}
		tmp = (rand()*32767) + rand();
		change ( t , x[i] , tmp );
		change ( t , y[i] , -tmp );
	}
	printf ( "YES\n" );
}
int main () {
	work ();
	return 0;
}

Measured memory_bytes: 23936
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
int a[100005][5], p[100005][5];
 
int main()
{
    int n, i, j;
    cin>>n;
    for (i=0;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
            if(i==0)
            {
                p[i][j]=a[i][j];
            }
            else if(j==0)
            {
                p[i][j]=a[i][j]+max(p[i-1][1],p[i-1][2]);
            }
            else if(j==1)
            {
                p[i][j]=a[i][j]+max(p[i-1][0],p[i-1][2]);
            }
            else if(j==2)
            {
                p[i][j]=a[i][j]+max(p[i-1][1],p[i-1][0]);
            }
        }
    }
    n--;
    cout<<max(p[n][0],max(p[n][1],p[n][2]))<<"\n";
 
    return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
#define MAX         100000
#define D(x)        cerr << #x " = " << (x) << endl

// Dynamic Convex Hull
struct point{
    LL x, y;
    point(){}
    point(int xx, int yy){
        x = xx;
        y = yy;
    }
};

bool operator < (const point &u, const point &v){
    if(u.x == v.x) return u.y < v.y;
    return u.x < v.x;
}

LL signedArea(point a, point b, point c)
{
    LL ret = (LL) a.x* (b.y - c.y) + (LL) b.x*(c.y - a.y) + (LL) c.x*(a.y - b.y);
    if(ret < 0) return -1;
    if(ret > 0) return +1;
    return 0;
}

LL triArea(point a, point b, point c) { return abs((LL) a.x* (b.y - c.y) + (LL) b.x*(c.y - a.y) + (LL) c.x*(a.y - b.y)); }

struct Dynamic_Convex_Hull{

    deque< point > hull;
    int n;
    LL Area;

    Dynamic_Convex_Hull(){
        Area = 0;
        n = 0;
        hull.clear();
    }

    bool brute(point p)
    {
        if(n < 3){
            n++;
            hull.push_back(p);
            if(n == 3 && signedArea(hull[0], hull[1], hull[2]) < 0) swap(hull[0], hull[1]);
            if(n == 3) Area = triArea(hull[0], hull[1], hull[2]);
            return true;
        }
        return false;
    }

    void addPoint(point p)
    {
        while(true){
            if(brute(p)) return;
            if(signedArea(p, hull.back(), hull[hull.size() - 2]) > 0){
                hull.push_front(hull.back());
                hull.pop_back();
            }
            else  break;
        }


        point previous = hull.back();
        while(true){
            if(brute(p)) return;
            if(signedArea(p, hull[0], hull[1]) < 0)
            {
                Area += triArea(p, hull[0], previous);
                previous = hull.front();
                n--, hull.pop_front();
            }
            else break;
        }
        Area += triArea(p, hull[0], previous);

        n++;
        hull.push_back(p);
    }
}solver;

point pnt[MAX+5];
bool imp[MAX+5];

LL prefix[MAX+5];
LL suffix[MAX+5];

const int limit = 1000000000;

int main()
{
    //freopen("in.txt", "r", stdin);

    int i, j, k, n;
    LL res = numeric_limits<LL>::max();

    scanf("%d", &n);
    for(i = 1; i <= n; i++)
        scanf("%lld %lld", &pnt[i].x, &pnt[i].y);

    sort(pnt + 1, pnt + n + 1);
    for(i = 1; i < n; i++)
        if(pnt[i].x == pnt[i+1].x)
            imp[i] = true;

    solver = Dynamic_Convex_Hull();

    for(i = 1; i <= n; i++)
    {
        solver.addPoint(pnt[i]);
        prefix[i] = solver.Area;
    }

    for(i = 1; i <= n; i++)
    {
        pnt[i].x = limit - pnt[i].x;
        pnt[i].y = limit - pnt[i].y;
    }
    sort(pnt + 1, pnt + n + 1);

    solver = Dynamic_Convex_Hull();
    for(i = 1; i <= n; i++)
    {
        solver.addPoint(pnt[i]);
        suffix[ n - i + 1 ] = solver.Area;
    }

    for(i = 1; i <= n; i++)
        if(imp[i] == false)
            res = min(res, prefix[i] + suffix[i+1]);

    if(res & 1) printf("%lld\n", res / 2 + 1);
    else printf("%lld\n", res / 2);
    return 0;
}

Measured memory_bytes: 7628
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {

    ll N;
    cin >> N;
    ll sum = 0;
    ll n = 0;
    rep(i,N){
        sum += i+1;
        if(sum>=N){
            n = i+1;
            break;
        }
    }
    rep(i,n){
        if(i+1!=sum-N) cout << i+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      double a = sc.nextDouble();
      double b = sc.nextDouble();
      double t = sc.nextDouble();
      double time = t+0.5;
      double cou = Math.floor(t/a);
      System.out.println((int)b*(int)cou); 
  }
}



Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define ms(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+5;
int t, a, b;

int main()
{
	while(cin >> t){
		a = t;
		int ans = 0;
		while(a){
			ans += a%10;
			a /= 10;
		}
		if(t%ans == 0){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b+c ||
     b == a+c ||
     c == a+b ) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import math
ans = 0
lst = 10
for i in range(5):
    a = input()
    if int(a[-1]) != 0:
        lst = min(lst, int(a[-1]))
    ans += math.ceil(int(a) / 10) * 10

if lst == 10:
    print(ans)
else:
    print(ans - (10 - lst))



Measured memory_bytes: 3060
n, k = map(int, input().split())
dat_h = list(map(int, input().split()))
dp = [1000000000000000] * (n + 1)
dp[0] = 0
for i in range(1, n):
    for j in range(1, k + 1):
        if (i - j) >= 0:
            dp[i] = min(dp[i], dp[i-j] + abs(dat_h[i] - dat_h[i-j]))
print(dp[n-1])

Measured memory_bytes: 52448
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] array = new int[n];
		
		for(int i = 0; i < n; i++){
			array[i] = scan.nextInt();
		}
		
		for(int j = 0; j < n / 2; j++){
			int a = array[j];
			array[j] = array[n - j - 1];
			array[n - j - 1] = a;
		}
		
		for(int k = 0; k < n; k++){
			System.out.print(array[k]);
			if(k == n - 1){
				System.out.println();
				break;
			}
			System.out.print(" ");
		}
	}
}

Measured memory_bytes: 26200
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {


            List<string> YesNo = new List<string>();

            int  count =Convert.ToInt32( Console.ReadLine());

            List<int> datList;

            string s="";

            for (int i = 0; i < count; i++)
            {
                s= Console.ReadLine();

                datList = new List<int>();

                datList.Add(Convert.ToInt32(s.Split(' ')[0]));
                datList.Add(Convert.ToInt32(s.Split(' ')[1]));
                datList.Add(Convert.ToInt32(s.Split(' ')[2]));

                datList.Sort();

                if (Math.Pow(datList[2], 2) == Math.Pow(datList[0], 2) + Math.Pow(datList[1], 2))
                { 
                    YesNo.Add("YES"); 
                }
                else {
                    YesNo.Add("NO"); 
                }

            }


            for (int i = 0; i < YesNo.Count; i++)
            {
                Console.WriteLine(YesNo[i]);
            }
            Console.ReadLine(); 
        }
    }

}

Measured memory_bytes: 5784
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

monster = sum(A)
for i in range(N):
    t = A[i] - B[i]
    if t < 0:
        A[i] = 0
        if A[i+1] + t < 0:
            A[i+1] = 0
        else:
            A[i+1] += t
    else:
        A[i] = A[i] - B[i]

print(monster - sum(A))

Measured memory_bytes: 18476
import sys
input = sys.stdin.readline

def main():
    N, M = map( int, input().split())
    L = [(0,0) for _ in range(N)]
    for i in range(N):
        a, b = map( int, input().split())
        L[i] = (b,a)
    L.sort(reverse = True)
    V = [0]*M
    W = [ i for i in range(M)]
    def find(A,x):
        p = A[x]
        if p == x:
            return x
        a = find(A,p)
        A[x] = a
        return a
 
    def union(A, x, y):
        #    bx, by = sorted([find(A,x), find(A,y)]) # bx, by = find(A,x), find(A,y)だと無限ループ。
        if find(A,x) > find(A,y):
            bx, by = find(A,y), find(A,x)
        else:
            bx, by = find(A,x), find(A,y)
        A[y] = bx
        A[by] = bx

    for i in range(N):
        b, a = L[i]
        t = M-a
        if t < 0:
            continue
        if V[t] == 0:
            V[t] = b
            if t > 0:
                if V[t-1] > 0:
                    union(W, t, t-1)
            if t < M-1:
                if V[t+1] > 0:
                    union(W, t, t+1)
            continue
        s = find(W,t)
        if s == 0:
            if V[0] == 0:
                V[0] = b
                if M > 1:
                    if V[1] > 0:
                        union(W, 0, 1)
        else:
            V[s-1] = b
            if s-1 > 0:
                if V[s-2] > 0:
                    union(W, s-1, s-2)
            union(W,s-1,s)
    print( sum(V))
            
            
            
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 126896
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;

bool check(long long a,long long b,long long c){
    return true;
}

int main(){
    string str;

    cin >> str;

    if(str.size()%2!=0){
        cout << "No" << endl;
        return 0;
    }
    for(int i=0; i<str.size()-1; i+=2){
        if(str.at(i)=='h' && str.at(i+1)=='i'){
            continue;
        }
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    
    
    int a = 0;
    int b = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (i%2 == 0)
        {
            if (S.at(i) == '0')
                a++;
            else
                b++;
        }
        else
        {
            if (S.at(i) == '0')
                b++;
            else
                a++;
        }
    }

    cout << min(a, b) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
 
long long Modpow(long long a, long long n, long long mod)
{
    long long ans = 1;
    while(n > 0)
    {
        if(n & 1)
        {
            ans = ans * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return ans;
}
 
long long Modinv(long long a, long long mod)
{
    return Modpow(a, mod - 2, mod);
}

int main()
{
    constexpr int MOD = 1000000007;
    
    int r1, c1, r2, c2;
    std::cin >> r1 >> c1 >> r2 >> c2;
    
    // rCr + r+1 C r + ... + nCr = n+1 C r+1
    // ゆえに
    // r+c1 C r + ... + r+c2 C r = r+c2+1 C r+1 - r+c1 C r+1
    
    long long num1 = 1;
    long long den = 1;
    long long num2 = 1;
    
    // r1+c2+1 C r+1, r1+c1 C r+1
    for(int i = 0; i < r1 + 1; ++i)
    {
        num1 = num1 * (r1 + c2 + 1 - i) % MOD;
        den = den * (i + 1) % MOD;
        num2 = num2 * (r1 + c1 - i) % MOD;
    }
    
    long long comb1 = num1 * Modinv(den, MOD) % MOD;
    long long comb2 = num2 * Modinv(den, MOD) % MOD;
    long long curPath = (comb1 - comb2) % MOD;
    if(curPath < 0)
    {
        curPath += MOD;
    }
    long long sum = curPath;
    
    for(int r = r1 + 1; r <= r2; ++r)
    {
        num1 = num1 * (r + c2 + 1) % MOD;
        num2 = num2 * (r + c1) % MOD;
        den = den * (r + 1) % MOD;
        comb1 = num1 * Modinv(den, MOD) % MOD;
        comb2 = num2 * Modinv(den, MOD) % MOD;
        curPath = (comb1 - comb2) % MOD;
        if(curPath < 0)
        {
            curPath += MOD;
        }
        sum = (sum + curPath) % MOD;
    }

    std::cout << sum << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[105];
int ans;
int main(void){
	int n; cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		bool k=true;
		for(int j=0;j<i;j++){
			if(a[j]>a[i]){
				k=false;
			}
		}
		if(k){
				ans++;
			}
	}
	cout<<ans<<endl;
	
}


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

// https://qiita.com/vain0x/items/43ba0051dcdb673b054f

int main(){
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << fixed;
    cout << setprecision(6) << double(W) * double(H) / 2.0 << ' ';
    if((W == x+x) && (H == y+y)){
        cout << '1' << endl;
    }else{
        cout << '0' << endl;
    }
    return 0;
}

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

int main() {
    int N, K;
    while (cin >> N >> K, N || K) {
        vector<int> v(N + 2);
        for (int i = 0; i < K; i++) {
            int x; cin >> x;
            v[x]++;
        }


        vector<pair<int,int> > d;
        int left;
        for (int i = 1, flag = false; i <= N; i++) {
            if (!flag && v[i]) left = i-1, flag = true;
            if (flag && !v[i]) d.push_back(pair<int,int>(left, i-1)), flag = false;
        }

        int ans = 0;
        for (int i = 0; i < (int)d.size(); i++) {
            if (!v[0]) ans = max(ans, d[i].second - d[i].first);
            else {
                ans = max(ans, d[i].second - d[i].first + 1);
                if (i + 1 < (int)d.size() && d[i].second + 1 == d[i+1].first) {
                    ans = max(ans,
                              d[i].second - d[i].first + 1
                              + d[i+1].second - d[i+1].first);
                }
            }
        }

        cout << ans << endl;

    }

    return 0;
}

Measured memory_bytes: 3392
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    int n = in.size();

    vi res(n);
    rep(i, n-1){
        if(in.substr(i, 2) == "RL"){
            int j = i, rcnt = 0;
            while(j >= 0 and in[j] == 'R') rcnt++, j--;
            j = i + 1; int lcnt = 0;
            while(j < n and in[j] == 'L') lcnt++, j++;

            res[i] = (rcnt + 1) / 2 + lcnt / 2;
            res[i+1] = rcnt / 2 + (lcnt + 1) / 2;
            i = j - 1;
        }
    }

    rep(i, n){
        cout << (i ? " ":"") << res[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1104
# 097A
# 入力値以内であるか判定
# 入力は、a,b,c,d ですべて整数

# 入力
a, b, c, d = map(int, input().split())

# 処理
if abs(a - b) <= d and abs(b - c) <= d :
    print("Yes")
elif abs(a - c) <= d:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9092
#include<bits/stdc++.h>
using namespace std;
template<typename T> int           ones_count_32(T x) { return __builtin_popcount(x); }
template<typename T> int  leading_zeros_count_32(T x) { return __builtin_clz(x); }
template<typename T> int trailing_zeros_count_32(T x) { return __builtin_ctz(x); }
template<typename T> int           ones_count_64(T x) { return __builtin_popcountll(x); }
template<typename T> int  leading_zeros_count_64(T x) { return __builtin_clzll(x); }
template<typename T> int trailing_zeros_count_64(T x) { return __builtin_ctzll(x); }
#define pi 3.141592653589793238
#define fastIO(); ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fr(i,a,b) for(int i=a;i<b;i++)
#define fb(i,b,a) for(int i=b;i>a;i--)
#define f0(a,b) for(int i=a;i<b;i++)
#define fn(b,a) for(int i=b;i>a;i--)
#define frll(i,a,b) for(long long int i=a;i<b;i++)
#define fbll(i,b,a) for(long long int i=b;i>a;i--)
#define f0ll(a,b) for(long long int i=a;i<b;i++)
#define fnll(b,a) for(long long int i=b;i>a;i--)
#define dbg(x); cout<<"\n"<<#x<<": "<<x;
#define ret return
#define ub upper_bound
#define lb lower_bound
#define psb push_back
#define psf push_front
#define pof pop_front
#define pob pop_back
#define sq(a) (a)*(a)
#define fs first
#define sc second
#define el "\n"
#define brk break
#define cont continue
#define all(a) a.begin(),a.end()
#define e9 1000000007
#define e8 100000007
#define e7 10000007
#define e6 1000007
#define e5 100007
#define inf 1e18+7
typedef long double ld;
typedef long long int lli;  //  1e-18 to 1e18
typedef vector<int> vi;
typedef multiset<int> msi;
typedef set<int> si;
typedef string str;
typedef priority_queue<int> pqi;
typedef map<int,int> mii;
typedef map<char,int> mci;
typedef vector<long long int> vll;
typedef pair<int,int> pii;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvll;
void readVec(vi &a,int n){
    a.resize(n);
    f0(0,n) cin>>a[i];
}
void writeVec(vi &a){
	for(int x:a) cout<<x<<" ";
	cout<<el;
}
void readVecll(vll &a,lli n){
    a.resize(n);
    f0(0,n) cin>>a[i];
}
void writeVecll(vll &a){
	for(lli x:a) cout<<x<<" ";
	cout<<el;
}
void solve(){
    int n,k;
    cin>>n>>k;
    vi h;
    readVec(h,n);
    vi mcr(n,e9);//min cost of reaching i
    mcr[0]=0;
    fr(i,0,n){
        fr(j,i+1,i+k+1){
            if(j<n) mcr[j]=min(mcr[j],mcr[i]+abs(h[i]-h[j]));
        }
    }
    cout<<mcr[n-1]<<el;
}
int main(){
    fastIO();
    int t(1);
    // cin>>t;
    while(t--) solve();
    ret 0; 
}

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

using namespace std;

int main(){
    int h,w; scanf("%d%d",&h,&w);
    
    string board[50];
    
    for(int i = 0 ; i < h ; i++) cin >> board[i];
    
    const int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};
    const int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
    
    for(int i = 0 ; i < h ; i++){
        for(int j = 0 ; j < w ; j++){
            if(board[i][j] == '#') continue;
            
            int num = 0;
            for(int d = 0 ; d < 8 ; d++){
                const int ni = i + dy[d];
                const int nj = j + dx[d];
                
                if(ni < 0 || h <= ni) continue;
                if(nj < 0 || w <= nj) continue;
                if(board[ni][nj] == '#') num++;
            }
            
            board[i][j] = char(num + '0');
        }
    }
    
    for(int i = 0 ; i < h ; i++)
        cout << board[i] << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] S = new String[N];
        int countAC = 0;
        int countWA = 0;
        int countTLE = 0;
        int countRE = 0;
        for(int i=0; i < N; i++){
            S[i] = sc.next();
            if("AC".equals(S[i])){
                countAC ++;
            }else if("WA".equals(S[i])){
                countWA ++;
            }else if("TLE".equals(S[i])){
                countTLE ++;
            }else if("RE".equals(S[i])){
                countRE ++;
            }
        }
        sc.close();

        System.out.println("AC x "+ countAC);
        System.out.println("WA x "+ countWA);
        System.out.println("TLE x "+ countTLE);
        System.out.println("RE x "+ countRE);
    }
}

Measured memory_bytes: 55920
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  while(cin>>n,n){
    vector<Int> m(n);
    vector<vector<Int> > v(n);
    for(Int i=0;i<n;i++){
      cin>>m[i];
      v[i].resize(m[i]);
      for(Int j=0;j<m[i];j++)
	cin>>v[i][j];
    }
    
    Int k;
    cin>>k;
    set<Int> l;
    for(Int i=0;i<k;i++){
      Int x;
      cin>>x;
      l.emplace(x);
    }
    
    vector<Int> ans;
    for(Int i=0;i<n;i++){
      Int cnt=0;
      for(Int j=0;j<m[i];j++)
	cnt+=l.count(v[i][j]);
      
      if(cnt==k) ans.emplace_back(i);
    }
    
    if(ans.size()==1u) cout<<ans[0]+1<<endl;
    else cout<<-1<<endl;
  }
  return 0;
}



Measured memory_bytes: 3172
def main():
    N = int(input())
    A = list()

    for i in range(N):
        a, b = map(int, input().split())
        A.append([a, b])

    A.reverse()
    ans = 0
    offset = 0

    for pair in A:
        a, b = pair

        if (a + offset) % b == 0:
            n = 0
        else:
            n = b - ((a + offset) % b)

        ans += n
        offset += n
        
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 24232
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)

using namespace std;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main()
{
  string s;
  cin>>s;
  int n = s.size();
  s = "$$" + s;
  vector<vecint> dp(n+2, vecint(2, 0));
  int ofs = 2;
  REP(i,n) {
    if (s[i+ofs] != s[i+ofs-1]) {
      dp[i+1][0] = max(dp[i+1][0], dp[i][0]+1);
    }
    if (s.substr(i+ofs,2) != s.substr(i+ofs-2,2)) {
      dp[i+2][1] = max(dp[i+2][1], dp[i][1]+1);
    }
    dp[i+1][0] = max(dp[i+1][0], dp[i][1]+1);
    dp[i+2][1] = max(dp[i+2][1], dp[i][0]+1);
  }
  cout<<*boost::max_element(dp[n])<<endl;
  return 0;
}


Measured memory_bytes: 11328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;

int main(){
  double n;
  cin>>n;
  double k=(int)n;
  double t=sqrt((n*n)/2.0)*2.0;
  if(n*n<=k*k+1.0){
    printf("%.10lf",max(t,k+1));
    return 0;
  }
  printf("%.10lf",t);
  return 0;
}



Measured memory_bytes: 3292
import sys

input = sys.stdin.readline

def main():
    s = [
        [[0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0]],
        
        [[0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0]],
        
        [[0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0]],
        
        [[0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0]]
        ]
    n = int(input())
    for i in range(n):
        a,b,c,f = map(int, input().split())
        if 0 <= s[a-1][b-1][c-1] + f <=9:
            s[a-1][b-1][c-1] += f
        
    for i in range(4):
        for k in range(3):
            print(" ", end="")
            print(*s[i][k])
        if i != 3:
            print("#"*20)

if __name__ == "__main__":
    main()
    


Measured memory_bytes: 5640
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a,inc=(b-a)/abs(b-a); i!=b ; i+=inc)
#define deb(x) cout<<#x<<"->"<<x<<endl;
#define print(arr,a,b) for(int i=a;i!=b;i++){cout<<arr[i]<<" ";}cout<<endl;
using ll=long long int;
int arr_min(int arr[],int a,int b){ int min=arr[0]; for(int i=a;i!=b;i++){if(min>arr[i]) min=arr[i];}return min;}
int arr_max(int arr[],int a,int b){ int max=arr[0]; for(int i=a;i!=b;i++){if(max<arr[i]) max=arr[i];}return max;}

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

	#ifndef ONLINE_JUDGE
      	freopen("input.txt", "r", stdin);
      	freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    while(t-->0){
    	int n;
    	cin>>n;
    	string str;
    	cin>>str;
    	ll count1=0;
    	ll count2=0;
    	ll count3=0;
    	for(int i=0;i<n;i++)
    	{
          if(str[i]=='R')
          	count1++;
          if(str[i]=='G')
          	count2++;
          if(str[i]=='B')
          	count3++;

    	}
    	int count=0;
    	ll total=count1*count2*count3;
    	if(total==0)
    	{
    		cout<<0;
    	}
    	
    	else
    	{
           for(int i=0;i<n-2;i++)
           {

             for(int j=i+1;j<n-1;j++)
             {
             	int k=(j-i)+j;
             	if(k<n)
             	{
             		if((j-i)==(k-j))
             		{
             			if(str[i]!=str[j] && str[j]!=str[k] && str[i]!=str[k])
             			{
             				count++;
             			}
             		}
             	}
             }
           


           }
             cout<<total-count;






    	}
    	

    	
    	
    }
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int A[N];
    int number[NUM]={0};
    rep(i, N){
        cin>>A[i];
        number[A[i]]++;
    }

    bool pairwise=true;
    rep(i, NUM){
        int cnt=0;
        if(i==0) continue;
        if(i==1) continue;
        for(int j=i; j<NUM; j+=i){
            cnt+=number[j];
        }
        if(cnt>=2){
            pairwise=false;
        }
    }

    if(pairwise){
        cout<<"pairwise coprime"<<endl;
        return 0;
    }

    int gc=A[0];
    rep(i, N){
        gc=gcd(gc, A[i]);
    }
    if(gc==1){
        cout<<"setwise coprime"<<endl;
        return 0;
    }

    cout<<"not coprime"<<endl;
    return 0;
}

Measured memory_bytes: 11384
package main

import (
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	const p int = 1e9 + 7
	pow := func(x int) int {
		res := 1
		for n := p - 2; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % p
			}
			x = x * x % p
		}
		return res
	}
	c := func(n, k int) int {
		if k > n-k {
			k = n - k
		}
		a, b := 1, 1
		for i := 1; i <= k; i++ {
			a = a * n % p
			n--
			b = b * i % p
		}
		return a * pow(b) % p
	}
	var n, m int
	Fscan(_r, &n, &m)
	ans := 1
	for i := 2; i*i <= m; i++ {
		e := 0
		for ; m%i == 0; m /= i {
			e++
		}
		if e > 0 {
			ans = ans * c(e+n-1, n-1) % p
		}
	}
	if m > 1 {
		ans = ans * n % p
	}
	Fprint(_w, ans)
}

func main() { run(os.Stdin, os.Stdout) }


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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define forn(low,high,i) for(i = low; i < high; i++)
#define forrev(high,low,i) for(i = high; i >= low; i--)
#define all(v) v.begin(),v.end()
#define decimal_digits cout << fixed << setprecision(15);

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

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(long long a, long long b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(long long a, long long b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(long long a, long long b){a %= mod; b %= mod; return (int)((long long) a * b % mod);}
inline int modexpo(long long a, long long b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(long long a, long long b){return mul(a, modexpo(b, mod - 2));}
inline int inv(long long a){return modexpo(a, mod - 2);}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  int a; cin >> a;
  cout << (a + a*a + a*a*a) << '\n';
}


#define GOOGLE 0
#define MULTIPLE_TC 0

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

  pre();

  int t = 1, T;
  if(MULTIPLE_TC)
    cin >> t;

  for(T = 1; T <= t; T++){
    if(GOOGLE)
      cout << "Case #" << T << ": ";
    solve();
  }

  ktj();
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<pair<ll,ll>>())
#define pb push_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec A(N);
    REP(i,0,N) cin >> A[i];
    vector<pair<ll,ll>> P;
    REP(i,0,M) {
        ll b, c;
        cin >> b >> c;
        P.pb({c, b});
    }

    ASC(A);
    DESC(P);
    ll k = 0, l;
    FORR(p,P) {
        ll b = p.second, c = p.first;
        l = 0;
        REP(i,k,MIN(b+k,N)) {
            if(A[i] < c) {
                A[i] = c;
                ++l;
            }
            else break;
        }
        k += l;
        if(k >= N) break;
    }

    ll sum = 0;
    REP(i,0,N) sum += A[i];
    PR(sum);


    return 0;
}

/*



*/

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

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

    int m = 0, ma = 1000000;
    int l, r;

    REP(i, M)
    {
        cin >> l >> r;
        if (l >= m)
            m = l;
        if (ma >= r)
            ma = r;
    }

    cout << max(ma - m + 1, 0);
}

Measured memory_bytes: 256
use std::io::*;

fn fizzbuzz_eq(n: usize, s: &str) -> bool {
  if      n % 15 == 0 { s == "FizzBuzz" }
  else if n %  3 == 0 { s == "Fizz" }
  else if n %  5 == 0 { s == "Buzz" }
  else { n == s.parse().unwrap() }
}

fn main() {
  let stdin = stdin();
  let mut lines = stdin.lock().lines().map(|l| l.unwrap());

  loop {
    let (m, n) = {
      let line = lines.next().unwrap();
      let mut iter = line.split_whitespace().map(|s| s.parse::<usize>().unwrap());

      (iter.next().unwrap(), iter.next().unwrap())
    };
    if m == 0 { return; }

    let mut players_alive = vec![true; m];
    let mut cur = 0;

    for i in 1..(n + 1) {
      let ans = lines.next().unwrap();
      let is_correct = fizzbuzz_eq(i, &ans);

      if !is_correct { players_alive[cur] = false; }

      if i < n {
        let mut iter = ((cur + 1)..(cur + m)).map(|p| p % m);
        cur = iter.find(|&p| players_alive[p]).unwrap();

        if !is_correct && !iter.any(|p| players_alive[p]) {
          lines.nth(n - i - 1);
          break
        }
      }
    }

    let mut iter = players_alive.into_iter().enumerate()
      .filter(|&(_, a)| a).map(|(n, _)| n + 1);
    let mut result = iter.next().unwrap().to_string();
    for n in iter {
      result.push_str(&format!(" {}", n));
    }
    println!("{}", result);
  }
}



Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i, n) for(int i = 0; i < (n); ++i)
const ll mod = 1e9 + 7;

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

bool pairCompare(const P &firstElof, const P &secondElof) {
    return firstElof.second < secondElof.second;
}

ll x[55], y[55];
int n;
ll ma = 0;

int main() {
    cin >> n;
    rep(i, n) { cin >> x[i] >> y[i]; }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(i == j)
                continue;
            ll p = x[i] - x[j];
            ll q = y[i] - y[j];
            ll cnt = 0;
            for(int k = 0; k < n; k++) {
                for(int l = 0; l < n; l++) {
                    if(k == l)
                        continue;

                    if(x[k] - x[l] == p and y[k] - y[l] == q) {
                        cnt++;
                    }
                }
            }
            ma = max(cnt, ma);
        }
    }
    cout << n - ma << "\n";
}


Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    auto tmp = unique(s.begin(), s.end());
    s.erase(tmp, s.end());
    cout << s.size() << '\n';
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
ll x, a[100010];

int main() {
    cin >> n >> x;
    rep(i, n) cin >> a[i];

    ll ans = 0;
    if (a[0] > x) {
        ans += a[0] - x;
        a[0] = x;
    }

    for (int i = 1; i < n; i++) {
        int sum = a[i-1] + a[i];
        if (sum > x) {
            ans += sum - x;
            a[i] -= sum - x;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
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;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int sum = 0;
	int tmp = -1;
	int cnt = 0;
	int a=0,b=0;
	s += ':';
	rep(i,s.size()-1){
		if(s[i] == '<'){
			++a;
			if(s[i+1] == ':'){
				sum += a * a - ((a-1) * a / 2);
			}
		}
		else{
			++b;
			if(s[i+1] == '<' || s[i+1] == ':'){
				sum += max(a,b);
				--b;
				sum += b * b - ((b-1) * b / 2);
				--a;
				sum += a * a - ((a-1) * a / 2);
				a = 0;
				b = 0;
			}
		}
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 1172
#include <iostream>
#include <string>

using namespace std;

int main() {
	string o, e;
	cin >> o >> e;

	int ao = o.size();
	int ae = e.size();

	string ans;
	for (int i = 0; i < ao; ++i) {
		
		ans = ans + o[i];
		if (i < ae) {
			ans = ans + e[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io, flush := NewIO()
	defer flush()

	n := io.ScanInt()
	nums := io.ScanInts(n)
	limit := math.Pow10(18)

	sort.Ints(nums)
	if nums[0] == 0 {
		fmt.Println(0)
		return
	}

	sum := 1
	for _, num := range nums {
		if sum*num > int(limit) || (sum*num)/num != sum {
			fmt.Println(-1)
			return
		}
		sum *= num
	}
	fmt.Println(sum)
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 8072
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
  int n,a,b,c,d,ans=50000;
  int A[2],B[2],C[2],D[2];
  cin >>n>>a>>b>>c>>d;
  a--;b--;c--;d--;
  for(int w=1; w<=n; w++){
    for(int i=0; i<n; i++){
      if(i == a){A[0] = i%w;A[1] = i/w;}
      if(i == b){B[0] = i%w;B[1] = i/w;}
      if(i == c){C[0] = i%w;C[1] = i/w;}
      if(i == d){D[0] = i%w;D[1] = i/w;}
    }
    int l = abs(A[0]-B[0])+abs(A[1]-B[1])+abs(C[0]-D[0])+abs(C[1]-D[1]);
    if(l<ans) ans = l;
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void){
    int a=0,b=0,c=0,d=10,n,t;
    while(d--){
        scanf("%d",&n);
        if(n>a)t=n,n=a,a=t;
        if(n>b)t=n,n=b,b=t;
        if(n>c)c=n;
    }
    printf("%d\n%d\n%d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <string.h>
#define MAX 100000000

char str[14];
char H[MAX];

int find(void);
void insert(void);
int getChar(char);
int getkey(void);

int main(){
	int i,j,n;
	char a[7];

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%s %s",a,str);
		if(a[0]=='i'){
			insert();
		}
		else if(a[0]=='f'){
			if(find())printf("yes\n");
			else printf("no\n");
		}
	}
	return 0;
}

int getChar(char ch){
	if(ch == 'A')return 1;
	else if(ch == 'C')return 2;
	else if(ch == 'G')return 3;
	else if(ch == 'T')return 4;
}

int getkey(){
	int sum=0, p=1,i;
	for(i=0;i<strlen(str);i++){
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int find(){
	int key = getkey();
	
	if(H[key]) return 1;
	else return 0;
}

void insert(){
	H[getkey()] = 1;
}

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

int main()
{
	int n, m;
	while (cin >> n >> m, n + m)
	{
		int ary[100] = {};
		int p = m;
		int i = 0;
		while (true)
		{
			if (p == 0)
			{
				p = ary[i];
				ary[i] = 0;
			}
			else
			{
				p--;
				ary[i]++;
			}
			if (ary[i] == m)
			{
				cout << i << endl;
				break;
			}
			i++;
			if (i == n) i = 0;
		}
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
#define N 100001

int partition(int *, int, int);

int main(){

  int A[N];
  int n,k,num,num2;

  scanf("%d",&n);

  for(k=0;k<n;k++){
    scanf("%d",&A[k]);
  }

  num=n-1;

  num2=partition(A,0,n-1);

  for(k=0;k<num2;k++){

    printf("%d ",A[k]);
    

  }
   
    
  printf("[%d] ",A[num2]);

  for(k=num2+1;k<n;k++){

    printf("%d",A[k]);

    if(k==n-1) printf("\n");
    else printf(" ");

  }


 return 0;

  
}

int partition(int *A,int p,int r){

  int i,j,x,temp1,temp2;

  x=A[r];
  i=p-1;
  
  for(j=p;j<=r-1;j++){

    if(A[j]<=x){
      i=i+1;
      temp1=A[i];
      A[i]=A[j];
      A[j]=temp1;
      
    }

  }

  temp2=A[i+1];
  A[i+1]=A[r];
  A[r]=temp2;

  return i+1;
    
}



Measured memory_bytes: 2128
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  int n = in();
  vector<list<int>> lines(n);
  int q = in();
  rep(i,q){
    int kind = in();
    if(kind==0){
      int t = in();
      int x = in();
      lines[t].emplace_back(x);
    }else if(kind==1){
      int t = in();
      foreach(i,lines[t]){
        output(i);
      }
      outendl();
    }else{
      int s = in();
      int t = in();
      lines[t].splice(lines[t].end(),lines[s]);
      lines[s].empty();
    }
  }
}



Measured memory_bytes: 18812