akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int N; cin >> N;
    vector <int> A(N+2);
    A[0]=0;
    A[N+1]=0;
    for (int i=1; i<=N; i++) cin >> A[i];
    
    ll sum=0;
    rep(i,N+1) sum+=abs(A[i]-A[i+1]);
    
    for (int i=1; i<=N; i++){
        cout << sum -( abs(A[i-1]-A[i]) + abs(A[i]-A[i+1]) )+ abs(A[i-1]-A[i+1]) << endl;
    }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  long N;
  cin >> N;
  //unordered_map<string, int> mp;
  vector<int> A(N);
  rep(i, N)
  {
    A[i] = 0;
  }
  for (int i = 1; i < N; i++)
  {
    int a;
    cin >> a;
    A[a-1] += 1;
  }
  //sort(mp.rbegin(), mp.rend());
  rep(i,N)
  {
    cout << A[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3988
N = int(input())
A = list(map(int,input().split()))
B = [0] * (N+1)

# 累積和を使う
for i in range(1,N+1):
    B[i] = A[i-1]+B[i-1]
# 累積和の配列完成
# print(B) 

ans = 0
MOD = 10**9+7
for i in range(N):
    ans += A[i] * (B[N] - B[i+1])
    ans %= MOD
print(ans)

Measured memory_bytes: 31536
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

const int N = 1e5+7;
int n,c,w[N],v[N],dp[N],ans;

int32_t main()
{
	fast;
	cin>>n>>c;
	for(int i=1;i<=n;i++)
		cin>>w[i]>>v[i];
	for(int i=1;i<=n;i++)
		for(int j=c;j>=1;j--)
			if(j>=w[i])
				dp[j] = max(dp[j],v[i]+dp[j-w[i]]), ans = max(ans,dp[j]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    char[][] map;
    char[][] round; // "":テヲツ慊ェ, B:テゥツサツ? W:テァツ卍ス, x:テゥツサツ津」ツ?ァテ」ツつづァツ卍ステ」ツ?ァテ」ツつづ」ツ?ェテ」ツ??n:テヲツ敖ュ
    int w, h;
    int B, W;


    void run(){
	while(sc.hasNext()){
	    w = sc.nextInt();
	    h = sc.nextInt();
	    if(w==0 && h==0) break;
	    
	    map = new char[h][w];
	    round = new char[h][w];
	    
	    for(int i=0; i<h; i++){
		String s = sc.next();
		Arrays.fill(round[i], 'o');
		for(int k=0; k<w; k++)
		    map[i] = s.toCharArray();
	    }
	    
	    for(int i=0; i<h; i++)
		for(int k=0; k<w; k++){
		    solve(i, k, map[i][k]);
		}
	    
	    count();
	    //show();
	    System.out.println(B+" "+W);
	}
    }

    void solve(int a, int b, char c){
	if(a<0 || a>=h || b<0 || b>=w) return;
	if(round[a][b]=='x' || round[a][b]=='n' || c=='.') return;
	
	if(map[a][b]=='B' || map[a][b]=='W'){
	    c = map[a][b];
	    round[a][b] = 'n';
	    solve(a+1, b, c);
	    solve(a-1, b, c);
	    solve(a, b+1, c);
	    solve(a, b-1, c);
	}
	else if(round[a][b]=='o'){
	    round[a][b] = c;
	    solve(a+1, b, c);
	    solve(a-1, b, c);
	    solve(a, b+1, c);
	    solve(a, b-1, c);
	}
	else if( (round[a][b]=='B' && c=='W') || (round[a][b]=='W' && c=='B')){
	    round[a][b] = 'x';
	    solve(a+1, b, c);
	    solve(a-1, b, c);
	    solve(a, b+1, c);
	    solve(a, b-1, c);
	}
    }

    void count(){
	B = 0;
	W = 0;
	for(int i=0; i<h; i++)
	    for(int k=0; k<w; k++)
		if(round[i][k]=='B') B++;
		else if(round[i][k]=='W') W++;
    }

    void show(){
	for(int i=0; i<h; i++){
	    for(int k=0; k<w; k++)
		System.out.print(round[i][k]+" ");
	    System.out.println();
	}
	System.out.println("-------------------");
    }
}

Measured memory_bytes: 46288
#include<stdio.h>
int c=0, n,i,j,l,m,r,q,a[1000000],temp[1000000];
void input(){
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
}
void pri(){
  for(i=0;i<n-1;i++)printf("%d ",a[i]);
  printf("%d\n%d\n",a[n-1],c);
}
void M(int x[],int left,int right){
  int mid,i,j,k;
  if(left>=right)return;
  mid=(left+right)/2;
  M(x, left, mid);
  M(x, mid + 1, right);
  for (i = left; i <= mid; i++) temp[i] = x[i];
  for (i = mid + 1, j = right; i <= right; i++, j--) temp[i] = x[j];
  i = left;
  j = right;
  for (k = left; k <= right; k++){
    if (temp[i] <= temp[j]){
        x[k] = temp[i++];
        c++;
    }else{
        x[k] = temp[j--];
        c++;
    }
  }
}
int main(){
  input();
  M(a,0,n-1);
  pri();
}


Measured memory_bytes: 5676
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string a[n];
	map<string,int> mp;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	int count1=mp["AC"];
	int count2=mp["WA"];
	int count3=mp["TLE"];
	int count4=mp["RE"];
	cout<<"AC x "<<count1<<endl;
	cout<<"WA x "<<count2<<endl;
    cout<<"TLE x "<<count3<<endl;
    cout<<"RE x "<<count4<<endl;

}

Measured memory_bytes: 6740
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0

signed main() {
	int n, x, ans = 0;
	cin >> n >> x;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 1; i < n; i++) {
		if (a[i] + a[i - 1] > x) {
			ans += a[i] + a[i - 1] - x;
			a[i] -= a[i] + a[i - 1] - x;
			if (a[i] < 0) a[i] = 0;
		}
	}
	cout << ans << endl;

	END;
}


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

int main(){
  
  int n,a,b;
  cin >>n;
 
  int q[10][10]={0};
 for(int i=1;i<=n; i++){
   a=i%10;
   b=i;
  while(b/10){
  	b/=10;
  }
 	q[a][b]++;
 }
 int sum=0;
  for(int i=1; i<10; i++){
  	for(int j=1; j<10; j++){
    	sum+=q[i][j]*q[j][i];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
class Node:
    def __init__(self,p,l,r):
        self.parent = p
        self.left = l
        self.right = r

def set_height(u,H):
    h1 = 0
    h2 = 0
    if tree[u].left != -1:
        h1 = set_height(tree[u].left,H) + 1
    if tree[u].right != -1:
        h2 = set_height(tree[u].right,H) + 1
    H[u] = max(h1,h2)
    return H[u]

def set_sibling(u,S):
    if tree[u].parent != -1:
        v = tree[tree[u].parent].left
        if v == u:
            v = tree[tree[u].parent].right
        S[u] = v
    else:
        S[u] = -1
    if tree[u].left != -1:
        set_sibling(tree[u].left, S)
    if tree[u].right != -1:
        set_sibling(tree[u].right, S)

def set_degree(u,D):
    d = 0
    if tree[u].left != -1:
        d += 1
    if tree[u].right != -1:
        d += 1
    D[u] = d
    if tree[u].left != -1:
        set_degree(tree[u].left, D)
    if tree[u].right != -1:
        set_degree(tree[u].right, D)

def set_depth(u,P,d):
    P[u] = d
    if tree[u].left != -1:
        set_depth(tree[u].left, P, d+1)
    if tree[u].right != -1:
        set_depth(tree[u].right, P, d+1)



n = int(raw_input().strip())
tree = {}
for i in range(n):
    nid, left, right = map(int, raw_input().strip().split(' '))
    if not nid in tree: tree[nid] = Node(-1,left,right)
    else:
        tree[nid].left = left
        tree[nid].right = right
    if not left == -1:
        if not left in tree: tree[left] = Node(nid,-1,-1)
        else: tree[left].parent = nid
    if not right == -1:
        if not right in tree: tree[right] = Node(nid,-1,-1)
        else: tree[right].parent = nid

r = -1
for i in range(len(tree)):
    if tree[i].parent == -1:
        r = i
        break

H = {}
set_height(r,H)
S = {}
set_sibling(r,S)
D = {}
set_degree(r,D)
P = {}
set_depth(r,P,0)

for i in range(len(tree)):
    if tree[i].parent == -1:
        t = "root"
    elif tree[i].left == -1 and tree[i].right == -1:
        t = "leaf"
    else:
        t = "internal node"
    print "node %s: parent = %s, sibling = %s, degree = %s, depth = %s, height = %s, %s" % (i, tree[i].parent, S[i], D[i], P[i], H[i], t)

Measured memory_bytes: 6568
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int N = in.i();
        int[] A = in.ii(N);
        Arrays.sort(A);
        long ans = A[A.length - 1];
        final int M = (A.length + 1) / 2;
        for (int i = A.length - 2; i >= M; i--) {
            ans += A[i] * 2;
        }
        if ((A.length & 1) == 1) {
            ans += A[M - 1];
        }
        out.println(ans);
    }

    static class MyReader extends BufferedReader {
        char[] cbuf = new char[1024];
        int head = 0;
        int tail = 0;

        MyReader() {
            super(new InputStreamReader(System.in));
        }

        char next() {
            if (head == tail) {
                try {
                    tail = read(cbuf, 0, cbuf.length);
                } catch (IOException e) {}
                head = 0;
            }
            return cbuf[head++];
        }

        void back() {
            head--;
        }

        boolean minus() {
            boolean minus;
            while (true) {
                char c = next();
                if (c != ' ' && c != '\n' && c != '\r') {
                    if (!(minus = c == '-')) back();
                    return minus;
                }
            }
        }

        void skip() {
            while (true) {
                char c = next();
                if (c != ' ' && c != '\n' && c != '\r') {
                    back();
                    break;
                }
            }
        }

        char[] s(final int N) {
            skip();
            char[] s = new char[N];
            for (int i = 0; i < s.length; i++) {
                s[i] = next();
            }
            return s;
        }

        int i() {
            boolean minus = minus();
            int n = 0;
            while (true) {
                int k = next() - '0';
                if (k < 0 || 9 < k) break;
                n = 10 * n + k;
            }
            return minus ? -n : n;
        }

        int[] ii(final int N) {
            int[] a = new int[N];
            for (int j = 0; j < a.length; j++) a[j] = i();
            return a;
        }

        long l() {
            boolean minus = minus();
            long n = 0;
            while (true) {
                int k = next() - '0';
                if (k < 0 || 9 < k) break;
                n = 10 * n + k;
            }
            return minus ? -n : n;
        }
    }
}


Measured memory_bytes: 38160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

int N, A[310][310], B[310][310];

void solve(){
	scanf("%d", &N);
	for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) scanf("%d", A[i]+j), B[i][j] = A[i][j];
	int ok[310][310] = {};
	for(int k=1;k<=N;k++) for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) {
		if(B[i][j] > B[i][k] + B[k][j]) {
			puts("-1");
			return;
		}
		else if(i != k && k != j && B[i][j] == B[i][k] + B[k][j]) ok[i][j] = 1;
	}
	ll ans = 0;
	for(int i=1;i<=N;i++) for(int j=i;j<=N;j++) ans += !ok[i][j] * A[i][j];
	printf("%lld\n", ans);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		// printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String N = String.valueOf(sc.nextLong() + 1);
		int l1 = (N.length() - 1) * 9;
		int l2 = Integer.parseInt(N.substring(0, 1)) - 1;
		System.out.println(l1 + l2);
	}
}


