akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M; cin >> N >> M;
    vvl out(N); vl incnt(N, 0);
    REP(i, N-1+M){
        ll a, b; cin >> a >> b; a--; b--;
        out[a].pb(b);
        incnt[b]++;
    }
    
    vl root(N, -LINF);
    queue<ll> st;
    REP(i, N){
        if(incnt[i] == 0){
            st.push(i); root[i] = -1;
        }
    }
    
    vl ans;
    while (!st.empty()) {
        ll now = st.front(); st.pop();
        ans.pb(now);
        for(ll to : out[now]){
            incnt[to]--;
            if(incnt[to] == 0){
                st.push(to);
                root[to] = now;
            }
        }
    }
    
    REP(i, N){
        cout << root[i]+1 << endstr;
    }
    return 0;
}


Measured memory_bytes: 8820
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int i;
    int v[n];
    for (i=0;i<n;i++) {
        int a;
        int b;
        cin >> a;
        b = n-i-1;
        v[b] = a;
    }
    cout << v[0];
    for (i=1;i<n;i++) {
        cout << " " << v[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define int long long  
const int MODN=1e9+7;
const int MAXN=1e5+10;
using namespace std;
/* Iterative Function to calculate (x^y)%p in O(log y) */
int quick_pow(int x, unsigned int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
vector<int> fact(MAXN,1);
int C(int n,int r){
	// cerr<<n<<" "<<r<<endl;
	int a=fact[n];int b=fact[n-r]*fact[r];
	return a*quick_pow(b,MODN-2,MODN)%MODN;
}
int modn(int a,int b){
	return ((a % b) + b) % b;
}
int32_t main(){
	int n,k;cin>>n>>k;
	vector<int> arrmv(n+1);
	for(int i=1;i<=n;i++)cin>>arrmv[i];
	sort(next(arrmv.begin(),1),arrmv.end());
	
	for(int i=1;i<=n+1;i++){
		fact[i]=i*fact[i-1];
		fact[i]%=MODN;
		// cerr<<fact[i]<<endl;
	}
	int maxsum=0;
	for(int i=k;i<=n;i++){
		// cerr<<arrmv[i]<<" "<<
		maxsum+=arrmv[i]*C(i-1,k-1);
		maxsum%=MODN;
	}
	int minsum=0;
	for(int i=1;i<=n-(k-1);i++){
		minsum+=arrmv[i]*C(n-i,k-1);
		minsum%=MODN;
	}
	
	cout<<modn((maxsum-minsum),MODN)<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans;
long long s[10];
char str[50];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",&str);
		if(str[0]=='M') s[1]++;
		if(str[0]=='A') s[2]++;
		if(str[0]=='R') s[3]++;
		if(str[0]=='C') s[4]++;
		if(str[0]=='H') s[5]++;
	}
	for(int i=1;i<=5;i++)
	for(int j=i+1;j<=5;j++)
	for(int k=j+1;k<=5;k++)
	ans+=(long long)s[i]*s[j]*s[k];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
def resolve():
    N, M = [int(i) for i in input().split()]
    path = [[] for _ in range(N)]
    for _ in range(M):
        A, B = [int(i) for i in input().split()]
        path[A - 1].append(B - 1)
        path[B - 1].append(A - 1)
    visited = [-1] * N
    que = [0]
    visited[0] = 0

    while que:
        v = que.pop(0)
        for nv in path[v]:
            if visited[nv] != -1:
                continue
            visited[nv] = v + 1
            que.append(nv)

    if -1 in visited:
        print("No")
    else:
        print("Yes")
        for i in range(N - 1):
            print(visited[i + 1])


resolve()


Measured memory_bytes: 36540
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
  ll x,y;
  cin >> x >> y;
  
  ll ans = 0;
  ll nx = x;
  while(nx <= y){
    nx *= 2;
    ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}

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

const int N = (int) 2e5 + 5;

int n, k;
long long a[N], s[N];
map <long long, long long> remain;

int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		s[i] = s[i - 1] + a[i];
	}
	remain[s[0] - 0]++;
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i - k >= 0) remain[(s[i - k] - (i - k)) % k]--;
		ans += remain[(s[i] - i) % k]++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k; cin >> n >> k;
  vector<int> a(n); for(int & i : a) cin >> i;
  vector<bool> is_winning(k + 1, false);
  for(int i = 1; i <= k; i++){
    for(int j : a) if(j <= i && !is_winning[i - j]) is_winning[i] = true;
  }
  if(is_winning[k]) cout << "First" << endl;
  else cout << "Second" << endl;
  return 0;
}

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

