akhauriyash/Code-Regression huggingface dataset:
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1000000007;

int main() {
  ll n, e;
  cin >> n >> e;
  vvll d(n, vll(n, INF));
  rep(i, e) {
    ll u, v, w;
    cin >> u >> v >> w;
    d[u][v] = w;
  }

  rep(i, n) d[i][i] = 0;

  rep(k, n) rep(i, n) rep(j, n) {
    if(d[i][k] != INF && d[k][j] != INF)
      chmin(d[i][j], d[i][k] + d[k][j]);
  }

  rep(i, n) {
    if (d[i][i] < 0) {
      puts("NEGATIVE CYCLE");
      return 0;
    }
  }

  rep(i, n) rep(j, n) {
    if (d[i][j] == INF)
      cout << "INF";
    else
      cout << d[i][j];

    if (j == n - 1)
      cout << endl;
    else
      cout << " ";
  }

  return 0;
}



Measured memory_bytes: 3228
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;

    queue<pair<int, int> > que;
    vector<vector<int> > table(h, vector<int>(w, 0));
    rep(i, h) {
        rep(j, w) {
            char ch;
            cin >> ch;
            if (ch == '#') {
                que.push(make_pair(i, j));
                table[i][j] = 0;
            } else {
                table[i][j] = -1;
            }
        }
    }

    // DFS
    while (not que.empty()) {
        auto xy = que.front();
        que.pop();

        int x = xy.first;
        int y = xy.second;

        rep(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];

            if (nx >= 0 and nx < h
                and ny >= 0 and ny < w
                and table[nx][ny] == -1) {

                que.push(make_pair(nx, ny));
                table[nx][ny] = table[x][y] + 1;
            }
        }
    }

    int ans = 0;
    rep(i, h) {
        rep(j, w) {
            ans = max(ans, table[i][j]);
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int a[105][105], b[105];

bool check() {
    if (b[a[1][1]] == b[a[2][2]] && b[a[2][2]] == b[a[3][3]] && b[a[3][3]] == 1) return true;
    if (b[a[3][1]] == b[a[2][2]] && b[a[2][2]] == b[a[1][3]] && b[a[1][3]] == 1) return true;
    for (int i = 1; i <= 3; i++) {
        if (b[a[i][1]] == b[a[i][2]] && b[a[i][2]] == b[a[i][3]] && b[a[i][3]] == 1) return true;
        if (b[a[1][i]] == b[a[2][i]] && b[a[2][i]] == b[a[3][i]] && b[a[3][i]] == 1) return true;
    }
    return false;
}

int main() {
    int n, x;
    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= 3; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &x);
        b[x] = 1;
    }

    printf("%s\n", (check() ? "Yes" : "No"));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int isprime(int n, int k = 2)
{
    if(n == 1) { return 0; }
    
    if(n < k * k) { return 1; }
    
    if(n % k == 0) { return 0; }
    
    return isprime(n, k + 1);
}

int solve(int n)
{
    int count_ = 0;
    
    for(int i = 1; i <= n; i++)
    {
        count_ += isprime(i) * isprime(n + 1 - i);
    }
    
    return count_;
}

int main()
{
    int n;
    
    while(cin >> n)
    {
        cout << solve(n) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pii pair<int, int>
#define LL long long
#define mp make_pair
#define pb push_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
int n, sum, ans, a[maxn];

int main() {
	#ifdef DEBUG
	freopen("text.in", "r", stdin);
	#endif
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for (int i = n; i; --i) {
		(ans += 1ll * a[i] * sum % mod) %= mod;
		(sum += a[i]) %= mod;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4432
n = input()
last = n[-1]
if last == "2" or last == "4" or last == "5" or last == "7" or last == "9":
    print('hon')
elif last == last == "0" or last == "1" or last == "6" or last == "8":
    print('pon')
else:
    print('bon')

Measured memory_bytes: 61640
#include<bits/stdc++.h>
#define For(i,j,k) for (int i=j;i<=k;i++)
using namespace std;
int a[105],n,m,ans;
int dp[55][105][105];
const int mo=1000000007;
void upd(int &x,int y){
	(x+=y)>=mo?x-=mo:233;
}
int main(){
	scanf("%d",&m); n=m*2-1;
	For(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	a[0]=a[1]; a[n+1]=a[n];
	dp[m][1][1]=1;
	for (int i=m;i;i--){
		int t=(a[i]!=a[i-1])+(a[m*2-i]!=a[m*2-i+1]);
		int tt=(a[i]!=a[i-1]);
		For(j,0,n) For(k,1,j)
			if (dp[i][j][k]){
				For(l,1,k-1) upd(dp[i-1][j-(k-l-1)+t][l+tt],dp[i][j][k]);
				upd(dp[i-1][j+t][k+tt],dp[i][j][k]);
				For(l,k+1,j) upd(dp[i-1][j-(l-k-1)+t][k+tt+1],dp[i][j][k]);
			}
	}
	For(i,0,n) For(j,0,n) 
		upd(ans,dp[0][i][j]);
	printf("%d\n",ans);
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {
    public static void main(String[] args) {

    	try{
    		InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader br = new BufferedReader(isr);
			while(true){
				String buf = br.readLine();
				StringTokenizer st=new StringTokenizer(buf," ");
	    		int x = Integer.parseInt(st.nextToken());
	    		int y = Integer.parseInt(st.nextToken());
				if(x == 0 && y==0) break;
				if(x > y){
					int storage=y;
					y=x;
					x=storage;
				}
				System.out.println(x+" "+y);
    		}

    	} catch(IOException e) {
    		System.err.println(e);
		}
    }
}

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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if((x-r)>=0 && (y-r)>=0 && (x+r)<=W && (y+r)<=H)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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


char bub[36][3];
char sel[36][3];
//入力数確認
int val;

void bubble(void){
  int s,i;
  char tmp[3];

  for(i = 0;i < val;i++){
    for(s = val-1;s > i;s--){
      if(bub[s][1]<bub[s-1][1]){
	strcpy(tmp,bub[s-1]);
	strcpy(bub[s-1],bub[s]);
	strcpy(bub[s],tmp);
      }
    }
  }
}

void select(void){
  int s,i,cmp;
  char tmp[3];
  
  for(i = 0;i < val;i++){
    cmp = i;
    for(s=i+1;s<val;s++){
      if(sel[s][1]<sel[cmp][1])
	cmp = s;
    }
    strcpy(tmp,sel[i]);
    strcpy(sel[i],sel[cmp]);
    strcpy(sel[cmp],tmp);
  }
}

int main(){
  
  //比較のフラグ
  int flg = 0;
  int j; 
  char scn[36][3];
  char kind[4];  

  scanf("%d",&val);
  
  for(j = 0;j < val;j++){
    scanf("%s",scn[j]);
    strcpy(bub[j],scn[j]);
    strcpy(sel[j],scn[j]);
  }

  //バブルソート
  bubble(); 
  for(j = 0;j < val - 1;j++)
    printf("%s ",bub[j]);
  printf("%s\n",bub[j]);
  //バブルソートは後ろから順番に並び替えられてゆき、同じ数字の時に順番が入れ替わらないので絶対に安定
  printf("Stable\n");
    
  //選択ソート
  select(); 
  for(j = 0;j < val - 1;j++)
    printf("%s ",sel[j]);
  printf("%s\n",sel[j]);

  //絶対安定のバブルソートと比較すれば良い
  for(j = 0;j < val;j++){
    if(strcmp(sel[j],bub[j]) != 0){
      flg = 1;
      break;
    }
  }
   
  if(flg == 0)printf("Stable\n");
  else printf("Not stable\n");
  
  return 0;
}

Measured memory_bytes: 620
def solve(N, a):
    count = 0
    for i in range(1,N+1):
        if i % 2 == 1 and a[i] % 2 ==1:
            count += 1
    return count
N = int(input())
a = [0] + list(map(int, input().split()))
print(solve(N, a))

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  string s, t;
  cin >> s >> t;
  bool flag = 1;
  rep(i, s.size()) {
    if (s.at(i) != t.at(i)) flag = 0;
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#define MAX 100000
typedef long long llong;
int n, k;
llong T[MAX];

int check(llong P) {
  int i = 0;
  for (int j = 0; j < k; j++) {
    llong s = 0;
    while (s + T[i] <= P) {
      s += T[i];
      i++;
      if (i == n) return n;
    }
  }
  return i;
}

int solve() {
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while (right - left > 1) {
    mid = (left + right) / 2;
    int v = check(mid);
    if (v >= n ) right = mid;
    else left = mid;
  }

  return right;
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> T[i];
  llong ans = solve();
  cout << ans << endl;
}


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

typedef long long LL;
const int MAXN = 8;
int a[MAXN];
int main() {
    for(int i=0; i<6; i++) cin>>a[i];
    if(a[4]-a[0] > a[5]) cout<<":(\n";
    else cout<<"Yay!"<<endl;
    return 0;
}


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

//LIFE IS NOT A PROBLEM TO BE SOLVED

#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) cout << mat[i][j] << " "; cout << endl; }

using namespace std;
typedef pair <int, int> ii;
typedef long long int ll;


int main(){
	
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k&1){
		printf("%lld\n", b-a);
	}else{
		printf("%lld\n", a-b);
	}
	
	return 0;
	while(k--){
		ll aa = b+c;
		ll bb = a+c;
		ll cc = a+b;
		a = aa, b = bb, c = cc;
	}
	
	cout << a-b << '\n';
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int a,b;
	cin>>a>>b;
	if(a+b>=10)cout<<"error"<<endl;
	else cout<<a+b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <tuple>
#include <utility>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
	

int main(){

	int a,b;
	cin>>a>>b;


	int i=0;
	while(a*i-i+1<b){
		i++;
	}

	cout<<i<<endl;
    return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}

void ff(int n, int t, vector<pii>& vp){
	sort(all(vp));
	VL dp(6020);
	
	rep(i, n) repr(j, t-1, 0) {
		dp[j + vp[i].first] = max(dp[j+vp[i].first], dp[j] + vp[i].second);
	}
	
	
	cout << *max_element(all(dp)) <<"\n";
}
void ff2(int n, int t, vector<pii>& vp){

	vector<VL> dp1(n+2, VL(t+3)), dp2(n+2, VL(t+3));
	rep(i, n) rep(j, t){
		amax(dp1[i+1][j], dp1[i][j]);
		if(j+vp[i].first<=t)
		 amax(dp1[i+1][j+vp[i].first], dp1[i][j] + vp[i].second);
	}
	repr(i, n-1, 0) rep(j, t) {
		amax(dp2[i][j], dp2[i+1][j]);
		if(j+vp[i].first<=t)
			amax(dp2[i][j+vp[i].first], dp2[i+1][j] + vp[i].second);
	}
	
	ll ans =0;
	rep(i, n) rep(j, t){
		amax(ans,  vp[i].second + dp1[i][j] + dp2[i+1][t-1-j]);
	}
	cout << ans <<"\n";
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, t;
	cin >>n >>t;
	vector<pii> vp(n);
	rep(i, n) cin >>vp[i].first >>vp[i].second;
	
	//ff(n, t, vp);
	ff2(n, t, vp);
	return 0;
}


Measured memory_bytes: 141440
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def lcm(a, b):
    return (a // gcd(a, b)) * b

while True:
    n = int(input())
    if n == 0:
        break

    students = [0] * n
    v_lcm = 1
    for i in range(n):
        students[i] = list(map(int, input().split()))
        v_lcm = lcm(v_lcm, students[i][1])
    mul_lcm = 1
    for i in range(n):
        mul_lcm = lcm(mul_lcm, (v_lcm // students[i][1]) * students[i][0])
    for i in range(n):
        print(mul_lcm // (v_lcm // students[i][1]) // students[i][0])



Measured memory_bytes: 5780
n=int(input())
data_origin=[input().split() for i in range(n)]
for i in range(n):
  data_origin[i][1] = int(data_origin[i][1])
data = sorted(data_origin, key=lambda x:x[1],reverse=True)
data = sorted(data, key=lambda x:x[0])
for i in data:
  print(1+data_origin.index(i))

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX_N = 100000;
int h[MAX_N], dp[MAX_N+1];
int n;
void solve(){
    dp[0] = 0;  dp[1] = abs(h[1]-h[0]);
    for(int i=2 ; i<n ; i++){
        dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
    }
    printf("%d", dp[n-1]);
}
int main(){
    scanf("%d", &n);
    for(int i=0 ; i<n ; i++){
        scanf("%d", &h[i]);
    }
    solve();
    return 0;
}

Measured memory_bytes: 896
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> &P){
os << P.first;
os << " ";
os << P.second;
os << "\n";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
//fixed<<setprecision(10)<<ans<<endl;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    
    int ans = 0;

    stack<int> q;
    vector<pair<int,int>> L; // ( ,みずたまり )

    REP(i,S.size()){
        char s = S[i];
        if(s=='\\'){
            q.push(i);
        }else if(s=='/'){
            if(q.empty())continue;
            int l = i-q.top();
            ans += l;
            while(!L.empty()){
                if(L.back().first < q.top()) break;
                l += L.back().second;
                L.pop_back();
            }
            L.push_back(mp(q.top(), l));
            q.pop();
        }
    }
    cout << ans << endl;
    cout << L.size();
    for(auto P:L)
    {
        cout << " " << P.second;
    }
    cout << endl;

}



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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    if(K < A) cout << K << endl;
    else if(K <= B) cout << A << endl;
    else cout << A - (K - A - B) << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    char b;
    cin >> b;
    if (b == 'A') cout << 'T';
    if (b == 'T') cout << 'A';
    if (b == 'G') cout << 'C';
    if (b == 'C') cout << 'G';
    cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;

int main(){
	LL a,b,c;
	cin >> a >> b >> c;
	if(a + b > c) cout << "No" << endl;
	else{
		if(4 * a * b < (a + b - c) * (a + b - c)) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int n, m; cin >> n >> m;
	vector<ll> a(m), b(m), c(m);
	rep(i, 0, m) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
	}
	vector<vector<ll>> dist(n);
	rep(i, 0, n) {
		dist[i].resize(n, INF);
		dist[i][i] = 0;
	}
	rep(i, 0, m) {
		dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
		dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
	}
	rep(k, 0, n)rep(i, 0, n)rep(j, 0, n) {
		dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	}
	int ans = m;
	rep(i, 0, m) {
		bool flag = false;
		rep(j, 0, n)if (dist[j][a[i]] + c[i] == dist[j][b[i]]) flag = true;
		if (flag) ans--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
/**
  * author : thegeniushead
**/
#include <bits/stdc++.h>
 
/*.....DEFINITIONS...... */
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define T() int tt; cin>>tt; while(tt--)
#define rep(i,start,lim) for(int i=start;i<lim;i++)
#define rep1(i,start,lim) for(int i=start; i<=lim; ++i)
#define repd(i,start,lim) for(int i=start;i>=lim;i--)
#define mp make_pair
#define pb push_back
#define lchild (2*node+1)
#define rchild (2*node+2)
#define ff first
#define ss second
#define br cout<<"\n"
#define MOD (1000000007LL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eps (1e-6)
#define what_is(x) cerr << #x << " is " << x << "\n";
#define int long long int
#define infll 9e18
#define inf 1e12

using namespace std;
 
/*.....TYPEDEFS ....*/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long double ld;
 
/*....USEFUL FUNCTIONS....*/
ll pwr(ll base, ll exp, ll mod=MOD){ll res=1; while(exp>0){if(exp%2){res=(res*base)%mod;}base=(base*base)%mod;exp/=2;}return res;}
ll gcd(ll a, ll b){ if(b==0)return a; else gcd(b, a%b);}
bool isPrime(ll n){if(n<=1)return false;if(n<=3)return true;if (n%2==0||n%3==0)return false;for(int i=5; i*i<=n; i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
 
/*....I/O Functions...*/
inline string rs(){char x[1234567];scanf("%s", x);string s = x; return s;}
inline int ri(){int x; scanf("%d", &x);return x;}
inline long long rl(){long long x; scanf("%lld", &x); return x;}
 
/*---------Solution below this line --------*/
 
const int N = 123456;

int r, g;

int32_t main()
{
	// FIO
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	
	cin >> r >> g;
	
	cout << 2 * g - r << '\n';
	
	
	
	
	
	
	
	
	
	
	
		
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = (a); i <= (n); i++)
#define repb(i, a, n) for (int i = (a); i >= (n); i--)
#define all(x) x.begin(), x.end()
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
inline void fastio() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
}

void co_elem(vector<int> &A) {
    rep(i, 0, A.size() - 1) {
        if (i < A.size() - 1) {
            cosp(A[i]);
        } else {
            co(A[i]);
        }
    }
}

void bubbleSort(vector<int> &A, int N, int &changed) {
    int flag = 1;
    int i = 0;
    while (flag) {
        flag = 0;
        repb(j, N - 1, i + 1) {
            if (A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                flag = 1;
                changed++;
            }
        }
        i++;
    }
}

void selectionSort(vector<int> &A, int N, int &changed) {
    rep(i, 0, N - 1) {
        int minv = A[i], tmp = 0;
        rep(j, i + 1, N - 1) {
            if (A[j] < minv) {
                minv = A[j];
                tmp = j;
            }
        }
        if (A[i] != minv) {
            swap(A[i], A[tmp]);
            changed++;
        }
    }
}

int main() {
    int N, changed = 0;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N - 1) {
        cin >> A[i];
    }
    selectionSort(A, N, changed);
    co_elem(A);
    co(changed);
    return 0;
}


Measured memory_bytes: 3076
n = int(input())
t, a = map(int, input().split())
H = list(map(int, input().split()))
Temps = [t - h * 0.006 for h in H]
Diff_abs = [abs(a - temp) for temp in Temps]
ans = Diff_abs.index(min(Diff_abs))
print(ans + 1)

Measured memory_bytes: 38256
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> m;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		m[a[i]] += 1;
	}
	for (int i = 0; i < n; ++i) {
		map<int, int>::reverse_iterator it = m.rbegin();
		int mx = it->first;
		if (a[i] == mx && it->second == 1) {
			++it;
			mx = it->first;
		}
		cout << mx << endl;
	}
	return 0;
}


Measured memory_bytes: 7936
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<ll,ll> P;
//ll const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

ll N,K,S;
ll A[100000];

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

    rep(i,N){
        if(i<K) A[i]=S;
        else A[i]=(S+3)/2+1;
    }

    rep(i,N) cout<<A[i]<<' ';
    cout<<endl;
}

Measured memory_bytes: 4408
#include<iostream>
#include<algorithm>
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS )
using namespace std;

class Point {
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}
	Point operator + (Point p) {
		return Point(x + p.x, y + p.y); 
	}
	Point operator - (Point p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator * (double a) {
		return Point(a * x, a * y);
	}
	Point operator / (double a) {
		return Point(x / a, y / a);
	}

	double abs() {
		return sqrt(norm());
	}
	double norm() {
		return x * x + y * y;
	}

	bool operator < (const Point &p)const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p)const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};

typedef Point Vector;

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}


int main() {
	int i, q, x0, x1, x2, x3, y0, y1, y2, y3;
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		Vector v1(x1 - x0, y1 - y0), v2(x3 - x2, y3 - y2);
		if (equals(dot(v1, v2), 0))cout << 1 << endl;
		else if (equals(cross(v1, v2), 0))cout << 2 << endl;
		else cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 3116
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

x, y = MAP()
for i in range(x + 1):
    foot = i * 2 + 4 * (x - i)
    if foot == y:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 72744
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  vi hs(N);
  cin >> hs;
  sort(rrng(hs));
  i64 r = INT64_MAX;
  F0R(i, N - K + 1) {
    chmin(r, hs[i] - hs[i + K - 1]);
  }
  cout << r;
}
#endif


Measured memory_bytes: 3724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		long N = Long.parseLong(str.substring(0, str.indexOf(" ")));
		long M = Long.parseLong(str.substring(str.indexOf(" ") + 1));
		long s = 0;
		long n = N;
		long m = M / 2;
		if(n <= m) s += n;
		else s += m;

		M -= 2 * s;

		if(M >= 4) s += M / 4;
		System.out.println(s);
	}
}

Measured memory_bytes: 21332
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <bitset>
#include <queue>
#include <deque>
#include <utility>
#include <algorithm>
#include <ctime>
using namespace std;

int const MAX_N = 512 * 1024;

int s[MAX_N];

int my_abs(int x) {
	if (x<0) return -x;
	return x;
}

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
 
	int n;
	scanf("%d",&n);
	for (int i=1; i<=n; i++) scanf("%d",&s[i]);
	int sum = 0;
	for (int i=1; i<=n; i++) sum += my_abs(s[i]-s[i-1]);
	sum += my_abs(s[0]-s[n]);
	for (int i=1; i<=n; i++) {
		int ip = i-1;
		if (ip<0) ip = n;
		int inn = i+1;
		if (inn>n) inn = 0;
		printf("%d\n",sum - my_abs(s[i]-s[ip])-my_abs(s[i]-s[inn])+my_abs(s[ip]-s[inn]));
	}
    return 0;
}  


Measured memory_bytes: 1664
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()
query = [getList() for i in range(N)]
query_before = copy.deepcopy(query)

def warshall_floyd(dist):
    for k in range(N):
        # i:start j:goal k:中間地点でループ回す
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    return dist

warshall_floyd(query)

if query != query_before:
    print(-1)
    exit()

edges = []
for i in range(N):
    for j in range(i + 1, N):
        edges.append([query[i][j], i, j])

cnt = 0
for i in edges:
    flag = True
    w, s, t = i
    for k in range(N):
        if k != s and k != t and w >= query[s][k] + query[k][t]:
            flag = False
            break
    if flag:
        cnt += w
print(cnt)

Measured memory_bytes: 92784
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0,nn=(intl)(n);i<nn;++i)
#define Rep1(i,n) for(intl i=1,nn=(intl)(n)+1;i<nn;++i)
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);}
#define Input2(a,b) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);cin>>(b).at(ii);}
#define mp make_pair
#define mt make_tuple
using intl = int64_t;
using vi = vec<intl>;
using vb = vec<bool>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
using si = set<intl>;
using vsi = vec<si>;
using mii = map<intl,intl>;
using vmii = vec<mii>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;



int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  
  intl N;
  cin >>N;
  vi A(N);
  Input(A);
  
  SortD(A);
  
  deque<intl> csp;
  intl bestsp;
  intl ans =0;
  for(auto a:A){
    if(csp.empty()){
      csp.push_back(a);
    }else{
      bestsp = csp.front();
      csp.pop_front();
      ans += bestsp;
      csp.push_back(a);
      csp.push_back(a);
    }
  }
  cout <<ans;
}
  
    

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

