akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
                #define ll long long
                #define f   first
                #define s   second
                #define pb          push_back
                #define mod        1000000007
                #define mod1       1000000009
                #define hell        998244353
                #define inf         1000000000000000000LL
                #define pi          3.14159265358979323
                //#define N           100005 
                const int N=200005;
                using namespace std;
                ll n,k,sum,q,res,m,val,ans;
                ll x,y;
                ll xx[]={1,0,-1,0};
                ll yy[]={0,1,0,-1};
                ll cnt[1000005];  
                void solve()    
                {   
                    string s;
                    cin>>s;
                    bool f=0;
                    n=s.size();
                    for(int i=0;i<n;i++) if(s[i]=='9') f=1;
                        if(f) cout<<"Yes\n";
                        else cout<<"No\n";


                }   
                int main()
                {   ios_base::sync_with_stdio(false);
                    cin.tie(0);cout.tie(0);
                    ll t=1; 
                   //cin>>t;
                     for(ll i=1;i<=t;i++)
                        solve();
                }            

Measured memory_bytes: 3628
import sys
n, m = map(int, input().split())
input = sys.stdin.readline
sys.setrecursionlimit(10**7)


class UnionFind:
    def __init__(self, n):
        self.p = [-1]*n
        self.r = [1]*n

    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def union(self, x, y):
        rx, ry = self.find(x), self.find(y)
        if rx != ry:
            if self.r[rx] > self.r[ry]:
                rx, ry = ry, rx
            if self.r[rx] == self.r[ry]:
                self.r[ry] += 1
            self.p[ry] += self.p[rx]
            self.p[rx] = ry

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

    def count_members(self, x):
        return -self.p[self.find(x)]

    def count_roots(self):
        return sum(p < 0 for p in self.p)


uf = UnionFind(n)
for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    uf.union(a, b)

ans = 0
for i in range(n):
    x = uf.count_members(i)
    if ans < x:
        ans = x
print(ans)


Measured memory_bytes: 14596
//#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 100000000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> T;

struct UnionFind{
    vector<long long int> par; //par[i] : iの親の番号
    vector<long long int> rnk; //root[i] : iの木のランク

    //コンストラクタ
    UnionFind(long long int n): par(n), rnk(n){
        //木の初期化
        for(long long int i = 0; i < n; i++){
            par[i] = i;
            rnk[i] = 1;
        }
    }

    //データxが属する木の根を再帰で取得
    long long int root(long long int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = root(par[x]);
        }
    }

    //xとyが同じ木に属しているかを判定
    bool same(long long int x, long long int y){
        return root(x) == root(y);
    }

    //xとyの木を併合
    void unite(long long int x, long long int y){
        long long int rx = root(x); //xの根
        long long int ry = root(y); //yの根
        if(rx == ry) return; //根が同じならそのまま

        if(rnk[rx] < rnk[ry]){
            par[rx] = ry;
            rnk[ry] += rnk[rx];
        }else{
            par[ry] = rx;
            rnk[rx] += rnk[ry];
        }
    }

    long long int size(long long int x){
        return rnk[root(x)];
    }
};

int main(){
    int n, m;
    cin >> n >> m;

    vector<P> edges;
    int i;
    for(i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges.push_back(make_pair(a, b));
    }

    int count = 0;
    int j;
    for(i = 0; i < m; i++){
        UnionFind uf(n);
        for(j = 0; j < m; j++){
            if(i == j) continue;
            uf.unite(edges[j].first, edges[j].second);
        }
        if(uf.size(0) < n) count++;
    }
    
    cout << count << endl;
}

Measured memory_bytes: 256
str = input()
N = int(str.split()[0])
L = int(str.split()[1])

l = []
for i in range(N) :
	l.append(L + i)

sum = 0
for i in range(N) :
	sum += l[i]
list = []
for i in range(N) :
	s = 0
	for j in range(N) :
		if (i != j) :
			s += l[j]
	list.append(s)
k = 0
min = 0
for i in range(N) :
	if (i == 0) :
		min = abs(sum - list[0])
		k = list[0]
	else :
		if (min > abs(sum - list[i])):
			min = abs(sum - list[i])
			k = list[i]
print(k)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int s[N][N],n,m,a,b;
int main(){
	scanf("%d%d%d%d",&n,&m,&b,&a);
	for(int i=1;i<=a;i++)for(int j=1;j<=b;j++)s[i][j]=1;
	for(int i=a+1;i<=n;i++)for(int j=b+1;j<=m;j++)s[i][j]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			printf("%d",s[i][j]);
		}
		puts("");
	}
}

Measured memory_bytes: 5248
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   S : Integer;
   W : Integer;
begin
   Get (S);
   Get (W);
   if W >= S then
      Put_Line ("unsafe");
   else
      Put_Line ("safe");
   end if;
end Solve;

Measured memory_bytes: 3660
#include <cassert>
#include <set>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

