akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n;
    cin>>n;
    
    for (ll a = 1; a <= 9 ; a++){
        for (ll b = 1; b <= 9; b++){
            if (a*b == n){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 256
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <unordered_set>
# include <unordered_map>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define STR(x) string x;cin>>x;
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

int v, e;
int cost[20][20];
int memo[1 << 16][15][15];
int dp(const int bit, const int now, const int goal)
{
	if (__builtin_popcount(bit) == v)return cost[now][goal];
	if (memo[bit][now][goal] != -1)return memo[bit][now][goal];
	int ans = INF;
	FOR(i, v)
	{
		if (bit & 1 << i || cost[now][i] < 0)continue;
		ans = min(ans, dp(bit | 1 << i, i, goal) + cost[now][i]);
	}
	return memo[bit][now][goal] = ans;
}

int main()
{
	cin >> v >> e;
	FOR(i, 20)FOR(j, 20)cost[i][j] = INF;
	memset(memo, -1, sizeof memo);
	FOR(i, e)
	{
		int s, t, d;
		cin >> s >> t >> d;
		cost[s][t] = d;
	}
	int ans = INF;
	FOR(i, v)
	{
		ans = min(ans, dp(1 << i, i, i));
	}
	if(ans<=(v+1)*1000)cout << ans << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 60696
import sys

n,k = map(int,input().split())
a = list(map(int,input().split()))

#各頂点が白(0)か黒(1)か
flag = [-1 for _ in range(n)]

#dfsで色を塗っていく
#頂点の数をN、辺の数をMとすると、O(N+M)で解ける
stack = [a[0]-1]
flag[0] = 0
count = 0
while stack:
	u = stack.pop()
	if flag[u] == -1:
		stack.append(a[u] - 1)
		count += 1
		if count == k:
			print(u+1)
			sys.exit()
		flag[u] = count
	else:
		loop = count - flag[u] + 1
		#print(count,flag[u],loop)
		num = (k - flag[u]) % loop
		#print(num)
		break

if num == 0:
	print(u + 1)
else:
	ans = a[u]
	for i in range(num-1):
		ans = a[ans-1]
	print(ans)


Measured memory_bytes: 32184
class UnionFind:
    def __init__(self, N):
        self.N = N
        self.par  = [i for i in range(self.N)]
        self.rank = [0 for _ in range(self.N)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split(" "))
p = list(map(int, input().split(" ")))
ind = {pi : i + 1 for i, pi in enumerate(p)}
uf = UnionFind(N + 1)

for _ in range(M):
    x, y = map(int, input().split(" "))
    uf.unite(x, y)

ans = 0
for i in range(1, N + 1):
    if i == ind[i] or uf.same(i, ind[i]):
        ans += 1
print(ans)

Measured memory_bytes: 100712
#include <iostream>
#include <math.h>
#include <algorithm>

int main()
{
    std::string s , t;
    std::cin >> s >> t;
    std::sort(s.begin(),s.end(),[](char &a,char &b){return a < b;});
    std::sort(t.begin(),t.end(),[](char &a,char &b){return a > b;});

    bool flug=true;
    for(int i=0;i<s.size()&&i<t.size();i++) if(s.at(i)!=t.at(i)) flug=false;

    std::cout << (flug
                    ?s.size() < t.size() ? "Yes":"No"
                    :s.at(0)  < t.at(0)  ? "Yes":"No")
              << std::endl;
    return 0;
}


Measured memory_bytes: 256
//解説より

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back

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

    bool dp[30009][4][1009];
    dp[0][0][0]=1;

    for(int i=0;i<N;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<1000;k++){
                if(false==dp[i][j][k])continue;

                dp[i+1][j][k]=true;//選ばない
                if(j<=2){//選ぶ
                    dp[i+1][j+1][k*10+(X[i]-'0')]=true;
                }
            }
        }
    }int cnt=0;
    for(int i=0;i<1000;i++){
        if(true==dp[N][3][i])cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 118528
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    long long int s, c;
    cin >> s >> c;
    cout << min(s, c / 2) + max((long long int)0, c - s * 2) / 4 << endl;
}


Measured memory_bytes: 3604
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	char s[25];
	while(~scanf("%s",s)){
		s[5]=' ';
		s[13]=' ';
		printf("%s\n",s);
	}
	
	return 0;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/agc020/tasks/agc020_b

//参考：
//http://ch3000.blog.fc2.com/blog-entry-44.html

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL K;
LL A[100001];

LL ans_min = 2,ans_max = 2;

void solve(){
	for (int i=K;i>=1;i--) {
		//最小化
		ans_min = A[i] * ceil(ans_min / (A[i] + .0));
		//最大化
		ans_max = A[i] * (ans_max / A[i]) + A[i] - 1;
	}
	if (ans_min > ans_max) ans_min = -1;
}

int main(){
    cin >> K;
    for(int i=1;i<=K;i++) cin >> A[i];

    solve();

	if(ans_min==-1){
		cout << -1 << endl;
		return 0;
	}
	cout << ans_min << " " << ans_max << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
      #define hell                         1000000007 
      #define M                            1000000007
      #define Maxi                      10000000000000000
      #define lcm(a,b)                     (a*b)/__gcd(a,b)
      #define ll                           long long
           
      #define vll                          vector<ll>
      #define vi                           vector<long long>
      #define pll                          vector< pair<ll,ll> >
      #define pb                           push_back
                  //#define mp                           make_pair
      #define all(v)                       v.begin(),v.end()
      #define lbnd                         lower_bound
      #define ubnd                         upper_bound
      #define bs                           binary_search
      #define F                            first
      #define S                            second
      #define rep(i,a,b)                   for(i=a;i<b;i++)
      #define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
      #define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
      #define ret(x)                       return cout<<x,0;
      #define dbg(x)                       cout << #x << " is " << x << endl;
      #define endl                           '\n'
           
           
                  // Debug //
           
      #define trace(x)                 cerr << #x << ": " << x << endl;
      #define trace1(x)                cerr << #x << ": " << x << endl;
      #define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
      #define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
      #define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
      #define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
      #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
           
           
      using namespace std;
      
     
      int main()
          {
           
          ios_base::sync_with_stdio(false);
          cin.tie(NULL);cout.tie(NULL);
        
          
          ll i,j;
          ll n;
          cin>>n;
          ll ans=100000000000000;
          for(i=1;i<=sqrt(n);i++)
          {
            if(n%i==0)
            {
              j=n/i;
              ans=min(ans,j-1+i-1);
            }
          }

          cout<<ans<<endl;

       return 0;
        }

Measured memory_bytes: 256
def main():
    N = int(input())
    adj = []
    for i in range(N):
        adj.append(list(map(int, input().split())))
    mod = 10 ** 9 + 7

    state_list = [[] for _ in range(N + 1)]
    for state in range(2 ** N):
        one_num = 0
        for j in range(N):
            if state >> j & 1:
                one_num += 1
        state_list[one_num].append(state)

    dp = [0] * (2**N)
    dp[0] = 1
    for i in range(N):
        for j in range(N):
            if adj[i][j]:
                for state in state_list[i]:
                    state_new = state | (2**j)
                    if state != state_new:
                        dp[state_new] = (dp[state_new] + dp[state]) % mod

    print(dp[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 117212
n,k = map(int, input().split())
count = 0
for b in range (k+1,n+1):
    
    if (k==0):
        x = (n//b)*(b-k) + max(n%b-k+1,0) -1
    else:    
        x = (n//b)*(b-k) + max(n%b-k+1,0)

    count += x
print(count)

Measured memory_bytes: 3060
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

ll x,y,z,k;
vl a,b,c;

void solve(){
    cin>>x>>y>>z>>k;
    a.resize(x);
    b.resize(y);
    c.resize(z);
    rep(i,x)cin>>a[i];
    rep(i,y)cin>>b[i];
    rep(i,z)cin>>c[i];
    sort(all(a),greater<>());
    sort(all(b),greater<>());
    sort(all(c),greater<>());

    priority_queue<pl> q;
    set<ll> added;
    q.emplace(a[0]+b[0]+c[0],0);
    added.insert(0);
    while(k--){
        pl p=q.top();q.pop();
        cout<<p.first<<endl;
        ll tx=p.second/1001/1001;
        ll ty=p.second/1001%1001;
        ll tz=p.second%1001;
        if(tx<x-1&&!added.count((tx+1)*1001*1001+ty*1001+tz)){
            q.emplace(a[tx+1]+b[ty]+c[tz],(tx+1)*1001*1001+ty*1001+tz);
            added.insert((tx+1)*1001*1001+ty*1001+tz);
        }
        if(ty<y-1&&!added.count(tx*1001*1001+(ty+1)*1001+tz)){
            q.emplace(a[tx]+b[ty+1]+c[tz],tx*1001*1001+(ty+1)*1001+tz);
            added.insert(tx*1001*1001+(ty+1)*1001+tz);
        }
        if(tz<z-1&&!added.count(tx*1001*1001+ty*1001+tz+1)){
            q.emplace(a[tx]+b[ty]+c[tz+1],tx*1001*1001+ty*1001+tz+1);
            added.insert(tx*1001*1001+ty*1001+tz+1);
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  vector <int> result(N);
  for (int i = 1; i <= N; i++) {
    
    for (int j = 1; j < 100; j++) {
      if(j*j > i) break;
      for (int k = 1; k < 100; k++) {
        if (j*j + k*k + j*k > i) break;
        for (int m = 1; m < 100; m++) {
          if (j*j + k*k + m*m + j*k + k*m + m*j == i) {
            result.at(i - 1) = result.at(i - 1) + 1;
          }
          if (j*j + k*k + m*m + j*k + k*m + m*j > i) {
            break;
          }
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << result.at(i) << endl;
  }  
  
  return 0;
}


Measured memory_bytes: 3608
#include<map>
#include<queue>
#include<iostream>
#include<cmath>
#include<cstdio>
#define pi acos(-1)
using namespace std;

/*int arr[10000];
vector<int>adj[10000];
vector<int>v1;
bool visited[10000];
void bfs(int s)
{
    int cnt=0;
    queue<int>q;
    q.push(s);
    v1.push_back(s);
    visited[s]=1;
    cnt++;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(int i=0;i<adj[u].size();i++){
            if(visited[adj[u][i]]==0){
                int v=adj[u][i];
                visited[v]=1;
                v1.push_back(v);
                q.push(v);
                cnt++;
            }
        }
    }
    int u=v1.size();
    for(int i=0;i<u;i++){
        arr[v1[i]-1]=cnt;
    }
    v1.clear();
}
void solve(int n)
{
    for(int i=0;i<n;i++)cout<<arr[i]<<" ";
}
int main()
{
    int m,n;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int k,j=0;
        cin>>k;
        int ara[k];
        while(j<k){
            cin>>ara[j];
            if(j){
                adj[ara[j-1]].push_back(ara[j]);
                adj[ara[j]].push_back(ara[j-1]);
            }
            j++;
        }
    }
    for(int i=0;i<n;i++){
        if(visited[i+1]==0){
          bfs(i+1);
        }
    }
    solve(n);
    //cout<<v2.size();
}
*/
int main()
{
    long long int a,b,t,k;
    cin>>t;
    map<int,int>m;
    for(int i=1;i<t;i++){
        cin>>b;
        m[b]++;
    }
    for(int i=1;i<=t;i++){
        cout<<m[i]<<"\n";
    }
}



Measured memory_bytes: 12976
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

int main(void){
    int n,k;
    int d,x;
    map<int,int> m;
    cin>>n>>k;
    for(int i=0;i<k;i++){
        cin>>d;
        for(int j=d;d>0;d--){
            cin>>x;
            m[x];
        }
    }
    cout<<n-m.size();
}

Measured memory_bytes: 3648
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

solve :: [Integer] -> String
solve argList = show $ min pa b
    where
        n = head argList
        a = head $ tail argList
        b = last argList
        pa = n * a

main = do
    argList <- getIntList
    putStrLn $ solve argList

Measured memory_bytes: 380
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

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

const long long mod = 100000007;

long long mod_pow(long long m, long long k) {
	long long res = 1;
	while(k > 0) {
		if(k & 1)
			(res *= m) %= mod;

		(m *= m) %= mod;
		k >>= 1;
	}
	
	return res;
}

long long mod_combination(long long n, long long r) {
	long long res = 1;

	for(long long i = 0; i < r; ++i)
		res = res * (n - i) % mod;

	long long tmp = 1;
	for(long long i = 1; i <= r; ++i)
		tmp = tmp * i % mod;

	res = res * mod_pow(tmp, mod - 2) % mod;

	return res;
}

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

	int r, c, ax, ay, bx, by;
	cin >> r >> c >> ay >> ax >> by >> bx;

	vector<int> x(9), y(9);
	int mn = INT_MAX;
	for(int i = 0; i < 9; ++i) {
		x[i] = abs(c * dx[i] + bx - ax);
		y[i] = abs(r * dy[i] + by - ay);
		if(mn > x[i] + y[i])
			mn = x[i] + y[i];
	}

	long long ans = 0;
	for(int i = 0; i < 9; ++i)
		if(mn == x[i] + y[i])
			ans = (ans + mod_combination(x[i] + y[i], y[i])) % mod;

	cout << ans << endl;

	return EXIT_SUCCESS;
}

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

int main(){
	int n ; cin >> n ;
	int cnt = 0 ;
	for(int i=1;i<=n;i++){
		int a ; cin >> a ;
		if(a!=i) cnt++ ;
	}
	if(cnt==0||cnt==2) cout << "YES" << endl ;
	else cout << "NO" << endl ;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

/* ソート関数 */
int int_sort( const void * a , const void * b ) {
  /* 引数はvoid*型と規定されているのでint型にcastする */
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}

int main(void){
    int N,K;
    scanf("%d %d",&N,&K);
    int buri[200001]={};
    for(int i=0;i<N;i++){
        int kari;
        scanf("%d",&kari);
        buri[kari]++;
    }
      qsort(( void * )buri , 200001 , sizeof( buri[0] ), int_sort );
      int ans=0;
    for(int i=0;i<200001-K;i++){
        ans+=buri[i];
    }
    printf("%d",ans);
    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  if (A == 1) A += 13;
  if (B == 1) B += 13;
  
  if (A > B) cout << "Alice" << endl;
  else if (B > A) cout << "Bob" << endl;
  else cout << "Draw" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i,j,k=0,ta,n,arr[1000],str[1000];
char s[1000],t[1000];
int main()
{
    scanf("%s %s",s,t);
    for(i=0; i<strlen(s)-1; i++)
    {
        arr[i]=s[i]-s[i+1];
    }

    arr[i]=s[i]-s[0];
    for(i=0; i<strlen(t)-1; i++)
    {
        str[i]=t[i]-t[i+1];
    }
    str[i]=t[i]-t[0];
    n=strlen(s);
    sort(arr,arr+n);
    sort(str,str+n);
    for(i=0; i<strlen(s); i++)
    {
        if(str[i]==arr[i])
            k++;
    }
    /*for(i=0; i<strlen(s); i++)
    {
        printf("%d %d\n",arr[i],str[i]);
    }*/
    if(k==strlen(s))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  int n;cin >> n;
  map<int,ll> mp;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
    mp[ a[i] ]++;
  }

  ll sum = 0;
  for(auto m:mp){
    sum += m.second * (m.second - 1) / 2;
  }

  rep(i,n){
    if(mp[ a[i] ] == 1) cout << sum << "\n";
    else{
      ll res = sum - mp[ a[i] ] * ( mp[ a[i] ] - 1 ) / 2 + ( mp[ a[i] ] - 1 ) * ( mp[ a[i] ] - 2 ) / 2;
      cout << res << "\n";
    }
  }
  
  return 0;
}


Measured memory_bytes: 10240
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

void Main()
{
	string S;
   
   	cin >> S;
  
    if(S[0] == S[1] && S[1] == S[2])
      printf("No");
  
    else
      printf("Yes");
 	
 	
}
 
int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
  Main();
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<iomanip>
#include<sstream>
#include<list>
#include<iterator>
#include<queue>
#include<stack>

#define ll long long
#define ull unsigned long long
#define pi acos(-1)
#define el cout<<"\n"
#define pb push_back
#define f1(i, n)        for (ll i = 1; i <= n; i++)
#define f0(i, n)        for (ll i = 0; i < n; i++)
#define fo(i, s, n)     for (ll i = s; i <= n; i++)


using namespace std;


//**************  MY CODE STARTS HERE  **************************//


int main()
{
    ll x,y,a,b,c,count=0,input;
    cin>>x>>y>>a>>b>>c;
    vector<ll> rif1,rif2,ch;
    for(ll i=0;i<a;i++)
    {
        cin>>input;
        rif1.push_back(input);
    }
    for(ll i=0;i<b;i++)
    {
        cin>>input;
        rif2.push_back(input);
    }
    for(ll i=0;i<c;i++)
    {
        cin>>input;
        ch.push_back(input);
    }
    sort(rif1.begin(),rif1.end(),greater<ll>());
    sort(rif2.begin(),rif2.end(),greater<ll>());

    if(rif1.size()>=x)
    {
        for(ll i=0;i<x;i++)
        {
            ch.push_back(rif1[i]);
        }
        
    }
    if(rif1.size()<x)
    {
        for(ll i=0;i<rif1.size();i++)
        {
            ch.push_back(rif1[i]);
        }
        
    }
    if(rif2.size()>=y)
    {
        for(ll i=0;i<y;i++)
        {
            ch.push_back(rif2[i]);
        }
        
    }
    if(rif2.size()<y)
    {
        for(ll i=0;i<rif2.size();i++)
        {
            ch.push_back(rif2[i]);
        }
        
    }
    sort(ch.begin(),ch.end(),greater<ll>());
    for(ll i=0;i<x+y;i++)
    {
        count+=ch[i];
    }
    cout<<count;el;
}


Measured memory_bytes: 7920
#include "bits/stdc++.h"

using namespace std;


#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 rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

#define mod 1000000007

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int N;
	cin >> N ;
	vector<int>X;
	X.resize(N);
	
	rep(i, N) {
		cin >> X[i];
	}
	
	double avg = accumulate(X.begin(), X.end(), 0)/double(N);
	avg = round(avg);
	int sum = 0;
	rep(i, N) {
		sum += (X[i] - avg)*(X[i] - avg);
	}
	print(sum);
}

Measured memory_bytes: 256
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7


Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

n = int(ri())
a = Ri()

m = int(ri())
summ = sum(a)
dic = {}
for i in a:
    dic[i] = dic.get(i,0 )+1

for _ in range(m):
    l,r = Ri()
    if l in dic:
        cnt = dic[l]
        summ -= cnt*l
        summ += cnt*r

        dic.pop(l)
        dic[r] = dic.get(r, 0) + cnt
    print(summ)

Measured memory_bytes: 87680
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

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

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


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

	vector<int> m( N );
	ll total = 0;
	rep( i, N )
	{
		cin >> m[i];
		total += m[i];
	}

	sort( ALL( m ) );
	X -= total;

	ll num = N;
	while ( X >= m[0] )
	{
		++num;
		X -= m[0];
	}

	cout << num << endl;

	return ( 0 );
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  int64_t N, H;
  cin >> N >> H;

  vector<int64_t> A(N);
  vector<int64_t> B(N);
  int64_t maxA = 0;
  rep(i, N) {
    cin >> A[i] >> B[i];
    maxA = max(maxA, A[i]);
  }
  sort(B.begin(), B.end(), greater<int64_t>());

  int64_t answer = 0;
  rep(i, N) {
    if (maxA < B[i]) {
      ++answer;
      H -= B[i];
      if (H <= 0) {
        cout << answer << endl;
        return 0;
      }
    }
  }

  answer += (H + maxA - 1) / maxA;
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 1920
#include <iostream>
using namespace std;
int main() {
  int h, w;
  while(1) {
    cin >> h >> w;
    if(h == 0 && w == 0) break;

    for(int i=0; i<h; i++) {
      for(int j=0; j<w; j++) {
        cout << "#";
      }
      cout << "\n";
    }
    cout << "\n";
  }
  return 0;
}



Measured memory_bytes: 3100
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll res = 0;
    rep(i, N) { cin >> A[i]; }
    if(A[0] != 0) {
        cout << -1 << endl;
        return 0;
    }

    for(int i = 1; i < N; i++) {
        if(A[i] - A[i - 1] > 1) {
            cout << -1 << endl;
            return 0;
        } else {
            if(A[i] <= A[i - 1]) {
                res += A[i];
            } else {
                res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
A = [int(i) for i in input().split()]

C = []
max_A = max(A)
max_idx = A.index(max_A)
min_A = min(A)
min_idx = A.index(min_A)

if abs(max_A) >= abs(min_A):
    for i in range(n):
        #A[i] += max_A
        C.append([max_idx+1, i+1])
    for i in range(1, n):
        #A[i] += A[i-1]
        C.append([i, i+1])
else:
    for i in range(n):
        #A[i] += min_A
        C.append([min_idx+1, i+1])
    for i in range(n, 1, -1):
        #A[n-i+2] += A[n-i+1]
        #C.append([n-i+2, n-i+3])
        C.append([i, i-1])

print(len(C))
for i, j in C:
    print('{0} {1}'.format(i, j))


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int H, W; cin >> H >> W;
    if(H % 2 == 1 && W % 2 == 0) swap(H, W);
    int alp[26] = {};
    bool ok = true;
    rep(i, H) rep(j, W){char temp; cin >> temp; alp[temp - 'a']++;}
    if(H % 2 == 1){
        //H, W両方奇数
        bool find_odd = false;
        rep(i, 26){
            if(find_odd && alp[i] % 2 == 1) ok = false;
            else if(alp[i] % 2 == 1) {find_odd = true; alp[i]--;}
        }
        if(!find_odd) ok = false;
        else{
            //H/2 + W/2個の奇数
            int need_minus2 = H/2 + W/2;
            rep(i, 26){
                if(alp[i] % 4 == 2){
                    need_minus2--;
                    alp[i] -= 2;
                }
                if(need_minus2 < 0 || alp[i] % 2 == 1) ok = false;
            }
            if(need_minus2 % 2 == 1) ok = false;
        }
        
    }
    else if(W % 2 == 0){
        //H, W両方偶数 ->全てが4の倍数である必要がある
        rep(i, 26) if(alp[i] % 4 != 0) ok = false;
    }
    else{
        //Wのみが奇数
        //計H/2回、任意のアルファベットカウンタから2を引いて(重複可)全てを4の倍数にする
        int need_minus2 = H/2;
        rep(i, 26){
            if(alp[i] % 4 == 2){
                need_minus2--;
                alp[i] -= 2;
            }
            if(need_minus2 < 0 || alp[i] % 2 == 1) ok = false;
        }
        if(need_minus2 % 2 == 1) ok = false;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

void solve(){}

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

int main()
{
	string s;
	int ans=0;
	
	cin >> s;
	for(int i=0;i<s.size()-1;i++)
	{
		if(s[i]!=s[i+1])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scin = new Scanner(System.in);
		
		String[] nums = scin.nextLine().split(" ");
		
		int num1 = Integer.parseInt(nums[0]);
		int num2 = Integer.parseInt(nums[1]);
		
		System.out.println(gcd(num1, num2));
	}
	
	public static int gcd(int a, int b) {
		if (Integer.min(a, b) == 0){
			return Integer.max(a, b);
		}
		
		if (a == b) {
			return a;
		}
		if (a > b) {
            return gcd(a-b, b);
		}
        return gcd(a, b-a); 
	}
}



Measured memory_bytes: 26352
#include <stdio.h>

void reverseNumbers(int size,int numbers[])
{
	for (--size; size>=0; size--) {
		printf("%d", numbers[size]);
		if (size != 0) {
			printf(" ");
		}
	}
	printf("\n");
}

int main(void) {
	int	numbers[100], i, length;
	scanf("%d", &length);
	for (i = 0; i < length; i++) {
		scanf("%d", &numbers[i]);
	}
	reverseNumbers(length,numbers);
	return 0;
}


Measured memory_bytes: 2024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int N, T;
  cin >> N >> T;
  int MI, X, Y;
  MI = 10000;
  rep(i, N) {
    cin >> X >> Y;
    if(Y <= T) {
      MI = min(X, MI);
    }
  }
  if(MI == 10000) {
    cout << "TLE" << endl;
  }
  else {
    cout << MI << endl;
  }
}

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

// clang-format off
#define forn(i, x, y) for(int i = x; i < y; i++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)

using ll = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVILL = vector<VLL>;
// clang-format on

const long long MOD = 1000000007;

int main()
{
  int H, W;
  cin >> H >> W;
  VVI grid(H, VI(W, 1));
  string line;
  forn(i, 0, H)
  {
    cin >> line;
    forn(j, 0, W) if (line[j] == '#') grid[i][j] = 0;
  }

  VVI dp(H, VI(W));
  dp[0][0] = 1;
  forn(i, 0, H)
  {
    forn(j, 0, W)
    {
      if (grid[i][j] == 0)
        continue;
      if (i > 0)
        dp[i][j] += dp[i - 1][j];
      if (j > 0)
        dp[i][j] += dp[i][j - 1];
      dp[i][j] %= MOD;
    }
  }
  cout << dp[H - 1][W - 1] << endl;

  return 0;
}


Measured memory_bytes: 11512
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
using namespace std;
typedef long long LL;

#define _CRT_SECURE_NO_WARNINGS
int N,A;
int main() {
	scanf("%d%d",&N,&A);
	if (N%500 <= A) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
using namespace std;



int main(){
  int N;
  int A[9];
  for(int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++){
      cin >> A[i*3 + j];
    }
  }

  cin >> N;
  bool a[9];
  for (int i = 0; i < 9; i++){
    a[i] = false;
  }
  for (int i = 0; i < N; i++){
    int b;
    cin >> b;
    for (int j = 0; j < 9; j++){
      if(A[j] == b) a[j] = true;
    }
  }

  if(a[0]==true && a[3] == true && a[6] == true){cout << "Yes" << endl;return 0;}
  if(a[0]==true && a[1] == true && a[2] == true){cout << "Yes" << endl;return 0;}
  if(a[1]==true && a[4] == true && a[7] == true){cout << "Yes" << endl;return 0;}
  if(a[3]==true && a[4] == true && a[5] == true){cout << "Yes" << endl;return 0;}
  if(a[2]==true && a[5] == true && a[8] == true){cout << "Yes" << endl;return 0;}
  if(a[6]==true && a[7] == true && a[8] == true){cout << "Yes" << endl;return 0;}
  if(a[0]==true && a[4] == true && a[8] == true){cout << "Yes" << endl;return 0;}
  if(a[2]==true && a[4] == true && a[6] == true){cout << "Yes" << endl;return 0;}
  cout << "No" << endl;



  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int maxn = 2e5+10;
struct node{
    ll pre,net,num;
};
stack<node>sp;
ll s[maxn],ans=0;
int n;
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>s[i];
    node fr,to;
    fr.net=fr.pre=1;fr.num=s[1];sp.push(fr);
    for(int i=2;i<=n;i++){
        to.num=s[i];
        to.pre=to.net=1;
        while(!sp.empty()&&to.num<=sp.top().num){
            fr=sp.top();sp.pop();
            if(!sp.empty()) sp.top().net+=fr.net;
            to.pre+=fr.pre;
            ans+=fr.pre*fr.num*fr.net;
        }
        sp.push(to);
    }
    while(!sp.empty()){
        fr=sp.top();sp.pop();
        if(!sp.empty()) sp.top().net+=fr.net;
        ans+=fr.pre*fr.num*fr.net;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6656
def main():
    from bisect import bisect_left
    from bisect import bisect_right

    N = int(input())

    A = sorted(map(int, input().split()))
    B = sorted(map(int, input().split()))
    C = sorted(map(int, input().split()))

    print(sum([bisect_left(A, Bi) * (N - bisect_right(C, Bi)) for Bi in B]))
    return


main()


Measured memory_bytes: 22720
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

class UnionFind {
public:
    vector<int> par;
    int N;
    UnionFind(int n) {
        par.resize(n, -1);
        N = n;
    }
    int Find(int n) {
        return par[n] < 0 ? n : par[n] = Find(par[n]);
    }
    bool Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        if (x == y) return false;
        if (-par[x] > -par[y]) swap(x, y);
        par[y] += par[x];
        par[x] = y;
        N--;
        return true;
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }
    int size(int x) {
        return -par[Find(x)];
    }
    int size() {
        return N;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin, n, m;
    UnionFind uf(n);
    REP(i, 0, m) {
        int a, b;
        cin, a, b;
        uf.Union(a - 1, b - 1);
    }
    print(uf.size() - 1);
    return 0;
}


Measured memory_bytes: 3728
fn get_num_of_digit(v: isize) -> isize {
    let fv = v as f64;
    (fv.log10() + 1.0).floor() as isize
}

fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let n: isize = line.trim().parse().unwrap();

    println!("{}", (1..n+1).filter(|&i| get_num_of_digit(i) % 2 == 1).count());
}


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

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

int N,A,B,C;
int L[10];

int mi=1<<30;

void dfs(int cur,int a,int b,int c,int co) {
	if(cur==N) {
		if(a==0 || b==0 || c==0) return;
		
		mi=min(mi,co+abs(A-a)+abs(B-b)+abs(C-c));
		
		return;
	}
	
	dfs(cur+1,a+L[cur],b,c,co+10);
	dfs(cur+1,a,b+L[cur],c,co+10);
	dfs(cur+1,a,b,c+L[cur],co+10);
	dfs(cur+1,a,b,c,co);
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A>>B>>C;
	FOR(i,N) cin>>L[i];
	
	dfs(0,0,0,0,-30);
	cout<<mi<<endl;
}


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


Measured memory_bytes: 256
from itertools import accumulate
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
W = list(map(int, input().split()))

ALL_SUM = sum(W)
W_acc = [0]+list(accumulate(W))

ans = float('inf')
for i in range(N):
    diff = abs(W_acc[i]-ALL_SUM+W_acc[i])
    ans = min(diff, ans)
print(ans)


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

bool G[2][9][9];


void solve() {
  const int vx[4] = {1, -1, -1, 1};
  const int vy[4] = {1, 1, -1, -1};
  int x = 1;
  int y = 0;
  int k = 1;
  int d = 0;
  int bx, by;
  int ax, ay;
  bx = x;
  by = y;
  while(1) {
    if((k == 1 && bx == 0 && by == 0 && x == 1 && y == 0)
       || (k == 0 && bx == 1 && by == 0 && x == 0 && y == 0)) {
      ax = 75;
      ay = 25;
      break;
    }
    if(G[k][y][x]) {
      if(k == 0) {
	switch(d) {
	case 0: d = 3; break;
	case 1: d = 2; break;
	case 2: d = 1; break;
	case 3: d = 0; break;
	}
      } else {
	switch(d) {
	case 0: d = 1; break;
	case 1: d = 0; break;
	case 2: d = 3; break;
	case 3: d = 2; break;
	}
      }
    } else if(k == 0 && (y == 0 || y == 8)) {
      ax = x*100+50;
      ay = y*100;
      break;
    } else if(k == 1 && (x == 0 || x == 8)) {
      ax = x*100;
      ay = y*100+50;
      break;
    }

    bx = x;
    by = y;
    if(k == 1) {
      switch(d) {
      case 0:
	++y;
	break;
      case 1:
	--x;
	++y;
	break;
      case 2:
	--x;
	break;
      case 3:
	break;
      }
    } else {
      switch(d) {
      case 0:
	++x;
	break;
      case 1:
	break;
      case 2:
	--y;
	break;
      case 3:
	++x;
	--y;
	break;
      }
    }
    k = 1-k;
  }

  cout << ax << " " << ay << endl;
}

main() {
  int n;
  while((cin >> n) && n != -1) {
    fill(G[0][0], G[2][9], false);
    for(int i = 0; i < n; ++i) {
      char d;
      int u, x, y;
      cin >> d >> x >> y;
      u = (d == 'x') ? 0 : 1;
      G[u][y][x] = true;
    }
    solve();
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include<math.h>
double hyo(int x,int h)
{
    double ans=x*x+x*(sqrt(h*h*4+x*x));
    return ans;
}
int main(void)
{
    int x,h;
    while(1==1)
    {
        scanf("%d\n",&x);
        scanf("%d\n",&h);
        if(x==0&&h==0)break;
        printf("%lf\n",hyo(x,h));
    }
    return 0;
}



Measured memory_bytes: 2032
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define ll long long
#include<stdio.h>
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;
int main()
{
    ll x,k,d;
    ll x1,x2;
    cin>>x>>k>>d;
    if(x<0) x=-x;
    if(x/d>=k)
    {
    	cout<<x-k*d<<endl;
    }
    else
    {
    	ll a,b;
    	a=x%d;
    	b=d-x%d;
    	k=k-x/d;
    	if(k%2==1) cout<<b<<endl;
		else cout<<a<<endl;
    }
}


Measured memory_bytes: 3192
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] arh) {
		Scanner sc=new Scanner(System.in);
		int kaisu=sc.nextInt();
		int[] bl=new int[kaisu];


		for(int i=0; i<kaisu; i++) {
			bl[i]=sc.nextInt();
		}
		Arrays.sort(bl);

		int points=0;
		int now_counter=1;
		int now_pointer=bl[0];
		int last_update=0;
		for(int i=1; i<kaisu; i++) {
			if(bl[i]!=now_pointer) {
				points+=now_counter%2;
				now_pointer=bl[i];
				now_counter=1;
				last_update=i;
			}
			else {
				now_counter++;
			}
		}
		points+=now_counter%2;

		System.out.println(points);
	}
}

Measured memory_bytes: 49884
#include <stdio.h>

int main() {
    int x;
    int y;
    int z;
    scanf("%d%d%d", &x, &y, &z);

    if (x == y)
        printf("%d\n", z);
    else if (y == z)
        printf("%d\n", x);
    else
        printf("%d\n", y);
    return 0;
}

Measured memory_bytes: 128