akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)

using namespace std;

vector<int> vec;

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int main(void) {
	long long a;
	long long b;

	vector<long long> vec;

	long long ans = 0;


	cin >> a;




	cout << (long long)3 * a * a;



}




Measured memory_bytes: 256
S = input()

ans,calc =0,0
for i in range(2 ** (len(S) - 1)):
    for j in range(len(S)):
        if (i >> (len(S)-1-j)) & 1:
            ans += calc
            calc = int(S[j])
        else:
            calc = calc*10 + int(S[j])
    ans += calc
    calc = 0
print(ans)


            

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
using namespace std;
char *result = new char[4];
char *strpick(char *str, int start)
{
	for (int i = 0; i < 3; i++)
	{
		result[i] = str[start+i];
	}
	result[3] = '\0';
	return result;
}
int main()
{
	char str[10001];
	char *tmp = new char[4];
	int ioi, joi, i;
	while (cin >> str)
	{
		if (cin.eof()) break;
		ioi = joi = 0;
		for (i = 0; i < signed(strlen(str))-2;)
		{
			if (str[i] == 'I' || str[i] == 'J')
			{
				tmp = strpick(str, i);
				if (strcmp(tmp, "IOI") == 0)
					ioi++, i+=2;
				else if (strcmp(tmp, "JOI") == 0)
					joi++, i+=2;
				else
					i++;
			}
			else
				i++;
		}
		cout << joi << endl << ioi << endl;
	}
}

Measured memory_bytes: 0
h, w, n = map(int, input().split())
a = [None] * n
s = set()
for i in range(n):
    y, x = map(int, input().split())
    a[i] = (y - 1, x - 1)
    s.add((y -1 , x - 1))
t = set()
e = [0] * 10
c = [-1, -1, -1, 0, 0, 0, 1, 1, 1]
d = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
for i in range(n):
    y, x = a[i]
    for j in range(9):
        y2 = y + c[j]
        x2 = x + d[j]
        if y2 <= 0 or x2 <= 0 or y2 >= h - 1 or x2 >= w - 1: continue
        z = 0
        if (y2, x2) in t: continue
        t.add((y2, x2))
        for k in range(9):
            y3 = y2 + c[k]
            x3 = x2 + d[k]
            if (y3, x3) in s: z += 1
        e[z] += 1
print(((h - 2) * (w - 2)) - sum(e))
for i in range(1, 10): print(e[i])


Measured memory_bytes: 124484
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

    int k;
    cin >> k;
    ll g = 0;
    rep(x, 1, k+1) {
        rep(y, 1, k+1) {
            rep(z, 1, k+1) {
                g += gcd(gcd(x, y), z);
            }
        }
    }
    cout << g << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,k,s=0,j,x=0;
    cin>>n>>k;
    int a[n];
    double ans;
    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<k;i++)s+=a[i];
    x=s;
    for(i=0,j=k;j<n;i++,j++)
    {
        s=s-a[i]+a[j];
        x=max(x,s);
    }
    x+=k;
    ans=(double)x/2;
    cout<<fixed<<setprecision(12)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //var card_dic = new Dictionary<string, int[]>();
            //card_dic.Add("S", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
            //card_dic.Add("H", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
            //card_dic.Add("C", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
            //card_dic.Add("D", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });


            //トランプのマスタリストを作ります
            string[] marks = new string[] { "S", "H", "C", "D" };
            string[] nums = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" };

            List<string> cards = new List<string>();

            foreach (var mark in marks)
            {
                foreach(var num in nums)
                {
                    cards.Add(mark + " " + num);
                }
            }

            //太郎の手持ちのカード枚数
            int taros_card_num;
            taros_card_num = int.Parse(Console.ReadLine());

            //太郎の手持ちのカード種類
            List<string> taros_cards = new List<string>();
            int n = 0;
            while (n< taros_card_num)
            {
                taros_cards.Add(Console.ReadLine());
                n++;
            }

            //比較
            var not_enough_cards = cards.Except<string>(taros_cards);

            foreach(var card in not_enough_cards)
            {
                Console.WriteLine(card);
            }

        }
    }
}



Measured memory_bytes: 16096
import sys
input = sys.stdin.readline
N = int(input())
s = [list(input())[: -1] for _ in range(N)]
res = 0
for a in range(N):
  f = 1
  for i in range(N):
    for j in range(N):
      if s[(i + a) % N][j] != s[(j + a) % N][i]:
        f = 0
        break
  if f: res += N
print(res)

Measured memory_bytes: 47056
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
string s;