int main(){
  long long N,M;
  cin>>N>>M;
  vector<long long>x(N),y(N),z(N);
  vector<long long>ans(N);
  long long maxans=0;

  for(int i=0;i<N;i++){
    cin>>x[i]>>y[i]>>z[i];
  }
  for(int si=0;si<8;si++){
    int a,b,c;
    if(si>>0&1) a = 1;
    else a = -1;
    if(si>>1&1) b = 1;
    else b = -1;
    if(si>>2&1) c = 1;
    else c = -1;
    
  
    for(int i=0;i<N;i++){
      ans[i] = a*x[i] + b*y[i] + c*z[i];
    }
    sort(ans.rbegin(),ans.rend());
    long long sum = 0;
    for(int i=0;i<M;i++){
        sum+=ans[i];
    }
    maxans=max(maxans,sum);
  }
  cout<<maxans<<endl;
  
  return 0;
}

  
    

Measured memory_bytes: 3640
def main():
    h, w, k = map(int, input().split())
    grid = [input() for _ in [0]*h]
    cnt = 0
    for i in range(2**h):
        yoko = []
        for t in range(h):
            if (i >> t) & 1:
                yoko.append(t)
        for j in range(2**w):
            tate = []
            for t in range(w):
                if (j >> t) & 1:
                    tate.append(t)
            red = [[0]*w for _ in [0]*h]
            for t in yoko:
                for l in range(w):
                    red[t][l] = 1
            for t in tate:
                for l in range(h):
                    red[l][t] = 1
            ans = 0
            for t in range(h):
                for t2 in range(w):
                    if red[t][t2] == 0 and grid[t][t2] == "#":
                        ans += 1
            if ans == k:
                cnt += 1
    print(cnt)


main()


Measured memory_bytes: 9240
#include <iostream>

