akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <bitset>
#include <functional>
using namespace std;
//typedef std::pair<std::string,double> P;

typedef long long ll;
typedef vector<int> VI;

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

//グラフの隣接リスト
VI g[100010];
//頂点の入次数を管理
int h[100010];
signed main(void) {

	//頂点数v, 辺の数e
	int v, e;
	cin >> v >> e;
	REP(i, e) {
		int s, t;
		cin >> s >> t;
		g[s].push_back(t); //sからtに向かう辺

		h[t]++;
	}
	stack<int> st;

	REP(i, v) if (h[i] == 0)st.push(i);
    
	//ソートされた後のグラフ
	VI ans;
	
	while (st.size()) {
		//stの集合から一つ取り出す
		int i = st.top(); st.pop();

		ans.push_back(i);

		for (auto& j : g[i]) {
			//隣接する頂点の入次数をマイナス1
			h[j]--;
			//これによって入次数が0になればstに追加
			if (h[j] == 0)st.push(j);
		}
	}

	for (auto i : ans) cout << i << endl;

	return 0;
}



Measured memory_bytes: 5960
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
#define mp make_pair
#define x first
#define y second
typedef pair<int,int> pii;
int fa[maxn];inline int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
set<int> s[maxn];map<pii,int> cnt;int n;queue<pii> q;
inline void init()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=1,a,b;i<=((n-1)<<1);i++)
	{
		scanf("%d%d",&a,&b);s[a].insert(b);s[b].insert(a);
		cnt[mp(a,b)]++;cnt[mp(b,a)]++;
		if(cnt[mp(a,b)]==2) q.push(mp(a,b));
	}
}
int main()
{
	init();
	set<int>::iterator it;
	while(q.size())
	{
		pii a=q.front();q.pop();int x=find(a.x),y=find(a.y);
		if(s[x].size()<s[y].size()) swap(x,y);s[x].erase(y);s[y].erase(x);
		for(it=s[y].begin();it!=s[y].end();it++)
		{
			int t=*it;cnt[mp(t,y)]=cnt[mp(y,t)]=0;
			s[t].erase(y);s[t].insert(x);s[x].insert(t);
			cnt[mp(t,x)]++;cnt[mp(x,t)]++;
			if(cnt[mp(t,x)]==2) q.push(mp(t,x));
		}
		fa[y]=x;s[y].clear();
	}
	int cnt=0;
	for(int i=1;i<=n;i++) if(find(i)==i) cnt++;
	puts(cnt>1?"NO":"YES");
}

Measured memory_bytes: 56320
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath> 
using namespace std;
int main(int argc, char *argv[])
{
	long long a,b;
	cin>>a>>b;
	if((a+b)%2==0)cout<<(a+b)/2<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

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

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define double long double
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    int n;
    cin>>n;VI re,re2;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        re.pb(x-y);
        re2.pb(x+y);
    }
    sort(all(re));
    sort(all(re2));
    int ans=max(re[n-1]-re[0],re2[n-1]-re2[0]);
    cout<<ans<<endl;
    
}


return 0;
}





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

const int MAXN = 1e5+5;

ll n, s, x[MAXN], p[MAXN], k;
vector<ll> v;

int main() {
	cin >> n >> s;
	for (int i = 0; i < n; ++i)
		cin >> x[i] >> p[i];
	k = -1;
	for (int i = 0; i < n; ++i)
		if (x[i] < s)
			k++;
	int l = 0, r = n-1;
	while (true) {
		if (k < l) {
			for (int i = r; i >= l; --i)
				v.push_back(i);
			break;
		} if (k >= r) {
			for (int i = l; i <= r; i++)
				v.push_back(i);
			break;
		}
		if (p[l] >= p[r]) {
			v.push_back(r);
			p[l] += p[r];
			r--;
		} else {
			v.push_back(l);
			p[r] += p[l];
			l++;
		}
	}

	ll pos = s;
	reverse(v.begin(), v.end());
	ll ans = 0;
	for (int i = 0; i < v.size(); ++i) {
		ans += abs(x[v[i]] - pos);
		pos = x[v[i]];
	}

	cout << ans << endl;
}

Measured memory_bytes: 2936
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#define ll long long
using namespace std;
struct dog {
	string a;
	int b;
};
int main()
{
	int h, a;
	cin >> h >> a;
	int ans;
	ans = h / a;
	if (h - ans*a == 0) {}
	else { ans += 1; }
	cout << ans;
}



Measured memory_bytes: 3644
n=int(input())
xls=[list(map(int,input().split())) for _ in range(n)]
lrs=sorted((x-l,x+l) for x,l in xls)
res=0
most_r=lrs[0][0]
for l,r in lrs:
  if l>=most_r:
    res+=1
    most_r=r
  elif most_r>r:
    most_r=r
print(res)

