akhauriyash/Code-Regression huggingface dataset:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    r, g, b = input().split()
    if int(r + g + b) % 4 == 0:
        print("YES")
    else:
        print("NO")
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 61928
(function(stdin) {
  // Define Function
  function Square(width, height) {
    return {
      getArea:function() {return width * height;},
      getPeriphery:function() {return (width + height) * 2;}
    };
  }

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');
  // const cols = Array.from(inputs[0].split(' '), Number);
  const cols = inputs[0].split(' ').map(Number);

  // Main Procedure
  const result = (function(a, b) {
    const square = Square(a, b);
    return [square.getArea(), square.getPeriphery()].join(' ');

  }(cols[0], cols[1]));

  // Display
  console.log(result);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15552
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

typedef struct {
	int a, b;
} edge;

map<pair<int, int>, int> e;

int Search(int n, int p, vector<list<int>>& d, vector<int>& ans) {
	int i = 1, k = ans[e[make_pair(min(n, p), max(n, p))]], num;
	num = d[n].size();
	for (auto itr = d[n].begin(); itr != d[n].end(); itr++) {
		if (*itr == p)
			continue;
		if (i == k)
			i++;
		ans[e[make_pair(min(n, *itr), max(n, *itr))]] = i++;
		num = max(num, Search(*itr, n, d, ans));
	}
	return num;
}

int main(void) {
	int num, i, a, b;
	cin >> num;
	vector<list<int>> d(num + 1);
	vector<int> ans(num - 1);
	for (i = 0; i < num - 1; i++) {
		cin >> a >> b;
		d[a].push_back(b);
		d[b].push_back(a);
		e[make_pair(a, b)] = i;
	}
	cout << Search(1, 0, d, ans) << "\n";
	for (i = 0; i < num - 1; i++) {
		cout << ans[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 17024
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Contests.ABC165
{
    /// <summary>
    /// 
    /// </summary>
    static class D
    {
        static void Main(string[] args)
        {
            var a = NextLong();
            var b = NextLong();
            var n = NextLong();

            var x = Math.Min(n, b - 1);
            Console.WriteLine(a * x / b - a * (x / b));
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 27480
import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7

# nCk % mod
# def modCom(n, k, mod):
#     p, q = 1, 1
#     for i in range(n-k+1, n+1):
#         p = (p * i) % mod
#     for i in range(2, k+1):
#         q = (q * i) % mod
#     return p * pow(q, mod-2, mod) % mod
# 
# X, Y = map(int, input().split())
# l, r = -1, X//2
# while l+1 < r:
#     m = (l+r)//2
#     n = X-2*m
#     if 2*n+m > Y:
#         l = m
#     else:
#         r = m
# m = r
# n = X-2*r
# if 2*m+n == X and m+2*n == Y:
#     print(modCom(n+m, n, MOD))
# else:
#     print(0)


# N = int(input())
# xy = [None]*N
# for i in range(N):
#     x, y = map(int, input().split())
#     xy[i] = (x, y)
# ans = 0
# for vs in itertools.permutations(xy, N):
#     d = 0
#     for v1, v2 in zip(vs, vs[1:]):
#         d += ((v1[0]-v2[0])**2+(v1[1]-v2[1])**2)**0.5
#     ans += d
# for i in range(1, N+1):
#     ans /= i
# print(ans)



# r = int(input())
# print(r*r)


N = int(input())
S = input()
for i in range(N):
    T = S[:i]
    if T + T == S:
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 38384
import numpy as np

N, M, C = [int(x) for x in input().split()]
B = np.array([int(x) for x in input().split()])
A = np.empty((N,M))

count = 0
for n in range(N):
    A[n] = [int(m) for m in input().split()]
    count = count + 1 if sum(A[n] * B)+C > 0 else count 
print(count)


Measured memory_bytes: 12428
use std::io;
use std::io::prelude::*;
use std::io::BufReader;

fn main() {
    let mut x = String::new();
    io::stdin().read_line(&mut x).unwrap();
    let hwk: Vec<usize> = x
        .trim_end()
        .split(' ')
        .map(|s| s.parse().unwrap())
        .collect();
    let h = hwk[0];
    let w = hwk[1];
    let k = hwk[2];
    let mut b: [[i32; 6]; 6] = Default::default();
    let lines = BufReader::new(io::stdin()).split(b'\n').into_iter();
    for (row, line) in b.iter_mut().zip(lines) {
        for (cell, x) in row.iter_mut().zip(line.unwrap()) {
            if x == b'#' {
                *cell = 1;
            }
        }
    }
    let mut ans = 0;
    for i in 0..1 << h {
        // 行を消すパターン
        for j in 0..1 << w {
            //　列を消すパターン
            let mut cnt = k as i32;
            for r in 0..h {
                if (i >> r) & 1 == 0 {
                    // 第rビットがゼロ
                    for c in 0..w {
                        if (j >> c) & 1 == 0 {
                            // 第cビットがゼロ
                            cnt -= b[r][c];
                        }
                    }
                }
            }
            if cnt == 0 {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2120
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        String result = a * b % 2 == 0 ? "Even" : "Odd";

        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */

/* main */

signed main() {
    int N;
    cin >> N;
    ll x[N], y[N];
    FOR(i, 0, N) {
        cin >> x[i] >> y[i];
    }
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }
    ll ans = 0;
    FOR(i, 0, N) {
        FOR(j, i + 1, N) {
            ll p = x[j] - x[i];
            ll q = y[j] - y[i];
            ll counter = 0;
            FOR(k, 0, N) {
                FOR(l, 0, N) {
                    if (x[l] - x[k] == p && y[l] - y[k] == q) {
                        counter += 1;
                    }
                }
            }
            ans = max(ans, counter);
        }
    }
    cout << N - ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N,K;
int main(){
  cin>>N>>K;
  prin((K!=1?N-K:0));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

map<int, P> mp;

signed main() {
    int n, x, m, ans = 0, ki = 0;
    cin >> n >> x >> m;

    while(1) {
        ki++;
        if(mp[x].second) {
            P p = mp[x];
            int plus = ans - p.first;
            int hab = ki - p.second;

            ans += ((n - ki) / hab) * plus;
            ki += hab * ((n - ki) / hab);
        }
        mp[x] = P(ans, ki);
        ans += x;
        x *= x;
        x = x % m;
        if(ki == n) break;
    }

    cout << ans << endl;
}


Measured memory_bytes: 6676
import itertools
import math
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
 

ans = sum(b)
for i in range(n-1):
    ind = a[i] - 1
    ind_next = a[i+1] - 1
    if ind + 1 == ind_next:
        ans += c[ind]
print(ans)
"""
for i in range(len(a)):
    #print(type(a[i]))
    sum+=int(b[int(a[i])-1])

    if a[i]==int(a[i-1])+1:
        sum+=int(c[int(a[i])-1])
        
print(sum)

"""

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

N, D, a = [int(x) for x in input().split()]
XH = []
for _ in range(N):
    XH.append([int(x) for x in input().split()])
XH.sort()

#####segfunc######
def segfunc(x,y):
    return x + y

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#入力
n = N
A = [0] * N

#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

#init
init(A)

import bisect

X = []
H = []
for i in XH:
    X.append(i[0])
    H.append(i[1])
ans = 0
for i in range(N):
    x, h = X[i], H[i]
    idx_left = bisect.bisect_left(X, x - 2 * D)
    idx_right = i
    tmp = query(idx_left, idx_right)
    if tmp < h:
        h -= tmp
        cnt = h // a + int(h % a != 0)
        ans += cnt
        update(i, a * cnt)
print(ans)
        


Measured memory_bytes: 107356
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << ((std::abs(a - b) <= d && std::abs(b - c) <= d) ||
                     std::abs(a - c) <= d
                 ? "Yes"
                 : "No")
         << endl;

    return 0;
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;

	ll ans =1LL;
	rep2(i, 1, n+1) (ans *= i) %=MD;
	rep2(i, 1, m+1) (ans *= i) %=MD;
	
	if((n+m+1)% 2) (ans *= 2)%=MD;
	if(abs(n-m) >1) ans =0;
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
def read():
    return stdin.readline().strip()

dict={}
output=[]

iteration=int(read())

max_val=-1

for _ in range(iteration):
    item=read()
    
    if dict.get(item) is None:
        dict[item]=0 
    dict[item]+=1 
    max_val = max(dict[item],max_val)
#max_val=max(dict.values())
for k,v in dict.items():
    
    if(max_val==v):
        output.append(k)
    
    
output.sort()
print('\n'.join(output))


Measured memory_bytes: 36676
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m,r;
vi a;
vvi g;

int main(){
	cin>>n>>m>>r;
	a=vi(r);
	g=vvi(n,vi(n,inf));
	for(int i=0;i<n;i++) g[i][i]=0;
	for(int i=0;i<r;i++){
		cin>>a[i];
		a[i]--;
	}
	for(int i=0;i<m;i++){
		int A,B,C;
		cin>>A>>B>>C;
		A--;B--;
		g[A][B]=C;
		g[B][A]=C;
	}
	for(int k=0;k<n;k++) for(int i=0;i<n;i++) for(int j=0;j<n;j++) g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
	vi p(r);
	for(int i=0;i<r;i++) p[i]=i;
	ll res=INF;
	do{
		ll tmp=0;
		for(int i=1;i<r;i++) tmp+=g[a[p[i]]][a[p[i-1]]];
		res=min(res,tmp);
	}while(next_permutation(p.begin(),p.end()));
	cout<<res<<endl;
}

Measured memory_bytes: 384
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READAR(A,N);
    ll neg=0;
    FORI(i,0,N)
    {
        if(A[i]<0)
        {
            neg++;
        }
    }
    if(neg%2==0)
    {
        ll ans=0;
        FORI(i,0,N)
        {
            ans+=abs(A[i]);
        }
        cout<<ans<<endl;
    }
    else
    {
        ll ans=0;
        ll mn=inf;
        FORI(i,0,N)
        {
            ans+=abs(A[i]);
            if(abs(A[i])<mn)
            {
                mn=abs(A[i]);
            }
        }
        cout<<ans-2*mn<<endl;
    }
    

//-----------------------------------------------------------------------------------------------------------//


   
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

using namespace std::chrono;

int main(void)
{
    IOS
    const int A = 26;
    const int M = 1e3;
    const int TL = 1700;
    auto stime = system_clock::now();
    int D; cin >> D;
    vector<int> c(A);
    REP(i,A) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(A));
    REP(i,D) REP(j,A) cin >> s[i][j];

    vector<int> last(A,-1);
    vector<int> ans(D);
    REP(i,D) {
        int mx = 0,a = -1;
        REP(j,A) {
            int tmp = (i-last[j])*c[j] + s[i][j];
            if (mx < tmp) {
                mx = tmp;
                a = j;
            }
        }
        ans[i]=a;
        last[a] = i;
    }
    auto calc = [&](const vector<int> &a){
        vector<int> l(A,-1);
        int score = 0;
        REP(i,D) {
            score += s[i][a[i]];
            l[a[i]] = i;
            REP(j,A) {
                score -= c[j]* (i-l[j]);
            }
        }
        return score;
    };

    int maxscore = calc(ans);

    random_device seed_gen;
    mt19937 engine(seed_gen());
    while(true) {
        auto time = system_clock::now();
        int t = duration_cast<milliseconds>(time-stime).count();
        if (t >= TL) break;

        REP(_,M) {
            vector<int> a(ans);
            a[engine()%D] = engine() % A;
            int tmp = calc(a);
            if (maxscore < tmp) {
                swap(ans,a);
                maxscore = tmp;
            }
        }
    }

    REP(i,D) OUT(ans[i]+1)

    return 0;
}

Measured memory_bytes: 3696
#include<stdio.h>

int isPrime(int x){
  int i;
  if(x < 2) return 0;
  else if(x == 2) return 1;
  if(x % 2 == 0) return 0;
  for(i=3; i*i<=x; i+=2){
    if(x%i == 0) return 0;
  }
  return 1;
}

int main(){
  int n, x, i;
  int cont = 0;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%d", &x);
    if(isPrime(x)) cont++;
  }
  printf("%d\n", cont);

  return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  bool sep[9] = {};
  string s;
  cin >> s;

  ll sum = 0;
  int rank = s.size();
  rank--;
  int pattern = (int)pow(2, rank);
  for(int i = 0; i < pattern; i++) {
    int tp = i;
    for(int j = 0; j < rank; j++) {
      sep[j] = (tp%2 == 1);
      tp /= 2;
    }
    ll crr = 0;
    for(int j = 0; j <= rank; j++) {
      crr += s[j] - '0';
      if(sep[j]){
        sum += crr;
        crr = 0;
      }else{
        crr *= 10;
      }
    }
    crr /= 10;
    sum += crr;
  }
  cout << sum << endl;
}

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

int dis2(int ax,int ay, int bx, int by){
  return (ax-bx)*(ax-bx) + (ay-by)*(ay-by);
}

int main(){
  int an,bn,r,ans;
  vector<int> ax[250][250],ay[250][250];
  int x,y,bx,by;
  int dx[] = {0,0,1,1,1,0,-1,-1,-1}, dy[] = {0,-1,-1,0,1,1,1,0,-1};

  while(scanf("%d %d %d",&an,&bn,&r), an||bn||r){
    for(int i=0;i<250;i++)
      for(int j=0;j<250;j++){
	ax[i][j].clear();
	ay[i][j].clear();
      }

    for(int i=0;i<an;i++){
      scanf("%d %d",&x,&y);
      ax[x/40][y/40].push_back(x);
      ay[x/40][y/40].push_back(y);
    }

    ans = 0;
    for(int i=0;i<bn;i++){
      scanf("%d %d",&bx,&by);
      for(int i=0;i<9;i++){
	x = bx/40+dx[i]; y= by/40+dy[i];
	if(x<0 || y<0 || 250<=x || 250<=y)continue;
	for(int j=0;j<(int)ax[x][y].size();j++){
	  if(dis2(ax[x][y][j],ay[x][y][j],bx,by) <= 16*r*r)ans++;
	}
      }
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 4756
(function () {
  var input = '';
  
  function main () {
    var i,
        inputLen,
        inputContent,
        BookIndex = {};

    inputLen = input.length - 1;
    
    for (i = 0; i < inputLen; i += 1) {
      inputContent = input[i].split(' ');

      if (BookIndex.hasOwnProperty(inputContent[0])) {
        BookIndex[inputContent[0]].push(inputContent[1]);
        BookIndex[inputContent[0]].sort(sortNum);
      } else {
        BookIndex[inputContent[0]] = [];
        BookIndex[inputContent[0]].push(inputContent[1]);
      }
    }

    BookIndex = sortHash(BookIndex);

    for (var prop in BookIndex) {
      console.log(prop);
      console.log(concatenateArrayElem(BookIndex[prop]));
    }
  }

  // Array.sortでの数値昇順化のための比較関数
  function sortNum (a, b) {
    return a - b;
  }

  // 連想配列の辞書順化
  function sortHash (hash) {
    var i,
        keysLen,
        keys = [],
        sortedHash = {};
    
    for (var k in hash) {
      keys.push(k);
    }
    
    keys.sort();
    keysLen = keys.length;

    for (i = 0; i < keysLen; i += 1) {
      sortedHash[keys[i]] = hash[keys[i]];
    }

    return sortedHash;
  }
  
  function concatenateArrayElem(ary) {
    var i,
        resultStr = '',
        len = ary.length;

    for (i = 0; i < len; i += 1) {
      resultStr += ary[i];

      if (i != len - 1) {
        resultStr += ' ';
      }
    }

    return resultStr;
  }

  
  process.stdin.resume();
  process.stdin.setEncoding('utf8');
  process.stdin.on('data', function (chunk) {
    input += chunk;
  });

  process.stdin.on('end', function () {
    input = input.split('\n');
    main();
  });
}());

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

int main() {
  string s,comp;
  comp = "yes";
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= s.size(); j++) {
      if (s[i] == s[j+i]) {
        comp = "no";
        break;
      }
    }
  }
  cout << comp << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  char s[100000+1];
  scanf("%s", s);

	int red = 0;
	int blue = 0;
	for (int i = 0; i < 100000+1; i++) {
		if (s[i] == '0') {
			red++;
		} else if (s[i] == '1') {
			blue++;
		} else {
			break;
		}
	}
	int answer = red;
	if (blue < red) {
		answer = blue;
	}
	answer *= 2;

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

  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() {
			while(st==null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch(IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static void main(String[] args) {
		FastReader ob = new FastReader();
		int arr[] =new int[3];
		arr[ob.nextInt()-1] = 1;
		arr[ob.nextInt()-1]= 1;
		for (int i = 0; i < arr.length; i++) {
			if(arr[i]==0) {
				System.out.println(i+1);
				break;
			}
		}
	}

}


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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; ++i) cin >> d[i];
  int num[999] = {0};
  for(int i = 0; i < n; ++i){
	  ++num[d[i]];
  }
  int res = 0;
  for(int i = 1; i <= 100; ++i){
	  if(num[i]){
		  ++res;
	  }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto a = readln.chomp.split.to!(int[]);
  sort(a);
  if (a.uniq.array.length == 2) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}


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

int main(void){
   int i;
   char S[11];//10
   char T[12];//11

  scanf("%s",S);
  scanf("%s",T);
  
  int lenS = strlen(S);
  int lenT=strlen(T);

  for(i=0;S[i]!='\0';i++){
     if(S[i]!=T[i]){
        printf("No\n");
        return 0;
     }
  }
  if(T[i+1]=='\0'){
     printf("Yes\n");
  }else{
     printf("No\n");
     return 0;
}
}

Measured memory_bytes: 1656
#include <stdio.h>
int main() {
	int n, a, x[100000], y[100000];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		if (i % 2 == 0) {
			x[i / 2] = a;
		} else {
			y[(i - 1) / 2] = a;
		}
	}
	if (n % 2 == 0) {
		for (int i = n / 2 - 1; i >= 0; i--) {
			printf("%d ", y[i]);
		}
		for (int i = 0; i < n / 2; i++) {
			printf("%d ", x[i]);
		}
	} else {
		for (int i = n / 2; i >= 0; i--) {
			printf("%d ", x[i]);
		}
		for (int i = 0; i < n / 2; i++) {
			printf("%d ", y[i]);
		}
	}
	return 0;
}

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

int a,b,c;
int main() {
  cin>>a>>b>>c;
  if(a<b){
      if(a<c){
          if(b<c){
              cout<<c-a<<"\n";
          }else{
              cout<<b-a<<"\n";
          }
      }else{
          cout<<b-c<<"\n";
      }
  }else{
      if(a<c){
          cout<<c-b<<"\n";
      }else{
          if(b>c){
              cout<<a-c<<"\n";
          }else{
              cout<<a-b<<"\n";
          }
      }
  }
}

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

void Print(const vector<double>& xs) {
  for (int i = 0; i < xs.size(); ++i) {
    cout << 0.5 * i << ": " << xs[i] << endl;
  }
}

int main() {
  int N;
  cin >> N;
  vector<int> t(N, -1), v(N, -1);
  vector<double> v_max, v_left, v_right;
  for (int i = 0; i < N; ++i) cin >> t[i];
  for (int i = 0; i < N; ++i) cin >> v[i];
  v_max.push_back(v[0]);
  for (int i = 0; i < N; ++i) {
    if (i >= 1)
      *--v_max.end() = min(v[i - 1], v[i]);
    for (int j = 0; j < t[i]; ++j) {
      v_max.push_back(v[i]);
      v_max.push_back(v[i]);
    }
  }
  v_left = v_max;
  double velocity = 0;
  for (int time = 0; time < v_left.size(); ++time) {
    if (v_left[time] >= velocity) {
      v_left[time] = velocity;
      if (time + 1 < v_left.size() && v_left[time + 1] > velocity)
        velocity += 0.5;
    } else {
      velocity = v_left[time];
    }
  }
  v_right = v_left;
  velocity = 0;
  for (int time = v_right.size() - 1; time >= 0; --time) {
    if (v_right[time] >= velocity) {
      v_right[time] = velocity;
      if (time - 1 >= 0 && v_right[time - 1] > velocity)
        velocity += 0.5;
    } else {
      velocity = v_right[time];
    }
  }
  double sum = 0;
  for (auto x : v_right) {
    sum += 0.5 * x;
  }
  cout << setprecision(17) << sum << endl;
}


Measured memory_bytes: 1272
import numpy as np

H,W = map(int,input().split())
# 周りに壁を、0,1化、壁をTrueで持つ
grid = np.ones((H+2,W+2),dtype=np.bool)
grid[1:-1,1:-1] = (np.array([list(input()) for _ in range(H)]) == '#')

# x軸方向の集計
def F(transpose):
  x = grid
  if transpose:
    x = x.T
  x = np.ravel(x) # to 1D array
  
  zero_idx = np.nonzero(x)[0]
  zero_span = np.diff(zero_idx) - 1 # 次の0までにある1の個数
  
  y = np.zeros(x.shape[0],dtype=np.int32)
  y[1:][zero_idx[:-1]] = zero_span # 1の個数の加算の起点
  y[zero_idx[1:]] -= zero_span # 1の個数の反映をやめる
  np.cumsum(y, out = y)
  if transpose:
    y = y.reshape(grid.T.shape).T
  else:
    y = y.reshape(grid.shape)
  return y

answer = (F(True) + F(False)).max() - 1
print(answer)

Measured memory_bytes: 145676
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int H = sc.nextInt(), N = sc.nextInt();

        int sum = 0;
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            sum += a;
        }

        if (sum >= H) {
            out.println("Yes");
        } else {
            out.println("No");
        }

        out.close();
    }


    public static PrintWriter out;

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}


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

int main(){
 int N,M;
 cin>>N>>M;
 int tmp;
 if(N == 1){
     int K;
   cin>>K;
   cout<<K;
 }
 else{
     vector <int> A;
for(int i = 0;i < N;i++){
   int K;
   cin>>K;
   for(int j = 0;j < K;j++){
       cin>>tmp;
       A.push_back(tmp);
   }
}
   int C,result = 0;
 for(int i = 1;i < M+1;i++){
    C = count(A.begin(),A.end(),i);
     if(C == N) result++;
 }
 cout<<result;
}
return 0;
 }


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String x = sc.next();
        long X = Long.parseLong(x);
        long sum = 100;
        for(int i = 1; i <= 4000; i++){
          sum = sum + (long)(sum * 0.01);
          if(sum >= X){
            System.out.println(i);
            break;
          }
        }  
    }
}

Measured memory_bytes: 35716
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
def solve(cnt,current_sum):
    for i in range(n-1):
        if current_sum * (current_sum + a[i+1]) < 0:#符号が違う
            current_sum += a[i+1]
            cnt += 0#そのまま
        elif current_sum < 0:
            cnt += 1 - (current_sum + a[i+1])
            current_sum = 1 
        else:
            cnt += (current_sum + a[i+1]) +1 
            current_sum = -1
    return cnt
if a[0] > 0:
    print(min(solve(0,a[0]),solve(1+abs(a[0]),-1)))
elif a[0] < 0:
    print(min(solve(0,a[0]),solve(1+abs(a[0]),1)))
else:
    print(min(solve(1,1),solve(1,-1)))


Measured memory_bytes: 14468
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

int H,W,K;
char c[6][6];

int main()
{
    int i, j,ans=0;
    cin >> H >> W >> K;
    rep0(i, H) rep0(j,W) cin >>c[i][j];

    int bh,bw,count;
    rep0(bh,1<<H) rep0(bw,1<<W){
        count=0;
        rep0(i,H)rep0(j,W){
            if(((1<<i)&bh) && ((1<<j)&bw) && c[i][j]=='#')
            count++;
        }
        //cout<<count<<endl;
        if(count==K)ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
import sys
import heapq

V, E, r = map(int, sys.stdin.readline().strip().split())

G = [[] for _ in range(V)]
for e in range(E):
    s, t, d = map(int, sys.stdin.readline().strip().split())

    G[s].append((t, d))
    # G[t].append((s, d))


distance = ['INF'] * V  # 何らかの数値: 探索済み  INF: 未探索
distance[r] = 0
que = []

for u, d_u in G[r]:
    heapq.heappush(que, (d_u, u))

while que:
    d_tot, u = heapq.heappop(que)
    if distance[u] is not 'INF':
        continue

    distance[u] = d_tot
    for v, d_v in G[u]:
        if distance[v] is not 'INF':  # v にすでに訪問済みであった場合
            continue
        heapq.heappush(que, (d_tot + d_v, v))

for i in distance:
    print(i)


Measured memory_bytes: 96224
#include <bits/stdc++.h>
using namespace std ;
int n;
int m;
int mb[110000];
int dis[110000];
int v[110000];
int d[110000];
int c[110000];
struct KT
{
	int y;
	int next;
}f[210000];
int len;
int lin[210000];
void DJ(int xx,int yy)
{
	f[++len].next=lin[xx];
	f[len].y=yy;
	lin[xx]=len;
}
void KT(int x,int ys,int jl)
{
	if(!mb[x]) 
	mb[x]=ys;
	if(!jl||dis[x]>=jl) 
	return ;
	dis[x]=jl;
	for(int i=lin[x];i;i=f[i].next)
	{
		int y=f[i].y;
		KT(y,ys,jl-1) ;
	}
}
int q;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u;
		int v;
		cin>>u>>v;
		DJ(u,v);
		DJ(v,u);
	}
	cin>>q;
	for(int i=1;i<=q;i++) 
	{
		cin>>v[i]>>d[i]>>c[i];
	}
	
	for(int i=q;i>=1;i--) 
	{
		KT(v[i],c[i],d[i]);
	}
	for(int i=1;i<=n;i++) 
	{
		cout<<mb[i]<<endl;
	}
	return 0;
}

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


#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";

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



template <class T> inline T biton(T n, T pos)
{
    return n | ((T)1 << pos);
}
template <class T> inline T bitoff(T n, T pos)
{
    return n & ~((T)1 << pos);
}
template <class T> inline T ison(T n, T pos)
{
    return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b)
{
    while (b)
    {
        a = a % b;
        swap(a, b);
    }
    return a;
}
template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
};

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

bool prime(long long n){

    for(int i=2;i*i<=n;i++){

        if(n%i==0){
            return false;
        }
    }

    return true;

}

void solve()
{
   long long x;
   cin>>x;

   while(true){
     if(prime(x)){
        cout<<x<<endl;
        return;
     }
     x++;
   }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    cout.tie(nullptr);
    cin.tie(nullptr);


    int t = 1;

    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;


public class Main {

	public static String encodeByAffin(int a, int b, String str) {
		StringBuilder sb = new StringBuilder();
		int l = str.length();
		for (int i = 0 ; i < l ; i++) {
			char c = str.charAt(i);
			if (c == ' ') sb.append(' ');
			else {
				char cp = (char) ((a*(c-97)+b)%26 + 97);
				sb.append(cp);
			}
		}
		return sb.toString();
	}

	public static String decodeAffin(int a, int b, String crypt) {
		char[] table = new char[123];
		for (int i = 97 ; i < 123 ; i++) {
			table[(char) ((a*(i-97)+b)%26 + 97)] = (char) i;
		}
		int l = crypt.length();
		StringBuilder sb = new StringBuilder();
		for (int i = 0 ; i < l ; i++) {
			char c = crypt.charAt(i);
			if (c == ' ') sb.append(' ');
			else sb.append(table[c]);
		}
		return sb.toString();
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Main m = new Main();

		List<Integer> alphas = Arrays.asList(1,3,5,7,9,11,15,17,19,21,23,25);
		List<Integer> betas = Arrays.asList(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25);


		int N = Integer.parseInt(br.readLine());
		for (int i = 0 ; i < N ; i++) {
			String crypt = br.readLine();
			int alpha = 0, beta = 0;
			LOOP: for (int a : alphas) {
				for (int b : betas) {
					String THIS = encodeByAffin(a, b, "this");
					String THAT = encodeByAffin(a, b, "that");
					if (crypt.contains(THIS) || crypt.contains(THAT)) {
						//System.out.println("a:"+a+" b:"+b);
						alpha = a; beta = b;
						break LOOP;
					}
				}
			}
			System.out.println(decodeAffin(alpha, beta, crypt));
		}

	}

}

Measured memory_bytes: 19152
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

class UnionFind
{   
public:
    static const int N_MAX = 1000000;
    int par[N_MAX];
    int n;
    
    UnionFind(int n)
        : n{n}
    {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
        }
    }
    
    void init()
    {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
        }
    }

    int root(int x)
    {
        if (par[x] == x) {
            return x;
        }
        return par[x] = root(par[x]);
    }
    
    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    
    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) {
            return;
        }
        par[ry] = root(x);
        return;
    }
    
    int groups()
    {
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            if (root(i) == i)
            ++cnt;
        }
        return cnt;
    }
};

int main()
{
        ll N, M;
        cin >> N >> M;
        UnionFind uf(N);
        rep(i, 0, M) {
                ll x, y, z;
                cin >> x >> y >> z;
                uf.unite(x-1, y-1);
        }
        cout << uf.groups() << endl;
}

Measured memory_bytes: 768
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int f = -1; int l = -1;
		for (int i=0; i<s.length(); i++) {
			if (s.charAt(i) == 'A' &&f < 0 ) f = i;
			if (s.charAt(i) == 'Z') l = i;
		}
		System.out.println(l+1-f);
	}
}


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

int Prime_n(int a,int d,int n){
  
  int cnt=0;
  bool isPrime;
  
  while(1){
    
    isPrime=true;
    
    if(a==1){
      isPrime=false;
    }else{
      REP(i,2,sqrt(a)){
	if(a%i==0){
	  isPrime=false;
	  break;
	}
      }
    }
    
    if(isPrime)cnt++;
    
    if(cnt==n)return a;
    
    a+=d;
    
  }
  
}
int main(){
  
  int a,d,n;

  while(1){
    cin >>a>>d>>n;
    if(a==0 && d==0 && n==0)break;  
    cout <<Prime_n(a,d,n)<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
n = int(input())
arr = [0 for x in range(n)]
sq = int(n ** 0.5)
for i in range(1, sq+1):
    for j in range(1, sq+1):
        for k in range(1, sq+1):
            ans = i ** 2 + j ** 2 + k ** 2 + i * j + j * k + k * i
            if ans <= n:
                arr[ans-1] += 1
for i in arr:
    print(i)


Measured memory_bytes: 9624
#include <iostream>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int ans[4] = {0,0,0,0};
  for(int i=0; i<n; ++i){
    string s;
    cin >> s;
    if(s == "AC"){
      ans[0]++;
    }
    if(s == "WA"){
      ans[1]++;
    }
    if(s == "TLE"){
      ans[2]++;
    }
    if(s == "RE"){
      ans[3]++;
    }
  }
  cout << "AC x " << ans[0] << endl;
  cout << "WA x " << ans[1] << endl;
  cout << "TLE x " << ans[2] << endl;
  cout << "RE x " << ans[3] << endl;
  return 0;
}


Measured memory_bytes: 3228
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <queue>
//#include <iostream>
//#include <sstream>
using namespace std;
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)
#define deb(x) cout << #x" = " << x << '\n'
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
//bitmask
int onbit(int x, int pos) {x |= (1 << pos); return pos;}
int offbit(int x, int pos) {x &= ~(1 << pos); return x;}
int test(int x, int pos) {return x & (1 << pos);}
int flip(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
int onbitall(int x, int pos) {x = (1 << pos)-1; return x;}
//constants
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
//moves
const int dx1[] = {0, 1, 0, -1};
const int dy1[] = {1, 0, -1, 0};
const int dx2[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy2[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
//    freopen("input.in", "r", stdin);
	int r;
	sf("%d", &r);
	if(r < 1200) puts("ABC");
	else if (r < 2800) puts("ARC");
	else puts("AGC");
	return 0;
}

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

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int V[N],C[N];
	int index = 0;
	while(cin >> V[index])
    {
      index++;
      if(index == N) break;
    }
	index = 0;
	while(cin >> C[index])
    {
      index++;
      if(index == N) break;
    }
	int total = 0;
	for(int i = 0;i <N;i++)
    {
    	if(V[i]-C[i] > 0) total+=V[i]-C[i];
    }
	cout << total << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b,t[5],i,j,x,k,ans=0;
scanf("%d %d",&a,&b);
for(i=a;i<=b;i++){
x=0;k=i;
for(j=10000;j>0;j/=10){
t[x]=(k-(k%j))/j;
k-=(t[x]*j);
x++;
}
if(t[0]==t[4]&&t[1]==t[3])ans++;
}
printf("%d",ans);
return 0;
}

Measured memory_bytes: 128
N, M = map(int,input().split())
s = [list(map(int,input().split())) for k in range(N)]
p = [list(map(int,input().split())) for k in range(M)]
ans = []
for e in s:
    temp = float("inf")
    u = 0
    for k in range(M):
        if temp > abs(e[0]-p[k][0]) + abs(e[1]-p[k][1]):
            temp = abs(e[0]-p[k][0]) + abs(e[1]-p[k][1])
            u = k+1
    ans.append(u)
print(*ans,sep="\n")


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

using namespace std;

int main(){
  long long n;
  cin>>n;
  vector<int> count(100001,0);
  vector<int> v(n);
  long long sum=0;
  for(auto i:v){
    cin>>i;
    sum+=i;
    count[i]++;
  }
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int b,c;
    cin>>b>>c;
    count[c]+=count[b];
    sum+=(c-b)*count[b];
    count[b]=0;
      cout<<sum<<endl;
  }

  
  return 0;
}


Measured memory_bytes: 4052