struct UnionFind{
private:
  vector<int> data;
public:
  int N;
  UnionFind(int n) : data(n, -1), N(n){}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    --N;
    if(data[y] < data[x]) swap(x,y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
  int size(int x){ return -data[find(x)]; }
};

struct Card {
  int r, c, a;
  Card(int r, int c, int a) : r(r), c(c), a(a) {}
};

bool comp(const Card &A, const Card &B){
  return A.a < B.a;
}

int main(){
  int N, H, W;
  cin >> N >> H >> W;
  vector<Card> C;
  for(int i = 0; i < N; ++i){
    int r, c, a;
    cin >> r >> c >> a;
    --r,--c;
    C.emplace_back(r,c,a);
  }
  sort(C.rbegin(), C.rend(), comp);
  UnionFind uf(H+W);
  long long ans = 0;
  set<int> used_cc;
  for(int i = 0; i < N; ++i){
    int r = C[i].r, c = C[i].c, a = C[i].a;
    int p = uf.find(r), q = uf.find(c+H);
    if(p == q){
      if(used_cc.count(p))
        continue;
      ans += a;
      used_cc.insert(p);
    }else{
      if(used_cc.count(p) and used_cc.count(q))
        continue;
      ans += a;
      uf.unite(p,q);
      if(used_cc.count(p) or used_cc.count(q))
        used_cc.insert(uf.find(p));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4596
#include <stdio.h>

int main(void)
{
	int n, a, b, pnt_a, pnt_b, i;
	for (;;) {
		scanf("%d", &n);
		if (!n)
			return 0;
		pnt_a = pnt_b = 0;
		for (i = 0; i < n; i++) {
			scanf("%d %d", &a, &b);
			if (a == b) {
				pnt_a += a;
				pnt_b += b;
			} else if (a > b)
				pnt_a += a + b;
			else
				pnt_b += a + b;
		}
		printf("%d %d\n", pnt_a, pnt_b);
	}
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int N;
string S;
int get(int f, int s) {
    if(s < 0) return 1;
    int ret = 0;
    int d[10] = {0};
    for(int i =  f; i < N-s; i++) {
        int c = S[i] - '0';
        if(d[c]) continue;
        d[c]++;
        ret += get(i+1, s-1);
    }
    return ret;
}
int main() {
    cin >> N >> S;
    cout << get(0, 2);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,p[25],check[3],ans;
int main(){
    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>p[i];
    }
    for (int i=1; i<n-1; i++) {
        check[0]=p[i-1];
        check[1]=p[i];
        check[2]=p[i+1];
        sort(check,check+3);
        if (check[1]==p[i]) {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define int long long

const int N = 55, mod = 1e9 + 7;
int n, K, dp[60][N][N], f[N][N];

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

    cin >> n >> K;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            bool a; cin >> a;
            if (a) dp[0][i][j] = 1;
        }
    }

    for (int i = 1; i < 60; ++i) {
        for (int u = 1; u <= n; ++u) {
            for (int v = 1; v <= n; ++ v) {
                for (int k = 1; k <= n; ++k) dp[i][u][v] = (dp[i][u][v] + 1LL * dp[i - 1][u][k] * dp[i - 1][k][v]) % mod;
            }
        }
    }

    for (int u = 1; u <= n; ++u) f[u][u] = 1;
    for (int i = 0; i < 60; ++i) if ( (K >> i) & 1) {
        int tmp[N][N]; memset(tmp, 0, sizeof tmp);
        for (int u = 1; u <= n; ++ u) for (int v = 1; v <= n; ++ v) for (int k = 1; k <= n; ++k) {
            tmp[u][v] = (tmp[u][v] + 1LL * f[u][k] * dp[i][k][v]) % mod;
        }
        for (int u = 1; u <= n; ++ u) for (int v = 1; v <= n; ++ v) {
            f[u][v] = tmp[u][v];
        }
    }

    int ans = 0;
    for (int u = 1; u <= n; ++ u) for (int v = 1; v <= n; ++ v) ans = (ans + f[u][v]) % mod;

    cout << ans;

    return 0;
}


Measured memory_bytes: 1792
N=int(input())
L=list(map(int,input().split()))
counter=0
t=0
for p in range (30):
  t=0
  for i in range(N):
    if L[i]%2==0:
      t+=1
  if t==N:
    for i in range(N):
      L[i]=int(L[i]/2)
    counter+=1
print(counter)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=10000;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
const int MAX=2010;
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
int main(){
	int n;
	while(cin>>n,n){
		char c[110];
		for(int i=0;i<n;i++){
			cin>>c[i];
		}
		int a[26]={};
		bool ff=false;
		char ans1;int ans2;
		for(int i=0;i<n;i++){
			a[c[i]-'A']++;
			for(int j=0;j<26;j++){
				bool f=true;
				for(int k=0;k<26;k++){
					if(j==k)continue;
					if(a[j]<=a[k]+(n-1-i)){
						f=false;
						break;
					}
				}
				if(f){
					ans1='A'+j;
					ans2=i+1;
					ff=true;
					break;
				}
			}
			if(ff){
				break;
			}
		}
		if(ff){
			cout<<ans1<<" "<<ans2<<endl;
		}else{
			cout<<"TIE"<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<int> > a(h, vector<int>(w));
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            cin >> a[y][x];
        }
    }

    vector<vector<int> > dp(w, vector<int>(w, 0));
    for(int y=0; y<h; ++y){
        for(int x1=0; x1<w; ++x1){
            for(int x2=x1; x2<w; ++x2){
                dp[x1][x2] += a[y][x1];
                if(x1 != x2)
                    dp[x1][x2] += a[y][x2];
            }
        }
        for(int x1=0; x1<w; ++x1){
            for(int x2=x1; x2<w; ++x2){
                if(x1 < x2 - 1)
                    dp[x1+1][x2] = max(dp[x1+1][x2], dp[x1][x2] + a[y][x1+1]);
            }
        }
        for(int x1=0; x1<w; ++x1){
            for(int x2=x1; x2<w; ++x2){
                if(x2 < w - 1)
                    dp[x1][x2+1] = max(dp[x1][x2+1], dp[x1][x2] + a[y][x2+1]);
            }
        }
    }

    int ans = 0;
    for(int x1=0; x1<w; ++x1){
        for(int x2=x1; x2<w; ++x2){
            ans = max(ans, dp[x1][x2]);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
N=int(input())
A=[]

for i in range(N):
    a=int(input())
    B=[]
    for __ in range(a):
        x,y=map(int,input().split())
        B.append((x-1,y))
    A.append(B)

ans=0
for bit in range(1<<N):
    flag=1
    honest=[(bit>>i)&1 for i in range(N)]
    for i in range(N):
        if (honest[i] == 0):
            continue
        for x,y in A[i]:
            if honest[x] != y:
                flag=0
    if flag:
        ans=max(ans,sum(honest))
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<iterator>
#include<math.h>
#include<cstring>
using namespace std;
void lets_play()

{
   int n,m;
   cin>>n>>m;

  if(m==n)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
    }

int main()
{
        lets_play();

}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;

#define ul unsigned long int
#define ull unsigned long long
#define li long long int


int main()
{
  ul x,y;
  cin>>x>>y;
  while (x>0||y>0) {
    if (x>y) swap(x,y);
    cout <<x<<" "<< y<<endl;
    cin >> x >> y;
  }

  return 0;
}



Measured memory_bytes: 3004
#include <map>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long n;
    cin >> n;

    unsigned long ans = 0;
    map<string, unsigned long> mp;
    string str;
    for(long i = 0; i < n; i++) {
        cin >> str;
        sort(str.begin(), str.end());
        if(mp[str]) ans += mp[str];
        mp[str]++;
    }

    printf("%lu\n", ans);

    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll int n=0,x=0,y=0,z=0,d=0,i=0;
  cin >> n >> d;
  for(i=0;i<n;i++){
  	cin >> y >> z;
    if(sqrt(y*y+z*z)<=d){x++;}
  }
  cout << x << endl;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define lg long long int
#define loop(i,s,e) for(lg i=s;i<=e;i++)
#define iloop(i,s,e) for(lg i=e;i>=s;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;

lg min(lg a,lg b)
{return a<b?a:b;}
lg max(lg a,lg b)
{return a>b?a:b;}
lg lcm(lg a ,lg b)
{
    return (a*b)/__gcd(a,b);
}

lg sol(vector<vector<lg>>& gr, vector<bool>& visited, lg in)
{
    visited[in]=true;
    vector<lg>nodes(1,in);
    lg ans=1;
    while(!nodes.empty())
    {
        vector<lg>temp;
        lg l = nodes.size();
        for(lg i=0;i<l;i++)
        {
            lg now = nodes[i];
            lg k = gr[now].size();
            for(lg j=0;j<k;j++)
            {
                lg at = gr[now][j];
                if(!visited[at])
                {
                    ans++;
                    visited[at]=true;
                    temp.pb(at);
                }
            }
        }
        nodes=temp;
    }
    return ans;
}

int main()
{
    lg n,m;
    cin>>n>>m;
    vector<vector<lg>>gr(n,vector<lg>(0,0));

    for(lg i=0;i<m;i++)
    {
        lg u,v;
        cin>>u>>v;
        u--;
        v--;
        gr[u].pb(v);
        gr[v].pb(u);
    }
    vector<bool>visited(n,false);
    lg ans=1;
    for(lg i=0;i<n;i++)
    {
        if(!visited[i])
        {
            ans=max(ans,sol(gr,visited,i));
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 17516
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  int scan; // scanf result
  double answer; // to output 
  int n; // to input 

  scan = scanf("%d", &n);

  answer = n * 2 * 3.141592;

  printf("%lf", answer);
  return (0);
}


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

int main() {
    long long L, R;
    cin >> L >> R;
    long long ans = 2019;
    long long i,j;
    
    if(R/2019 > L/2019){
        ans= 0;
    }else{
        for(i=L;i<R;i++){
            for(j=L+1;j<=R;j++){
                ans = min(ans,(i*j)%2019);
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define INF  (int)1e9
#define LINF (long long)1e18

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

using Edge   = vector<vector<pair<int, int>>>; // src   -> dst, weight
using Vertex = vector<pair<int, bool>>;        // index -> cost, visited

int graph_bfs(int         start,
              const int&  goal,
              const Edge& edge,
              Vertex&     vertex) {
    queue<int> queue;
    queue.push(start);

    while(!queue.empty()) {
        auto src = queue.front();
        queue.pop();

        REP(i, edge[src].size()) {
            auto dst = edge[src][i].first;

            if(vertex[src].first + 1 < vertex[dst].first) {
                vertex[dst].first = vertex[src].first + 1;
                queue.push(dst);
            }
        }
    }

    return vertex[goal].first;
}

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

    int N, M;
    std::cin >> N >> M;

    Edge   edge(N * 3);
    Vertex vertex(N * 3, make_pair(INF, false));

    REP(i, M) {
        int l, r;
        std::cin >> l >> r;
        edge[(l - 1) * 3 + 0].emplace_back((r - 1) * 3 + 1, 0);
        edge[(l - 1) * 3 + 1].emplace_back((r - 1) * 3 + 2, 0);
        edge[(l - 1) * 3 + 2].emplace_back((r - 1) * 3 + 0, 0);
    }

    int S, T;
    std::cin >> S >> T;

    auto start = (S - 1) * 3;
    auto goal  = (T - 1) * 3;

    vertex[start].first = 0;
    auto min_move_num = graph_bfs(start, goal, edge, vertex);
    if(min_move_num == INF) {
        std::cout << -1 << std::endl;
    }
    else {
        std::cout << min_move_num / 3 << std::endl;
    }

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") {
    cout << "Cloudy" << endl;
    return 0;
  }
  if (s == "Cloudy") {
    cout << "Rainy" << endl;
    return 0;
  }
  if (s == "Rainy") {
    cout << "Sunny" << endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int top=1,yoko[4]={2,3,5,4},soko=6,total;
	int n,i,temp;
	char str[10];
	while(1){
		total=1;
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",str);
			switch(str[0]){
				case 'N':
					temp=top;
					top=yoko[0];
					yoko[0]=soko;
					soko=yoko[2];
					yoko[2]=temp;
					break;
				case 'E':
					temp=top;
					top=yoko[3];
					yoko[3]=soko;
					soko=yoko[1];
					yoko[1]=temp;
					break;
				case 'S':
					temp=top;
					top=yoko[2];
					yoko[2]=soko;
					soko=yoko[0];
					yoko[0]=temp;
					break;
				case 'W':
					temp=top;
					top=yoko[1];
					yoko[1]=soko;
					soko=yoko[3];
					yoko[3]=temp;
					break;
				case 'R':
					temp=yoko[0];
					yoko[0]=yoko[1];
					yoko[1]=yoko[2];
					yoko[2]=yoko[3];
					yoko[3]=temp;
					break;
				case 'L':
					temp=yoko[0];
					yoko[0]=yoko[3];
					yoko[3]=yoko[2];
					yoko[2]=yoko[1];
					yoko[1]=temp;
					break;
				default :
					break;
			}
			total+=top;
		}
		printf("%d\n",total);
		top=1;
		soko=6;
		yoko[0]=2;
		yoko[1]=3;
		yoko[2]=5;
		yoko[3]=4;
	}
	return 0;
}

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

using namespace std;

const long long INF = 1'000'000'000'000'000'000ll, MOD = 1'000'000'007;

vector<vector<int>> graph, pre, G, ST, TS;
vector<int> U, V, W, fromS, fromT;
vector<long long> dist;
vector<bool> vis;
set<pair<int, int>> used;

int other(int ed, int u) {
	return U[ed] == u ? V[ed] : U[ed];
}

void dijkstra(int s, int t) {
	int n = (int)graph.size();
	dist.assign(n, INF);
	dist[s] = 0;
	priority_queue<pair<long long, int>> pq;
	pq.push({0, s});
	while (!pq.empty()) {
		long long d = -pq.top().first;
		int u = pq.top().second;
		pq.pop();
		if (d != dist[u]) {
			continue;
		}
		for (int ed: graph[u]) {
			int v = other(ed, u), w = W[ed];
			if (dist[u] + w < dist[v]) {
				dist[v] = dist[u] + w;
				pre[v] = {u};
				pq.push({-dist[v], v});
			} else if (dist[u] + w == dist[v]) {
				pre[v].push_back(u);
			}
		}
	}
}

void make_graph(int u) {
	if (vis[u]) {
		return;
	}
	vis[u] = true;
	for (int v: pre[u]) {
		G[u].push_back(v);
		G[v].push_back(u);
		ST[v].push_back(u);
		TS[u].push_back(v);
		make_graph(v);
		used.insert({u, v});
		used.insert({v, u});
	}
}

int calc(int u, vector<int> &vec, const vector<vector<int>> &adj, int base) {
	int &ans = vec[u];
	if (ans != -1) {
		return ans;
	}
	if (u == base) {
		return ans = 1;
	}
	ans = 0;
	for (int v: adj[u]) {
		ans = (ans + calc(v, vec, adj, base)) % MOD;
	}
	return ans;
}

int sq(int x) {
	return (long long)x * x % MOD;
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	int s, t;
	scanf("%d %d", &s, &t);
	s--, t--;
	U.resize(m);
	V.resize(m);
	W.resize(m);
	graph.assign(n, {});
	for (int i = 0; i < m; i++) {
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		u--, v--;
		graph[u].push_back(i);
		graph[v].push_back(i);
		U[i] = u, V[i] = v, W[i] = w;
	}
	pre.assign(n, {});
	dijkstra(s, t);
	G.assign(n, {});
	ST = TS = G;
	vis.assign(n, false);
	make_graph(t);
	fromS.assign(n, -1);
	fromT.assign(n, -1);
	int st = calc(t, fromS, TS, s), ts = calc(s, fromT, ST, t);
	int ans = (long long)st * ts % MOD;
	for (int i = 0; i < n; i++) {
		if (2 * dist[i] == dist[t]) {
			ans = (ans + MOD - (long long)sq(fromS[i]) * sq(fromT[i]) % MOD) % MOD;
		}
	}
	for (int i = 0; i < m; i++) {
		if (dist[U[i]] > dist[V[i]]) {
			swap(U[i], V[i]);
		}
		if (!used.count({U[i], V[i]})) {
			continue;
		}
		long long delta = abs(dist[t] - dist[V[i]] - dist[U[i]]);
		if (delta < W[i]) {
			//printf("%d %d %d %d %d %d\n", U[i], V[i], fromS[U[i]], fromT[V[i]], sq(fromS[U[i]]), sq(fromT[V[i]]));
			ans = (ans + MOD - (long long)sq(fromS[U[i]]) * sq(fromT[V[i]]) % MOD) % MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 49328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vector<vector<P>> g(n);
  rep(i, n - 1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(P(b, i));
    g[b].push_back(P(a, i));
  }
  vl ans(n - 1, 0);
  vb seen(n, false);
  queue<P> q;
  q.push(P(0, 0));
  seen[0] = true;
  while(!q.empty()) {
    int i = q.front().first;
    int parent = q.front().second;
    q.pop();
    ll k = 1;
    for(auto v : g[i]) {
      if(seen[v.first]) continue;
      if(k == parent) k++;
      ans[v.second] = k;
      q.push(P(v.first, k));
      seen[v.first] = true;
      k++;
    }
  }
  cout << *max_element(all(ans)) << '\n';
  rep(i, n - 1) cout << ans[i] << '\n';
}

Measured memory_bytes: 8960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                if (input.All(n => n == 0)) break;

                int a1 = input[0], m1 = input[1];
                int a2 = input[2], m2 = input[3];
                int a3 = input[4], m3 = input[5];

                long cntX = ReturnCount(a1, m1);
                long cntY = ReturnCount(a2, m2);
                long cntZ = ReturnCount(a3, m3);

                long lcm;
                lcm = cntX * cntY / GCD(cntX, cntY);
                lcm = cntZ * lcm / GCD(cntZ, lcm);

                sb.AppendLine(lcm.ToString());
            }
            Console.Write(sb);
        }

        static int ReturnCount(int a, int m)
        {
            int pos = 1, cnt = 0;

            do
            {
                pos = (a * pos) % m;
                cnt++;

            } while (pos != 1);

            return cnt;
        }

        static long GCD(long n1, long n2)
        {
            long x = Math.Max(n1, n2);
            long y = Math.Min(n1, n2);
            long r = x % y;

            while (r != 0)
            {
                x = y;
                y = r;
                r = x % y;
            }
            return y;
        }
    }
}

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

#define L 300

double dp[L + 5][L + 5][L + 5];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, C[3] = { 0, 0, 0 };
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        C[a - 1]++;
    }
    for (int k = 0; k <= L; k++)
    {
        for (int j = 0; j <= L; j++)
        {
            for (int i = 0; i <= L; i++)
            {
                double h = 1;
                if (i) h += dp[i - 1][j][k] * i / N;
                if (j) h += dp[i + 1][j - 1][k] * j / N;
                if (k) h += dp[i][j + 1][k - 1] * k / N;
                int ce = N - i - j - k;
                if (ce < N) dp[i][j][k] = 1.0 * h * N / (N - ce);
                else dp[0][0][0] = 0;
            }
        }
    }
    cout << setprecision(16) << dp[C[0]][C[1]][C[2]] << '\n';
    return(0);
}

Measured memory_bytes: 219392
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(void) {
    string s;
    cin >> s;
    
    cout << s.rfind("Z")-s.find("A")+1;
    
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 1e5+10;
int dp[maxn][2],a[maxn],n;
int solve(int i,int s){
	if( i == n ) return s ? -1e17 : 0;
	int &ans = dp[i][s];
	if( ans != -1 )return ans;
	return ans = max( a[i] * ( s ? -1 : +1 )  + solve(i+1,0) , a[i] * ( s ? +1 : -1 ) + solve(i+1,1) );
}
int32_t main(){
	IOS
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cout<<solve(0,0);

	
}
 
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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

int main(){
	int n;
  	cin >> n;
  	char a;
  	for(int i = 0; i<n;i++) {
		cin >> a; 
      	if(a == 'Y') {
          	cout << "Four\n";
          	return 0;
        }
    }  
	cout << "Three\n";
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {
    
    string S,T;
    cin >> S >> T;
    cout << T+S << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define ri(a) scanf("%d", &a)
#define rii(a,b) scanf("%d %d", &a, &b)
#define riii(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define rl(a) scanf("%lld", &a)
#define rll(a,b) scanf("%lld %lld", &a, &b)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define ROF(i,n,m) for(int i=n; i>m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second

const int INF = 0x3f3f3f3f;
const ll LLINF = 1e18;
const int maxN = 1e5; // CAMBIAR ESTE

// GJNM

int main() {
	ll x, k, d;
	rll(x, k), rl(d);
	x = abs(x);
	if ( x / d >= k ) {
		printf("%lld\n", x - d * k);
		return 0;
	}
	ll aux_k = k;
	k -= x / d;
	x = x - d * (x / d);
	k = k & 1;
	x = x - k * d;
	printf("%lld\n", abs(x));

	return 0;
}

Measured memory_bytes: 3784
N = int(input())
A_list = input().split()
A_list = [int(x) for x in A_list]

sum = 0
tmp_mae = A_list[0]
for i in range(1,N):
    tmp_ushiro = A_list[i]
    if(tmp_mae > tmp_ushiro):
        sabun = tmp_mae - tmp_ushiro
        sum += sabun
    else:
        sabun = 0
    tmp_mae = tmp_ushiro + sabun

print(sum)

Measured memory_bytes: 32244
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n';
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    int ans = 0;
    for(int i=1; i<=n; i++) if(to_string(i).length()%2)ans++;
    out(ans);

    return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "2 4 6" ].parse.expand.solve == "YES" );
	assert( [ "2 5 6" ].parse.expand.solve == "NO" );
	assert( [ "3 2 1" ].parse.expand.solve == "YES" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split.to!( long[] );
	return tuple( abc[ 0 ], abc[ 1 ], abc[ 2 ] );
}

auto solve( long a, long b, long c )
{
	return ( b - a == c - b ) ? "YES" : "NO";
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

	int a,b,sum,cnt=0;

	while(scanf("%d %d",&a,&b)!=EOF){
		
		sum=a+b;

		cnt=0;

		while(sum>0){
			sum=sum/10;
			cnt=cnt+1;
		}

		printf("%d\n",cnt);

	}

	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
int x[100100], y[100100], z[100100];

class UnionFind {
private:
    static const int MAX = 100100;
    int par[MAX];
    int r[MAX];
public:
    UnionFind(int n = MAX) {
        for (int i = 0; i < n; i++) {
            par[i] = i;
            r[i] = 0;
        }
    }

    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (r[x] < r[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (r[x] == r[y]) r[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int solve() {
    UnionFind uf;
    for (int i = 0; i < m; i++) {
        uf.unite(x[i], y[i]);
    }
    set<int> s;
    for (int i = 0; i < n; i++) {
        s.insert(uf.find(i));
    }
    return (int)s.size();
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i] >> z[i];
        x[i]--;
        y[i]--;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 6912
#include <cstdio>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main(void){
  int n;
  long long res=0;
  cin >> n;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    res += a;
  }
  cout << res/n << endl;
}

Measured memory_bytes: 1156
# -*- coding: utf-8 -*-
import sys

def main():
	S = input()
	S = list(S)
	
	if S[0] != "A":
		print("WA")
		sys.exit()
		
	tmp = S[2:-1]
	p = -1
	flg = False
	for i, val in enumerate(tmp):
		if val == "C":
			flg = True
			p = i + 2
	if flg == False:
		print("WA")
		sys.exit()
		
	for i, val in enumerate(S):
		if i == 0 or i == p:
			continue
		if val.islower() == False:
			print("WA")
			sys.exit()
	
	print("AC")
		
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
long long gcd(long long a,long long b){
	long long c=a%b;
	if(c) return gcd(b,c);
	else return b;
}
int main(){
	long long x;
	cin>>x;
	x=360/gcd(360,x);
	cout<<x<<endl;
}

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

using namespace std;


#define MAXN 200001
int n, m, a[MAXN], h[MAXN], r[MAXN], ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    h[a[i]]++;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = max(i-h[i]+1, 1); j <= i; ++j) {
      if (!r[j]) ans++;
      r[j]++;
    }
  }
  for (int i = 0; i < m; ++i) {
    int ii, v;
    cin >> ii >> v;
    int ri = a[ii]-h[a[ii]]+1;
    if (ri>0) {
      r[ri]--;
      if (!r[ri]) ans--;
    }
    h[a[ii]]--;

    a[ii] = v;

    h[a[ii]]++;
    ri = a[ii]-h[a[ii]]+1;
    if (ri>0) {
      if (!r[ri]) ans++;
      r[ri]++;
    }
    cout << n-ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D;
scanf("%d%d%d%d",&A,&B,&C,&D);
if(A*B>C*D)
{
    printf("%d\n",(A*B));
   // printf("the first rectangle has an area of %d * %d = %d,and the second rectangle has an area of %d * %d = %d .\n thus,the output should be %d,the larger area.",A,B,(A*B),C,D,(C*D),(A*B));
}
else
if(A*B<C*D){
printf("%d\n",(C*D));
//printf("the first rectangle has an area of %d * %d = %d,and the second rectangle has an area of %d * %d = %d .\n thus,the output should be %d,the larger area.",A,B,(A*B),C,D,(C*D),(C*D));
}
else
    printf("%d\n",(A*B));
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k,x,y,cx,cy,costo=0;
	cin>>n;
	cin>>k;
	cin>>x;
	cin>>y;
	if(k>n){
		cx=n;
		cy=0;
	}
	else{
		cx=k;
		cy=n-k;
	}
	
	for(int i=0;i<cx;i++){
		costo+=x;
	}
	for(int i=0;i<cy;i++){
		costo+=y;
	}
	cout<<costo;
	
	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef long double ld;
const double E = 1e-7;
const ll INF = 1e17;
#define forn(i, s, f) for (int i = s; i < f; ++i)
#define ft first                                                 
#define sec second
#define fora(i, n) for (auto i : n)
#define sz(a) (int)(a).size()
#define sort_(a) sort(a.begin(), a.end())
#define pb push_back
#define mp make_pair
#define rsort_(a) sort(a.begin(), a.end()); reverse(a.begin(), a.end())
#define fast_ cin.tie(0), ios_base::sync_with_stdio(false)
// ____________________________________________________________
#define cina(a) forn(i,0,sz(a)) cin >> a[i]
#define cinpr(a) cin >> a.ft >> a.sec 
//--------------------------------------------------------------

const int MAXN = 3 * 1e5;


int main() {
    ll n, k; cin >> n >> k;  
    if (n == 0) {
        cout << 0 << '\n';
        return 0;
    }
    cout << min(n % k, k - n % k) << '\n';
    /*ll ans = __gcd(n,k);
    cout << "gcd: " <<ans << '\n';
    
    if ((k == ans) || (n == ans)) {
        cout << 0 << '\n';
        return 0;
    }
    cout << ans << '\n';
    */return 0;
}

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


void hind(int in[], int out[], int length) {
  int temp[length];
  fill(&temp[0], &temp[length], 0);
  for(int i = 0; i < length; i++) {
    for(int j = 0; j < length; j++) {
      if(in[j] == in[i]) {
	temp[j]++;
      }
    }
  }
  for(int i = 0; i < length; i++) {
    out[i] = temp[i];
  }
}

bool isEqual(int a[], int b[], int length) {
  for(int i = 0; i < length; i++) {
    if(a[i] != b[i]) return false;
  }
  return true;
}

void dainyu(int a[], int b[], int length) {
  for(int i = 0; i < length; i++) {
    a[i] = b[i];
  }
}

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    int data[n];
    for(int i = 0; i < n; i++) {
      cin >> data[i];
    }

    int cnt;
    int data2[n];
    dainyu(data2, data, n);
    for(cnt = 0; !(cnt >= 1 && isEqual(data, data2, n)); cnt++) {
      dainyu(data, data2, n);
      hind(data, data2, n);
    }
    cout << cnt-1 << endl;
    for(int i = 0; i < n; i++) {
      if(i != 0) cout << ' ';
      cout << data2[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	long N;
	cin >> N;

	long sum = 0;
	long max = 0;
	long p = 0;
	for (long i = 0; i < N; i++) {
		cin >> p;
		sum += p;
		if (max < p) {
			max = p;
		}
	}

	sum -= max / 2;

	cout << sum << endl;

	return 0;
}



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp {
    char name[100];
    int t;
}P;

P Q[LEN];
int head,tail,n;
void en(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P de(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) {return a<b ? a:b; }

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d%d",&n, &q);
    
    for(i = 1;i <= n; i++){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    head = 1; tail = n + 1;
while(head != tail){
    u = de();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if( u.t >0) en(u);
else{
    printf("%s %d\n",u.name, elaps);
  }   
}

    return 0;
    
    
}



Measured memory_bytes: 11860
#include<bits/stdc++.h>
using namespace std;
#define N 100000
#define mod 1000000007
#define pb push_back
vector<int> nei[N+1];
int dpy[N+1],dpn[N+1];
int dp(int x=1,int fa=0){
	dpy[x]=dpn[x]=1;
	for(int i=0,to;i<nei[x].size();i++)if((to=nei[x][i])!=fa){
		dp(to,x);
		dpy[x]=1ll*dpy[x]*dpn[to]%mod;
		dpn[x]=1ll*dpn[x]*(dpy[to]+dpn[to])%mod;
	}
	return (dpy[x]+dpn[x])%mod;
}
int main(){
	int n;scanf("%d",&n);
	while(--n){
		int x,y;scanf("%d%d",&x,&y);
		nei[x].pb(y);nei[y].pb(x);
	}
	printf("%d\n",dp());
	return 0;
}
/*1
3
1 2
2 3
*/
/*2
4
1 2
1 3
1 4
*/
/*3
1
*/
/*4
10
8 5
10 8
6 5
1 5
4 8
2 10
3 6
9 2
1 7
*/

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

int main () {
    int a, b;
    cin >> a >> b;
    if (a%2 == 0) {
        cout << "No" << endl;
    } else if (b%2 == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>

using namespace std;


long long sk(long long n, long long m) {
	long long N = max(n, m);
	long long M = min(n, m);

	if (M == 0) return N;

	return sk(M, N%M);
}


int N;
vector< pair<int, int> > ba;

int main() {

	cin >> N;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;

		ba.push_back(make_pair(b, a));
	}

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

	int time = 0;
	for (int i = 0; i < N; i++) {
		time += ba[i].second;

		if (time > ba[i].first) {
			cout << "No" << endl;

			return 0;
		}
	}

	cout << "Yes" << endl;


	return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

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

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


int main()
{
    int k;
    cin>>k;
    string s;
    cin>>s;
    int n=s.size();

    string str2="...";

    if(n<=k)
        cout<<s;
    else
    {
         for(int i=0;i<k;i++)
            cout<<s[i];
         cout<<"...";
    }


    return 0;
}


Measured memory_bytes: 3628
n = int(input())
P = list(map(int,input().split()))

count = 0
for i in range(n-1):
    if i+1 == P[i]:
        P[i],P[i+1] = P[i+1],P[i]
        count += 1
        
if P[n-1] == n:
    count += 1
    
print(count)

Measured memory_bytes: 53036
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

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

signed main(){
    string s, t;
    int q;
    cin >> s >> t >> q;

    vector<int> ss(s.length()+1);
    vector<int> tt(t.length()+1);
    rep(i, (int)s.length()){
        ss[i+1] = ss[i] + (s[i] == 'A' ? 1 : 2);
    }
    rep(i, (int)t.length()){
        tt[i+1] = tt[i] + (t[i] == 'A' ? 1 : 2);
    }

    rep(i, q){
        int a, b, c, d;
        cin >> a >> b >> c >> d;

        int x = ss[b] - ss[a-1];
        int y = tt[d] - tt[c-1];

        if(x % 3 == y % 3){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int a[105];

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

	int m = 0;
	REP(i, N)
	{
		cin >> a[i];
		m += a[i];
	}

	int ans = 0;
	REP(i, N)
	{
		if (abs(m - a[ans] * N) > abs(m - a[i] * N))
		{
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<iomanip>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
ll num[200005]={0};
ll aray[200005]={0};
int main(){
  ll n;
  cin>>n;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    aray[i]=a;
    num[a]++;
  }
  ll ans=0;
  for(int i=0;i<200005;i++){
    if(num[i]>0) ans+=num[i]*(num[i]-1)/2;
  }
  for(int i=0;i<n;i++){
    ll a=aray[i];
    if(num[a]<2) {
      cout<<ans<<endl;
      continue;
    }
    else{
      ll kans=ans;
      kans-=num[a]*(num[a]-1)/2;
      kans+=(num[a]-1)*(num[a]-2)/2;
      cout<<kans<<endl;
    }
  }
}


Measured memory_bytes: 4736
#include<iostream>
#include<cstring>

using namespace std;

int main(){
	string moji[3];
	for(int i=0;i<3;i++){
		cin >> moji[i];
	}

	if(moji[0][moji[0].length()-1] == moji[1][0]){
		if(moji[1][moji[1].length()-1] == moji[2][0]){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}else{
		cout << "NO" << endl;
	}

	return 0;
}	
		


Measured memory_bytes: 256