#define MOD (1000000)

int f(int x, int y){
	static int64_t dp[1001][1001];

	if(x>y) swap(x,y);

	if(dp[x][y] == 0){
		if(x == 0 || y == 0){
			dp[x][y] = 1 + 1;
		}else{
			dp[x][y] = 1 + ((f(x-1,y) + f(x,y-1)) % MOD);
		}
	}

	return dp[x][y]-1;
}

struct Node {
	vector<Node*> win;

	int game;
	int64_t pattern;

	void foo(){
		game=0;
		pattern=1;
		for(Node * p : win){
			p->foo();
			pattern = (((pattern * f(p->game + 1, game)) % MOD) * p->pattern )% MOD;
			game += p->game + 1;
		}
	}
};

int main(){
	int N; cin>>N;
	
	Node node[N + 1];
	
	bool lose[N + 1];
	fill(lose, lose + N + 1, false);
	
	for(int i=1; i<N; ++i){
		int winner, loser;
		cin >> winner >> loser;
		
		node[winner].win.push_back(node + loser);
		
		lose[loser] = true;
	}

	for(int i=1; i<=N; ++i){
		if( !lose[i] ){
			node[i].foo();
			cout << node[i].pattern << endl;
			break;
		}
	}
}



Measured memory_bytes: 5788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = ll(1e9+7);