Measured memory_bytes: 25300
#include<iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string.h>
using namespace std;
long long a[100005];
bool b[100005]={0};
int n,m;
long long sum=0;
int main()
{
    scanf("%d%d",&n,&m);
   a[0]=1, a[1]=1,a[2]=2;
    for(int i=1;i<=m;i++)
    {
        int p;
       scanf("%d",&p);
        b[p]=1;
        a[p]=0;
    }

    for(int i=2;i<=n;i++)
    {
            if(b[i])
            a[i]=0;
             else  a[i]=(a[i-1]+a[i-2])%1000000007;
    }
    printf("%lld\n",a[n]);
}


Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  int N;cin>>N;
  string S;cin>>S;
  vint cnt(N+1,0);
  repeat(i,N){
    cnt[i+1] = cnt[i]+(S[i]=='#');
  }
  int ans = INF;
  repeat(i,N+1){
    ans = min(ans,N-i-cnt[N]+2*cnt[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1412
#include <stdio.h>
#define N_MAX 100

char suspicious[N_MAX];
char knows[N_MAX + 1][N_MAX + 1];

int main(void)
{
    int n, m, k, i, j, the_suspicious;

    while(scanf("%d", &n), n)
    {
        /* initialize */

        the_suspicious = 0;

        for(i = 1; i <= n; i++)
        {
            for(j = 1; j <= n; j++)
                knows[i][j] = 0;

            suspicious[i] = 1;
        }

        /* read N members */

        for(i = 1; i <= n; i++)
        {
            scanf("%d", &m);

            while(m--)
            {
                scanf("%d", &j);
                knows[i][j] = 1;
            }
        }

        /* find the suspicious */

        scanf("%d", &k);

        while(k--)
        {
            scanf("%d", &j);

            for(i = 1; i <= n; i++)
                if(!knows[i][j])
                    suspicious[i] = 0;
        }

        for(i = 1; i <= n; i++)
            if(suspicious[i])
            {
                if(the_suspicious)
                {
                    the_suspicious = 0;
                    break;
                }
                the_suspicious = i;
            }

        if(the_suspicious)
            printf("%d\n", the_suspicious);
        else
            puts("-1");
    }

    return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    rep(0, i, N)
    {
        cin >> x[i];
    }
    int ans = 1000000000;
    rep(0, i, N - K + 1)
    {
        int a;
        if (abs(x[i + K - 1]) > abs(x[i]))
        {
            a = abs(x[i]);
        }
        else
        {
            a = abs(x[i + K - 1]);
        }
        ans = min(ans, x[i + K - 1] - x[i] + a);
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for i in range(A+1):

    for j in range(B+1):

        for k in range(C+1):
            ans = 500 * i + 100 * j + 50 * k
            if ans == X:
                count+=1
    
print(count)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) (x.begin(),x.end())
using namespace std;

int main(){
ll K,X;
cin>>K>>X;
ll tmp=X-(K-1);


for(ll i=0;i<K*2-1;i++){
cout<<tmp+i<<" ";
}




return 0;

}


Measured memory_bytes: 256
import math
N=int(input())
A = [[int(i) for i in input().split()] for N in range(N)] 
S=0
for x in range(0,N-1):
  for y in range(x+1,N):
    S=S+math.sqrt((A[x][0]-A[y][0])**2+(A[x][1]-A[y][1])**2)
ave=S*2/N
print(ave)

Measured memory_bytes: 3064
#include <stdio.h>

const int *map[52][52];

void search(int w,int h)
{
  if(map[w][h]){
    map[w][h]=0;
    search(w-1,h-1);
    search(w,h-1);
    search(w+1,h-1);
    search(w-1,h);
    search(w+1,h);
    search(w-1,h+1);
    search(w,h+1);
    search(w+1,h+1);
  }
}

int main(void)
{
  int w,h,i,j,ans;
  
  for(;;){
    scanf("%d %d", &w, &h);
    if(!(w|h)) break;

    for(i=1;i<h+1;i++)
      for(j=1;j<w+1;j++)
	scanf("%d", &map[j][i]);
    for(i=1,ans=0;i<h+1;i++)
      for(j=1;j<w+1;j++)
	if(map[j][i]){
	  ans++;
	  search(j,i);
	}
    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;


void weather_predicition()
{
  string s;
  cin >> s;

  if (s == "Sunny") cout << "Cloudy\n";
  else if (s == "Cloudy") cout << "Rainy\n";
  else if (s == "Rainy") cout << "Sunny\n";
}


void odds_of_oddness()
{
  int n;
  cin >> n;

  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (i % 2 != 0) ++cnt;
  }

  cout << (float)cnt / (float)n << "\n";
}


void curtain()
{
  int a, b;
  cin >> a >> b;

  if (a - 2 * b > 0) cout << a - 2 * b << "\n";
  else cout << 0 << "\n";
}


void cant_wait_for_holiday()
{
  string s;
  cin >> s;

  vector<string> S{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

  int cnt = 7;
  for (int i = 0; i < 7; ++i)
  {
    if (s == S[i]) cout << cnt << "\n"; 
    --cnt;
  }

}


void blackjack()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

  if (accumulate(a.begin(), a.end(), 0) >= 22) cout << "bust\n";
  else cout << "win\n";
}


void round_one()
{
  int a, b;
  cin >> a >> b;

  cout << 6 - a - b;
}


void strings()
{
  string s, t;
  cin >> s >> t;

  cout << t + s << "\n";
}


void yen_conins()
{
  int k, x;
  cin >> k >> x;

  if (k * 500 - x >= 0) cout << "Yes\n";
  else cout << "No\n";
}


void tap_dance() 
{
  string s;
  cin >> s;

  int flag = 1;
  for (int i = 1; i <= s.size(); ++i)
  {
    if (i % 2 == 0)
    {
      if (s[i] == 'L') flag = 0;
    }
    else
    {
      if (s[i] == 'R' ) flag = 0;
    }
  }
  if (flag) cout << "Yes\n";
  else cout << "No\n";
}


void roller_coaster()
{
  int n, k;
  cin >> n >> k;

  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    int h;
    cin >> h;
    if (h >= k) ++cnt;
  }
  cout << cnt << "\n";
}


void takoyaki_festival2019()
{
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) cin >> d[i];

  int v_sum = 0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = i + 1; j < n; ++j)
    {
      v_sum += d[i] * d[j];
    }
  }
  cout << v_sum << "\n";
}



int main()
{
  //weather_predicition();
  //odds_of_oddness();
  //curtain();
  //cant_wait_for_holiday();
  //blackjack();
  //round_one();
  //strings();
  //yen_conins();

  //tap_dance();
  //roller_coaster();
  takoyaki_festival2019();
}

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

using namespace std;

bool IsMatch(string a, string b)
{
	if (a.size() + 1 != b.size())
	{
		return false;
	}

	return a == b.substr(0, a.size());
}

int main()
{
	string a, b;
	cin >> a >> b;

	if (IsMatch(a, b))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3132
#include"iostream"
#include"cstdio"
#include"cmath"
#include"cstring"
#include"algorithm"
#include"stack"
#include"queue"
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long
#define MAXN 1000005 

int n,f[200005];
int l,r,m;
int mu[200005];
int ans=0;

void init(){for(int i=1;i<=n;i++) f[i]=i;}

int getf(int u){return f[u]=(f[u]==u)?u:getf(f[u]);}

void merge(int u,int v){int t1=getf(u),t2=getf(v);if(t1!=t2) f[t2]=t1;}

int main()
{
	cin>>n>>m;
	init();
	for(int i=1;i<=m;i++)
	{
		cin>>l>>r;
		merge(l,r);
	}
	for(int i=1;i<=n;i++)
	{
		mu[getf(i)]++;
	}
	for(int i=1;i<=n;i++) ans=max(ans,mu[i]);
	printf("%d\n",ans);
	return 0;
} 

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

int main() {
	// your code goes here
	int N, Z, W; cin >> N >> Z >> W;
	int a[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	if (N == 1) return cout << abs(a[N - 1] - W), 0;
	cout << max(abs(a[N - 1] - a[N - 2]), abs(a[N - 1] - W));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n;
long long ans;
long long gcd(long long x,long long y)
{
	if(y==0LL)return x;
	return gcd(y,x%y);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		long long t;
		scanf("%lld",&t);
		if(i==1)ans=t;
		else ans=ans/gcd(ans,t)*t;
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 256
from collections import deque
n=int(input())
a=list(map(str,input().split()))
b=deque()
#print(b)
for i in range(n):
    if i%2==0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
b=list(b)
if n%2==1:
    b=b[::-1]
print(" ".join(b))

Measured memory_bytes: 26564
b=[]
num=int(input())
a=input().split()


if num%2==0:
    for i in range(num-1,0,-2):
        print(a[i],end=" ")
    for i in range(0,num,2):
        print(a[i],end=" ")
else:
    for i in range(num-1,0,-2):
        print(a[i],end=" ")
    print(a[0],end=" ")
    for i in range(1,num,2):
        print(a[i],end=" ")
    


print("")


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

int main(){
  int match=0;
  string s,t;
  cin >> s;
  cin >> t;

  for(int i=0;i<3;i++) {
    if(s[i]==t[i]) match++;
  }

  cout << match << endl;
  return 0;
}


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

struct obj
{
	int B;
	int C;
};

bool cmp(const obj& a, const obj& b)
{
	// 降順
	return a.C > b.C;
}

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

	vector<long> cardList(N);
	for (int i = 0; i < N; i++)
	{
		cin >> cardList[i];
	}

	vector<obj> actionList(M);
	for (int i = 0; i < M; i++)
	{
		obj action;
		cin >> action.B >> action.C;
		actionList[i] = action;
	}

	sort(actionList.begin(), actionList.end(), cmp);
	sort(cardList.begin(), cardList.end());

	int j = 0;
	for (int i = 0; i < M; i++)
	{
		obj action = actionList[i];
		for (int k = 0; k < action.B; k++)
		{
			if (action.C > cardList[j])
			{
				cardList[j] = action.C;
				j++;
			}
			else
			{
				break;
			}
		}

		if (j > N)
		{
			break;
		}
	}

	cout << accumulate(cardList.begin(), cardList.end(), 0LL) << endl;

	return 0;
}

Measured memory_bytes: 1920
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		int max =Math.max(a+b,a-b);
		System.out.println(Math.max(max, a*b));
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int n,id;
char ch;
char s[200];
int t[26];
P a[26];

void solve(){
  fill(t,t+26,0);
  for(int i=0;i<n;i++){
    id=s[i]-'A';
    t[id]++;
    for(int j=0;j<26;j++)a[j]=P(t[j],j);
    sort(a,a+26);
    reverse(a,a+26);
    if(a[0].first>a[1].first+(n-1-i)){
      cout<<(char)(a[0].second+'A')<<' '<<i+1<<endl;
      return;
    }
  }
  cout<<"TIE"<<endl;
}

int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>s[i];
    solve();
  }
  return 0;
}

Measured memory_bytes: 3032
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

class Knapsack {
    struct item { 
        long long v, w; 
    };

    long long W;
    vector<item> items;
    long long lv;
    long long lv_w;

    pair<long long, long long> solve_rec(size_t k, long long v, long long w) {
        if (w + items[k].w > W) return solve_rec(k+1, v, w);
        long long cv = v, cw = w;
        for (size_t i = k; i < items.size(); ++i) {
            if (cw + items[i].w <= W) {
                cw += items[i].w;
                cv += items[i].v;
            }
        }
        if (lv < cv || (lv == cv && lv_w > cw)){
            lv = cv;
            lv_w = cw;
        }
        double fv = v, fw = w;
        for (size_t i = k; i < items.size(); ++i) {
            if (fw + items[i].w <= W) {
                fw += items[i].w;
                fv += items[i].v;
            } else {
                fv += items[i].v * (W - fw) / items[i].w;
                break;
            }
        }
        if (fv - lv < 1 || fv < lv) return make_pair(lv, lv_w);
        solve_rec(k+1, v+items[k].v, w+items[k].w);
        return solve_rec(k+1, v, w);
    }

    public:
    Knapsack() {}
    Knapsack(long long W_) : W(W_) {}
    void add_item(long long v, long long w) {
        items.push_back({v, w});
    }
    pair<long long, long long> solve() {
        sort(items.begin(), items.end(), [](const item &a, const item &b) { 
                return a.v * b.w > a.w * b.v;
                });
        lv = 0;
        return solve_rec(0, 0, 0);
    };
};

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int main(void){
    int W,N,v[1001],w[1001];
    int cas = 1;
    while(cin>>W){
        if(W==0) break;
        printf("Case %d:\n",cas++);
        Knapsack solver(W);
        cin>>N;
        REP(i,N){
            scanf("%d,%d",&v[i],&w[i]);
            solver.add_item(v[i], w[i]);
        }
        pair<long long, long long> p = solver.solve();
        printf("%lld\n%lld\n", p.first, p.second);
    }
    return 0;
}

Measured memory_bytes: 1540
from fractions import gcd
n,m = map(int, input().split())
s = input()
t = input()

u = gcd(n,m)
l = n*m//u
x = n//u
y = m//u
for i in range(u):
    # print(n, m, u, l, i, i*x, s[i*x], i*y, t[i*y])
    if s[i * x] != t[i * y]:
        print(-1)
        break
else:
    print(l)

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

int h, w, k;

map<pair<int, int>, long long> dp;

long long dfs(int now, int x) {
	if (now == h) return x == k - 1;
	auto status = make_pair(now, x);
	if (dp.count(status)) return dp[status];
	long long res = 0;
	for (int i = 0; i < 1 << (w - 1); i++) {
		bool check = true;
		for (int j = 0; j < w - 2; j++) {
			if ((i >> j & 1) && (i >> (j + 1) & 1)) {
				check = false;
				break;
			}
		}
		if (check) {
			if (0 < x && (i >> (x - 1) & 1)) {
				res += dfs(now + 1, x - 1);
				res %= INF;
			}
			else if (x + 1 < w && ((i >> x) & 1)) {
				res += dfs(now + 1, x + 1);
				res %= INF;
			}
			else {
				res += dfs(now + 1, x);
				res %= INF;
			}
		}
	}
	return dp[status] = res;
}

void hawawa()
{
	int n, k;
	string str;
	cin >> n >> k;
	cin >> str;
	str[k - 1] = str[k - 1] - 'A' + 'a';
	cout << str << "\n";
}


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


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<long long> ans(4);
    ans[0] = a*c;
    ans[1] = a*d;
    ans[2] = b*c;
    ans[3] = b*d;

    long long max = ans[0]; 
    for (int i = 0; i < 4; i++) {
        //cout << ans[i] << endl;
        if (max < ans[i]) {
            max = ans[i];
        }
    }
    cout << max << endl;
}

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

#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long a,b,c,d;

    cin>>a>>b>>c>>d;
    cout<<max(max(a*d,a*c),max(b*d,b*c))<<'\n';
    
    return 0;
}

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