Measured memory_bytes: 41388
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
typedef vector<int> VI;
typedef vector<VI> VVI;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; 
    cin >> n;
	VVI abc(3, VI(n)), dp(n + 1, VI(3));
	rep(i,n) cin >> abc[0][i] >> abc[1][i] >> abc[2][i];
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 3; j++) dp[i][j] = max(dp[i-1][(j + 1) % 3], dp[i-1][(j + 2) % 3]) + abc[j][i-1];
	}
	cout << *max_element(dp[n].begin(), dp[n].end()) << endl;
 
 
	return 0;
}

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

#define endl '\n'
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f

typedef long long ll;
typedef pair <int, int> pii;
typedef vector<vector <ll>> dv; 
const ll MOD = 1e9+7;

ll n, k; 

dv prod(dv &a, dv &b){
  dv ans(n+1, vector <ll> (n+1));
  for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
      for(int k=1; k<=n; k++){
        ans[i][j]+=(a[i][k]*b[k][j])%MOD;
        ans[i][j]%=MOD;
      }
    } 
  }
  return ans;
}

dv exp(dv &a, ll e){
  dv ans(n+1, vector <ll> (n+1));
  for(int i=1; i<=n; i++) ans[i][i]=1;
  while(e){
    if(e&1) ans=prod(ans, a);
    e/=2;
    a=prod(a, a);
   }
  return ans;
}

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

  cin >> n >> k;
  dv m(n+1, vector <ll> (n+1));
  for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
      cin >> m[i][j];
    }
  }
  m=exp(m, k);

  ll ans=0;
  for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
      ans+=m[i][j];
      ans%=MOD;
    }
  }
  cout << ans << endl;
} 

Measured memory_bytes: 384
import java.util.Scanner;
import java.lang.Math;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int minj,z,cnt=0;
        int a[] = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0; i < n-1; i++){
            minj = i;
            int x = a[i];
            for(int j=i+1;j<n;j++){
                if(a[j] < a[minj]){
                    minj = j;
                }
            }
            if(a[minj]!=x) cnt++;
            z = a[i];
            a[i] = a[minj];
            a[minj] = z;
        }
        for(int i = 0; i<n-1;i++){
            System.out.printf("%d ",a[i]);
        }
        System.out.printf("%d%n%d%n",a[n-1],cnt);
        sc.close();
    }
}



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

int main(){
  int64_t N, A, B;
  int64_t count;
  cin >> N >> A >> B;
  if (N % (A + B) == 0){
    count = N / (A + B) * A;
  }
  else if (N % (A + B) <= A){
    count = N / (A + B) * A + N % (A + B);
  }
  else{
    count = N / (A + B) * A + A;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>    
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define int long long
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define fone for(i=0;i<n;i++)
#define endl "\n"
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N          = 5000*100+1;
const ll N2      = 1000*1000+5;
const ld PI  = 3.14159265;
const ll R   = 250;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
    }

signed main ()
{
    fastio();
    int k;
    int ans=0;
    cin>>k;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=k;j++)
        {
            for(int l=1;l<=k;l++)
            {
                int t=__gcd(i,j);
                ans+=__gcd(t,l);
            }
        }
    }
cout<<ans<<endl;
    return 0;
    
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
const int NMAX=52;
int n,m,a,b,sum_cities[NMAX];
int main(){
  scanf("%d %d", &n, &m);
  for(int i=0;i<m;i++){
    scanf("%d %d", &a, &b);
    sum_cities[a]++;
    sum_cities[b]++;
  }
  for(int i=1;i<n+1;i++){
    printf("%d\n",sum_cities[i]);
  }
  return 0;
}

Measured memory_bytes: 384
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

a,b,k = iim()

for i in range(k):
    if i%2 == 0:
        if a%2 == 1:
            a -= 1
        a = a//2
        b += a
    else:
        if b%2 == 1:
            b -= 1
        b = b//2
        a += b