ll N, M, dp[1005][1005];  // dp[i][j] = tのi文字目までみてbのj文字目までつくる通り
string t, b;

int main() {
    cin >> t >> b;
    N = t.size();
    M = b.size();
    b.push_back('#');
    dp[0][0] = 1;
    for(int i=0;i<N;i++){
        for(int j=0;j<=M;j++){
            // i文字目を使わない遷移
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= MOD;
            // i文字目を使う遷移
            if(t[i]==b[j]){
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j+1] %= MOD;
            }
        }
    }
    cout << dp[N][M] << endl;
    return 0;
}


Measured memory_bytes: 11008
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>

#define lowbit(x) (x&(-x))
#define MAX(a,b) (a<b?b:a)
#define MIN(a,b) (a<b?a:b)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e7;
const int maxn = 3e5 + 5;
ll mod = 1e9 + 7;

int n;
ll a[maxn], b[maxn], cnt[maxn],idx[maxn], ans[maxn];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", a + i);
		b[i] = a[i];
	}
	sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; i++)
	{
		a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
		++cnt[a[i]];
		if (!idx[a[i]]) idx[a[i]] = i;
		else idx[a[i]] = MIN(idx[a[i]], i);
	}
	
	int cur = 100000, nxt;
	while (cur && !cnt[cur]) cur--;
	while (cur)
	{
		nxt = cur - 1;
		while (nxt && !cnt[nxt]) --nxt;

		ans[idx[cur]] += cnt[cur] * (b[cur] - b[nxt]);
		cnt[nxt] += cnt[cur];
		idx[nxt] = MIN(idx[nxt], idx[cur]);
		cur = nxt;
	}
	for (int i = 1; i <= n; i++)
	{
		printf("%lld\n", ans[i]);
	}
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}