int f(int n, int k) {
  int res = k;
  for (int i = 0; i < n - 1; i++) {
    res *= k - 1;
  }
  return res;
}

int main() {
  int N, K;
  cin >> N >> K;
  int ans = f(N, K);
  cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc167/tasks/abc167_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;

  ll rest = K;
  ll sum = 0;

  ll a_ct = min(A, rest);
  sum += a_ct;
  rest -= a_ct;

  ll b_ct = min(B, rest);
  sum += 0;
  rest -= b_ct;

  ll c_ct = min(C, rest);
  sum -= c_ct;
  rest -= c_ct;

  cout << sum << "\n";
}


Measured memory_bytes: 3644
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> hist(1000 + 1, 0);
  set<int64_t> bars;
  for (int64_t i = 0; i < N; ++i) {
    int64_t l;
    cin >> l;
    ++hist[l];
    bars.insert(l);
  }

  vector<int64_t> bars_array;
  for (const auto b : bars) {
    bars_array.push_back(b);
  }

  int64_t result = 0;
  const int64_t nb = static_cast<int64_t>(bars_array.size());
  for (int64_t i = 0; i < nb; ++i) {
    for (int64_t j = i + 1; j < nb; ++j) {
      for (int64_t k = j + 1; k < nb; ++k) {
        if (bars_array[i] + bars_array[j] > bars_array[k]) {
          result += hist[bars_array[i]] * hist[bars_array[j]] * hist[bars_array[k]];
        }
      }
    }
  }
  for (int64_t i = 0; i < nb; ++i) {
    for (int64_t j = i + 1; j < nb; ++j) {
      if (hist[bars_array[i]] >= 2 && bars_array[i] * 2 > bars_array[j]) {
        result += hist[bars_array[i]] * (hist[bars_array[i]] - 1) / 2 * hist[bars_array[j]];
      }
      if (hist[bars_array[j]] >= 2) {
        result += hist[bars_array[j]] * (hist[bars_array[j]] - 1) / 2 * hist[bars_array[i]];
      }
    }
  }
  for (int64_t i = 0; i < nb; ++i) {
      if (hist[bars_array[i]] >= 3) {
        result += hist[bars_array[i]] * (hist[bars_array[i]] - 1) * (hist[bars_array[i]] - 2) / 6;
      }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>

using namespace std;

string signature(const string& s) {
  stringstream ss;
  char prev = s[0];
  int x = 1;
  for (int i = 1; i < s.size(); i++) {
    char c = s[i];
    if (prev == c) {
      x++;
    } else {
      ss << prev << x;
      x = 1;
    }
    prev = c;
  }
  ss << prev << x;
  return ss.str();
}

int main() {
  int N;
  cin >> N;
  unordered_map<string, size_t> m;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    m[signature(s)]++;
  }
  size_t ans = 0;
  for (auto p : m) {
    ans += p.second * (p.second - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12068
# C問題
n, x = map(int, input().split())
a = list(map(int, input().split()))
new_a = []
new_a += a
if a[0] > x:
    new_a[0] = x
for i in range(n-1):
    while True:
        if new_a[i] + new_a[i+1] > x:
            new_a[i+1] = x-new_a[i]
        if new_a[i] + new_a[i+1] <= x:
            break

print(sum(a) - sum(new_a))

Measured memory_bytes: 14540
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

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

    return false;
}

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

    vector<int> A(N);
    int a_max = 0;
    rep(i, N)
    {
        cin >> A[i];
        chmax(a_max, A[i]);
    }

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

    vector<bool> dp(a_max + 1, true);
    rep(i, N)
    {
        if ((i > 0) && (A[i] == A[i - 1]))
        {
            dp[A[i]] = false;
        }

        if (dp[A[i]])
        {
            int a = A[i] * 2;
            while (a <= a_max)
            {
                dp[a] = false;
                a += A[i];
            }
        }
    }

    int cnt = 0;
    rep(i, N)
    {
        if (dp[A[i]])
        {
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 3984
a = list(map(int,input().split()))
n = a[0]
k = a[1]
su = []
for j in range(n):
  su.append(0)
for i in range(k):
  d = int(input())
  b = list(map(int,input().split()))
  for l in range(d):
    count=b[l]
    su[count-1]=1
print(su.count(0))

Measured memory_bytes: 9200
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
vector<int> g[N];
int vis[N];
int dis[N];
void dfs(int v, int d){
    vis[v] = 1;
    dis[v] = d;
    for(auto to : g[v]){
        if(vis[to]) continue;
        dfs(to, d + 1);
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n + 1, 0);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        g[i].PB(a[i]);
    }
    dfs(1, 0);
    if(vis[2]){
        cout << dis[2];
    }else{
        cout << -1;
    }
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 12416
object Main extends App {
	val strAry = io.StdIn.readLine().split(' ')
	val num1 = strAry(0).toInt
	val num2 = strAry(1).toInt
	val num3 = strAry(2).toInt
	val num4 = strAry(3).toInt
	val num5 = strAry(4).toInt
	
	// x座標からrを引いて-になったらだめ
	// x座標にrを足してnum1より大きかったらだめ
	// y座標からrを引いて-になったらだめ
	// y座標にrを足してnum2より大きかったらだめ
	// それ以外はok
	
	val result = (num1, num2, num3, num4, num5) match {
		case (w, h, x, y, r) if (x - r) < 0 => "No"
		case (w, h, x, y, r) if (x + r) > w => "No"
		case (w, h, x, y, r) if (y - r) < 0 => "No"
		case (w, h, x, y, r) if (y + r) > h => "No"
		case _ => "Yes"
	}
	
	println(result)
}


Measured memory_bytes: 43872
n=int(input())
def g(x):
    z=0
    while x>=1:
        z+=1
        x=x//10
    return z
def f(a,b):
    return max(g(a),g(b))
i=1
ans=10**10
while i*i<=n:
    if n%i==0:
        ans=min(ans,f(i,n//i))
    i+=1
print(ans)


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

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    int n;
    cin >> n;
    vector<mint> a(n);
    rep(i, n) cin >> a[i];
    vector<mint> sum(n);
    rep(i, n) {
        if (i == 0) continue;
        else sum[n - i - 1] = sum[n - i] + a[n - i];
    }
    mint ans = 0;
    rep(i, n) {
        ans += a[i] * sum[i];
    }
    cout << ans << endl;
    return 0;
}
/*
g++ -std=c++17 -Wall -Wextra -g -O0 -fsanitize=undefined,address main.cpp && oj t
*/

Measured memory_bytes: 6424
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s, int v, vector<int>& d, whei(edge)& G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size(); i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}



int main() {
	ll n;
	cin >> n;
	for (ll i = sqrt(n); i > 0; i--) {
		if (n % i == 0) {
			cout << to_string(n/i).size() << endl;
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

int main() {
	long long int N;
	cin >> N;
	vector<long long int>len( N + 1, LLONG_MAX / 6 );
	len[0] = 0;
	vector<vector<long long int>>AB( N + 1 );
	for( size_t i = 1; i < N; i++ ) {
		long long int A, B;
		cin >> A >> B;
		AB[A].push_back( B );
		AB[B].push_back( A );
	}
	long long int K;
	cin >> K;
	typedef pair<long long int, long long int> PLL;
	priority_queue<PLL, vector<PLL>, greater<PLL>>que;
	vector<PLL>VP;
	for( size_t i = 0; i < K; i++ ) {
		long long int V, P;
		cin >> V >> P;
		len[V] = P;
		AB[0].push_back( V );
		que.push( make_pair( P, V ) );
		VP.push_back( make_pair( V, P ) );
	}
	while( que.size() ) {
		auto now = que.top(); que.pop();
		for( auto i : AB[now.second] ) {
			if( len[i] > len[now.second] + 1 ) {
				len[i] = len[now.second] + 1;
				que.push( make_pair( len[i], i ) );
			}
		}
	}
	for( auto x : VP ) {
		if( len[x.first] != x.second ) {
			cout << "No" << endl;
			return 0;
		}
	}
	for( size_t i = 1; i <= N; i++ ) {
		for( auto j : AB[i] ) {
			if( abs( len[i] - len[j] ) != 1 ) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	for( size_t i = 1; i <= N; i++ ) {
		cout << len[i] << endl;
	}
}

Measured memory_bytes: 11740
n = int(input())
scores = [int(input()) for _ in range(n)]
scores_not_10 = [i for i in scores if not i % 10 == 0]
scores_not_10.sort()
ans = sum(scores)
for i in range(len(scores_not_10)):
    if ans % 10 != 0:
        print(ans)
        exit()
    else:
        ans -= scores_not_10[i]
print(0)

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

int main(){
	int n, m;
	cin >> n >> m;
	vector<bool> ac(n);
	vector<int> pena(n);

	rep(i, m){
		int d;
		string s;
		cin >> d >> s;
		if(s == "WA"){
			if(!ac.at(d-1)) pena.at(d-1)++;
		}
		if(s == "AC") ac.at(d-1) = true;
	}

	int ans_pena = 0;
	int ans = 0;
	rep(i, n){
		if(ac.at(i)){
			ans_pena += pena.at(i);
			ans++;
		}
	}

	cout << ans << " " << ans_pena << endl;

	return 0;
}

Measured memory_bytes: 640
import math
a, b, x = map(int, input().split())

if a * a * b == x:
    print(0)
# 台形の場合
elif a * a * b < 2 * x:
    y = 2 * x / (a*a) - b
    print(90 - math.degrees(math.atan(a/(b-y))))

else:
    y = 2 * x / a / b
    print(90 - math.degrees(math.atan(y/b)))

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

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

#define int long long

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

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

void MAIN() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size() / 2; i++) {
    if (s[i] != s[s.size() - i - 1]) {
      cout << "No" << '\n';
      return;
    }
  }
  cout << "Yes" << '\n';
}

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


Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  ll a,b; cin >> a >> b;
  if ( a == b && a != 0 ) {
    cout << "Positive" << endl;
  } else if ( a == 0 || b == 0 || a < 0 && b > 0 ) {
    cout << "Zero" << endl;
  } else if ( a > 0 || (a < 0 && b < 0 && abs(a-b)%2 == 1) ) {
    cout << "Positive" << endl;
  } else if ( a < 0 && b < 0 && abs(a-b)%2 == 0 ) {
    cout << "Negative" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <iostream>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;
//https://codeforces.com/contest/1228/problems
//https://codeforces.com/contest/1228/submit
/*int main() {
    int n;
    s(n)
    int count0 = 0;
    int count1 = 0;
    int x;

    for(int i = 0; i < n; i ++) {
        s(x)
        if(x % 4 == 0) {
            count0 ++;
        }else if(x % 2 == 0){
            count1 ++;
        }
    }
    n -= count0*3;
    if(n <= 0) {
        puts("Yes");
    } else {
        n ++;
        if(n <= count1){
            puts("Yes");
        }else{
            puts("No");
        }
    }
    return 0;
}
*/
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long

ll cmd(ll a, ll b){
return b==0?a:cmd(b,a%b);}
ll gcd(ll a , ll b){
    ll k = cmd(a,b);
    return (a/k)*b;
}
ll a[10000]={0};
int main(){
    int n;
    ll num=1;
    cin >>n;
    for(int i=1;i<=n;i++){
        cin >>a[i];
    }
    for(int i=1;i<=n;i++){
        num=gcd(a[i],num);
    }
    cout<<num<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main(){
  unsigned long long n; cin >> n;
  vector<unsigned long long> v(n, 0);
  vector<unsigned long long> res(n, 0);
  for(unsigned long long i = 0; i < n; i++){
    cin >> v[i];
    res[v[i] -1]++;
  }
  unsigned long long sum = 0;
  for(unsigned long long i = 0; i < n; i++){
    sum += (res[i] * (res[i] - 1)) / 2;
  }
  for(unsigned long long i = 0; i < n; i++){
    cout << sum - (res[v[i]-1] - 1) << endl;
  }
}
    







Measured memory_bytes: 5760