using namespace std;

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

    for (int i=1; i<10; i++) {
        if (n % i == 0) {
            if (n / i < 10) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  char s[H][W];
  REP(h,H)REP(w,W)cin>>s[h][w];
  vector<vector<int> > dp(H,vector<int>(W,1e9));
  dp[0][0]=s[0][0]=='#';
  REP(h,H){
    REP(w,W){
      if(h<H-1)dp[h+1][w]=min(dp[h+1][w],dp[h][w]+(s[h][w]=='.' and s[h+1][w]=='#'));
      if(w<W-1)dp[h][w+1]=min(dp[h][w+1],dp[h][w]+(s[h][w]=='.' and s[h][w+1]=='#'));
    }
  }
  cout<<dp[H-1][W-1]<<endl;
  return 0;
}


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

using namespace std;

int main(int argc, char* argv[]){
    int A, B, C;
    cin >> A >> B >> C ;

    if((A < C && C < B ) || (A  > C  &&  C > B)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int l, r, d, ans=0;
    cin >> l >> r >> d;
    for(int i=l; i<=r; ++i){
        if (i%d==0)ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3628
n,k = map(int,input().split())
b = [bi-1 for bi in list(map(int,input().split()))]
a = 0

f = [0]*n
c = 1
for i in range(k):
    if f[a]:
        k %= c-f[a]
        for i in range(k):
            a = b[a]
        print(a+1)
        break
    f[a] = c
    k -= 1
    c += 1
    a = b[a]
else:
    print(a+1)

Measured memory_bytes: 32336
#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>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define mod   998244353
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define endl "\n"
    #define pii pair<ll,ll>
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    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;

/**********************************************************************************************************************/

signed main()/*Check flow...question galat mat padhna */
{
    fast;   
    string s;
    cin>>s;
    ll ans=0;
    For(i, s.length())
    {
        if(i%2==1)
        {
            if(s[i]=='R')ans++;
        }
        else 
        {
            if(s[i]=='L')ans++;
        }
    }
    if(ans)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}      

Measured memory_bytes: 256
import Control.Monad
import qualified Data.IntMap as M

main = do
  li <- getLine
  let [n,k] = map read $ words li
  abs <- forM [1..n] (\_ -> do
    li <- getLine
    let [a,b] = map read $ words li
    return (a,b)
    )
  let ans = compute k abs
  print ans

{-
大きさをキーに、要素数を値にしたIntMapを更新する
キーの小さい順に取り出して、k番目を特定する
-}

compute :: Int -> [(Int,Int)] -> Int
compute k abs = loop k (M.assocs m)
  where
    m = foldl step M.empty abs
    step m (a,b) = M.insertWith (+) a b m
    loop k ((a,b):abs)
      | k <= b = a
      | True   = loop (k-b) abs


Measured memory_bytes: 115068
n = int(input())
d = sorted(list(map(int,input().split())),reverse=True)
m = int(input())
t = sorted(list(map(int,input().split())))

for i in t:
    while d:
        tmp_d = d.pop()
        if i == tmp_d:
            break
    else:
        print("NO")
        exit()
print("YES")




Measured memory_bytes: 123600
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n,k;
int main(){
    cin>>n>>k;
    int now=0;
    while(n>=1){
        now++;
        n/=k;
    }
    cout<<now<<endl;
    return 0;
}

Measured memory_bytes: 256
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
int n,m,a,b;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
        

	int a1[1000] = {0};
	int a2[1000] = {0};
	a1[1] = 300000;
	a1[2] = 200000;
	a1[3] = 100000;
	a2[1] = 300000;
	a2[2] = 200000;
	a2[3] = 100000;

	cin >> a >> b;
	int ans = a1[a]+a2[b];
	if(a==1 && b==1)ans+= 400000;

	cout << ans << endl;

    

return 0;
}
///....


Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    S = input()

    ans = 0

    c = 0

    for s in S:
        if s in "ATCG":
            c += 1
            ans = max(ans, c)
        else:
            c = 0

    print(ans)


main()


Measured memory_bytes: 5108
#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int n, m, f[5];
string s, t, q;

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi();
	cin >> s >> t;
	for (int i = 0; i < n; i+=1)
	{
		q = q + s[i];
		q = q + t[i];
	}
	cout << q << endl;
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
from decimal import *

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B = map(int, raw_input().split())
print A / B + (A % B != 0)

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

namespace ConsoleApp2
{
    public class Program
    {
        static long mod = (long)Math.Pow(10, 9) + 7;

        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] aString = Console.ReadLine().Split(' ');

            List<int> balls = new List<int>();
            int[] relatedBall = new int[N];

            for (int i = N-1; i > -1; i--)
            {
                if((relatedBall[i]+int.Parse(aString[i]))%2 == 1)
                {
                    balls.Add(i + 1);

                    #region Divisor
                    int Number = i+1;
                    int max = (int)Math.Sqrt(Number);
                    for (int j = 1; j < max; j++)
                    {
                        if (Number % j == 0)
                        {
                            relatedBall[j-1]++;
                            relatedBall[Number / j-1]++;
                        }
                    }

                    if (Number % max == 0)
                    {
                        if (Number / max == max) relatedBall[max-1]++;
                        else
                        {
                            relatedBall[max-1]++;
                            relatedBall[Number/max-1]++;
                        }
                    }


                    #endregion
                }
            }

            Console.WriteLine(balls.Count);
            Console.WriteLine(string.Join(" ",balls));

            Console.ReadLine();
        }

        private static long[] Read(string input)
        {
            string[] strings = input.Split(' ');
            long num = strings.Length;
            long[] ints = new long[num];
            for (int i = 0; i < num; i++)
            {
                ints[i] = long.Parse(strings[i]);
            }

            
            return ints;
        }
    }
}


Measured memory_bytes: 32600
x, k, d = map(int, input().split())
i = 1
x = abs(x)

if k*d <= x:
    print(x-k*d)
else:
    i = x//d + 1
    #print(i)
    if (k-i)%2 == 0:
        print(abs(x-d*i))
    else:
        print(x-d*i + d)


Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 1e+6 + 1;

int main()
{
    int N;
    cin >> N;
    vector<int> A;
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        A.push_back(a);
    }
    sort(A.begin(), A.end());

    int S[MAX_N];
    fill_n(S, MAX_N, 0);
    for (auto a : A)
    {
        int tmp = a;
        if (S[a] == 0)
        {
            while (a <= MAX_N)
            {
                S[a]++;
                a = a + tmp;
            }
        }
        else
        {
            S[a]++;
        }
    }

    int ans = 0;
    for (auto a : A)
    {
        if (S[a] == 1)
        {
            ans++;
        }
    }

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

Measured memory_bytes: 7992
#include <bits/stdc++.h>
int freq[35];
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int k;
    cin >> k;
    for (int j = 1; j <= k; j++) {
      int t;
      cin >> t;
      freq[t]++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++)
    if (freq[i] == n)
      ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

void wa() {
  cout << "WA" << endl;
  exit(0);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  cin >> s;
  int n = s.size();
  if (s[0] != 'A') wa();
  int cnt = 0;
  for (int i = 2; i < n-1; i++) {
    cnt += s[i] == 'C';
  }
  if (cnt != 1) wa();
  for (int i = 1; i < n; i++) {
    if (s[i] == 'C') continue;
    if ('A' <= s[i] && s[i] <= 'Z') wa();
  }
  cout << "AC" << endl;

  return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    string S; cin >> S;
    cout << (S=="ABC" ? "ARC" : "ABC") << en;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string.h>
#include <math.h>
typedef long long ll;
#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REP(i,x,y)	for (int (i)=(x);(i)<(y);(i)++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef pair<int, int> Point;
typedef vector<vector<Point>> Graph;

int C[100001];
int A,B;

int main() {
	cin >> A >> B;
	
	REP(i, 10000, 100000)
	if (i/10000 == i%10 && ((i%10000)/1000)==((i%100)/10)) C[i]++;
	REP(i, 10000, 100000) C[i] += C[i-1];
		
	cout << C[B] - C[A-1];

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

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

	ll sum = 0;
	if (M == 1 && N == 1) {
		sum = 1;
	}
	else if (M == 1) {
		sum = N - 2;
	}
	else if (N == 1) {
		sum = M - 2;
	}
	else {
		sum = (N - 2) * (M - 2);
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
N = input()
N = int(N)

B = input().split()
ans = []
for i in range(N):
    ans.append(0)

if 2<=N and N<= 100:
    ans[0] = int(B[0])
    for i in range(len(B)):
        b = int(B[i])
        ans[i+1] = b

        tmp = ans[i]
        if tmp > b:
            ans[i] = b
        

    # print(ans)

ko = 0
for i in ans:
    ko += i
print(ko)


# 0 0 10 10 10 23

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



int main(){
    long double A,B;
    cin >> A >> B;
    //cout << A*B  << endl;
    ll ans = A*B;
    cout << ans << endl;
    
}


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

int main(){
  int D, N;
  cin >> D >> N;
  if (D == 0){
    if (N == 100){
      cout << "101" << endl;
    }
    else {
      cout << N << endl;
    }
  }
  else if (D == 1){
    if (N == 100){
      cout << "10100" << endl;
    }
    else {
      cout << N*100 << endl;
    }
  }
  else {
    if (N == 100){
      cout << "1010000" << endl;
    }
    else {
      cout << N*10000 << endl;
    }
  }
}

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

int main() {
    string str;
    cin >> str;
    
    for(int i=0; i<str.size(); i++){
        if(count(str.begin(), str.end(), str[i])%2 != 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<string> s(n);
  re(i, n) cin >> s[i];

  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());

  cout << s.size() << endl;

  return 0;
}


Measured memory_bytes: 9536
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
vector<string>s,t;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    s.resize(n);
    rep(i,n)cin>>s[i];
    cin>>m;
    t.resize(m);
    rep(i,m)cin>>t[i];
    map<string,int>sm,tm;
    rep(i,n)sm[s[i]]++;
    rep(i,m)tm[t[i]]++;
    int ans=0;
    rep(i,n){
        int temp=sm[s[i]]-tm[s[i]];
        chmax(ans,temp);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int vy[] = {-1, 1, 0, 0}, vx[] = {0, 0, 1, -1};
 
 
map< string, set< string > > names;
set< string > visited;
set< string > rec(string name)
{
  set< string > ret;
  if(visited.find(name) != visited.end()) return(ret);
  visited.insert(name);
  if(names[name].empty()) {
    ret.insert(name);
  } else {
    for(auto p : names[name]) {
      set< string > pp = rec(p);
      if(pp.size() > ret.size()) swap(pp, ret);
      while(!pp.empty()) {
        ret.insert(*pp.begin());
        pp.erase(pp.begin());
      }
    }
  } 
  return(ret);
}
 
int main()
{
  int N;
  while(cin >> N, N) {
    string F = "";
    while(N--) {
      string S;
      cin >> S;
      string C = "";
      vector< string > buff;
      for(int i = 0; i < S.size(); i++) {
        if(isalpha(S[i])) C += S[i];
        else buff.push_back(C), C = "";
      }
      for(int i = 1; i < buff.size(); i++) {
        names[buff[0]].insert(buff[i]);
      }
      if(F.empty()) F = buff[0];
    }
    cout << rec(F).size() << endl;
    visited.clear();
    names.clear();
  }
}

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

int main(){
  int n;

  while(cin>>n,n!=0){
    int cnt=0;
  
    for(int i=1; i<n; ++i){
      int sum=0;
      for(int j=i; sum<n; ++j){
	sum = sum + j;
	if(sum==n){++cnt;}
      }
    }
    cout << cnt <<endl;
  } 
  return 0;
}
      
	  


Measured memory_bytes: 3024
#include<bits/stdc++.h>
#define endl '\n'
#define mp make_pair
typedef long long int ll;
using namespace std;
int main()
{
    ll n;
    string s;
    cin>>s;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]==s[i+1]) {cout<<"Bad"; return 0; }
    }
    cout<<"Good";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

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

		int N = sc.nextInt();

		long[] S_A = new long[N];
		long min = Long.MAX_VALUE;

		S_A[0] = sc.nextLong();

		for (int i = 1; i < N; i++) {
			S_A[i] = sc.nextLong() + S_A[i-1];
		}

		for (int i = 0; i < N; i++) {
			min = Math.min(Math.abs(S_A[N-1]-S_A[i]*2),min);
		}

		System.out.println(min);

	}
}


Measured memory_bytes: 61540
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, s, n) for(int i = s; i < n; i++)
#define rRep(i, n) for(int i = n - 1; i >= 0; i--)

int32_t main() {
	FAST
	int n;
	cin >> n;
	string s;
	cin >> s;

	string t = s.substr(0, n/2);
	t = t + t;
	if(s == t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


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

#define F first
#define S second
#define x1 privet1
#define x2 privet2
#define y1 privet3
#define y2 privet4
#define time privet5
#define left privet6

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 1000011, log_n = 32, max_m = 111, mod = 1000000007, inf = 1011111111, p = 997;

int n, a[max_n];

int main() {
    //freopen("substr.in", "r", stdin);
    //freopen("substr.out", "w", stdout);
    int cnt = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        if (a[i] % 2 == 1) {
            cnt++;
        }
    }
    if (cnt % 2 == 0) {
        cout << "YES\n";
    } else {
    cout << "NO\n";}
    return 0;
}


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

int main(){
    string s, new_s;
    cin >> s;
    new_s = "2018/";
    for(int i = 5; i < s.length(); i++){
        new_s += s[i];
    }
    cout << new_s;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int mp[2005];
int main(){
	string s1,s2,s3;
	cin >> s1;
	if(s1=="Sunny")cout << "Cloudy" << endl;
	if(s1=="Cloudy")cout << "Rainy" << endl;
	if(s1=="Rainy")cout << "Sunny" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  if ((B - A) % 2 == 0)
    cout << "Alice" << endl;
  else
    cout << "Borys" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int>x(n);
    rep(i,n)cin >> x[i];
    vector<int>y(n);
    rep(i,n)y[i] = x[i];
    sort(all(y));
    int m = y[n/2-1];
    rep(i,n){
        if(x[i]>m)cout << m << endl;
        else cout << y[n/2] << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

ll K;
const int N=50;

int main(){
  cin>>K;

  vector<ll> A(N,0);
  for(int i=0;i<N;i++) A[i]=N-1+(K/N);

  K%=N;
  for(int i=0;i<K;i++){
      A[i]=A[i]+N-(K-1);
  }
  for(int i=K;i<N;i++){
      A[i]=A[i]-K;
  }

  cout<<N<<endl;
  for(int i=0;i<N;i++) cout<<A[i]<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import static java.lang.System.out;

class SmallLargeOrEqual {
    private int a;
    private int b;

    SmallLargeOrEqual(int a, int b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public String toString() {
        return String.format((this.a == this.b) ? "==" : ((this.a > this.b) ? ">" : "<"));
    }
}

public class Main {
    public static void main(String... args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        out.println("a " + new SmallLargeOrEqual(a, b) + " b");
    }
}

Measured memory_bytes: 26004
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = [int(i) for i in input().split()]

    if a[1] == 1 or a[0] ==a[1]:
        print(0)
    else:
        print(a[0]-a[1])


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int n,i,j;
    cin>>n;
    int dp[n+1]={0};
    for(i=1;i<=n-1;++i)
    {
        cin>>j;
        dp[j]++;
    }
    for(i=1;i<=n;++i)
        cout<<dp[i]<<endl;
}

Measured memory_bytes: 5240
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll x, y, z; cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  int ans = 0;
  int x[n];
  for(int i = 0; i < n; i++){
    cin >> x[i];
  }
  for(int i = 0;i < n; i++) {
    if(2*x[i] < k)
      ans += x[i]*2;
    else
      ans += (k - x[i]) *2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
TA = [LIST() for _ in range(N)]

T = TA[0][0]
A = TA[0][1]

for t, a in TA[1:]:
	p = max(-(-T//t), -(-A//a))
	T = t*p
	A = a*p
	
print(T+A)



Measured memory_bytes: 10584
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll a[505][505];

int main() {
  ll H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }
  ll cnt = 0;
  vector<pair<pair<ll, ll>, pair<ll, ll>>> q;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W - 1; j++) {
      if (a[i][j] % 2) {
        a[i][j]--;
        a[i][j + 1]++;
        q.push_back({{i, j}, {i, j + 1}});
        cnt++;
      }
    }
  }
  for (int i = 0; i < H - 1; i++) {
    if (a[i][W - 1] % 2) {
      a[i][W - 1]--;
      a[i + 1][W - 1]++;
      q.push_back({{i, W - 1}, {i + 1, W - 1}});
      cnt++;
    }
  }
  cout << cnt << endl;
  for (auto p : q) {
    printf("%d %d %d %d\n", p.first.first + 1, p.first.second + 1,
           p.second.first + 1, p.second.second + 1);
  }
  return 0;
}

Measured memory_bytes: 9348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int main() {
	var(int, n, h, w);
	int a, b, ans = 0;
	rep(i, 0, n) {
		cin >> a >> b;
		if (h <= a && w <= b)
			++ans;
	}
	print(ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
#define MP pair<int, int>
typedef long long LL;
const int mod=1000000007;
const LL inf=0x3f3f3f3f3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=100005;

int n;
LL dis[maxn];
int inq[maxn];
vector<pair<int, int> > E[maxn];

struct Spfa{

    void init(){
        for(int i=0;i<maxn;i++){
            dis[i]=inf;
            E[i].clear();
            inq[i]=0;
        }
    }

    int spfa(int s){
        queue<int> Q;
        dis[s]=0;
        inq[s]=1;
        Q.push(s);
        while(!Q.empty()){
            int u=Q.front();
            Q.pop();
            inq[u]=0;
            for(int i=0;i<E[u].size();i++){
                int v=E[u][i].first;
                if(dis[v]>dis[u]+E[u][i].second){
                    dis[v]=dis[u]+E[u][i].second;
                    if(inq[v])continue;
                    Q.push(v);
                    inq[v]=1;
                }
            }
        }
        return dis[n];
    }
};

int main()
{
    while(~scanf("%d", &n)){
        Spfa spfa;
        spfa.init();
        int u, v ,w;
        for(int i=0;i<n-1;i++){
            scanf("%d%d%d", &u, &v, &w);
            E[u].push_back(make_pair(v, w));
            E[v].push_back(make_pair(u, w));
        }
        int q, k;
        scanf("%d%d", &q, &k);
        spfa.spfa(k);
        for(int i=0;i<q;i++){
            scanf("%d%d", &u, &v);
            printf("%lld\n", dis[u]+dis[v]);
        }
    }
    return 0;
}


Measured memory_bytes: 9204
import math
X = int(input())
while True:
    i = 2
    if X == 2 or X == 3:
        break
    Y = int(math.sqrt(X))
    while i != Y+1:
        if X % i == 0:
            X += 1
            break
        i += 1
    if i == Y+1:
        break
print(X)


Measured memory_bytes: 2940
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
    n=int(input())
    V=[int(_) for _ in input().split()]
    even=V[0::2]
    odd=V[1::2]
    even_c=Counter(even)
    odd_c=Counter(odd)
    even_ci,odd_ci=list(even_c.items()),list(odd_c.items())
    even_ci.sort(key=itemgetter(1),reverse=True)
    odd_ci.sort(key=itemgetter(1),reverse=True)
    if even_ci[0][0]==odd_ci[0][0]:
        if len(even_ci)>1 and len(odd_ci)>1:
            print(min(sum(even_c.values())-even_ci[1][1]+sum(odd_c.values())-odd_ci[0][1],
                        sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[1][1]))
        elif len(even_ci)>1 and len(odd_ci)==1:
            print(sum(even_c.values())-even_ci[1][1])        
        elif len(even_ci)==1 and len(odd_ci)>1:
            print(sum(odd_c.values())-odd_ci[0][1])        
        else:
            print(n//2)   
    else:
        print(sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[0][1])

if __name__=='__main__':
    main()

Measured memory_bytes: 65132
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	string s, t;
	cin >> n >> s >> t;
	for (ll i = 0; i < n; i++) {
		cout << s[i] << t[i];
	}
	cout << endl;
}




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

#define INF 1234567890
#define ll long long

int N, K;
ll A[200201];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K;
	for(int i=1; i<=N; i++)
		cin >> A[i];
	for(int i=K+1; i<=N; i++)
	{
		if (A[i-K] < A[i])
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 5180
from collections import deque
from copy import copy

N, M, Q = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(Q)]

queue = deque()
for i in range(1, M+1):
    queue.append([i])
for _ in range(N-1):
    while 1:
        if queue[0] == [1] * N:
            break
        x = queue.popleft()
        for i in range(x[-1], M+1):
            y = copy(x)
            y.append(i)
            queue.append(y)

score_max = 0
for A in queue:
    score = 0
    for a, b, c, d in X:
        if int(A[b-1]) - int(A[a-1]) == c:
            score += d
    score_max = max(score, score_max)

print(score_max)


Measured memory_bytes: 103612
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

char S[21][21] ;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int solve(int H, int W, int si, int sj, int gi, int gj) {
    int dist[H][W];
    repp(i,0,H) {
        repp(j,0,W) dist[i][j] = -1;
    }
    dist[si][sj] = 0;
    queue<pair<int, int> > q; q.push(make_pair(si, sj));

    while(!q.empty()) {
        pair<int, int> current_pos = q.front();
        int x = current_pos.first;
        int y = current_pos.second;
        q.pop();

        for (int direction = 0; direction < 4; ++direction) {
            int next_x = x + dx[direction];
            int next_y = y + dy[direction];
            if (next_x < 0 || next_x >= H || next_y < 0 || next_y >= W) continue; // 場外アウトならダメ
            if (S[next_x][next_y] == '#') continue; // 壁はダメ

            // まだ見ていない頂点なら push
            if (dist[next_x][next_y] == -1) {
                q.push(make_pair(next_x, next_y));
                dist[next_x][next_y] = dist[x][y] + 1; // (next_x, next_y) の距離も更新
            }
        }
    }
    return dist[gi][gj];
}

int main() {
    int H, W; cin >> H >> W;

    repp(i,0,H) {
        repp(j,0,W) cin >> S[i][j];
    }
    int res = 0;
    repp(i,0,H) {
        repp(j,0,W) {
            repp(k,0,H) {
                repp(l,0,W) {
                    if (S[i][j] == '#' || S[k][l] == '#') continue;
                    res = max(res, solve(H,W,i,j,k,l));
                }
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 764