akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define endl '\n'

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define Pi 3.14159265358979
#define A first
#define B second

typedef long long ll;
typedef vector <int> vi;
typedef vector<ll> vl;
typedef pair <int, int> pi;
typedef pair <ll, int> pl;
typedef pair <ll, ll> pll;
typedef pair <double, double> pd;

//change these according to prob constraints
const int INF = 0x3f3f3f3f;
const int MAX = 100005;
const int MAX1 = 1005;
const int MAX2 = 105;
const int LEN = 105;
const int BASE = 1000000000;
const double EPS = 1e-7;
const int MOD = 1000000007;
//g++ -std=c++11 your_file.cpp -o your_program

ll mypow(ll a, ll b){
	ll ans=1;
	while(b){
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ifstream in("");
	ofstream out("");
	clock_t begin = clock();
	int n;
	cin >> n;
	vi arr;
	REP(i, n - 1){
		int tmp;
		cin >> tmp;
		arr.pb(tmp);
		if (i == 0){
			arr.pb(tmp);
		}
	}
	REP(i, n - 1){
		if (arr[i] > arr[i + 1]) arr[i] = arr[i + 1];
	}
	int sum = 0;
	REP(i, n) sum += arr[i];
	cout << sum << endl;
	clock_t end = clock();
    double esecs = double(end - begin) / CLOCKS_PER_SEC;
    //cout << esecs << " seconds" << endl;
	return 0;	
}

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

#define MAXN 300000

int n,v[MAXN],w[MAXN],fa[MAXN],f[513][100010];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",v+i,w+i);
		fa[i]=i/2;
	}
	for(int i=1;i<=512;++i)
	{
		for(int j=1;j<w[i];++j)f[i][j]=f[fa[i]][j];
		for(int j=w[i];j<=100000;++j)f[i][j]=max(f[fa[i]][j],f[fa[i]][j-w[i]]+v[i]);
	}
	int q;
	scanf("%d",&q);
	while(q--)
	{
		int x,l;
		scanf("%d%d",&x,&l);
		if(x<=512)
		{
			printf("%d\n",f[x][l]);
			continue;
		}
		vector<pair<int,int> > bps;
		while(x>512)
		{
			bps.push_back(make_pair(v[x],w[x]));
			x=fa[x];
		}
		int cnt=bps.size(),ans=0;
		for(int i=0;i<(1<<cnt);++i)
		{
			int totw=0,totv=0;
			for(int j=0;j<cnt;++j)
			{
				if(!((i>>j)&1))continue;
				totv+=bps[j].first;
				totw+=bps[j].second;
			}
			if(totw<=l)ans=max(ans,f[x][l-totw]+totv);
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 206864
import java.util.*

private fun readInts() = readLine()!!.split(" ").map { it.toInt() }
private fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
private fun <K, V> Map<out K, V>.toMutableMap(): MutableMap<K, V> = LinkedHashMap(this)
private fun <K, V> mutableMapOf(): MutableMap<K, V> = LinkedHashMap()
private fun <K, V> mutableMapOf(vararg pairs: Pair<K, V>) = pairs.toMap().toMutableMap()

fun main(args: Array<String>) {
    (readLine()!!.toInt() downTo 1)
        .asSequence()
        .first {
            Math.sqrt(it.toDouble()).toInt().let { root -> root * root == it }
        }
        .apply { println(this) }
}

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

int N, M;
int L[100005], R[100005];

int main()
{
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> L[i] >> R[i];
    }

    int l_max = 0;
    int r_min = INT_MAX;

    for (int i = 0; i < M; i++) {
        if (l_max < L[i]) {
            l_max = L[i];
        }

        if (r_min > R[i]) {
            r_min = R[i];
        }
    }

    int ans = r_min - l_max + 1;

    if (ans < 0) {
        ans = 0;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
string s;
cin>>s;
int a[26];
for(int i=0;i<26;i++) a[i]=0;
for(int i=0;i<s.size();i++){
  a[s[i]-'a']++;
}
for(int i=0;i<26;i++){
  if(a[i]%2!=0){
    cout<<"No"<<endl;
    return 0;
  }
}
cout<<"Yes"<<endl;

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int x  = sc.nextInt();
     
    if(x >= 30){
    	System.out.println("Yes");
    }else{
    	System.out.println("No");
      }
}
}


Measured memory_bytes: 35732
#include<bits/stdc++.h>
#define f(i,p,q) for(int i=p;i<q;i++)
using namespace std;
typedef long long ll;
long long int ar[64];
long long  int n,k;


void call(long long int x)
  { int index=0;
   	while(x!=0)
   	 {   
		if((x&1)==1)
   	      ar[index]++;
   	 	index++;
        x=x>>1;
	 }
   }

int main()
{
   cin>>n>>k;
   int l=0;
 
  long long int kk=k;
  
  while(kk!=0)
    { kk=kk>>1;
      l++;
    }
	
	vector<long long int>v;
  
   for(int i=0;i<n;i++)
   {  long long int x;cin>>x;
      v.push_back(x);
     call(x);
   	 
   }
  
   long long  int ans=0;
   
   for(int i=l-1;i>=0;i--)
   {
   
      if(n-ar[i]>ar[i]&&((ans^(1ll<<i))<=k))
	      ans=ans^(1ll<<i);
   }  
  long long  int res=0;
   
    for(int i=0;i<n;i++)
      res+=ans^v[i];
     
	  cout<<res;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

struct edge{int u,d;};
using namespace std;

int main(){
  int i,j,n,m,l,r,d,t;
  priority_queue<int> pq;
  queue<int> que;
  cin >> n >> m;
  struct edge e;
  vector<edge> v[n+1];
  long long p[n+1]={0},x;
  int num[n+1]={};
  bool ch[n+1]={};
  //for(i=0;i<=n;i++)num[i]=-1;
  for(i=0;i<m;i++){
    cin >> l >> e.u >> e.d;
    if(!ch[l])ch[l]=1;//使われる辺
    num[e.u]++;//入ってくる辺の数
    v[l].push_back(e);
  }
  if(m==0){//入力が無ければ必ずyes
    cout << "Yes" << endl;
    return 0;
  }
  for(i=1;i<=n;i++){
    if(num[i]==0 && ch[i])que.push(i);
    //入ってくる辺が無くて使われてる辺
  }
  if(que.empty()){
    cout << "No" << endl;
    //元々その辺がない(一番左説の物がない,閉路等)
    return 0;
  }
  while(!que.empty()){
    t = que.front();
    //cout << t << "t"<<endl;
    que.pop();
    for(i=0;i<v[t].size();i++){//ダイクストラ
      x = p[t] + v[t][i].d;
      if(p[v[t][i].u]==0 || p[v[t][i].u]==x){
        //値をすでに持っているならそれと一致しないとout
        //値をもっていないときは更新
        p[v[t][i].u]=x;
        num[v[t][i].u]--;//入ってくる辺を減らす
        if(num[v[t][i].u]==0){
          que.push(v[t][i].u);
          //入ってくる辺が無くなったらpush
        }
      }
      else{//値が一致しない
        cout << "No" << endl;
        return 0;
      }
    }
  }
  //for(i=1;i<=n;i++)cout << p[i] << " ";
  //cout << endl;
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef  long long ll;



int main(){
  int N, K;
  ll diff = 1000000001;
  cin >> N >> K;
  vector<int> h(N);
  for(int i=0; i<N; ++i){
    cin >> h[i];
  }

  sort(h.begin(), h.end());

  for(int i=0; i < N-K+1; ++i){
    if(diff > (h[i+K-1]-h[i]))
      diff = h[i+K-1]-h[i];
  }
  cout << diff << endl;
  return 0;
}




Measured memory_bytes: 640
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

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

	if (A == B) {
		cout << A + B << endl;
	}
	else {
		cout << max(A, B) * 2 - 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
vector<int>g[110000];
int segtree[524288];
int query(int a,int b,int c,int d,int e){
	if(d<a||b<c)return 999999999;
	if(c<=a&&b<=d)return segtree[e];
	return min(query(a,(a+b)/2,c,d,e*2),query((a+b)/2+1,b,c,d,e*2+1));
}
void update(int a,int b){
	a+=262144;
	while(a){
		segtree[a]=min(segtree[a],b);
		a/=2;
	}
}
int rev[110000];
int num;
int sz;
int at[110000];
int e[300000];
int bfs[110000];
int left[110000];
void dfs(int a){
	at[a]=num;
	rev[num]=a;
	left[a]=sz;
	e[sz++]=num;
	num++;
	for(int i=0;i<g[a].size();i++){
		dfs(g[a][i]);
		e[sz++]=at[a];
	}
}
int main(){
	int a;scanf("%d",&a);
	for(int i=1;i<a;i++){
		int p;scanf("%d",&p);p--;
		g[p].push_back(i);
	}
	for(int i=0;i<524288;i++)segtree[i]=999999999;
	dfs(0);
	for(int i=0;i<sz;i++)update(i,e[i]);
	//for(int i=0;i<a;i++)printf("%d ",left[i]);printf("\n");
	//for(int i=0;i<a;i++)printf("%d ",at[i]);printf("\n");
	
	queue<int>Q;
	Q.push(0);
	long long ret=0;
	int last=0;
	while(Q.size()){
		int At=Q.front();Q.pop();
		ret+=bfs[At]+bfs[last]-2*bfs[rev[query(0,262143,min(left[At],left[last]),max(left[At],left[last]),1)]];
		last=At;
		for(int i=0;i<g[At].size();i++){
			bfs[g[At][i]]=bfs[At]+1;
			Q.push(g[At][i]);
		}
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 14352
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

vl sieve(ll n){
    vl res(n+1);
    iota(all(res), 0);
    for(ll i = 2; i*i <= n; i++){
        if(res[i] < i) continue;
        for(ll j = i*i; j <= n; j += i){
            if(res[j] == j) res[j] = i;
        }
    }
    return res;
}

vector<pll> prime_factorize(ll n, const vl& min_factor){
    vector<pll> res;
    while(n > 1){
        ll prime = min_factor[n];
        ll num = 0;
        while(min_factor[n] == prime){
            num++;
            n /= prime;
        }
        res.push_back(make_pair(prime, num));
    }
    return res;
}

int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    auto min_factor = sieve(N);
    rep(i, N){
        if(i == 0) continue;
        auto pf = prime_factorize(i, min_factor);
        ll tmp = 1;
        for(auto x : pf){
            tmp *= x.second + 1;
        }
        ans += tmp;
    }
    cout << ans;
}

Measured memory_bytes: 11192
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=2010;

int n,a[maxn];
vector<int> path[maxn],son[maxn],ans[maxn];
vector<int> seq;
bool vis[maxn];

int gcd(int a,int b)
{
	int temp;
	while(b!=0)
	{
		int temp=a%b;
		a=b;b=temp;
	}
	return a;
}

void dfs(int p)
{
	for(int i=0;i<path[p].size();i++)
	{
		int temp=path[p][i];
		if (!vis[temp])
		{
			vis[temp]=true;
			seq.push_back(temp);
			son[p].push_back(temp);
			dfs(temp);
		}
	}
	return;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	    scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	
	for(int i=1;i<n;i++)
	    for(int j=i+1;j<=n;j++)
	    	if (gcd(a[i],a[j])!=1)
	    	{
	    		path[i].push_back(j);
	    		path[j].push_back(i);
	    	}
	
	seq.push_back(n+1);
	for(int i=1;i<=n;i++)
		if (!vis[i])
		{
			vis[i]=true;
			seq.push_back(i);
			son[n+1].push_back(i);
			dfs(i);
		}
	
	for(int i=n;i>=0;i--)
	{
		int now=seq[i];
		vector<int> cur;
		ans[now].push_back(now);
		for(int j=0;j<son[now].size();j++)
		{
			int temp=son[now][j];
			cur.clear();cur.push_back(now);
			for(int k1=1,k2=0;k1<ans[now].size() || k2<ans[temp].size();)
			{
				if (k1==ans[now].size() || k1<ans[now].size() &&
				    k2<ans[temp].size() && ans[now][k1]<ans[temp][k2])
				{
				    cur.push_back(ans[temp][k2]);
				    k2++;
				}
				else
				{
					cur.push_back(ans[now][k1]);
					k1++;
				}
			}
			swap(cur,ans[now]);
		}
	}
	
	for(int i=1;i<ans[n+1].size();i++)
		printf("%d ",a[ans[n+1][i]]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 27136
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

bool cmp(int a, int b){
   return a < b;	
}

void solve(){
   int a, b, c;
   cin >> a >> b >> c;
   int ret = min({a + b, c + a, b + c},cmp);
   cout << ret << endl;	
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// DAME
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> s(n+1, vector<int>(n+1, 0));
    int l, r;
    rep(i, m){
        cin >> l >> r;
        s[l][r]++;
    }
    rep(i, n+1)rep(j, n+1){
        if (i==0 or j==0) continue;
        s[i][j] += s[i-1][j] + s[i][j-1] - s[i-1][j-1];
    }
    int ans;
    rep(i, q){
        cin >> l >> r;
        ans = s[r][r] - s[r][l-1] - s[l-1][r] + s[l-1][l-1];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 998244353//1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000000
#define N 1000001
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int x,n;
   cin>>x>>n;
   map<int,int>mp;
   for(int i=0;i<n;i++)
   {
       int val;
       cin>>val;
       mp[val]=1;
   }
   int j=x;
   int ans;
   int mn=1e9;
   while(mp[j])
   {
       j--;
   }
   if(abs(x - j)<=mn)
   {
       mn=abs(x - j);
       ans=j;
   }
   j=x;
   while(mp[j])
   {
       j++;
   }
   if(abs(x - j)<mn)
   {
       mn=abs(x - j);
       ans=j;
   }
   cout<<ans<<endl;




}


Measured memory_bytes: 3660
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

int main()
{
    ll A, B;
    cin >> A >> B;
    cout << A * B << endl;
}


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


int main(){
    string s;
    cin>>s;
    int cnt=0,n=s.size();
    bool ok=true;
    bool t=0;
    while(cnt!=n){
        if(t){
            if(s.substr(cnt,6)=="eraser") cnt+=6,t=0;
            else if(s.substr(cnt,5)=="erase") cnt+=5,t=0;
            else if(s.substr(cnt,2)=="er") cnt+=2,t=0;
            else if(s.substr(cnt,5)=="dream") cnt+=5,t=1;
            else {
                ok=false;
                cerr<<cnt<<" "<<t<<endl;
                break;
            }
            continue;
        }
        if(s.substr(cnt,5)=="dream") cnt+=5,t=1;
        else if(s.substr(cnt,6)=="eraser") cnt+=6,t=0;
        else if(s.substr(cnt,5)=="erase") cnt+=5,t=0;
        else{
            ok=false;
            cerr<<cnt<<endl;
            break;
        }
        cerr<<cnt<<endl;
    }

    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 1000000000000000000
char ans[1005][1005];
void solve(int y,int x,int n,int k){
	if(n==3){
		if(k==0){
			ans[y][x+1]='a';
			ans[y][x+2]='a';
			ans[y+1][x]='b';
			ans[y+2][x]='b';
		}else{
			ans[y][x]='c';
			ans[y][x+1]='c';
			ans[y][x+2]='d';
			ans[y+1][x+2]='d';
			ans[y+1][x]='e';
			ans[y+2][x]='e';
			ans[y+2][x+1]='f';
			ans[y+2][x+2]='f';
		}
		return;
	}
	if(n==4){
		ans[y][x]='g';
		ans[y][x+1]='g';
		ans[y+1][x]='h';
		ans[y+1][x+1]='h';
		ans[y+2][x]='i';
		ans[y+3][x]='i';
		ans[y+2][x+1]='j';
		ans[y+3][x+1]='j';
		ans[y][x+2]='k';
		ans[y+1][x+2]='k';
		ans[y][x+3]='l';
		ans[y+1][x+3]='l';
		ans[y+2][x+2]='m';
		ans[y+2][x+3]='m';
		ans[y+3][x+2]='n';
		ans[y+3][x+3]='n';
		return;
	}
	if(n%2==0){
		solve(y,x,n/2,0);
		solve(y,x+n/2,n/2,0);
		solve(y+n/2,x,n/2,0);
		solve(y+n/2,x+n/2,n/2,0);
		return;
	}
	if(n%3==0){
		for(int i=0;i<n;i+=3)for(int j=0;j<n;j+=3)solve(y+i,x+j,3,0);
		return;
	}
	if(n%6==5){
		int p=(n+1)/6;
		for(int i=0;i<2*p-1;i++){
			for(int j=0;j<2*p-1;j++){
				if((i+2*p-1-j)%(2*p-1)<p-1)solve(y+1+i*3,x+1+j*3,3,1);
				else solve(y+1+i*3,x+1+j*3,3,0);
			}
		}
		int cnt=0;
		for(int i=0;i*2<n-1;i++,cnt++){
			char q;
			if(cnt%2==0)q='o';
			else q='p';
			ans[y][x+i*2]=q;
			ans[y][x+i*2+1]=q;
		}
		for(int i=0;i*2<n-1;i++,cnt++){
			char q;
			if(cnt%2==0)q='q';
			else q='r';
			ans[y+i*2][x+n-1]=q;
			ans[y+i*2+1][x+n-1]=q;
		}
		for(int i=0;i*2<n-1;i++,cnt++){
			char q;
			if(cnt%2==0)q='s';
			else q='t';
			ans[y+n-1][x+n-1-i*2]=q;
			ans[y+n-1][x+n-1-i*2-1]=q;
		}
		for(int i=0;i*2<n-1;i++,cnt++){
			char q;
			if(cnt%2==0)q='u';
			else q='v';
			ans[y+n-1-i*2][x]=q;
			ans[y+n-1-i*2-1][x]=q;
		}
		return;
	}
	int p=(n-1)/6;
	for(int i=0;i<p*2;i++){
		for(int j=0;j<p*2;j++){
			if((i+p*2-j)%(2*p)<p-1)solve(y+i*3,x+j*3,3,1);
			else solve(y+i*3,x+j*3,3,0);
		}
	}
	for(int i=0;i*2<n-1;i++){
		char q;
		if(i%2==0)q='o';
		else q='p';
		ans[y+i*2][x+n-1]=q;
		ans[y+i*2+1][x+n-1]=q;
	}
	for(int i=0;i*2<n-1;i++){
		char q;
		if(i%2==0)q='o';
		else q='p';
		ans[y+n-1][x+i*2]=q;
		ans[y+n-1][x+i*2+1]=q;
	}
}
int n;
int main(void){
    cin>>n;
    if(n==2){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)ans[i][j]='.';
	solve(0,0,n,0);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			printf("%c",ans[i][j]);
		}
		printf("\n");
	}
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(string, s);
  vector<int> cnt(26,0);
  REP(i,s.size()){
    cnt[s[i]-'a']++;
  }

  int center = 0, num = 0;
  REP(i,cnt.size()){
    if (i == 'x'-'a') continue;
    if (cnt[i]%2==1) {
      ++center;
      num = i;
    }
  }

  if (center > 1) {
    OUT(-1)BR;
    return 0;
  }

  int ans = 0, lb=0, ub=s.size()-1;
  REP(i,s.size()) {
    if (lb >= ub){
      break;
    }
    if (s[lb] == s[ub]) {
      ++lb;
      --ub;
      continue;
    }
    ++ans;
    if (s[lb] == 'x') {
      ++lb;
    } else if (s[ub] == 'x') {
      --ub;
    } else {
      OUT(-1)BR;
      return 0;
    }
  }
  OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	long long a[200005];

	long long sum=0;

	for(int i=1;i<=n;i++)
	{
		cin >> a[i-1];
		sum+=a[i-1];
	}

	long long min=abs(sum-a[0]-a[0]);
	long long fi=0;
	long long se=sum;

	for(int i=1;i<=n-1;i++)
	{
		fi+=a[i-1];
		se-=a[i-1];
		long long tmp=abs(fi-se);
		if(tmp<min)
			min=tmp;
	}

	cout << min << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

int main()
{
	int A, B;

	std::cin >> A >> B;

	int result = std::max(A+B, std::max(A-B, A*B));
	std::cout << result << "\n";
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d", $K, $S);

$sum = 0;
for($i=0;$i<=$K && $i <= $S;++$i){
    $d = $S - $i;
    if ($d > 2*$K) {
        continue;
    }
    $sum += min($K, $d) - max($d - $K, 0) + 1;
}

print "$sum\n";



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

int main(){
    string s;
    cin >> s;
    string t = "";
    for(int i=0;i<s.size();++i){
        if(s[i] != 'x')t.push_back(s[i]);
    }

    int left = 0, right = t.size() - 1;
    bool flag = true;
    while(right > left){
        if(t[right] != t[left]){
            flag = false;
            break;
        }
        right--;
        left++;
    }

    if(flag){
        int l = 0, r = s.size() - 1, cnt = 0;
        while(r > l){
            if(s[r] == 'x' && s[l] != 'x'){
                r--;
                cnt++;
            }else if(s[r] != 'x' && s[l] == 'x'){
                l++;
                cnt++;
            }else{
                r--;
                l++;
            }
        }
        cout << cnt << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vit vector<lint>::iterator
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define mod 1000000007
#define graph_set(n) struct edge{int to,int cost;} vector<edge> G((n))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define range(x,y) ((x) >= 0 && (x) < h && (y) >= 0 && (y) < w)
#define pyes cout << "Yes" << endl
#define pno cout << "No" << endl
typedef vector<long long> vi;
typedef vector<pair<long long, long long>> vp;
typedef vector<vector<long long>> vvi;
typedef pair<long long, long long> pi;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e14;

//////////////////////////////////////////////////////////////////////
int x[10][10];
int main(void) {
	ll n, d; cin >> n >> d;
	REP(i, n) {
		REP(j, d) {
			cin >> x[i][j];
		}
	}
	int c = 0;
	for (int i = 0; i < n-1; i++)
	{
		for (int j = i+1; j < n; j++)
		{	
			int dd = 0;
			for (int k = 0; k < d; k++)
			{
				dd += qp(x[i][k] - x[j][k], 2);
			}
			int sq = (int)sqrt(dd);
			if (qp(sq, 2) == dd) c++;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
/*  ex 5_4
    shu_t */

#include <stdio.h>

int main(void){
    char capital_str[11];//store str (1<=|S|<=10 + '\0')
    char *ptr;//pointer
    int length=0,ans=0;//length of partial str
    //input str
    scanf("%s",capital_str);
    //store address
    ptr = capital_str;
  
    while(*ptr){//until null
        if(*ptr=='A'||*ptr=='T'||*ptr=='G'||*ptr=='C'){
            length++;//increment
        }else{//stop increment
            if(length > ans){
                ans = length;//renewal answer value
            }
        length = 0;//initialize length
        }
        ptr++;//increment
    }
    //case of continuing longest partial str to the end 
    if(length > ans){
        ans = length;
    }
    //output the answer
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1732
import java.util.BitSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	public static int w, h;
	public static char[][][] map = new char[50][50][2];
	public static final int[] dx = {1, 0, -1, 0};
	public static final int[] dy = {0, 1, 0, -1};
	public static int[] gx = new int[2];
	public static int[] gy = new int[2];
	public static int[] sx = new int[2];
	public static int[] sy = new int[2];
	public static BitSet used = new BitSet(50*50*50*50);
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			w = in.nextInt();
			h = in.nextInt();
			if(w == 0) break;
//			map = new char[2][h][w];
			for(int j=0; j<h; j++){
				for(int i=0; i<2; i++){
					map[i][j] = in.next().toCharArray();
					for(int k=0; k<w; k++){
						if(map[i][j][k] == '%'){
							gx[i] = k;
							gy[i] = j;
						}else if(map[i][j][k] == 'L' || map[i][j][k] == 'R'){
							sx[i] = k;
							sy[i] = j;
						}
					}
				}
			}
			used.clear();
			Queue<Integer> qu = new LinkedList<Integer>();
			qu.add(set(sy[0], sx[0], sy[1], sx[1]));
			used.set(id(qu.peek()));
			boolean goal = false;
			while(!qu.isEmpty()){
				int p = qu.poll();
				int y1 = p>>18;
				int x1 = (p>>12)&mask;
				int y2 = (p>>6)&mask;
				int x2 = p&mask;
				if(goal(y1, x1, y2, x2)){
					goal = true;
					break;
				}
				if(oneGoal(y1, x1, y2, x2)) continue;
				for(int i=0; i<4; i++){
					int np = move(y1, x1, y2, x2, i);
					int id = id(np);
					if(used.get(id)) continue;
					used.set(id);
					qu.add(np);
				}
			}
			System.out.println(goal?"Yes":"No");
		}
	}
	
	public static int set(int y1, int x1, int y2, int x2){
		return y1<<(6+6+6) | x1<<(6+6) | y2<<6 | x2;
	}
	
	public static int move(int y1, int x1, int y2, int x2, int dir){
		int nx1 = x1+dx[dir];
		int ny1 = y1+dy[dir];
		if(out(ny1, nx1) || map[0][ny1][nx1] == '#'){
			nx1 = x1;
			ny1 = y1;
		}
		int nx2 = x2-dx[dir];
		int ny2 = y2+dy[dir];
		if(out(ny2, nx2) || map[1][ny2][nx2] == '#'){
			nx2 = x2;
			ny2 = y2;
		}
		return set(ny1, nx1, ny2, nx2);
	}
	
	public static boolean out(int y, int x){
		return x < 0 || x >= w || y < 0 || y >= h;
	}
	
	public static boolean goal(int y1, int x1, int y2, int x2){
		return x1 == gx[0] && y1 == gy[0] && x2 == gx[1] && y2 == gy[1];
	}
	
	public static boolean oneGoal(int y1, int x1, int y2, int x2){
		return x1 == gx[0] && y1 == gy[0] || x2 == gx[1] && y2 == gy[1];
	}
	
	public static int id(int y1, int x1, int y2, int x2){
		return y1*h*w*w + x1*h*w + y2*w + x2;
	}
	
	public static final int mask = (1<<6)-1;
	public static int id(int hash){
		return (hash>>18)*h*w*w + ((hash>>12)&mask)*h*w + ((hash>>6)&mask)*w + (hash&mask);
	}
}

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

using ll = long long;

ll lcm(ll a, ll b) {
    ll g = std::__gcd(a, b);
    return a / g * b;
}

int n;
ll t;
std::vector<ll> vec;

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> t;
        vec.push_back(t);
    }
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        ans = lcm(ans, vec[i]);
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
ab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
n = int(input())
s = input()
l = ''
# 何もじめか当てる
for S in s:
  i = 0
  for w in ab:
    if S == w:
      l += ab[i+n]
      break
    i += 1
# １文字ずつ変えていく
print(l)

Measured memory_bytes: 3060
import std;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "money", long, "stack");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto N = sread();
    auto digit = N.length;
    auto p = new string[](0);

    void dfs(string s)
    {
        if (!s.empty())
            p ~= s;

        if (s.length == digit)
        {
            return;
        }

        dfs(s ~ '3');
        dfs(s ~ '5');
        dfs(s ~ '7');
    }

    dfs([]);
    p.sort!"a.to!(long)<b.to!(long)"();
    // p.writeln;
    long cnt;
    foreach (i; iota(p.length))
    {
        if (p[i].to!(long) > N.to!(long))
            break;

        bool has753()
        {
            bool seven, five, three;
            foreach (e; p[i])
            {
                switch (e)
                {
                case '7':
                    seven = true;
                    break;
                case '5':
                    five = true;
                    break;
                case '3':
                    three = true;
                    break;
                default:
                    break;
                }
            }
            return seven && five && three;
        }

        cnt += has753();
    }
    cnt.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 4440
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] NR = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToArray();
        Console.WriteLine(NR[0] > 10 ? NR[1] : NR[1] + 100 * (10 - NR[0]));
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n, m; cin>>n>>m;
    vector<vector<int>> v(m);
    for(int i=0; i<m; i++){
        int k; cin>>k;
        for(int j=0; j<k; j++){
            int s; cin>>s;
            s--;
            v[i].eb(s);
        }
    }

    vector<int> p(m);
    for(int i=0; i<m; i++) cin>>p[i];

    int sum = 0;
    for(int bit=0; bit<(1<<n); bit++){
        vector<int> num;
        for(int i=0; i<n; i++){
            if((1 << i) & bit){
                num.eb(i);
            }
        }

        int ans = 0;
        for(int i=0; i<m; i++){
            int cnt = 0;
            for(int j=0; j<num.size(); j++){
                for(int k=0; k<v[i].size(); k++){
                    if(num[j] == v[i][k]){
                        cnt++;
                        break;
                    }
                }
            }

            if(cnt % 2 == p[i]){
                ans++;
            }
        }

        if(ans == m){
            sum++;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib> // abs(x-y)
#include <iomanip> // 出力の桁数指定
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
  int k, x;
  cin >> k >> x;

  cout << (500*k >= x ?"Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    
    string ans = "Yes";
    
    while(true){
        
        C -= B;
        
        if(C <= 0)break;
        
        A -= D;
        
        if(A <= 0){
            ans = "No";
            break;
        }
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }
  //lazy部分を評価、代入                                                                          
    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }
  //[a,b)にxを加算                                                                              
    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }
  //[l,r)のうち[a,b)の総和を計算                                                                  
    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

const ll n_max=1LL*1e6;
ll ls[n_max],rs[n_max];
vector<ll> G[n_max];
ll idx=0;
void dfs(ll v, ll p){
  ls[v]=idx++;
  for(ll u:G[v]){
    if(u!=p) dfs(u,v);
  }
  rs[v]=idx++;

}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,q;
  cin >> n >> q;
  ll a,b;
  rep(i,n-1){
    cin >> a >> b;
    a--;b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  dfs(0,-1LL);
  LazySegmentTree seg(vector<ll>(2*n, 0) );
  ll p,x;
  rep(i,q){
    cin >> p >> x;
    p--;
    seg.add(ls[p],rs[p],x);    
  }
  /*  cout << "ls" << endl;
  rep(i,n) {
    cout << ls[i] << endl;
  }
  cout << "rs" << endl;
  rep(i,n) {
    cout << rs[i] << endl;
    }*/
  rep(i,n){
    cout << seg.getsum(ls[i],ls[i]+1)<< endl;
  }  
  return 0;
}


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    int H,W;
    cin >> H >> W;

    vector<vector<int> >c(10, vector<int>(10));
    vector<vector<int> >result(10, vector<int>(10));
    
    rep(i,10)
    {
        rep(j,10)
        {
            cin >> c[i][j];
            result[i][j] = c[i][j];
        }
    }

    vector<vector<int> > A(H, vector<int>(W));
    rep(i,H)
    {
        rep(j,W) cin >> A[i][j];
    }

    rep(k,10)
    {
        rep(i,10)
        {
            rep(j,10)
            {
                result[i][j] = min(result[i][j], result[i][k] + result[k][j]);
            }
        }
    }

    ll ans = 0;
    rep(i,H)
    {
        rep(j,W)
        {
            if(A[i][j] > -1 ) ans += result[A[i][j]][1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	
	int len=s.size();
	int n=0;
	
	string left,right;
	if(len%2==0)
	{
		left=s.substr(0,len/2);
		right=s.substr(len/2,len);
	}
	else
	{
		left=s.substr(0,(len-1)/2);
		right=s.substr((len+1)/2,len);
		
	}
	
	for(int i=0;i<left.size();i++)
	{
		if(left[i]!=right[right.size()-i-1])
		n++;
	}
	cout<<n<<endl;
	return 0;
	
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int[] a = new int[8];
        while(scan.hasNext()){
        	int n = scan.nextInt();
        	if(n == 0){
        		break;
        	}
        	for(int i = 0;i < n;i++){
        		for(int j = 0;j < 8;j++){
        			a[j] = scan.nextInt();
        		}
        		int x = a[0]*a[4] - a[1]*a[5] - a[2]*a[6] - a[3]*a[7];
        		int y = a[0]*a[5] + a[1]*a[4] + a[2]*a[7] - a[3]*a[6];
        		int z = a[0]*a[6] - a[1]*a[7] + a[2]*a[4] + a[3]*a[5];
        		int w = a[0]*a[7] + a[1]*a[6] - a[2]*a[5] + a[3]*a[4];
        		System.out.println(x + " " + y + " " + z + " " + w);
        	}
        }
    }
}

Measured memory_bytes: 23628
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
        int c = Integer.parseInt(scan.next());

        if(a+b==c|b+c==a|a+c==b){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23124
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int d = a / b;
		int r = a % b;
		double f = (double) a / (double) b;
		System.out.printf("%d %d %f\n", d, r, f);
	}
}

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

using namespace std;

int main(){
    int N,ans=1,mx;
    cin >> N;
    vector<int> P(N);
    for(int i=0;i<N;i++){
        cin >> P[i];
    }

    mx = P[0];

    for(int i=1;i<N;i++){
        if(mx>=P[i]){
            mx = min(P[i],mx);
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int a,b;
    cin >> a >> b;
    if (a>=13) cout << b << endl;
    else if (a>=6) cout << b/2 << endl;
    else cout << 0 << endl;

    return 0; 
}


Measured memory_bytes: 3648
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n; cin >> n;
  cout << 180 * n - 360 << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	int lo = int(1e9);
	int s = 0;
	for (int i = 0; i < N; i++) {
		int v; cin >> v;
		s += v;
		if (v % 10) lo = min(lo, v);
	}
	cout << max(0, s % 10 ? s : (s - lo)) << '\n';
	return 0;
}


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

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

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

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

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

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

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	string S, T;
	cin >> S >> T;

	ll ans = ll_max;
	rep(i, 0, S.size() - T.size() + 1) {
		ll cnt = 0;
		rep(j, 0, T.size()) {
			if (S[i + j] != T[j]) {
				cnt++;
			}
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int n,r,g,b,ans;
int main(){
	//freopen("input.txt","r",stdin);
	cin >> r >> g >> b >> n;
	for(int i = 0;i <= n;i++)
		for(int j = 0;j <= n;j++){
			int temp = i*r + j*g;
			if(temp > n)break;
			temp = n - temp;
			if(temp%b == 0)ans++;
		}
	printf("%d\n",ans);
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

const int MAX = 15001000;
bool IsPrime[MAX];
int MinFactor[MAX];
vector<int> preprocess(int n = MAX) {
    vector<int> res;
    for (int i = 0; i < n; ++i) IsPrime[i] = true, MinFactor[i] = -1;
    IsPrime[0] = false; IsPrime[1] = false;
    MinFactor[0] = 0; MinFactor[1] = 1;
    for (int i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            MinFactor[i] = i;
            res.push_back(i);
            for (int j = i*2; j < n; j += i) {
                IsPrime[j] = false;
                if (MinFactor[j] == -1) MinFactor[j] = i;
            }
        }
    }
    return res;
}

vector<pair<int,int> > prime_factor(int n) {
    vector<pair<int,int> > res;
    while (n != 1) {
        int prime = MinFactor[n];
        int exp = 0;
        while (MinFactor[n] == prime) {
            ++exp;
            n /= prime;
        }
        res.push_back(make_pair(prime, exp));
    }
    return res;
}

int main() {

    ll n; cin >> n;

    preprocess();

    ll ans = 0;
    for (ll i = 1; i <= n; ++i) {

        auto p = prime_factor(i);

        ll cnt = 1;
        for (auto t : p) {
            cnt *= t.second + 1;
        }
        ans += i * cnt;
    }

    cout << ans << endl;
}


Measured memory_bytes: 80688
from collections import defaultdict
 
d = defaultdict(int)
 
N = input()
A = list(map(int, input().split())) 
for i in A:
    d[i] += 1

ans = sum(A)
 
Q = int(input())

for _ in range(Q):
    B, C = map(int, input().split())
    ans = ans - B*d[B] + C*d[B]
    print(ans)
    d[C] += d[B]
    d[B] = 0

Measured memory_bytes: 94588