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

int main(void)
{
  int a,b;
  double ans;
  char str[8];
  
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d%d",&a,&b);
  
  ans = (a+b) / 2.0;
  ans = ceil(ans);
  
  printf("%d",(int)ans);
  
  return 0;
}

Measured memory_bytes: 128
/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define pii pair<int,int>
#define dbg(x) cout << (#x) << " is " << (x) << '\n' 
#define F first
#define S second
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

void solve()
{ 
   map<string,int> mp;
   int n;
   cin >> n;
   f(i,n)
   {
       string s;
       cin >> s;
       mp[s]++;
   }
   cout << mp.size() << '\n';
   return;
}

signed main()
{
  FAST
  int T=1;
  //  cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 19184
S = list(map(int,input().split()))

if S[0] + S[1] + S[2] > 2 * 10 ** 9:
    print('Error')
elif S[0] >= S[3]:
    print(S[3])
elif S[3] > S[0] and S[3] <= S[0] + S[1]:
    print(S[0])
elif S[3] > S[0] + S[1] and S[3] <= S[0] + S[1] + S[2]:
    print(-1 * (S[3] - S[0] - S[1]) + S[0])
else:
    print('Error')

Measured memory_bytes: 9216
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

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

	private void solve() throws IOException {
		try {
			//			solveA();
			solveB();
			// solveC();
			// solveD();
			// solveE();
			// solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		String strA = next();
		String strB = next();

		if (strA.equals("H")) {
			System.out.println(strB.equals("H") ? "H" : "D");
		} else {
			System.out.println(strB.equals("H") ? "D" : "H");
		}

	}

	private void solveB() {
		int numW = nextInt();
		int numA = nextInt();
		int numB = nextInt();

		long res = 0;

		if (numA + numW < numB) {
			res = Math.abs(numB - (numA + numW));
		} else if (numB + numW < numA) {
			res = Math.abs(numA - (numB + numW));
		}
		System.out.println(res);
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	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;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

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

Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

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

    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll dp[n+1][n+1], ps[n+1][n+1];   

    loop(i,0,n+1) loop(j,0,n+1) ps[i][j] = dp[i][j] = 0;
    
    loop(j,1,n+1) {
        dp[1][j] = 1;
        ps[1][j] = ps[1][j-1] + dp[1][j];
    }
    for(ll i=2; i<n+1; i++){
        for(ll j=1; j<=i; j++){
            if(s[i-2]=='>'){
                dp[i][j] = (ps[i-1][i-1]%mod - ps[i-1][j-1]%mod + mod)%mod;
            }
            else if(s[i-2]=='<'){
                dp[i][j] = ps[i-1][j-1]%mod;
            }
            ps[i][j] = ps[i][j-1] + dp[i][j];
        }
    }
    ll ans = 0;
    loop(i,1,n+1){
        ans = (ans%mod + dp[n][i]%mod)%mod;
    }
    print(ans);

}



Measured memory_bytes: 140928
import java.util.*;
import java.util.Map.Entry;
 
 
 
public class Main{
	
	public int num;
	public int vol;
 
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}
 
 
 
	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}
 
 
	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}
 
 
	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}
 
 
	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	int N=sc.nextInt();
	int other=0;
	for(int i=1;i<=N;i++) {
		if(i%2!=0) {
			other++;
		}
	}
	System.out.println(String.format("%.8f", (double)other/(double)N));
 }
	
 
 
}


Measured memory_bytes: 23892
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long N,x,i,cnt,t;
vector<long> a;