int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> v(n), c(n);
	rep(i,n) cin >> v.at(i);
	rep(i,n) cin >> c.at(i);
	int ans = 0;
	rep(i,n) ans += max(0, v.at(i) - c.at(i));
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >>N;
  
   vector<int> d(N);
   for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
sort(d.begin(), d.end());
int ans=0;
 for (int i = 0; i < N; i++) {
 if(d[i]!=d[i+1]){
   ans++;
 }
   
} 
  cout <<ans<<endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdint>
#include<cstdio>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(b); ++i)
#define rep(i,n) for(int i=0; i<n; ++i)
#define all(v) begin(v), end(v)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const double PI = acos(-1.0);

int main() {
  std::ios::sync_with_stdio(false);

  int a,b,c;
  cin >> a >> b >> c;
  if (a + b < c) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    char s[16];
    int i,cnt=0;
    for(i=0;i<16;i++){
        s[i]=0;
    }
    scanf("%s",s);
    for(i=0;i<15;i++){
        if(s[i]!='x'){
            cnt++;
        }
    }
    if(cnt>=8){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> A(N), B(N);
    REP(i, 0, N) cin >> A[i] >> B[i];

    ll ans = 0;
    for (int i = N - 1; i >= 0; i--) {
        if ((A[i] + ans) % B[i] != 0) {
            ans += ((A[i] + ans) / B[i] + 1) * B[i] - (A[i] + ans);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
	char S[100];
	int i,count=0;
	long int K;
	
	scanf("%s",S);
	scanf("%ld",&K);
	
	for(i=0;S[i]!='\0';i++){
		if(S[i]!='1'){
			printf("%c\n",S[i]);
			return 0;
		} else{
			count++;
			if(count==K){
				printf("1\n");
				return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;


llint n, x;
llint b[100005], l[100005], u[100005];
bool used[100005];
vector<pair<P, llint> > vec;
vector<P> vec2;

bool check(llint m)
{
	llint sum = 0;
	for(int i = 1; i <= n; i++) sum -= l[i]*b[i];
	for(int i = 1; i <= n; i++) used[i] = false;
	
	llint full = m/x, rem = m%x;
	if(m/x >= n) return true;
	
	//cout << sum << endl;
	//cout << full << endl;
	
	llint fsum = 0;
	for(int i = 0; i < full; i++){
		used[vec[i].second] = true;
		fsum += vec[i].first.first;
	}
	llint ret = 0;
	for(int i = 1; i <= n; i++){
		llint tmp = fsum + min(rem, b[i]) * l[i];
		if(b[i] < rem) tmp += (rem-b[i]) * u[i];
		if(used[i]){
			tmp -= l[i]*b[i]+u[i]*(x-b[i]);
			tmp += vec[full].first.first;
		}
		ret = max(ret, tmp);
	}
	return ret+sum >= 0;
}

int main(void)
{
	cin >> n >> x;
	for(int i = 1; i <= n; i++){
		cin >> b[i] >> l[i] >> u[i];
	}
	for(int i = 1; i <= n; i++){
		vec.push_back(make_pair(make_pair(l[i]*b[i]+u[i]*(x-b[i]), -b[i]), i));
	}
	sort(vec.rbegin(), vec.rend());
	
	check(100);
	
	llint ub = 1e10+5, lb = -1, mid;
	while(ub-lb>1){
		mid=(ub+lb)/2;
		if(check(mid)) ub = mid;
		else lb = mid;
	}
	cout << ub << endl;
	return 0;
}

Measured memory_bytes: 7284
#include<iostream>
using namespace std;
int main()
{
    long long int x,m,n,y,s=0;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>x;
        s=s+x;
    }
    y=n-s;
    if(y>0||y==0)
    cout<<y;
    else
        cout<<-1;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int gcd(int a , int b)
{
	return b ? gcd(b , a % b) : a;
}
int a[N] , pre[N] , suf[N]; 
signed main()
{
	int n; 	
	cin >> n;
	for(int i = 1 ; i <= n ; i ++) cin >> a[i];
	for(int i = 1 ; i <= n ; i ++)
	{
		pre[i] = gcd(pre[i - 1] , a[i]);
		suf[n - i + 1] = gcd(suf[n - i + 2] , a[n - i + 1]);
	}
	int ans = 1;
	for(int i = 1 ; i <= n ; i ++) ans = max(ans , gcd(pre[i - 1] , suf[i + 1]));
	cout << ans << '\n' ;
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

struct UnionFind {
  vector<int> data; // 根の場合は集合の大きさ*-1、子の場合は親の番号が入る
  UnionFind(int size) : data(size, -1) { }
  bool link(int x, int y) { //新たな併合を行うとtrue
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  int root(int x) { // 代表元を返す
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) { // 要素xが含まれる集合の大きさ
    return -data[root(x)];
  }
  bool same(int x, int y) { // 同じ集合ならtrue
    return root(x) == root(y);
  }
  int num() { // 異なる集合の数
    int res = 0;
    REP(i, data.size()) res += root(i) == i;
    return res;
  }
};

const int MAX_N = 112345;
int P[MAX_N];
bool done[MAX_N];

int main2() {
  CLR(done, 0);
  int N = nextInt();
  int M = nextInt();
  UnionFind uf(N);
  REP(i, N) { P[i] = nextInt() - 1; }
  REP(i, M) {
    int x = nextInt() - 1;
    int y = nextInt() - 1;
    uf.link(x, y);
  }
  map<int, set<int>> R;
  map<int, vector<int>> I;
  REP(i, N) {
    int root = uf.root(i);
    R[root].insert(i);
    I[root].push_back(P[i]);
  }
  int ans = 0;
  REP(i, N) {
    if (I[i].size() == 0) continue;
    auto S = R[i];
    for (int x : I[i]) {
      if (S.count(x) > 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 26112
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
int n;
int p[200010];
int c[200010],f[200010];
int main(){
  scan(n);
  rep(i,n){
    scan(p[i]);
  }
  rep(i,n+1){
    c[i]=0;
    f[i]=0;
  }
  rep(i,n){
    if(c[p[i]-1]==1){
      f[p[i]]=1;
    }
    c[p[i]]=1;
  }

  int res=0,len=1;
  rep1(i,n){
    if(f[i]==0){
      res=max(res,len);
      len=1;
    }
    else{
      len++;
    }
  }
  res=max(res,len);
  prin(n-res);


    



  
  return 0;
}


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

int main(){
	int n;
	cin>>n;
	bool ans;
	int a[1000];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++){
		if(a[i]%2==0){
			if(a[i]%3==0 ||a[i]%5==0){
				ans=true;
				
			}else{
				ans=false;
				break;
			}
		}
		
	}
	if(ans==true)
		cout<<"APPROVED\n";
	else
		cout<<"DENIED\n";
		
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
string board[60];
int main(){
    int H, W;
    cin >> H >> W;
    int dh[8] = {1, 1, 0, -1, -1, -1, 0, 1};
    int dw[8] = {0, 1, 1, 1, 0, -1, -1, -1};
    for(int i = 0; i < H; i++)
        cin >> board[i];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int count = 0;
            if(board[i][j] == '.'){
                for(int k = 0; k < 8; k++){
                    int x = i + dh[k];
                    int y = j + dw[k];
                    if(x <= H && y <= W && x >= 0 && y >= 0 && board[x][y] == '#')
                        count++;
                }
                board[i][j] = '0' + count;
            }
        }
    }
    for(int i = 0; i < H; i++)
        cout << board[i] << endl;
    return 0;
}

Measured memory_bytes: 256