print(a,b)

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

   i32 h,w, tmp1 = 0, tmp2 = 0; cin >> h >> w;
   vec<bool> panish1(h), panish2(w);
   vec<string> grid(h);
   rep(i,h) cin >> grid[i];

   bool can;
   rep(i,h) {
       can = 1;
       rep(j,w) if(grid[i][j] == '#') can = 0;
       if(can) {
           panish1[i] = 1;
           ++tmp1;
       }
   }
   rep(j,w) {
       can = 1;
       rep(i,h) if(grid[i][j] == '#') can = 0;
       if(can) {
           panish2[j] = 1;
           ++tmp2;
       }
   }

   i32 nh = h-tmp1, nw = w-tmp2;
   vec<string> answer;
    rep(i,h) {
        if(panish1[i]) continue;
        string tmp;
        rep(j,w) {
            if(panish2[j]) continue;
            tmp.push_back(grid[i][j]);
        }
        answer.push_back(tmp);
    }

    for(auto s : answer) {
        cout << s << '\n';
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
#define reg register
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
#define input(a){a=0;char c=gc();int f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc();}while(c>='0'&&c<='9'){a=(a<<3)+(a<<1)+(c&15);c=gc();}a*=f;}
static char buf[1<<21],*p1=buf,*p2=buf;
char bu[1<<21],cha[20];int p,pp=-1;
#define flush(){fwrite(bu,1,pp+1,stdout),pp=-1;}
#define output(x){if(pp>1<<20)flush();if(x<0)bu[++pp]=45,x=-x;do{cha[++p]=x%10+48;}while(x/=10);do{bu[++pp]=cha[p];}while(--p);}
#define Endl bu[++pp]='\n'
#define Space bu[++pp]=' '
#define pc(c) bu[++pp]=c
const int N=110;
char s[N];
int main()
{
	cin>>s;
	cout<<s[0]<<strlen(s)-2<<s[strlen(s)-1];
	flush();
	return 0;
}

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

int func(int a){
  if(a%2==0){
    return a/2;
  }else{
    return 3*a+1;
  }
}

int main(){
  int s;
  cin >> s;
  int a;
  int b=s;
  int i=2;
  set<int> se;
  se.insert(s);
  while(1){
    a=func(b);
    if(se.count(a)){
      cout << i << endl;
      return 0;
    }
    i++;
    b=a;
    se.insert(a);
  }
  return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n
    def find(self, x):
        if 0 > self.parents[x]:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if 0 > x]
    # グループの数を返す
    def group_count(self):
        return len(self.roots())
    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = MAP()
ab = [LIST() for _ in range(M)]
ans = 0

for i in range(M):
	tree = UnionFind(N)
	for j in range(M):
		if j != i:
			tree.union(ab[j][0]-1, ab[j][1]-1)
	if tree.group_count() == 2:
		ans += 1

print(ans)




Measured memory_bytes: 5652
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <queue>
using namespace std;

int main(){
    char x,y;
    scanf("%c %c",&x,&y);
    if(x < y){
        printf("<\n");
       // printf("%d<%d.\n",x-55,y-55);
    }
    else if(x > y){
        printf(">\n");
       // printf("%d>%d.\n",x-55,y-55);
    }
    else{
        printf("=\n");
       // printf("%d=%d.\n",x-55,y-55);
    }

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        long res = 0;
        for (int i = 1; i <= k; i++) {
            for (int j = 1; j <= k; j++) {
                for (int l = 1; l <= k; l++) {
                    res += gcd(i, gcd(j, l));
                }
            }
        }

        System.out.println(res);
    }
    static int[][] memo = new int[201][201];
    private static int gcd(int m, int n) {
        if(memo[m][n] > 0) return memo[m][n];
        if(m < n) return memo[m][n] = gcd(n, m);
        if(n == 0) return m;
        return memo[m][n] = gcd(n, m % n);
    }

}

Measured memory_bytes: 37352
package main

import "fmt"