inline void solve(){
  IN2(N,x);
  a.resize(N);
  REP(i,N){
    IN(a[i]);
    if(i>=1){
      if(a[i-1]+a[i]>x){
        // while(a[i]!=0&&a[i-1]+a[i]>x){
        //   a[i]--;
        //   cnt++;
        // }
        t=a[i-1]+a[i]-x;
        a[i]-=t;
        cnt+=t;
        if(a[i]<0){
          cnt-=abs(a[i]);
          a[i]=0;
        }
        if(a[i-1]+a[i]>x){
          // while(a[i-1]!=0&&a[i-1]+a[i]>x){
          //   a[i-1]--;
          //   cnt++;
          // }
          t=a[i-1]+a[i]-x;
          a[i-1]-=t;
          cnt+=t;
          if(a[i-1]<0){
            cnt-=abs(a[i-1]);
            a[i-1]=0;
          }
        }
      }
      // cout<<a[i-1]<<" "<<a[i]<<endl;
    }
  }
  // REP(i,N){
  //   cout<<a[i]<<" ";
  // }
  // cout<<endl;
  OUT(cnt);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 1152
(N, K) = list(map(int, input().split()))
P = list(map(int, input().split()))

max_pos = 0
max_value = sum(P[:K])
tmp_sum = max_value
for i in range(N-K):
    tmp_sum = tmp_sum - P[i] + P[i+K]
#    print(i, max_value, tmp_sum, P[i:i+K], "-", P[i], "+", P[i+K])
    if tmp_sum > max_value:
        max_value = tmp_sum
        max_pos = i + 1

#print("--------", max_pos)
total = 0
for i in range(max_pos, max_pos + K):
    total += (P[i] + 1) / 2
#    print(i, total, sum(list(range(1, P[i] + 1))) / P[i])

print(total)


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

using namespace std;

typedef long long ll;

int main(){
    int n,D;
    scanf("%d%d",&n,&D);
    vector<int> d(n+1,0);
    for(int i = 1; i<=n; i++)
        scanf("%d",&d[i]);
    vector<int> dp(n+1,0);
    dp[n] = 1;
    for(int i = n-1; i>=0; i--){
        if(dp[i+1]<=d[i+1]/2)
            dp[i] = dp[i+1];
        else
            dp[i] = dp[i+1]+d[i+1];
    }
    vector<int> pref(n+1,0);
    pref[0] = D;
    int f = 0;
    for(int i = 1; i<=n; i++){
        int f2 = f+d[i];
        if(D<f)
            f2 = f-d[i];
        if(abs(f2-D)<abs(f-D))
            f = f2;
        pref[i] = abs(f-D);
    }
    int q;
    scanf("%d",&q);
    while(q--){
        int qi;
        scanf("%d",&qi);
        if(pref[qi-1]>=dp[qi])
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const int MAX = 4;

static const ll MAX_N = 100001;
static const ll MAX_M = 100001;

char m[1000][1000];
ll d[1000][1000];
bool v[1000][1000];

queue<pair<ll, ll>> q;

int main() {
	ll h, w; cin >> h >> w;
	rep(i, 0, h)rep(j, 0, w) {
		cin >> m[i][j];
		if (m[i][j] == '#') {
			q.push({ i,j });
			d[i][j] = 0;
		}
		else {
			d[i][j] = INF;
		}
	}

	ll y[4] = { 0,1,-1,0 };
	ll x[4] = { 1,0,0,-1 };
	ll ans = 0;
	while (!q.empty()) {
		pair<ll, ll> p = q.front(); q.pop();
		ans = max(ans, d[p.first][p.second]);
		rep(i, 0, 4) {
			ll ny = p.first + y[i];
			ll nx = p.second + x[i];
			if (!v[ny][nx] && ny >= 0 && ny < h && nx >= 0 && nx < w && m[p.first][p.second] == '#') {
				d[ny][nx] = min(d[ny][nx], d[p.first][p.second] + 1);
				m[ny][nx] = '#';
				v[ny][nx] = true;
				q.push({ ny,nx });
			}
		}
	}

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

Measured memory_bytes: 26548
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <climits>
#include <cmath>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <stack>
#include <bitset>
using namespace std;
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define fi first
#define se second
#define ll long long
#define ii pair<int, int>

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("Test.inp", "r", stdin);
	//freopen("RATING.out", "w", stdout);
	int n, k;
	cin >> n >> k;
	vector <int> a(n);
	for (int &i : a) cin >> i;
	sort(a.begin(), a.end());
	ll ans = 0;
	rep(i, 0, n - k - 1) ans += a[i];
	cout << ans;
	return 0;
}

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

d, g = [int(x) for x in input().split()]
pc = [[int(x) for x in input().split()] for _ in range(d)]

ans = float("inf")

for i in range(2 ** d):
    i_bin = bin(i)[2:].zfill(d)
    s = set() # コンプリートボーナスをもらう
    for j in range(len(i_bin)):
        if i_bin[j] == "1":
            s.add(j)
    cnt = 0
    total = 0
    for k in s:
        cnt += pc[k][0]
        total += (k + 1)*pc[k][0]*100 + pc[k][1]
    if total >= g:
        ans = min(ans, cnt)
        continue
    for l in range(d - 1, -1, -1):
        flag = 0
        if l in s:
            continue
        for m in range(1, pc[l][0]):
            total += (l + 1) * 100
            cnt += 1
            if total >= g:
                flag = 1
                break
        if flag:
            break
    if total >= g:
        ans = min(ans, cnt)

print(ans)
            

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

int main(){
  int N;
  cin >> N;
  const int Ntot= 3*N;

  vector<int64_t> data(Ntot);
  for(int i=0; i<Ntot; i++){
    cin >> data.at(i);
  }
  vector<pair<int64_t, int64_t>> scores(N+1);
  // 先頭について
  priority_queue<int64_t, vector<int64_t>, greater<int64_t>> head;
  int64_t sum= 0;
  for(int i=0; i<N; i++){
    head.push(data.at(i));
    sum+= data.at(i);
  }
  scores.at(0).first= sum;

  for(int i=0; i<N; i++){
    int64_t cut_cand= head.top();
    if(data.at(N+i) > cut_cand){
      head.pop();
      head.push(data.at(N+i));
      sum+= data.at(N+i)- cut_cand;
    }

    scores.at(i+1).first= sum;
  }

  // 末尾について
  priority_queue<int64_t> tail;
  sum= 0;
  for(int i=1; i<=N; i++){
    tail.push(data.at(Ntot- i));
    sum+= data.at(Ntot- i);
  }
  scores.at(N).second= sum;

  for(int i=1; i<=N; i++){
    int64_t cut_cand= tail.top();
    if(data.at(Ntot- N- i) < cut_cand){
      tail.pop();
      tail.push(data.at(Ntot- N- i));
      sum+= data.at(Ntot- N- i)- cut_cand;
    }

    scores.at(N-i).second= sum;
  }

  // スコア算出
  int64_t ans= INT64_MIN;
  for(int i=0; i<=N; i++){
    ans= max(ans, scores.at(i).first- scores.at(i).second);
  }

  cout << ans << endl;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int x, y; cin >> x >> y;

    if (x % y) cout << x << '\n';
    else cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 256
# メインアイデア
# T分割と||分割で差が小さい方を探す
# 90度回転させた場合も考える
# 総合的に小さい方を採用する
# 図的な解説は別のPDFをアップロードしてある
import sys
H, W = list(map(int, input().split()))

# 3の倍数の場合は即座に0とわかる
if (H * W) % 3 == 0:
    print(0)
    exit()


def try_divi(W, H):
    # パターン1
    err = W
    # パターン2
    w2, w3 = W // 2, W // 2
    if W % 2:
        w2 += 1
    for h1 in range(1, H // 2 + 1):
        h2 = H-h1
        S1, S2, S3 = h1*W, w2*h2, w3*h2
        new_err = max(S1, S2, S3) - min(S1, S2, S3)
        if new_err < err:
            err = new_err
    return err


print(min(try_divi(W, H), try_divi(H, W)))


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int X[1010],Y[1010],H[1010];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>X[i]>>Y[i]>>H[i];
	
	for(x=0;x<=100;x++) {
		for(y=0;y<=100;y++) {
			
			ll R=H[0]+abs(x-X[0])+abs(y-Y[0]);
			FOR(i,N) {
				if(H[i]>0) {
					R=H[i]+abs(x-X[i])+abs(y-Y[i]);
					break;
				}
			}
			
			FOR(i,N) {
				ll R2=max(0LL,R-abs(x-X[i])-abs(y-Y[i]));
				if(H[i]!=R2) break;
			}
			if(i==N) {
				cout<<x<<" "<<y<<" "<<R<<endl;
				return;
			}
			
		}
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp,x,y;
string str;
set<ll> s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	if(n<m)
	swap(n,m);
	cin>>a;
	cout<<(a+(n)-1)/(n);
	
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main (String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int r = stdIn.nextInt();
		int d = stdIn.nextInt();
		int x = stdIn.nextInt();
		for(int i = 1;i <=10;i++) {
			x = cal(r,d,x);
			System.out.println(x);
		}
	}
	static int cal(int r,int d,int x) {
		return r * x - d;
	}
}

Measured memory_bytes: 21712
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

getDiffList :: [Int] -> [Int]
getDiffList [x] = []
getDiffList (x : xs) = (head xs - x) : getDiffList xs

main = do
  [n, m] <- getIntList
  xs <- getIntList
  let xs' = sort xs
  let ds = reverse (sort (getDiffList xs'))
  print $ last xs' - head xs' - sum (take (n - 1) ds)


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

using namespace std;

int main()
{
    long long n ;
    cin>>n ;
    long long arr[n] ;
    for(long long i = 0 ; i < n ; ++i)
        cin>>arr[i] ;
    sort(arr , arr + n) ;
    long long ans = 0 ;
       long long prev = arr[n/2] ;
       if(n % 2 == 0)
        prev = arr[n/2-1];
       map<long long , long long>mp ;
       mp[prev]++;
       long long now1 = 0 , now2 = n-1 ;
       long long x = 0 ;
       for(long long i = 0 ; i < n ; ++i)
       {
           if(mp[arr[i]] > 0)
           {
               mp[arr[i]]--;
               x = 1 ;
               continue;
           }
           if((i-x) % 2 == 1)
           {
               ans += abs(prev - arr[now1]);
               prev = arr[now1];
               now1++;
           }
           else
           {
               ans += abs(arr[now2] - prev) ;
               prev = arr[now2];
               now2--;
           }
       }
       prev = arr[n/2] ;
       if(n % 2 == 0)
        prev = arr[n/2-1];
       map<long long , long long>mp2 ;
       mp2[prev]++;
       now1 = 0 , now2 = n-1 ;
       x = 0 ;
       long long sum = 0 ;
       for(long long i = 0 ; i < n ; ++i)
       {
           if(mp2[arr[i]] > 0)
           {
               mp2[arr[i]]--;
               x = 1 ;
               continue;
           }
           if((i-x) % 2 == 0)
           {
               sum += abs(prev - arr[now1]);
               prev = arr[now1];
               now1++;
           }
           else
           {
               sum += abs(arr[now2] - prev) ;
               prev = arr[now2];
               now2--;
           }
       }
    ans = max(ans , sum);
    return cout<<ans<<"\n" , 0 ;
}


Measured memory_bytes: 14076
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        scanner.nextLine();
        int[] a = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] b = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int sum = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] > b[i]) {
                sum += a[i] - b[i];
            }
        }
        System.out.println(sum);
    }

}


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

vector<int> vec(4);

string judge(int su, int num, string op) {
    if (num == 4) {
        if (su == 7 - vec[0]) {
            return op;
        }
        else return "";
    }
    if (judge(su + vec[num], num + 1, op + "+") != "") {
        return judge(su + vec[num], num + 1, op + "+");
    }
    if (judge(su - vec[num], num + 1, op + "-") != "") {
        return judge(su - vec[num], num + 1, op + "-");
    }
    return "";
}

int main() {
    char A,B,C,D; cin >> A >> B >> C >> D;
    vec[0] = A - '0', vec[1] = B - '0', vec[2] = C - '0', vec[3] = D - '0';
    string op = "";

    string a = judge(0, 1, op);
    cout << vec[0] << a[0] << vec[1] << a[1] << vec[2] << a[2] << vec[3] << "=7" << endl;
}

Measured memory_bytes: 3636
package main

import (
	"fmt"
)

func main() {
	var k int
	a := make([]int, 5)
	for i := 0; i < 5; i++ {
		fmt.Scan(&a[i])
	}
	fmt.Scan(&k)
	for i := 0; i < 4; i++ {
		for j := i + 1; j < 5; j++ {
			if a[j]-a[i] > k {
				fmt.Println(":(")
				return
			}
		}
	}
	fmt.Println("Yay!")
}


Measured memory_bytes: 512
// #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);
#define fou(i,a,n) for(int i=a;i<n;i++)
#define fod(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(n) fou(_,0,n)
#define tra(a,x) for(auto& a : x)
#define elif(c) else if(c)
#define VI vector<int>
#define VD vector<double>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVD vector<VD>
#define VVC vector<VC>
#define VVS vector<VS>
#define emb emplace_back
#define pub push_back
#define pob pop_back
#define me min_element
#define Me max_element
#define mp make_pair
#define fi first
#define se second
#define si(vec) ((int)(vec).size())
#define all(vec) vec.begin(),vec.end()
#define lla(vec) vec.rbegin(),vec.rend()
#define sortup(vec) sort(all(vec))
#define sortdown(vec) sort(lla(vec))
template<class T>void mini(T &a,T b){a=min(a,b);}
template<class T>void maxi(T &a,T b){a=max(a,b);}
#define in(T,...) T __VA_ARGS__;_cin(__VA_ARGS__);
#define out(...) _cout(__VA_ARGS__);
void _cin(){}template<class Head,class...Tail>void _cin(Head&head,Tail&&...tail){cin>>head;_cin(forward<Tail>(tail)...);}
template<class Head>void _cout(Head head){cout<<head<<endl;}template<class Head,class...Tail>void _cout(Head head,Tail...tail){cout<<head<<" ";_cout(forward<Tail>(tail)...);}
void addin(){}template<class Head,class...Tail>void addin(vector<Head>&vechead,Tail&&...tail){in(Head,head);vechead.emb(head);addin(forward<Tail>(tail)...);}
template<class C>void vecout(vector<C> vec){int vecsize=si(vec);fou(i,0,vecsize-1)cout<<vec[i]<<" ";out(vec[vecsize-1]);}
template<class C> C gcd(C a,C b){if(a&&b)return gcd(min(a,b),max(a,b)%min(a,b));else return a;}template<class C> C lcm(C a,C b){return a/gcd(a,b)*b;}

// #define int int64_t
// #define double long double


signed main(){
  IOS;

  in(int,d,n);
  int x=pow(100,d)*((n==100)?101:n);
  out(x);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LL long long int
const LL MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//            When something is important enough, you do it even if the odds are not in your favor.

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    LL t=1;//cin>>t;
    while(t--){
      LL n,i,ans=0;cin>>n;
      LL a[n];
      fo(i,0,n) cin>>a[i];
      LL mx=0;
      fo(i,0,n){
        ans+=max((LL)0,mx-a[i]);
        mx=max(mx,a[i]);
      }
      cout<<ans;
    }
    return 0;
}

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

int H,W;
vector<vector<int>> G(1400,vector<int>(1400));
vector<vector<int>> dp(1400,vector<int>(1400));

int getLargestSquare(){
    int maxv=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            dp[i][j]=(G[i][j]+1)%2;
            maxv|=dp[i][j];
        }
    }
    for(int i=1;i<H;i++){
        for(int j=1;j<W;j++){
            if(G[i][j]){
                dp[i][j]=0;
            }
            else{
                dp[i][j]=min(min(dp[i-1][j],dp[i-1][j-1]),dp[i][j-1])+1;
                maxv=max(maxv,dp[i][j]);
            }
        }
    }
    return maxv*maxv;
}