int main(){
	cin >> s;
	
	int c=0;
	REP(i,0,s.size()) if(s[i]=='1') c++;
	
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    def solve(ans, xflg, yflg, xyflg):
        print(len(ans) - 1)
        for x, y in ans[1:]:
            if xyflg:
                x, y = y, x
            if xflg:
                x *= -1
            if yflg:
                y *= -1
            print(x, y)
        exit()

    K = int(input())
    X, Y = map(int, input().split())

    if (X+Y)%2 == 1 and K%2 == 0:
        print(-1)
        exit()

    xflg = 0
    yflg = 0
    xyflg = 0
    if X < 0:
        xflg = 1
        X *= -1
    if Y < 0:
        yflg = 1
        Y *= -1
    if X < Y:
        xyflg = 1
        X, Y = Y, X

    ans = [(0, 0)]
    x = y = 0
    while abs(X - x) + abs(Y - y) >= K:
        if y < Y:
            y_new = min(Y, y + K)
            x_new = x + (K - y_new + y)
        else:
            y_new = y
            x_new = x + K
        x, y = x_new, y_new
        ans.append((x, y))

    if ans[-1][0] == X and ans[-1][1] == Y:
        solve(ans, xflg, yflg, xyflg)

    x_last, y_last = ans[-1]
    if (x_last+y_last)%2 != (X+Y)%2 or K%2 == 0:
        ans.pop()
        if ans:
            x_last, y_last = ans[-1]
        else:
            if K&1:
                x_last, y_last = -K, 0
                ans.append((0, 0))
                ans.append((-K, 0))
            else:
                x_last, y_last = 0, 0
                ans.append((0, 0))
    A = X - x_last
    B = Y - y_last
    ans.append((x_last + (A+B) // 2, y_last - K + (A+B) // 2))
    ans.append((X, Y))
    solve(ans, xflg, yflg, xyflg)



if __name__ == '__main__':
    main()


Measured memory_bytes: 60500
import sys
N=int(input())
a=list(map(int,input().split()))
b,c,d=0,1,0
while True:
    while True:
        if a[b]%(2**c)>=2**(c-1):
            d+=1
        b+=1
        if b==N:
            if d%2==1:
                print('No')
                sys.exit()
            else:
                break
    b,d=0,0
    c+=1
    if c==27:
        break
print('Yes')

Measured memory_bytes: 14212
#include <vector>
    #include <list>
    #include <map>
    #include <set>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <bitset>
    #include <algorithm>
    #include <functional>
    #include <numeric>
    #include <utility>
    #include <sstream>
    #include <iostream>
    #include <iomanip>
    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <ctime>
    #include <string>
    #include <climits>
    #include <tuple>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> P;
    typedef tuple<int,int,int,int> T;
     
     
     
     
    int bit[100003],n;
    int sum(int i){
        int s=-1;
        while(i>0){
            s=max(bit[i],s);
            i-=i&-i;
        }
        return s;
    }
    void add(int i,int x){
        while(i<=n){
            bit[i]=max(bit[i],x);
            i+=i&-i;
        }
    }
    int main(){
        string s;
        int w;
        cin>>s;
        cin>>w;
        for(int i=0;i<s.size();i++){
            if (i%w==0)cout<<s[i];
        }
        cout<<endl;
        return 0;
    }


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

#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      ll x,k,d;
      cin>>x>>k>>d;

      if(x<0) x *= (-1);

      if(x>=d){
            ll vagfol=x/d;
            ll vagses=x%d;

            if(vagfol>=k){cout<<x-(k*d)<<endl;bye;}
            ll rem= k-vagfol;
            if(rem%2==0){cout<<vagses<<endl; bye;}
            else{cout<<abs(vagses-d)<<endl;bye;}
      }
      else{
            if(k%2==0){cout<<x<<endl;bye;}
            cout<<abs(x-d)<<endl;
      }


      bye;
}


Measured memory_bytes: 3668
import math

n,d = map(int, input().split())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
count = 0

for i in range(n):
    r = math.sqrt(x[i]**2 + y[i]**2)
    if r <= d:
        count += 1 

print(count)

Measured memory_bytes: 116808
let rec f a b = if b = 0 then a else f b (a mod b)
let _ = Scanf.scanf "%d %d %s %s" @@ fun n m s t -> for i = 0 to n - 1 do if m * i mod n = 0 && m * i / n < m && s.[i] <> t.[m * i / n] then (print_endline "-1"; exit 0) done; Printf.printf "%d\n" @@ n / f n m * m

Measured memory_bytes: 2688
def main():
    N = 4
    edge = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = (int(i) for i in input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    even, odd = 0, 0
    for e in edge:
        if len(e) % 2 == 1:
            odd += 1
        else:
            even += 1
    if odd == 2 and even == 2:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
use proconio::{input, fastout};
use proconio::marker::Chars;

#[fastout]
fn main() {
    input!{
        s: Chars,
    }
  	let ng = s.iter().enumerate().any(|(i, c)|
        if i & 1 == 1 {
            *c == 'R'
        } else {
            *c == 'L'
        }
    );
  	if ng {
    	println!("No");
  	} else {
    	println!("Yes");
  	}
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
bool e[2000][2000];
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  int a[n - 1], b[n - 1];
  vector<int> g[n];
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    e[a[i]][b[i]] = e[b[i]][a[i]] = 1;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  int res = 0;
  if (k % 2 == 0) {
    k /= 2;
    int v;
    int memo[n];
    for (int i = 0; i < n; i++) {
      memset(memo, -1, sizeof(memo));
      queue<int> q;
      memo[i] = 0, q.push(i);
      while (!q.empty()) {
        v = q.front(); q.pop();
        for (auto j : g[v]) {
          if (memo[j] == -1) {
            memo[j] = memo[v] + 1;
            q.push(j);
          }
        }
      }
      sort(memo, memo + n);
      res = max(res, (int) (upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)));
    }
  } else {
    k /= 2;
    int v;
    int memo[n];
    for (int i = 0; i < n - 1; i++) {
      memset(memo, -1, sizeof(memo));
      queue<int> q;
      memo[a[i]] = memo[b[i]] = 0;
      q.push(a[i]); q.push(b[i]);
      while (!q.empty()) {
        v = q.front(); q.pop();
        for (auto j : g[v]) {
          if (memo[j] == -1) {
            memo[j] = memo[v] + 1;
            q.push(j);
          }
        }
      }
      sort(memo, memo + n);
      res = max(res, (int) (upper_bound(memo, memo + n, k) - lower_bound(memo, memo + n, 0)));
    }
  }
  cout << n - res << "\n";
  return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b == c + d){
		cout << "Balanced" << "\n";
	}else{
	cout << ( (a + b > c + d) ? "Left" : "Right") << "\n";
	}	
	return 0;
}


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

int main() {
    int n,m,c,ai,swi;
    int rec[21],cnt=0;
    int b[21];
    while(scanf("%d%d%d",&n,&m,&c)==3)
    {
        swi=0,cnt=0;
        memset(rec,0,sizeof(rec));
        for(int i=1;i<=m;i++)
            scanf("%d",&b[i]);
        for(int i=1;i<=n;i++)
        {
            int res=0;
            for(int j=1;j<=m;j++)
            {
                scanf("%d",&ai);
                res+=ai*b[j];
            }
            if(res+c>0)
                rec[i]=1,cnt++;
        }
        printf("%d\n",cnt);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<long long>v[100005];
long long ans[100005];
map< pair<long long,long long>,long long>m;
void dfs(int s,int par)
{
    if(par==-1)
    {
        ans[s]=0;
    }
    else if(m[make_pair(s,par)]%2==0)
    {
        ans[s]=ans[par];
    }
    else
    {
        ans[s]=1-ans[par];
    }
    int i;
    for(i=0;i<v[s].size();i++)
    {
        if(v[s][i]!=par)
        {
            dfs(v[s][i],s);
        }
    }
}
int main()
{
    int n;
    cin>>n;
    int i;
    long long int a,b,c;
    for(i=1;i<=n-1;i++)
    {
        cin>>a>>b>>c;
        v[a].push_back(b);
        v[b].push_back(a);
        m[make_pair(a,b)]=c;
        m[make_pair(b,a)]=c;
    }
    dfs(1,-1);
    for(i=1;i<=n;i++)
    {
        cout<<ans[i]<<endl;
    }
}



Measured memory_bytes: 24704
// A - Kenken Race
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	a--, b--, c--, d--;
	string s;
	cin >> s;

	bool ans = true;
	if (d < c) swap(a, b), swap(c, d);
	string t = s;
	t[b] = 'b';
	t[a] = 'a';
	int i = a, j = b;
	for ( ; ; ) {
		if (j == d) break;
		if (j + 1 <= d && t[j + 1] == '.') {
			t[j] = '.', t[j + 1] = 'b', j += 1;
		} else if (j + 2 <= d && t[j + 2] == '.') {
			t[j] = '.', t[j + 2] = 'b', j += 2;
		} else if (j + 1 == i || j + 2 == i) {
			if (i + 1 <= c && t[i + 1] == '.') {
				t[i] = '.', t[i + 1] = 'a', i += 1;
			} else if (i + 2 <= c && t[i + 2] == '.') {
				t[i] = '.', t[i + 2] = 'a', i += 2;
			} else {
				ans = false;
				break;
			}
		} else {
			ans = false; break;
		}
	}
	if (ans)
		for ( ; ; ) {
			if (i == c) break;
			if (i + 1 <= c && t[i + 1] == '.') {
				t[i] = '.', t[i + 1] = 'a', i += 1;
			} else if (i + 2 <= c && t[i + 2] == '.') {
				t[i] = '.', t[i + 2] = 'a', i += 2;
			} else {
				ans = false;
				break;
			}
		}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 720
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		String S=stdIn.next();
		String ans="";
		for(int i=0;i<S.length();i++){
			char b=S.charAt(i);
			int a=(int)(b-'A')+N;
			if(a>25)
				a-=26;
			b=(char)(a+'A');
			ans+=String.valueOf(b);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 147540
A,B,C,X,Y = map(int, input().split())
if C*2 < A+B:
    v = C*2*min(X,Y) + A*(X-min(X,Y)) + B*(Y-min(X,Y))
    v2 = C*2*max(X,Y)
    print(min(v,v2))
else:
    print(A*X + B*Y)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        long n = stdIn.nextLong();
        long min = n + 1;
        long index = n; 
        
        for(long i = 1; i <= Math.sqrt(n); i++){
            if(n % i == 0){
                if(i + n / i < min){
                    min = i + n / i;
                }
            }
        }
        
        System.out.println(min - 2);
    }
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 10005;
int N;
vector<int> E[MAX_N];
int S[MAX_N];
int D[MAX_N];

using II = pair<int, int>;

class Node {
public:
    Node(II v = unitValue) : value(v) {

    }

    Node operator + (const Node& monoid) const {
      return min(this->getValue(), monoid.getValue());
    }

    static Node unit() {
        return Node(unitValue);
    }

    void setValue(II l) {
        this->value = l;
    }

    II getValue() const {
        return this->value;
    }

private:
    II value;
    static II unitValue;
};
II Node::unitValue = II(1145141919, -1);

template <class T>
class SegmentTree {
public:
    SegmentTree(int size) {
        init(size);
    }

    void init(int size) {
        vec.clear();
        k = 1;
        while(k < size) {
            k *= 2;
        }
        for(int i = 0; i < 2*k; i++) {
            vec.push_back(T::unit());
        }
    }

    void update(int i, T x) { //iをxに変更する
        i += k-1;
        vec[i] = x;
        while(i > 0) {
            i = (i-1)/2;
            vec[i] = vec[i*2+1] + vec[i*2+2];
        }
    }

    T find(int l, int r) {
        return _find(l, r, 0, 0, k);
    }

private:
    vector<T> vec;
    int k;

    T _find(int l, int r, int k, int x, int y) {
        if (r <= x || y <= l) { //重なってない場合
            return T::unit();
        } else if (l <= x && y <= r) { //完全にかぶってる場合
            return vec[k];
        } else { //中途半端にかぶってる場合
            int mid = (x+y)/2;
            T lNode = _find(l, r, 2*k+1, x, mid);
            T rNode = _find(l, r, 2*k+2, mid, y);
            return lNode + rNode;
        }
    }
};

SegmentTree<Node> sg(MAX_N);
int ans[MAX_N];

signed main()
{
  cin >> N;
  REP(n,N-1) {
    int a, b; cin >> a >> b; a--; b--;
    E[a].push_back(b);
    E[b].push_back(a);
    D[a]++; D[b]++;
  }

  REP(n,N) {
    cin >> S[n];
  }

  sort(S, S+N);

  REP(n,N) {
    sg.update(n,II(D[n],n));
  }

  REP(n,N) {
    II ret = sg.find(0,N).getValue();
    int pos = ret.second;
    ans[pos] = S[n];
    for(int next : E[pos]) {
      sg.update(next, II(sg.find(next, next+1).getValue().first-1, next));
    }
    sg.update(pos, II(1145141919, pos));
  }

  int sum = 0;
  REP(n,N) {
    for(int next : E[n]) {
      sum += min(ans[n], ans[next]);
    }
  }
  sum /= 2;

  cout << sum << endl;
  REP(n,N) {
    cout << ans[n];
    if(n < N-1) {
      cout << " ";
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int A, B;
    cin >> A >> B;

    rep(i,1100) {
        if (i * 8 / 100 == A && i * 10 / 100 == B) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <math.h>

#define INT_MAX       2147483647

#define ll long long

using namespace std;

int solve()
{
	int n, x;
	cin >> n >> x;

	vector<int> nums(n);
	for (int i = 0; i < n; i++)cin >> nums[i];

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

	int sum = 0;
	int cnt = 0;
	int i = 0;
	for (i = 0; i < n; i++)
	{
		sum += nums[i];
		if (sum <= x) cnt++;
		else break;

	}

	if (sum < x && i == n) cnt--;

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

int main()
{

	solve();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class T> inline T re(){
	T N = 0; char c = getchar(); bool neg = 0;
	for (; c < '0' || c > '9'; c = getchar()) neg |= c == '-';
	for (; c >= '0' && c <= '9'; c = getchar())
		N = (N<<3)+(N<<1) + c - '0';
	return neg ? -N : N;
}

const int mxsz = 1e5 + 3;
int n;
LL a[mxsz], d[mxsz];

inline void CANNOT(){
	puts("NO"); exit(0);
}
int main(){
	n = re<int>();
	for (int i = 1; i <= n; i++) a[i] = re<LL>();
	a[n+1] = a[1];
	LL totdiff = 0, tot = 0, add = 1LL * n * (n+1) / 2;
	for (int i = 1; i <= n; i++){
		totdiff += (d[i] = a[i] - a[i+1]);
		tot += a[i];
	}
	if (tot % add != 0) CANNOT();
	if (totdiff != 0) CANNOT();
	LL m = tot / add;
	LL totx = 0;
	for (int i = 1; i <= n; i++){
		if ((d[i] + m) % n != 0){
			CANNOT();
		}
		LL tmp = (d[i] + m) / n;
		if (tmp < 0) CANNOT();
		totx += tmp;
	}
	if (totx != m) CANNOT();
	cout << "YES\n";
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi(i,a,b) for(int i=a; i<=b; i-=-1)
#define fid(i,a,b) for(int i=a; i>=b; i--)
#define ll long long
#define F first
#define S second
#define VanLoi "a"
#define maxn 100005
#define pii pair<int, int>
#define MOD 1000000007
#define B 107
#define gb(i,j) ((i >> j) & 1)
#define pb push_back
#define reset(x) memset(x, 0, sizeof(x))
#define Block 400
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

int n, l[maxn], a[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen(VanLoi".inp","r",stdin);
    freopen(VanLoi".out","w",stdout);
    #endif // ONLINE_JUDGE
    cin >> n;
    fi(i, 1, n) cin >> a[i];
    l[1] = 0;
    l[2] = abs(a[1] - a[2]);
    fi(i, 3, n) l[i] = min(l[i - 1] + abs(a[i] - a[i - 1]), l[i - 2] + abs(a[i] - a[i - 2]));
    cout << l[n];
}


Measured memory_bytes: 4424
#include <bits/stdc++.h>
#define REP(a,b) for(int a=0; a<(b); ++a)
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define FWDS(a,b,c,d) for(int a=(b); a<(c); a+=d)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)
#define ALL(a) (a).begin(), (a).end()
#define SIZE(a) ((int)(a).size())
#define VAR(x) #x ": " << x << " "
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define gcd __gcd
#define x first
#define y second
#define st first
#define nd second
#define pb push_back

using namespace std;

template<typename T> ostream& operator<<(ostream &out, const vector<T> &v){ out << "{"; for(const T &a : v) out << a << ", "; out << "}"; return out; }
template<typename S, typename T> ostream& operator<<(ostream &out, const pair<S,T> &p){ out << "(" << p.st << ", " << p.nd << ")"; return out; }

typedef long long LL;
typedef pair<int, int> PII;
typedef long double K;
typedef vector<int> VI;

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

const int MAXN = 100010;

int n;
vector<int> out[MAXN];
long long stones[MAXN];
bool vis[MAXN];
bool ok;

long long solve(int u, bool root = 0){
	//printf("solve %d\n", u);
	vis[u] = 1;
	long long sup = 0;
	long long mup = -1;
	for(int v : out[u]) if(!vis[v]){
		long long up = solve(v);
		//printf("%d from %d %lld\n", u, v, up);
		sup += up;
		mup = max(mup, up);
	}
	if(root){
		if(sup != stones[u]) ok = 0;
		return 0;
	}
	if(mup == -1) return stones[u];
	// 2x + y = sup
	// x + y = stones[u]
	long long x = sup - stones[u];
	long long y = stones[u] - x;
	//printf("%d %lld %lld\n", u, x, y);
	if(x < 0 || y < 0) ok = 0;
	if(y < mup - (sup - mup)) ok = 0;
	return y;
}

int main(){
	scanf("%d", &n);
	FWD(i,1,n+1) scanf("%lld", &stones[i]);
	FWD(i,1,n){
		int a, b;
		scanf("%d %d", &a, &b);
		out[a].push_back(b);
		out[b].push_back(a);
	}
	ok = 1;
	FWD(i,1,n+1) if(SIZE(out[i]) == 1){
		solve(i, 1);
		break;
	}
	printf(ok?"YES\n":"NO\n");
	return 0;
}


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

inline void Read(int &x)
{
    x=0;int f=1;char a=getchar();
    while(a<'0'||'9'<a) {if (a=='-') f=-f; a=getchar();}
    while('0'<=a&&a<='9') x=x*10+(a-'0'),a=getchar();
    x*=f;
}

int N,M,C,ans;
int bi[100];

int main()
{
    Read(N),Read(M),Read(C);
    for(int i=1;i<=M;i++) Read(bi[i]);
    for(int i=1;i<=N;i++)
    {
    	int sum=C;
    	for(int j=1,k;j<=M;j++)
    		Read(k),sum+=bi[j]*k;
    	if (sum>0) ans++;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n, i;
  scanf("%d", &n);
  int a[n];

  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  for (i = n - 1; i >= 0; i--) {
    printf("%d", a[i]);
    if (i > 0 && i < n) putchar(' ');
  }
  putchar('\n');
  return 0;
}

Measured memory_bytes: 600
// B.

#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	char cnt[256] = {};
	bool ans = true;
	for (char c : s) {
		if (++cnt[c] >= 2) {
			ans = false;
		}
	}
	cout << (ans ? "yes" : "no") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[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;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge{
    ll cost;
    int to;
};


void dfs(int v,int p,vector<vector<edge>>& G,vi& ans,int color){
    //edgeのcostが偶数ならcolorは同じ、奇数なら1-color(color0の時１、color1の時0、まぁboolでやってもいいと思う)
    ans[v] = color;
    for(auto e:G[v]){
        if(e.to==p)continue;//逆流禁止
        if(e.cost%2 == 0) dfs(e.to,v,G,ans,color);
        else dfs(e.to,v,G,ans,1-color);
    }
}

int main()
{
  int N;
  cin >> N;
  vector<vector<edge>> G(N);
  vi ans(N,0);

  rep(i,N-1){
      int u,v;
      ll cost;
      cin >> u >> v >> cost;
      u--,v--;
      G[u].push_back(edge{cost,v});
      G[v].push_back(edge{cost,u});
  }
  
  dfs(0,-1,G,ans,0);

  for(auto a:ans){
      fin(a);
  }
  
}



Measured memory_bytes: 11264
#include <iostream>
#include <cstring>
#include <map>
#define INF 1000000
using namespace std;
typedef pair<int,int> P;

int electro[32][32];   // w h
P memo[32][32][32][32]; //sw sh ew eh
 
int h,w,s;

P divide(int sw,int sh,int ew,int eh){
	if(memo[sw][sh][ew-1][eh-1].first>0)
		return memo[sw][sh][ew-1][eh-1];
	P res;
	int mtmp=electro[w-1][h-1];
	int etmp=electro[ew-1][eh-1];
	if(sw)
		etmp-=electro[sw-1][eh-1];
	if(sh)
		etmp-=electro[ew-1][sh-1];
	if(sw&&sh)
		etmp+=electro[sw-1][sh-1];
	mtmp-=etmp;
	
	res.first=1,res.second=s-mtmp;
	for(int i=sw+1;i<ew;i++){
		P tmp,tmp2;
		tmp=divide(sw,sh,i,eh);
		tmp2=divide(i,sh,ew,eh);
		tmp.first+=tmp2.first;
		tmp.second=min(tmp.second,tmp2.second);
		if( (res.first < tmp.first&&0<=tmp.second) || (tmp.first == res.first&&0<=tmp.second&&res.second < tmp.second))
			res=tmp;
	}

	for(int j=sh+1;j<eh;j++){
		P tmp,tmp2;
		tmp=divide(sw,sh,ew,j);
		tmp2=divide(sw,j,ew,eh);
		tmp.first+=tmp2.first;
		tmp.second=min(tmp.second,tmp2.second);
		if( (res.first < tmp.first&&0<=tmp.second) || (tmp.first == res.first&&0<=tmp.second&&res.second < tmp.second))
			res=tmp;
	}
//	cout << res.first << " "  <<res.second  << endl;
	return memo[sw][sh][ew-1][eh-1]=res;
}

int main(void){
	while(cin >> h >> w >> s,h|w|s){
		memset(electro,0,sizeof(electro));
		memset(memo,0,sizeof(memo));
		for(int j=0;j<h;j++){
			for(int i=0;i<w;i++){
				cin >> electro[i][j];
				if(i)
					electro[i][j]+=electro[i-1][j];
				if(j)
					electro[i][j]+=electro[i][j-1];
				if(i&&j)
					electro[i][j]-=electro[i-1][j-1];
			}
		}
		/*for(int j=0;j<h;j++){
			for(int i=0;i<w;i++){
				cout << electro[i][j] <<" ";
			}
			cout << endl;
		}*/
		P ans=divide(0,0,w,h);
		cout << ans.first << " " << ans.second << endl;
		//cout << memo[0][0][0][0] << endl;
	}
	return 0;
}

Measured memory_bytes: 9368
from collections import deque
import sys
K = int(input())
q = deque([1,2,3,4,5,6,7,8,9])
num = 0
if K<=9:
    print(q[K-1])
    sys.exit()
for i in range(10**5):
    p = q.popleft()
    num += 1
    if num == K:
        print(p)
    if p%10 != 0:
        q.append(p*10+p%10-1)
    q.append(p*10+p%10)
    if p%10 != 9:
        q.append(p*10+p%10+1)

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

pair<int, int> dfs(int node, auto& g, auto& seen, int depth, int k, bool is_root) {
    seen[node] = true;
    vector<pair<int, int>> sons;

    for (int v : g[node]) {
        if (seen[v])
            continue;
        auto result = dfs(v, g, seen, depth + 1, k, false);
        sons.push_back(result);
    }
        
    pair<int, int> current_res = make_pair(depth > k / 2, depth == (k / 2) + 1);

    for (auto son : sons) {
        current_res.first += son.first;
        current_res.second += son.second;
    }
    
    if (not is_root) {
        return current_res;
    }

    if (k % 2 == 0) {
        return current_res;
    }
    
    int best = 0;

    for (auto son : sons) {
        best = max(best, son.second);
    }

    return make_pair(current_res.first - best, -1);
}

int main() {
   int n, k; cin >> n >> k;
   vector<vector<int>> g(n);

   for (int i = 0; i < n - 1; i += 1) {
        int a, b; cin >> a >> b;
        a -= 1, b -= 1;
        g[a].push_back(b);
        g[b].push_back(a);
   }
    
   int ans = n;

   for (int center = 0; center < n; center += 1) {
       vector<int> seen(n, 0);
       auto res = dfs(center, g, seen, 0, k, true);

       ans = min(ans, res.first);
   }

   cout << ans << "\n";
}   

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

using namespace std;
#define INF 1000007
#define MOD 1000000007
#define int long long
#define maxn 1e5+4
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef std::pair<int, int> P;

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) { return a / gcd(a, b) * b; }

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

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

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

int a, b;

void f(int x) {
    while (x) {
        a++;
        b = x;
        x /= 10;
    }
}

int solve(string S, int now) {
    int N = 0;
    if (now == S.size()) {
        string count = "";
        for (int i = 0; i < S.size(); i++) {
            if (S[i] == '+') {
                N += stoll(count);
                count = "";
            } else {
                count = count + S[i];
            }
        }
        if (count != "") {
            N += stoll(count);
        }
    } else {
        string R = S;
        R.insert(now, "+");
        //cout << "solve(R, now + 2):" << R << " " << now + 2 << " solve(S, now + 1):" << S << " " << now + 1 << endl;
        N = solve(R, now + 2) + solve(S, now + 1);
    }
    return N;
}

signed main() {
    string S;
    cin >> S;
    cout << solve(S, 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli n,k;  cin>>n>>k;
    vector<lli> dp;
    dp.resize(100010, INT_MAX);
    vector<lli> stones(n);    
    for(auto &x: stones)
    {
        cin>>x;
    }
    dp[0] = 0;
    dp[1] = abs(stones[1] - stones[0]);

    for(int i = 2; i < n; i++)
    {
        for(int j = 1; j<=k; j++)
        {
            if( i - j >= 0)
            {
                dp[i] = min(  abs(stones[i] - stones[i-j]) + dp[i-j] , dp[i] );
            }
        }
    }

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


    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <cctype>
using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int ans=1,tmp=v[0];
    for(int i=1;i<n;i++){
        if(tmp<v[i]){
            ans++;
            tmp=v[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//
// Created by ss250251 on 2/16/2020.
//

#include<bits/stdc++.h>
using namespace std;
#define INF 1e18L + 7
#define MOD 1e9+7
template <typename T>
void max_self(T&a,T b){
    a = max(a,b);
}
template <typename T>
void min_self(T&a,T b){
    a = min(a,b);
}

int main(){
    int n, k;
    cin>>n>>k;
    vector<bool>dp(k+1,0);
    vector<int>vals(n);
    for(int i=0;i<n;i++){
        cin>>vals[i];
    }

    for(int i=1;i<=k;i++){
        for(auto x:vals){
            if(i-x>-1){
                dp[i] = max((int)dp[i],(int)!dp[i-x]);
            }
        }
    }
    cout<<(dp[k]?"First":"Second");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;

int main()
{
  int64_t N, K, init = 0, cnt = 0, ans = 0;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (int i = N - 1; i >= 0; i--)
  {
    for (int j = N - 1; j >= 0; j--)
    {
      if (i == j)
        continue;
      if (A.at(i) > A.at(j) && i < j)
      {
        init++;
        cnt++;
      }
      else if (A.at(i) > A.at(j))
      {
        cnt++;
      }
    }
  }
  for (int i = 0; i < K; i++)
  {
    ans += (init + cnt * i) % MOD;
  }
  cout << ans % MOD << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int l,a[25];

int main(){
	while(cin>>l&&l){
		rep(i,l)cin>>a[i];
		int n=32,cur=0;
		while(n){
			n-=(n-1)%5;
			cout<<n<<endl;
			n-=a[cur++];
			if(cur==l)cur=0;
			if(n<0)n=0;
			cout<<n<<endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define U(i, a, b) for (int i = (a); i <= (b); ++i)
#define D(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
int gi() {
  int f = 1, x = 0; char ch = getchar();
  while (ch < '0' || ch > '9') { if (ch == '-') f = -f; ch = getchar(); }
  while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
  return f * x;
}
typedef long long LL;
typedef pair<int,int> pi;

const int N = 200020;
int n, A[N], cnt[N * 5];
vector<int> di[N * 5];
int main() {
	n = gi();
	for (int i = 1; i <= n; ++i) A[i] = gi(), ++cnt[A[i]];
	for (int i = 1; i <= 1000000; ++i)
		for (int j = i; j <= 1000000; j += i) di[j].push_back(i); 
	
	LL ans = 0;
	for (int i = 1; i <= n; ++i) {
		bool flag = 1; --cnt[A[i]];
		for (int j = 0; j < di[A[i]].size(); ++j) {
			flag &= (!cnt[di[A[i]][j]]);
		}
		if (flag) ++ans;
		++cnt[A[i]];
	}
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 122652
import java.util.*;
public class Main {
  	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      String a[] = new String[N];
      int AC = 0;
      int WA = 0;
      int TLE = 0;
      int RE = 0;
      for (int count = 0; count < N; count++){
  	    a[count] = sc.next();
        if (a[count].equals("AC")){
          AC++;
        } else if (a[count].equals("WA")){
          WA++;
        } else if (a[count].equals("TLE")){
          TLE++;
        } else {
          RE++;
        }
      }
      System.out.println("AC x " + AC);
      System.out.println("WA x " + WA);
      System.out.println("TLE x " + TLE);
      System.out.println("RE x " + RE);
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   int n;cin >>n;
   vector<ll>a(n);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
    }
    sort(all(a));
    ll ans=0;
    if(n%2==1){
        ll now=0;
        for (int i = 0; i < n / 2 - 1; ++i) {
            now-=a[i]*2;
        }
        for (int i =n/2+2; i <n; ++i) {
            now+=a[i]*2;
        }
        now+=a[n/2+1];
        now-=a[n/2-1];
        ans=max(now+a[n/2]-a[n/2-1],now-a[n/2]+a[n/2+1]);
    }
    else {
        ll now=0;
        for (int i = 0; i < n / 2 - 1; ++i) {
            now-=a[i]*2;
        }
        now-=a[n/2-1];
        for (int i =n/2+1; i <n; ++i) {
            now+=a[i]*2;
        }
        now+=a[n/2];
        ans=max(ans,now);
    }
    cout <<ans <<endl;
}


Measured memory_bytes: 4056
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

struct UnionFind {
  std::vector<int> parent;
  int __size;
  UnionFind(int size_) : parent(size_, -1), __size(size_) {}
  void unite(int x, int y) {
    if ((x = root(x)) != (y = root(y))) {
      if (parent[y] < parent[x]) std::swap(x, y);
      parent[x] += parent[y];
      parent[y] = x;
      __size--;
    }
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  int size(int x) { return -parent[root(x)]; }
  int size() { return __size; }
};

int main() {
  int n, k, l;
  cin >> n >> k >> l;

  UnionFind uf1(n);
  for (int i = 0; i < k; i++) {
    int a, b; cin >> a >> b;
    uf1.unite(a-1, b-1);
  }

  UnionFind uf2(n);
  for (int i = 0; i < l; i++) {
    int a, b; cin >> a >> b;
    uf2.unite(a-1, b-1);
  }

  map<pair<int, int>, int> mp;
  for (int i = 0; i < n; i++) {
    mp[make_pair(uf1.root(i), uf2.root(i))]++;
  }

  for (int i = 0; i < n; i++) {
    cout << mp[make_pair(uf1.root(i), uf2.root(i))];
    cout << (i == n-1 ? "\n" : " ");
  }

  return 0;
}

Measured memory_bytes: 13568
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

        public static long d(long sx,long sy,long gx,long gy)
        {
            return Math.Abs(gx - sx) + Math.Abs(gy - sy);
        }
      



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var nk = Reads();
            var n = nk[0];
            var k = nk[1];
            var p = Reads();
           
            var ans = 0.0;
            for (int i = 0; i < k; i++)
            {
                ans += (p[i] + 1) / 2.0;
            }
            var memo=ans;
            for (int j = 0; j < n - k; j++)
            {
                var tmp = memo - (p[j] + 1) / 2.0 + (p[k + j] + 1) / 2.0;
                if (ans < tmp) ans = tmp;
                memo = tmp;
            }
            Console.WriteLine(ans);


            Console.Out.Flush();
        }
    }
}




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

int main(){
	char ss[2][110][111];
	int w,h,i,x,y,loop;
	
	while(~scanf("%d%d",&w,&h)){
		if(w==0 && h==0)break;
		
		memset(ss,0,sizeof(ss));
		
		for(i=0;i<w;i++){
			scanf(" %s ",ss[0][i]);
		}
		
		x=0;
		y=0;
		loop=0;
		ss[1][y][x]=1;
		while(1){
			switch(ss[0][y][x]){
			case '>':
				++x;
				loop=ss[1][y][x];
				ss[1][y][x]=1;
				break;
			case '<':
				--x;
				loop=ss[1][y][x];
				ss[1][y][x]=1;
				break;
			case '^':
				--y;
				loop=ss[1][y][x];
				ss[1][y][x]=1;
				break;
			case 'v':
				++y;
				loop=ss[1][y][x];
				ss[1][y][x]=1;
				break;
			}
			
			if(loop)break;
			if(ss[0][y][x]=='.')break;
		}
		
		if(loop==1){
			printf("LOOP\n");
		}else{
			printf("%d %d\n",x,y);
		}
	}
	return 0;
}

Measured memory_bytes: 0
/** 
 *  Author : Parth Prajapati aka (PARTH_4399, hungry_chef)
 *  Institute : Pandit Deendayal Petroleum University
 **/
#include<bits/stdc++.h>

using namespace std; 

#define start_cooking int main()
#define food_is_ready return 0;
#define main_ingredient_added ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void cook()
{
    // start with your recipe
    long long n, k, powof2 = 1099511627776, cnt, ans = 0;
    int i, j;
    cin>>n>>k;
    vector<long long> a(n), b(n);
    for(i=0;i<n;++i)
    {
        cin>>a[i];
        b[i] = a[i];
    }
    for(i=0;i<41;++i)
    {
        // cnt is count of numbers in array with nth but set
        cnt = 0;
        for(j=0;j<n;++j)
        {
            if(a[j] >= powof2)
            {
                ++cnt;
                a[j] -= powof2;
            }
        }
        // if there are more zeros, set a bit
        // but check whether it doesn't exceed given k
        if(cnt*2 < n && ans+powof2 <= k)
            ans += powof2;
        powof2 /= 2LL;
    }
    //cout<<ans<<" ";
    long long sum = 0;
    for(i=0;i<n;++i)    sum += (ans^b[i]);
    cout<<sum<<"\n";
}

start_cooking
{
    main_ingredient_added
    //int t;
    //cin>>t;
    //while(t--)
        cook();
    food_is_ready
}

Measured memory_bytes: 1792
#include<cstdio>
#include<vector>
#include<algorithm>
#include<climits>
#include<cmath>
using namespace std;
int main(){
    int n,m;
    for(;;){
        scanf("%d%d",&n,&m);
        if(n==0&&m==0)break;
        vector<vector<vector<int> > > mdan(n,vector<vector<int> >(m+1));
        vector<vector<pair<int,int> > > sube(n);
        int ki,x,d;
        for(int i=0;i<n;i++){
            scanf("%d",&ki);
            for(int j=0;j<ki;j++){
                scanf("%d%d",&x,&d);
                sube[i].push_back(make_pair(x,d));
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<=m;j++){
                mdan[i][j]=vector<int>(sube[i].size(),-1);
            }
        }
        for(int j=0;j<sube[0].size();j++){
            mdan[0][0][j]=0;
        }
        if(m>0){
            for(int j=0;j<sube[1].size();j++){
                mdan[1][1][j]=0;
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<sube[i].size();j++){
                if(i==0)mdan[i][0][j]=0;
                if(i>=1){
                    for(int l=0;l<sube[i-1].size();l++){
                        for(int k=0;k<=m;k++){
                            if(mdan[i-1][k][l]!=-1){
                                int newd=mdan[i-1][k][l]+(sube[i-1][l].second+sube[i][j].second)*abs(sube[i-1][l].first-sube[i][j].first);
                                if(mdan[i][k][j]==-1||mdan[i][k][j]>newd)mdan[i][k][j]=newd;
                            }
                        }
                    }
                }
                if(i>=2){
                    for(int l=0;l<sube[i-2].size();l++){
                        for(int k=0;k<=m;k++){
                            if(k>=1&&i>=2&&mdan[i-2][k-1][l]!=-1){
                                int newd=mdan[i-2][k-1][l]+(sube[i-2][l].second+sube[i][j].second)*abs(sube[i-2][l].first-sube[i][j].first);
                                if(mdan[i][k][j]==-1||mdan[i][k][j]>newd)mdan[i][k][j]=newd;
                            }
                        }
                    }
                }
            }
        }
        int mi=INT_MAX;
        for(int l=0;l<sube[n-1].size();l++){
            for(int k=0;k<=m;k++){
                if(mdan[n-1][k][l]!=-1)mi=min(mi,mdan[n-1][k][l]);
            }
        }
        if(n-2>=0){
            for(int l=0;l<sube[n-2].size();l++){
                for(int k=0;k<m;k++){
                    if(mdan[n-2][k][l]!=-1)mi=min(mi,mdan[n-2][k][l]);
                }
            }
        }
        printf("%d\n",mi);
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    set<string> s;
    for (int i = 0; i < n; ++i) {
        string t;
        cin >> t;
        s.insert(t);
    }
    cout << s.size() << "\n";
    return 0;
}

Measured memory_bytes: 19252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;

int main(){ 
  string s;
  cin >> s;
  s += '#';
  int prev = 0;
  int res = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[prev] != s[i]) {
      if (s[prev] == 'R') res = max(res, i - prev);
      prev = i;
    }
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 3596
Public Class Main
    Public Shared Sub Main(ByVal args() As String)
        Dim a, b As Char
        Dim arr(2) As String
        arr = Split(Console.ReadLine())
        a = arr(0) : b = arr(1)
        If Integer.Parse(a) < Integer.Parse(b) Then
            Console.WriteLine(New String(a, Integer.Parse(b)))
        Else
            Console.WriteLine(New String(b, Integer.Parse(a)))
        End If
    End Sub
End Class


Measured memory_bytes: 13408