func scanNums(nums_len int) (nums []int) {
	var num int
	for i := 0; i < nums_len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func main() {
	var n int
	fmt.Scan(&n)
	nums := scanNums(n)

	count := 0
	pos := 1
	for i := 0; i < n; i++ {
		pos = nums[pos-1]
		count++

		if pos == 2 {
			break
		}
	}

	if count == n {
		count = -1
	}

	fmt.Println(count)
}


Measured memory_bytes: 6912
#include<iostream>
using namespace std;
#include<map>
#include<queue>
#include<cstdio>
#include<string>
#include<algorithm>

typedef pair<string,int> P;

int main()
{
  int n;
  char a;
  string cube;
  string goal = "111111111222444666555333333333";
  cin >> n;
  
  while(n--){
    cube = "";
    for(int i = 0;i < 30;i++){
      cin >> a;
      cube += a;
    }
    queue<P> que;

    map<string,int> used;

    que.push(P(cube,0));
    while(!que.empty()){
      P p = que.front();que.pop();
      string now = p.first;
      int co = p.second;
      if(now == goal){
	cout << co << endl;
	break;
      }
      if(used[now] == 1)continue;
      used[now] = 1;
      string next;
      next = now;
      swap(next[0],next[27]);
      swap(next[1],next[28]);
      swap(next[2],next[29]);
      swap(next[14],next[15]);
      swap(next[18],next[20]);

      que.push(P(next,co+1));
      next = now;

      swap(next[6],next[21]);
      swap(next[7],next[22]);
      swap(next[8],next[23]);
      swap(next[17],next[12]);
      swap(next[9],next[11]);

      que.push(P(next,co+1));
      next = now;
     
      swap(next[0],next[23]);
      swap(next[3],next[26]);
      swap(next[6],next[29]);
      swap(next[9],next[20]);
      swap(next[15],next[17]);

      que.push(P(next,co+1));
      next = now;
     
      swap(next[2],next[21]);
      swap(next[5],next[24]);
      swap(next[8],next[27]);
      swap(next[12],next[14]);
      swap(next[11],next[18]);

      que.push(P(next,co+1));
    }
  }
}

Measured memory_bytes: 1288
if __name__ == '__main__':
    N = int(input())
    h = list(map(int, input().split()))
    
    DP = [0]
    for i in range(1, N):
        if i == 1:
            DP += [abs(h[i]-h[i-1])]
            continue
        DP += [min(DP[i-1]+abs(h[i]-h[i-1]), DP[i-2]+abs(h[i]-h[i-2]))]
    
    print(DP[-1])


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

int main(){
    int n;
    while (1){
	cin >> n;
	if (n == 0) break;
	int t;
	vector<long long> v;
	for (int i = 0; i < n; i++){
	    cin >> t;
	    v.push_back(t);
	}
	sort(v.begin(), v.end());

	long long sum = 0, m = 0;
	for (int i = 0; i < n; i++){
	    sum += m;
	    m += v[i];
	}
	cout << sum << endl;
    }
}

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

//[1,m]にあるnの倍数の個数
long divnum(long m,long n){
  if(m < 1){ return 0; }
  return m/n;
}

//[l,g]にあるnの倍数の個数
long divnum(long l, long g, long n){
  return divnum(g, n) - divnum(l-1, n);
}

long gcd(long a, long b){
  if(a > b) a ^= b ^= a ^= b; //swap
  return (b%a == 0)? a : gcd(b%a, a);
}

int main(){
  long A,B,C,D;
  cin >> A >> B >> C >> D;
  cout << B-A+1 - divnum(A,B,C) - divnum(A,B,D) + divnum(A,B,C*D/gcd(C,D)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
#define REV(x) (reverse(x.begin(),x.end()))

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

	int N;
	cin >> N;
	int SO[101]={};
	FOR(i,2,N+1){
		int k = i;
		FOR(j,2,i+1){
			while(k%j==0){
				SO[j]++;
				k /= j;
			}
		}
	}

	int ans = 0;
	FOR(i,2,101){
		if(SO[i]>=74)ans++;
		FOR(j,2,101){
			if(i==j)continue;
			if(SO[i]>=2&&SO[j]>=24)ans++;
			if(SO[i]>=4&&SO[j]>=14)ans++;
			FOR(k,j+1,101){
				if(i==k)continue;
				if(SO[i]>=2&&SO[j]>=4&&SO[k]>=4)ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}

const int MAX = 510000;
const int MOD = 1000000007;

int64_t fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int divide(int a){
    int ans = 0 ;
    while (1)
    {
        if (a%2 == 0)
        {
            ans ++ ;
            a /= 2 ;
        }else
        {
            return ans ;
        }
        
        
    }
    
}


int main(){
    int n ;
    cin >> n ;
    vector<int> a(n+1) ;
    for (int i = 0; i < n+1; i++)
    {
        cin >> a.at(i) ;
    }
    int64_t ans = 0 ;
    int64_t now = 1 ;
    //下から頂点の最大個数、最小個数を考える
    vector<pair<int64_t,int64_t> > bup(n+1,pair<int64_t,int64_t>()) ;
    bup.at(n) = make_pair(a.at(n),a.at(n)) ;
    for (int i = 1; i < n+1; i++)
    {
        bup.at(n-i).first = (bup.at(n-i+1).first + 1)/2 + a.at(n-i) ;
        bup.at(n-i).second = bup.at(n+1-i).second + a.at(n-i) ;
    }
    vector<pair<int64_t,int64_t> > tdown(n+1,pair<int64_t,int64_t>()) ;
    for (int i = 0; i < n+1; i++)
    {
        if (now < bup.at(i).first)
        {
            cout << -1 << endl ;
            return 0 ;
        }else
        {
            if (now > bup.at(i).second)
            {
                now = bup.at(i).second ;
            }
            ans += now ;
            now -= a.at(i) ;
            now *= 2 ;
        }
        
        
    }
    cout << ans << endl ;
    
}

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

int LCG(int x, int y);

int main(){
 int a,b;
 int g;
 long l;
 while(cin >> a >> b){
    g = LCG(a,b);
    l = (long)a*b/g;
    cout << g << " " << l << endl;
 }
}

int LCG(int x, int y){
    int m = x%y;
    if(m == 0){
        return y;
    }
    LCG(y,m);
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
int n, ans[10005];

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

	cin >> n;
	for(int i = 1; i*i <=n; i++){
		for(int j = 1; j*j<=n; j++){
			for(int k = 1; k*k<=n; k++){
				int tmp = i*i + j*j + k*k + i*j + i*k + j*k;
				if(tmp <= n) ans[tmp]++;
			}	
		}
	}

	for(int i = 1; i<=n; i++)
		cout << ans[i] << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3592
#include <cstdio>

int cnt[110000];

int main () {
	int N, M;
	scanf ("%d%d", &N, &M);
	for (int i = 0; i < M; i++) {
		int u, v;
		scanf ("%d%d", &u, &v);
		cnt[u]++;
		cnt[v]++;
	}
	for (int i = 1; i <= N; i++)
		if (cnt[i] & 1) {
			puts ("NO");
			return 0;
		}
	puts ("YES");
}



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

int main()
{
	long double w, h, x, y;
	cin >> w >> h >> x >> y;
	cout << fixed << setprecision(10) << (w / 2) * h << " " << (w / 2 == x && h / 2 == y ? 1 : 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int a[15][15];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	int sum=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			int x=0;
			for(int k=0;k<m;k++){
				x+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			double m=sqrt(x);
			if(m-(int)m==0) sum++;
		}
	}
	cout<<sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        readll(a1); readll(a2);
        ll a1_orig(a1);
        ll a3 = 0;
        forr(i,0,n-2) {
            readll(kk);
            a3 = a3 ^ kk;
        }
        ll c = (a1+a2) - a3;
        if ((c%2!=0) || (c<0)) {
            cout << -1 << endl; continue;
        }
        c /= 2;

        int ret = 0;
        bool problem = false;
        ll pow2 = 1;
        ll new_min_a1 = 0;
        set<ll> pows;
        while ((c>0)||(a3>0)) {
            int b_and = c%2, b_xor = a3%2; c /= 2; a3 /= 2;
            int b_a1 = a1%2; a1 /= 2;

            if (b_and==1) {
                new_min_a1 += pow2;
                if (b_xor==1) {  problem = true;  }
            } else {
                if (b_xor==0) {
                } else {
                    pows.insert(pow2);
                }
            }
            pow2 *= 2;
        }
        if ((problem) || (a1_orig<new_min_a1)) {
            cout << -1 << endl; continue;
        }
        auto it = pows.end();
        while (it!=pows.begin()) {
            --it;
            if (new_min_a1+*it<a1_orig) {  new_min_a1+=*it;  }
        }
        if (new_min_a1==0) {
            cout << -1 << endl; continue;
        }
        cout << a1_orig-new_min_a1 << endl;

        
    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

Measured memory_bytes: 3664
eval"N,K,*A="+`dd`.split*?,
S=->a{a.reduce:+}
s,*l=S[A]
1.upto(3e4){|j|s%j<1&&l<<j<<s/j}
p l.select{|h|a=A.map{|x|x%h}
S[a.min(N-S[a]/h)]<=K}.max

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

#define xyMAX 1001
#define qMAX 151

char x[xyMAX],y[xyMAX];

int max(int a, int b){
  if(a > b) {
    printf("a\n");return a;}
  else if(a <= b) return b;
}

int lcs(char x[],char y[]){
  int m,n,i,j;
  int c[xyMAX][xyMAX];
  m = strlen(x);
  n = strlen(y);
  for(i=1; i<=m; i++) c[i][0] = 0;
  for(j=1; j<=n; j++) c[0][j] = 0;
  for(i=1; i<=m; i++){
    for(j=1; j<=n; j++){
      if(x[i-1] == y[j-1]) c[i][j]=c[i-1][j-1]+1;
      else if(c[i-1][j] >= c[i][j-1])c[i][j]=c[i-1][j];
      else c[i][j] = c[i][j-1];
    }
  }
  return c[m][n];

}


int main(){
  int i,j,num;
  scanf("%d",&num);
  for(i=0; i<num; i++){
    scanf("%s%s",x,y);
    printf("%d\n",lcs(x,y));
  }
  return 0;

}

Measured memory_bytes: 4520
using System;
class Hello{
static void Main(){
string [] str=Console.ReadLine().Split(' ');
int W=int.Parse(str[0]);
int H=int.Parse(str[1]);
int x=int.Parse(str[2]);
int y=int.Parse(str[3]);
int r=int.Parse(str[4]);

x+=r;
y+=r;

if(x>W||y>H||x<=0||y<=0)Console.WriteLine("No");
else Console.WriteLine("Yes");
}
}


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

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
 
#define INF 10e9
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
 
int main() {
    long long int n;
    cin >> n;

    long long int a[100010][3];

    long long int i, j, k;
    for(i = 0; i < n; i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }

    long long int dp[100010][3];

    for(i = 0; i <= n; i++){
        for(j = 0; j < 3; j++){
            dp[i][j] = 0;
        }
    }

    for(i = 1; i <= n; i++){
        for(j = 0; j < 3; j++){
            for(k = 0; k < 3; k++){
                if(k == j) continue;
                dp[i][k] = max(dp[i][k], dp[i-1][j] + a[i-1][k]);
            }
        }
    }

    long long int ans = 0;
    for(i = 0; i < 3; i++){
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
}

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

#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define endl '\n'
typedef long long li;
const int N = 1e5 + 10;
int n;
int a[N];
int dp[N];
li solve(int i){

	if(i>=n-1)
		return 0;
	if(dp[i]!=-1)
		return dp[i];
	int p = abs(a[i]-a[i+1]) + solve(i+1);
	int q = INT_MAX;
	if(n-i>2){

		q = abs(a[i]-a[i+2]) + solve(i+2);
	}
	return dp[i] = min(p,q);
}
int main(){
	cin>>n;
	for(int i = 0 ; i < n ; ++i)
		cin>>a[i];

	dp[0] = 0;
	dp[1] = abs(a[0]-a[1]);

	for(int i = 2 ; i < n ; ++i)
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]) , dp[i-2] + abs(a[i]-a[i-2]));

	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
n,a,b,c,d=map(int,input().split())
s=input()
if '##'in s[min(a,b,c,d):max(a,b,c,d)-1]:
  print('No')
else:
  if c<d:
    print('Yes')
  else:
    if '...' in s[b-2:d+1]:
      print('Yes')
    else:
      print('No')


Measured memory_bytes: 3572
#include<stdio.h>
int main(){
	int A, B;
	scanf("%d %d",&A,&B);

	if(A-B==0){
	printf("Draw\n");
	}else if(A==1 || B==1){
	if(A==1) printf("Alice\n");
	else printf("Bob\n");
	}else if(A<B)printf("Bob\n");
	else printf("Alice\n");

	return 0;



}


Measured memory_bytes: 128
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        N: usize,
        As: [i64; N],
    }

    let mut money = 1000;
    let mut stocks = 0;

    // 株を買うなら全力で買ったほうがいい…はず
    // 初日: 翌日上がるなら買う、下がるなら何もしない
    if As[0] < As[1] {
        let buy = money / As[0];
        stocks += buy;
        money -= As[0] * buy;
    }

    // 1日目以降
    // 翌日のほうが高いなら買う
    // 翌日と同じなら何もしない
    // 翌日のほうが下がるなら売る
    for d in 1..N - 1 {
        dbg!(money);
        dbg!(stocks);

        if As[d] < As[d + 1] {
            let buy = money / As[d];
            stocks += buy;
            money -= As[d] * buy;
        } else if As[d] > As[d + 1] {
            money += stocks * As[d];
            stocks = 0;
        }
    }

    dbg!(money);
    dbg!(stocks);


    // 最終日: 全部売る
    money += stocks * As[N - 1];
    // stocks = 0;

    println!("{}", money);

}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    string s;
    cin >> s;
    ll k = s.size();
    ll ans = 0;
    for(i = 0;i < k;++i){
        if(s.at(i) == 'o') ++ans;
    }
    ans += 15 - k;
    if(ans > 7) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3592
W, H, N = gets.split.map(&:to_i)
XYAs = readlines.map{|l| l.split.map(&:to_i)}

xmin, xmax = 0, W
ymin, ymax = 0, H
XYAs.each do |x, y, a|
  case a
  when 1; xmin = [x, xmin].max
  when 2; xmax = [x, xmax].min
  when 3; ymin = [y, ymin].max
  when 4; ymax = [y, ymax].min
  end
end
puts (xmax > xmin && ymax > ymin) ? (xmax - xmin)*(ymax - ymin) : 0


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>

#define GET_STDIN fgets(buf, 1024, stdin)
#define FOR(i, f, n, b) for(int i = (f); i < (n); i += (b))

using namespace std;

int main() {
  int n, y;
  char buf[1024];

  GET_STDIN;
  sscanf(buf, "%d %d", &n, &y);

  int sum = 0;
  bool is_success = false;

  FOR(i, 0, n + 1, 1) {
    FOR(j, 0, n + 1, 1) {
      int z = y - 999 * n - 9001 * i - 4001 * j;
      if (z >= 0 && z <= n && i + j + z == n) {
        printf("%d %d %d\n", i, j, z);
        is_success = true;
        break;
      }
    }
    if (is_success) {
      break;
    }
  }

  if (!is_success) {
    printf("-1 -1 -1\n");
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using ll = long long;
using ld = long double;
using Pa = std::pair<ll, ll>;
using namespace std;
ll MOD = 998244353;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n, ll mod) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x) % mod, n / 2, mod) % mod);
	else
		return (x * pow(x, n - 1, mod) % mod);
}
vector<ll>primess(ll n) {
	vector<ll>a;
	while (n % 2 == 0)n /= 2, a.push_back(2);
	ll sosuu = 3;
	while (n != 1) {
		if (n % sosuu == 0)n /= sosuu, a.push_back(sosuu);
		else if (sosuu > sqrt(n) + 2) {
			a.push_back(n);
			break;
		}
		else sosuu += 2;
	}
	return a;
}
signed main() {
	ll n; cin >> n;
	ll ans = 1000;
	vector<ll>a(n);
	rip(i, n)cin >> a[i];
	rip(i, n - 1) {
		if (a[i] < a[i + 1])ans += (a[i + 1] - a[i]) * (ans / a[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n)
{
	vector<pair<ll, ll>> p;
	for (ll i = 2; i * i <= n; i++)
	{
		if ((n % i) != 0)
			continue;
		pair<ll, ll> a = make_pair(i, 0);
		while ((n % i) == 0)
		{
			n /= i;
			a.second += 1;
		}
		p.push_back(a);
	}

	if (n != 1)
		p.push_back(make_pair(n, 1));
	return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a)
{
	ll b = MOD, u = 1, v = 0;
	while (b)
	{
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0)
	{
		u += MOD;
	}
	return u;
}
// 順列
ll permutation(const ll n, const ll m)
{
	ll result = 1;
	for (ll i = n; i > n - m; i--)
	{
		result = (result * i) % MOD;
	}
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x)
{
	if (x == 0)
		return 1;
	ll res = repeat_square(n, x / 2);
	res = res * res % MOD;
	if ((x % 2) == 1)
		res = res * n % MOD;
	return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m)
{
	ll p = permutation(n, m);
	ll div = 1;
	for (ll i = 2; i <= m; i++)
	{
		div = (div * i) % MOD;
	}
	return (p * modinv(div)) % MOD;
}

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

	vector<int> C(N-1, 0), S(N-1, 0), F(N-1, 0);
	rep(i, N-1) {
		cin >> C[i] >> S[i] >> F[i];
	}

	vector<int> result(N, 0);
	rep(i, N) {
		int t = 0;
		rep(j, i, N-1) {
			if (t < S [ j ]) t = S [ j ];
			else if ( t % F [ j ]==0);
			else t = t + F [ j ] - t % F [ j ];
			t += C [ j ];
		}

		result[i] = t;
	}

	rep(i, N) {
		cout << result[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	set<ll> s;
	int n;
	cin>>n;
	REP(i,n) {
		ll a;
		cin>>a;
		if(s.count(a)!=0) s.erase(a);
		else s.insert(a);
	}
	cout<<s.size()<<endl;
}


Measured memory_bytes: 4992
#include<iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
long N,W,weight[1<<7],value[1<<7];
long dp[1<<7][1<<17];
int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {
            // i 番目の品物を選ぶ場合
            if (sum_w + weight[i] <= W) {
                chmax(dp[i+1][sum_w + weight[i]], dp[i][sum_w] + value[i]);
            }
            // i 番目の品物を選ばない場合
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 103552
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<numeric>
#include<map>
#include <queue>

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define VI vector<int>
#define INF 1145141919

typedef long long ll;
typedef long double ld;

using namespace std;

class Card {
public:
    char l;
    int n;

    Card(char l, int n) {
        this->l = l;
        this->n = n;
    }

    bool operator==(const Card &a) const {
        return n == a.n && l == a.l;
    }

    bool operator<(const Card &a) const {
        return n < a.n;
    }
};

void bubleSort(vector<Card> *a, int n) {
    int flag = true;
    while (flag) {
        flag = 0;
        for (int i = n - 1; i >= 1; i--) {
            if ((*a)[i].n < (*a)[i - 1].n) {
                swap((*a)[i], (*a)[i - 1]);
                flag = true;
            }
        }
    }
}

void selectionSort(vector<Card> *a, int n) {
    REP(i, n) {
        int minj = i;
        FOR(j, i, n) {
            if ((*a)[j].n < (*a)[minj].n)
                minj = j;
        }
        swap((*a)[i], (*a)[minj]);
    }
}

void solver() {
    int n;
    vector<Card> vc, vc2, vc3;
    cin >> n;
    REP(i, n) {
        string str;
        cin >> str;
        vc.push_back(Card(str[0], int(str[1] - '0')));
    }
    //copy
    REP(i, n) {
        vc2.push_back(vc[i]);
        vc3.push_back(vc[i]);
    }

    bubleSort(&vc2, n);
    selectionSort(&vc3, n);

    stable_sort(ALL(vc));

    bool f1 = vc == vc2;
    bool f2 = vc == vc3;

    REP(i, n - 1)cout << vc2[i].l << vc2[i].n << " ";
    cout << vc2[n - 1].l << vc2[n - 1].n << endl;
    cout << (f1 ? "Stable" : "Not stable") << endl;
    REP(i, n - 1)cout << vc3[i].l << vc3[i].n << " ";
    cout << vc3[n - 1].l << vc3[n - 1].n << endl;
    cout << (f2 ? "Stable" : "Not stable") << endl;

}

int main() {
    solver();
    return 0;
}


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

int main(){
    int N,M;
    cin >> N >> M;
    int a[M], b[M], c[N+1]={}, d[N+1]={};

    for(int i=0; i<M; i++){
        cin >> a[i] >> b[i];
    }

    for(int i=0; i<M; i++){
        if( a[i]==1 ){
            c[b[i]]++;
        }
        if( b[i]==N ){
            d[a[i]]++;
        }
    }    

    for(int i=0; i<N; i++){
        if( c[i]>0 && d[i]>0 ){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;

    return 0;
}

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


int main(){
  int a;
  int b;
  int c;
  int d;
  cin >> a >> b >> c >> d;
  while(true){
    c = c-b;
    if(c<1){
      cout << "Yes" << endl;
      break;
    }
    a = a-d;
    if(a<1){
      cout << "No" << endl;
      break;
    }
  }

}


Measured memory_bytes: 3620
#include<stdio.h>
#define SIZE 30
int main()
{
  int w,n;
  int result[SIZE];
  int i;
  int x,y,rep;
  scanf("%d",&w);
  for(i=0;i<w;i++) result[i]=i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d,%d",&x,&y);
      rep=result[x-1];
      result[x-1]=result[y-1];
      result[y-1]=rep;
    }
  for(i=0;i<w;i++) printf("%d\n",result[i]+1);
  return 0;
}

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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int total = 0;
	vector<int> v(n);
	int x;
	for(int i = 0; i < n; i++) {
		cin >> x;
		total += x;
		v[i] = x;
	}
	int count = 0;
	double minp = (1/(4* (double) m))*total;
	for(int i = 0; i < n; i++) {
		if(v[i] >= minp) count++;
	}

	if(count >= m) {
		cout << "Yes" << "\n";
	} else {
		cout << "No" << "\n";
	}
}


Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
lr_list = [list(map(int, input().split())) for _ in range(Q)]
count = 0
counts = [0] * N
for i in range(1, N):
    if S[i-1] == 'A' and S[i] == 'C':
        count += 1
    counts[i] = count
for l, r in lr_list:
    l -= 1
    r -= 1
    print(counts[r] - counts[l])


Measured memory_bytes: 30688
#include<iostream>
#include<queue>
#define INF 1e9
using namespace std;

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

int main(){
    int h,w;
    cin>>h>>w;
    char m[55][55];
    int d[55][55];
    int cnt=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>m[i][j];
            d[i][j]=INF;
            if(m[i][j]=='#') cnt++;
        }
    }

    queue<pair<int,int>> q;
    q.push(make_pair(0,0));
    d[0][0]=0;
    while(!q.empty()){
        int x=q.front().first;
        int y=q.front().second;
        q.pop();
        if(x==w-1&&y==h-1) break;
        for(int i=0;i<4;i++){
            int nx=x+dx[i];
            int ny=y+dy[i];
            if(nx>=0&&nx<w&&ny>=0&&ny<h&&m[ny][nx]!='#'&&d[ny][nx]==INF){
                q.push(make_pair(nx,ny));
                d[ny][nx]=d[y][x]+1;
            }
        }
    }

    int ans;
    if(d[h-1][w-1]==INF) ans=-1;
    else ans=h*w-cnt-d[h-1][w-1]-1;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    ll n,i,j,mn=LLONG_MAX;
    cin>>n;
    vector<ll>v(n);
    for(i=0;i<n;i++)
        cin>>v[i];
    for(i=1;i<=100;i++)
    {
        ll s=0;
        for(j=0;j<n;j++)
            s+=((i-v[j])*(i-v[j]));
        mn=min(mn,s);
    }
    cout<<mn<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
void cppio(){ ios_base::sync_with_stdio(0); cin.tie(0); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()

const int maxn = int(2e5) + 10;

int n;
int a[maxn];
int b[maxn];

int main()
{
	cppio();
	cin >> n;
	rrep(i, n) cin >> a[i];
	rrep(i, n) cin >> b[i];

	priority_queue<pp> pq;
	rrep(i, n) pq.emplace(b[i], i);

	ll cnt = 0;
	while(pq.size()) {
		int x, i; tie(x, i) = pq.top(); pq.pop();
		//printf("pop i %d x %d (b %d)\n", i, x, b[i]);
		if(b[i] != x) continue;

		if(b[i] < a[i]) {
			cout << -1 << '\n';
			return 0;
		}

		if(b[i] == a[i]) continue;

		int i1 = (i+n-2)%n + 1;
		int i2 = i%n + 1;

		int df = (b[i1] + b[i2]);
		int c = (b[i] - max({a[i], b[i1] + b[i2]}) + df - 1) / df;

		if(c == 0) continue;

		//printf("b: %d (%d) %d / df %d, c %d\n", b[i1], b[i], b[i2], df, c);

		cnt += c;
		b[i] -= df * c;

		pq.emplace(b[i], i);
	}

	rrep(i, n) if(a[i] != b[i]) {
		cout << -1 << '\n';
		return 0;
	}

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3956
n = int(input())
xs = list(map(int, input().split()))
def cost(xs, neg=False):
    sign = -1 if neg else 1
    if sign * xs[0] > 0:
        ret = 0
        sum_ = xs[0]
    else:
        ret = abs(sign - xs[0])
        sum_ = sign
    for x in xs[1:]:
        sign *= -1
        sum_ += x
        if sum_ * sign <= 0:
            ret += abs(sign - sum_)
            sum_ = sign
    return ret

print(min(cost(xs), cost(xs, neg=True)))

Measured memory_bytes: 14332