int main(){
    cin>>H>>W;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>G[i][j];
        }
    }

    cout<<getLargestSquare()<<endl;
}


Measured memory_bytes: 18036
def dfs(s: str, n: int, i: int, x: str):
    return sum(list(map(int,x.split('+')))) if i==n-1 else dfs(s,n,i+1,x+s[i+1])+dfs(s,n,i+1,f'{x}+{s[i+1]}')

s=input()
n=len(s)
print(dfs(s,n,0,s[0]))

Measured memory_bytes: 9000
#include <bits/stdc++.h>
#define int long long
/// n-s=p(b-1);
using namespace std;
int f(int b,int n){
    if(n<b) return n;
    return f(b,n/b)+n%b;
}
main(){
    int n,s;
    scanf("%lld %lld",&n,&s);
    for(int b=2;b<=sqrt(n);++b)
        if(f(b,n)==s) return printf("%lld\n",b),0;
    int D=1;
    for(;D*D<=n-s;++D)
        if((n-s)%D==0&&f(D+1,n)==s)
            return printf("%lld\n",D+1),0;
    for(--D;D;--D)
        if((n-s)%D==0&&f((n-s)/D+1,n)==s)
            return printf("%lld\n",(n-s)/D+1),0;
    if(n==s) return printf("%lld\n",n+1),0;
    printf("-1\n");
    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

bool in(string s1, string s2) {
  int64 idx = 0;
  REP(i, s2.size()) {
    if (idx < s1.size() && s1[idx] == s2[i]) idx++;
  }
  return idx == s1.size();
}

::std::vector<::std::int64_t> divisors(::std::int64_t x) {
	::std::vector<::std::int64_t> res;
	for (::std::int64_t i = 1; i*i <= x; ++i) {
		if (x % i == 0) {
			res.push_back(i);
			if (i * i != x) res.push_back(x / i);
		}
	}
	::std::sort(res.begin(), res.end());
	return res;
}

int main(void) {
  int64 N, M;
  cin >> N >> M;
  vector<int64> G(N+1, 0);
  REP(i, M) {
    int64 l, r;
    cin >> l >> r;
    G[l-1]++;
    G[r]--;
  }
  int64 res = 0;
  REP(i, N) {
    G[i+1] += G[i];
    if (G[i] == M) res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	int a;
	int b;
	int c;
	
	scanf("%d", &a);
	scanf("%d", &b);
	
	if(a==1 && b==2) puts("3");
	else if(a==1 && b==3) puts("2");
	else if(a==2 && b==1) puts ("3");
	else if(a==2 && b==3) puts("1");
	else if(a==3 && b==1) puts("2");
	else if(a==3 && b==2) puts("1");
	
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  int odds=1;
  for(int x:A){
    if(x%2==0)
      odds*=2;
  }
  int ans=1;
  for(int i=0;i<N;i++){
    ans*=3;
  }
  cout<<ans-odds<<endl;
}


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


int main(void){
    int n, k;
    cin>>n>>k;
    vector<int> v(n);
    rep(i, n) {
        int a;
        cin>>a;
        --a;
        v[a]++;
    }
    sort(v.begin(), v.end(), greater<int>());
    int ans=0;
    for(int i= k;i<n;i++) ans+=v[i];
    cout<<ans<<endl; 
    return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using llu = long long unsigned;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

llu power( llu b, llu x ){
    ll t = 1;
    while( x ){
        if( x&1 ) t *= b;
        b *= b;
        x >>= 1;
    }
    return t;
}
llu powerm( llu b, llu x, llu m ){
    ll t = 1;
    while( x ){
        if( x&1 ) t *= b;
        t %= m;
        b *= b;
        b %= m;
        x >>= 1;
    }
    return t;
}

int main() {

    string s,t;
    cin >> s >> t;
    while( s.size() < t.size() ) s += s;

    int N = s.size();
    int M = t.size();

    s += s;

    llu b = 1000000007;
    llu bb = 998244353;
    llu m = 1000000007;

    llu hs = 0;
    llu ht = 0;
    llu hhs = 0;
    llu hht = 0;
    vector<bool> eq(N,false);
    vi id(N,0);
    vi dep(N,0);

    Rep(i,M){
        ht = ht*b + t[i];
        hht = (hht*bb + t[i])%m;
    }

    Rep(i,M){
        hs = hs*b + s[i];
        hhs = (hhs*bb + s[i])%m;
    }

    Rep(i,N){
        if( ht == hs && hht == hhs ) eq[i] = true;
        hs = hs*b + s[M+i] - s[i] * power(b,M);
        hhs = hhs*bb + s[M+i] - s[i] * powerm(bb,M,m) + m;
        hhs %= m;
    }


    int idd = 1;
    int ans = 0;
    int tmp = 0;
    function<int(int)> dfs = [&]( int from ){
        if( dep[from] ) return dep[from];
        id[from] = idd;

        if( !eq[from] ) return 0;

        int to = (from+M)%N;
        if( id[from] == id[to] ){
            return -1000000007;
        }
        return dep[from] = dfs(to)+1;

    };
    Rep(i,N){
        int from = i;
        tmp = dfs(from);
        if( tmp < 0 ) { ans = -1; break; }
        ans = max(ans,tmp);
        idd++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 26312
N = int(input())
A = [-1] + list(map(int, input().split()))
B, C = list(map(int, input().split())), list(map(int, input().split()))

ans = 0
for i in range(1, N + 1):
    ans += B[A[i] - 1]
    if A[i] == A[i - 1] + 1:
        ans += C[A[i] - 2]

print(ans)


Measured memory_bytes: 3060
N=int(input())
a=list(map(int, input().split()))
a.sort()
s1=0
s2=0
#print(a)
for i in range(N) :
    if i%2 == 0 :
        s1+=a[i]
    else :
        s2+=a[i]
print(abs(s1-s2))

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

using namespace std;

int main()
{
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if(t <= s) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3632
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

int N;
string s[100000];

void solve()
{
    ll ans = 0;
    int i = 0;

    sort(s, s+N);
    while(i < N){
        int j = 1;
        while(i+j < N){
            if(s[i] == s[i+j]) ans += j;
            else break;
            j++;
        }
        i += j;
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N){
        cin >> s[i];
        sort(ALL(s[i]));
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 5760
#include <stdio.h>
#include <math.h>


typedef struct Point{ 
double x; 
double y; 
}Point_t;

void kock(int n, Point_t a,Point_t b){
	if(n == 0)return;
	Point_t s, t, u;
	double th = M_PI * 60.0 / 180.0;
	
	s.x = (2.0 * a.x + 1.0 * b.x) /3.0;
	s.y = (2.0 * a.y + 1.0 * b.y) /3.0;
	t.x = (1.0 * a.x + 2.0 * b.x) /3.0;
	t.y = (1.0 * a.y + 2.0 * b.y) /3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;


	kock(n-1,a,s);
	printf("%.8f %.8f\n",s.x , s.y);
	kock(n-1,s,u);
	printf("%.8f %.8f\n",u.x , u.y);
	kock(n-1,u,t);
	printf("%.8f %.8f\n",t.x , t.y);
	kock(n-1,t,b);
}

int main(void){
	Point_t a, b;
	int n;
	
	scanf("%d",&n);
	
	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;

	printf("%.8f %.8f\n",a.x , a.y);
	kock(n,a,b);
	printf("%.8f %.8f\n",b.x , b.y);

	return 0;
}


Measured memory_bytes: 2044
use std::collections::HashMap;
use std::io;

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let s = input_line_str();
    let mut m = HashMap::new();
    for z in s.chars() {
        let p = m.entry(z).or_insert(0);
        *p += 1;
    }
    let mut flag = true;
    for (_i, x) in &m {
        if *x % 2 != 0 {
            flag = false;
            break;
        }
    }
    if flag {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int Maxn=300;
char s[Maxn];
int ans=0;
void Solve()
{
    cin>>(s+1);
    int len=strlen(s+1);
    for(int i=1;i<=len/2;i++) if(s[i]!=s[len-i+1]) ans++;
    printf("%d",ans);
}
int main()
{
    Solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */

struct UnionFind{
  vector<long long> data;
  UnionFind(long long N) :data(vector<long long>(N,-1)){}
  void boot(long long n){
    for(long long i = 0;i < n;i++)data.push_back(-1);
    return;
  }
  long long root(long long x){
    if(data[x] < 0)return x;
    else return data[x] = root(data[x]);
  }
  bool same(long long x,long long y){
    return root(x) == root(y);
  }
  void unite(long long x,long long y){
    if(!same(x,y)){
      x = root(x);
      y = root(y);
      if(data[x] < data[y]){
        data[x] += data[y];
        data[y] = x;
      }
      else{
        data[y] += data[x];
        data[x] = y;
      }
    }
    return;
  }
  long long getsize(long long x){
    return -data[root(x)];
  }
};

/* main */

signed main(){
    ll N,K,L;
    cin >> N >> K >> L;
    UnionFind train(N);
    UnionFind road(N);
    FOR(i,0,K){
        ll p,q;
        cin >> p >> q;
        road.unite(p-1,q-1);
    }
    FOR(i,0,L){
        ll r,s;
        cin >> r >> s;
        train.unite(r-1,s-1);
    }
    map<pl,ll> m;
    FOR(i,0,N)m[make_pair(road.root(i),train.root(i))]++;
    FOR(i,0,N){
        cout << m[make_pair(road.root(i),train.root(i))] << ' ';
    }
}

Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
  int n, W;
  cin>>n>>W;
  int w[n], v[n];
  for(int i=0; i<n; i++)
    cin>>w[i]>>v[i];
  int dp[n+1][W+1];
  for(int i=0; i<=n; i++){
    for(int j=0; j<=W; j++){
      if(i == 0 || j == 0)
        	dp[i][j] = 0;
      else if( w[i-1] <= j)
        dp[i][j] = max(dp[i-1][j-w[i-1]] + v[i-1], dp[i-1][j]);
      else
        	dp[i][j] = dp[i-1][j];
    }
  }
  cout<<dp[n][W];
  return 0;
}

Measured memory_bytes: 79104
#include<stdio.h>

int main(void){
    int n;
    scanf("%d", &n);
    int data[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &data[i]);
    }
    for(int i = 0; i < n; i++){
        if(data[i] % 2 == 0 && (data[i] % 3 != 0 && data[i] % 5 != 0)){
            printf("DENIED\n");
            return 0;
        }
    }
    printf("APPROVED\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h> 
#define int long long int 
using namespace std; 
int32_t main(){ 
    int n,m; 
    cin>>n>>m; 
    int ans = n * ( n - 1) / 2; 
    ans += (m * ( m - 1) ) / 2; 
    cout<<ans<<endl; 
}

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


int main()
{
	int n,a,sum=0;
	vector<int>v;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n-1;i++)
	{
		sum+=v[i];
	}
	if(sum>v[n-1])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<ll> A(X), B(Y), C(Z);
  for (int i = 0; i < X; i++)
    cin >> A[i];
  for (int i = 0; i < Y; i++)
    cin >> B[i];
  for (int i = 0; i < Z; i++)
    cin >> C[i];
  sort(A.begin(), A.end(), greater<ll>());
  sort(B.begin(), B.end(), greater<ll>());
  sort(C.begin(), C.end(), greater<ll>());
  vector<ll> res;
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      for (int k = 0; k < Z; k++) {
        if ((i + 1) * (j + 1) * (k + 1) <= K)
          res.push_back(A[i] + B[j] + C[k]);
        else
          break;
      }
    }
  }
  sort(res.begin(), res.end(), greater<ll>());
  for (int i = 0; i < K; i++)
    cout << res[i] << '\n';
  return 0;
}


Measured memory_bytes: 1404
<?php

function chmin(&$a, $b) {
    if ($a > $b) {
        $a = $b;
    }
}
function chmax(&$a, $b) {
    if ($a < $b) {
        $a = $b;
    }
}

fscanf(STDIN, "%d", $n);
$h = explode(' ', trim(fgets(STDIN)));

$dp = array_fill(0, $n, PHP_INT_MAX);
$dp[0] = 0;
$dp[1] = abs($h[1] - $h[0]);
for ($i = 2; $i < $n; ++$i) {
    chmin($dp[$i], $dp[$i - 1] + abs($h[$i - 1] - $h[$i]));
    chmin($dp[$i], $dp[$i - 2] + abs($h[$i - 2] - $h[$i]));
}

echo $dp[$n - 1];


Measured memory_bytes: 16884
n = int(input())
w = list(map(int, input().split()))
s2 = ans = sum(w)
s1 = 0
for i in range(n-1):
  s2 -= w[i]
  s1 += w[i]
  if ans < abs(s2-s1):
    break
  else:
    ans = abs(s2-s1)

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
// #include<iostream>
// #include<vector>
// #include<cmath>
// #include<iomanip>
using namespace std;

const double PI= acos(-1.0);

int gcd_func(int a, int b){
    return b? gcd_func(b, a%b) : a;
} 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
   // freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int a,b,c,d,e; cin >> a>>b>>c>>d>>e;
    if(!a)
        cout << 1 << endl;
    else if(!b)
        cout << 2 << endl;
    else if(!c)
        cout << 3 << endl;
    else if(!d)
        cout << 4 << endl;
    else
        cout << 5 << endl;
    return 0;
}

Measured memory_bytes: 3604
fn main() {
    let n = read::<usize>();
    let a1 = read_vec::<usize>();
    let a2 = read_vec::<usize>();

    let mut ma = 0;
    for i in 1..n+1 {
        let mut sum = 0;
        for x in 0..i {
            sum += a1[x];
        }
        for y in i-1..n {
            sum += a2[y];
        }
        if ma < sum {
            ma = sum;
        }
    }
    println!("{}", ma);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
#define NIL -1
#define MAX 100001
struct Node
{
	int nParent;
	int nLeft, nRight;
};
Node nN[MAX];
int nD[MAX];


void rec(int nRoot, int nDepth)
{
	nD[nRoot] = nDepth;
	if (nN[nRoot].nRight != NIL)
	{
		rec(nN[nRoot].nRight, nDepth);
	}
	if (nN[nRoot].nLeft != NIL)
	{
		rec(nN[nRoot].nLeft, nDepth + 1);
	}
}

void print(int u)
{
	int i, c;
	cout << "node " << u << ": parent = " << nN[u].nParent << ", depth = " << nD[u] << ", ";
	if (nN[u].nParent == NIL)
	{
		cout << "root, ";
	}
	else if (nN[u].nLeft == NIL)
	{
		cout << "leaf, ";
	}
	else
	{
		cout << "internal node, ";
	}
	cout << "[";
	for (int i = 0, c = nN[u].nLeft; c != NIL; i++, c = nN[c].nRight)
	{
		if (i)
		{
			cout << ", ";
		}
		cout << c;
	}
	cout << "]" << endl;
}


int main()
{
	int nIn;
	cin >> nIn;
	int id, k;
	int c;
	int l, r;
	for (int i = 0; i < nIn; i++)
	{
		nN[i].nLeft = NIL;
		nN[i].nRight = NIL;
		nN[i].nParent = NIL;
	}
	for (int i = 0; i < nIn; ++i)
	{
		cin >> id >> k;
		for (int j = 0; j < k; ++j)
		{
			cin >> c;
			if (j == 0)
			{
				nN[id].nLeft = c;
			}
			else
			{
				nN[l].nRight = c;
			}
			l = c;
			nN[l].nParent = id;
		}
	}
	for (int i = 0; i < nIn; ++i)
	{
		if (nN[i].nParent == NIL)
		{
			r = i;
		}
	}
	rec(r, 0);

	for (int i = 0; i < nIn; ++i)
	{
		print(i);
	}
}


Measured memory_bytes: 7684