akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
	double a,s;
	int i;
	while(scanf("%lf",&a)!=EOF){
		s=a;
		for(i=2;i<=10;i++){
			if(i%2){
				a/=3;
			}
			else{
				a*=2;
			}
			s+=a;
		}
		printf("%.8f\n",s);
	}
	return 0;
}

Measured memory_bytes: 652
from sys import stdin

K = int(stdin.readline().rstrip())
[A, B] = [int(x) for x in input().rstrip().split()]


flag=0
K_temp=K
while(True):
    if(K_temp>B):
        break
    if(K_temp>=A and K_temp<=B):
        flag=1
        break
    else:
        K_temp+=K

if flag==1:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 61752
import           Control.Monad
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

main = do
  [k, n] <- getIntList
  as <- getIntVec n

  let dist i | i == 0    = (as V.! 0) + (k - (as V.! (n-1)))
             | otherwise = (as V.! i) - (as V.! (i-1))

      calcMaxD i m | i == n    = m
                   | otherwise = calcMaxD (i+1) (max m (dist i))

      maxD = calcMaxD 0 0

      ans = k - maxD

  print ans

Measured memory_bytes: 6396
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int BUF = 200005;
const int MOD = 1000000007;
const int INF = 1<<30;


int nVal, nPick;
int val[BUF];

void read() {
    cin >> nVal >> nPick;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}


void work() {
    int nNeg = 0, nZero = 0, nPos = 0;
    int neg[BUF], pos[BUF];

    for (int i = 0; i < nVal; ++i) {
        if (val[i] < 0) {
            neg[nNeg++] = val[i];
        } else if (val[i] > 0) {
            pos[nPos++] = val[i];
        } else {
            ++nZero;
        }
    }

    sort(neg, neg + nNeg);
    sort(pos, pos + nPos);

    long double posLogSum[BUF];
    posLogSum[0] = logl(pos[0]);
    for (int i = 1; i < nPos; ++i) {
        posLogSum[i] = posLogSum[i - 1] + logl(pos[i]);
    }
    
    long double maxV = -INF;
    int nNegPickMax = -1;
    long double cur = 0;
    for (int nNegPick = 0; nNegPick <= min(nNeg, nPick); nNegPick += 2) {
        if (nNegPick) {
            cur += logl(fabs(neg[nNegPick - 1]));
            cur += logl(fabs(neg[nNegPick - 2]));
        }
        
        int nRemainPick = nPick - nNegPick;
        if (nRemainPick > nPos) {
            continue;
        }
        
        long double sum = (nPos == 0 ? 0 : posLogSum[nPos - 1]) - (nRemainPick == nPos ? 0 : posLogSum[nPos - 1 - nRemainPick]);
        if (maxV < cur + sum) {
            maxV = cur + sum;
            nNegPickMax = nNegPick;
        }
    }
    
    if (nNegPickMax != -1) {
        int ans = 1;
        for (int i = 0; i < nNegPickMax; ++i) {
            ans = 1LL * ans * (MOD + neg[i]) % MOD;
        }
        for (int i = 0; i < nPick - nNegPickMax; ++i) {
            ans = 1LL * ans * pos[nPos - 1 - i] % MOD;
        }
        cout << ans << endl;
        return;
    } else if (nZero) {
        cout << 0 << endl;
        return;
    }

    
    reverse(neg, neg + nNeg);

    long double minV = INF;
    
    cur = logl(fabs(neg[0]));
    for (int nNegPick = 1; nNegPick <= min(nNeg, nPick); nNegPick += 2) {
        if (nNegPick > 1) {
            cur += logl(fabs(neg[nNegPick - 1]));
            cur += logl(fabs(neg[nNegPick - 2]));
        }
        
        int nRemainPick = nPick - nNegPick;

        if (nRemainPick > nPos) {
            continue;
        }
        
        long double sum = nRemainPick == 0 ? 0 : posLogSum[nRemainPick - 1];
        if (minV > cur + sum) {
            minV = cur + sum;
            nNegPickMax = nNegPick;
        }
    }

    int ans = 1;
    for (int i = 0; i < nNegPickMax; ++i) {
        ans = 1LL * ans * (MOD + neg[i]) % MOD;
    }
    for (int i = 0; i < nPick - nNegPickMax; ++i) {
        ans = 1LL * ans * pos[i] % MOD;
    }
    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 8336
S = input()

A = S[0]
ans = 'No'

if A == S[1]:
    B = S[2]
    if B == S[3]:
        ans = 'Yes'
else:
    B = S[1]
    if A == S[2] and B == S[3]:
        ans = 'Yes'
    if B == S[2] and A == S[3]:
        ans = 'Yes'

if A == B:
    ans = 'No'

print(ans)


Measured memory_bytes: 3060
S=input()
if S == "MON":
  print(6)
elif S == "TUE":
  print(5)
elif S == "WED":
  print(4)
elif S == "THU":
  print(3)
elif S == "FRI":
  print(2)
elif S == "SAT":
  print(1)
else:
  print(7)


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(void){
  int n;
  cin >> n;
  string s[3];
  for(int i=0;i<3;i++){
    cin >> s[i];
  }
  long sum=0;
  for(int i=0;i<n;i++){
    if(s[0][i]==s[1][i] && s[1][i]==s[2][i]){
        
    }else if(s[0][i]==s[1][i] || s[1][i]==s[2][i] || s[0][i]==s[2][i]){
        sum += 1;
    }else{
        sum += 2;
    }
  }
  cout << sum << endl;
  
  return 0;  
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(n):
        a[i] *= -1

    heapify(a)
    while m:
        b = heappop(a)
        b = (-b)//2
        heappush(a, -b)
        m -= 1
    print(-sum(a))

if __name__ == '__main__':
    main()

Measured memory_bytes: 14636
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#if defined(_MSC_VER)
#pragma warning(disable : 4996)  // VSでscanfを使う．
#endif

typedef pair<int ,int> P;

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

  if (n == 3 && k >= 2) {
    cout << -1 << endl;
    return 0;
  }

  if (k <= n) {
    vector<P> ans;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        ans.push_back(P(i, j));
      }
    }

    if (ans.size() - k < n - 1) {
      cout << -1 << endl;
      return 0;
    }

    cout << ans.size() - k << endl;
    for (int i = 0; i < ans.size() - k; i++) {
      cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
  } else if (k == n + 1) {
    if (n < 6) {
      cout << -1 << endl;
      return 0;
    }

    cout << n << endl;
    for (int i = 1; i < n; i++) {
      cout << i << " " << i + 1 << endl;
    }
    cout << 2 << " " << n << endl;
    return 0;
  } else {
    int diff = n * (n - 1) / 2 - (n - 1) - k;

    if (diff < 0 || diff > ((n - 1) * (n - 2) / 2)) {
      cout << -1 << endl;
      return 0;
    }

    vector<P> ans;

    for (int i = 2; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        ans.push_back(P(i, j));
      }
    }

    cout << (n - 1) + diff << endl;
    for (int i = 2; i <= n; i++) {
      cout << 1 << " " << i << endl;
    }
    for (int i = 0; i < diff; i++) {
      cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
  }

  cout << -1 << endl;

  return 0;
}



Measured memory_bytes: 384
<?php
    $n;
    $l;
    $ar;
    fscanf(STDIN, "%d %d", $n, $l);
    for($i = 0; $i < $n; $i++){
        $s;
        fscanf(STDIN, "%s", $s);
        $ar[] = $s;
    }
    sort($ar, SORT_STRING);
    foreach($ar as $s){
        echo $s;
    }
    echo "\n";
?>


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int main(){
  int z;
  string s="";
  bool f=false;
  cin>>z;
  while(f==false){
    if(z%2==0) s='0'+s;
    else{
      s='1'+s;
      z--;
    }
    z/=-2;
    if(z==0) f=true;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 3592
n = gets.to_i
a = gets.chomp.split.map(&:to_i)

def bubble_sort(ary,num)
  flag = 1
  times = 0
  while flag == 1
    flag = 0
    for j in 1..num-1
      if ary[num-j] < ary[num-j-1]
        i = ary[num-j-1]
        ary[num-j-1] = ary[num-j]
        ary[num-j] = i
        flag = 1
        times += 1
      end
    end
  end
  puts ary.join(" ")
  puts times
end

bubble_sort(a,n)

Measured memory_bytes: 8680
n, w = map(int,input().split())
wv = [list(map(int,input().split())) for i in range(n)]

dp = [[0] * (w + 1) for i in range(n)]

for i in range(n):
    for j in range(w + 1):
        if j == 0:
            nw = wv[i][0]
            if nw <= w:
                dp[i][nw] = wv[i][1]

        elif dp[i - 1][j] != 0:
            nw = wv[i][0] + j
            if nw <= w:
                dp[i][nw] = max(dp[i][nw], dp[i - 1][j] + wv[i][1])

        dp[i][j] = max(dp[i - 1][j], dp[i][j])
print(max(dp[-1]))

Measured memory_bytes: 119916
#include <bits/stdc++.h>
#include <stdio.h>
#define ms(s, n) memset(s, n, sizeof(s))
#define rp(i,l,m) for(int i=l; i<m; ++i)
#define Rp(i,l,m) for(int i=l; i<=m; i++)
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define sz(a) int((a).size())
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = (int) 1e9+7;
const ld PI = acos((ld) -1);
inline ll gcd(ll a, ll b) {ll r; while (b) {r=a%b;a=b;b=r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p=MOD){ll r=1; for(;k;k>>=1){if(k&1)r=r*n%p;n=n*n%p;}return r;}
#define nmax 200005
int k, n;
string s;
inline void Init(){
    cin >> n >> k;
}
inline void Solve(){
    if(k==1) cout << 0;
    else cout << n-k;
}
int main(int argc, char** argv){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    Init();
    Solve();
    return 0;
}



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

using namespace std;

int main() {
    int n, x;
    cin >> n;
    map<long long, int> mp;
    mp[0] = 1;

    long long s = 0;
    long long ans = 0;

    for (int i = 0; i < n; i++) {
        cin >> x;
        s += x;
        ans += mp[s];
        mp[s]++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#define int long long
using namespace std;

#define fin(i,n) for (int i = 0; i < n; i++)
#define fin2(i,a,b) for (int i = a; i < b; i++)
#define ford(i,n) for (int i = n-1; i >= 0; i--)
#define ford2(i,a,b) for (int i = a-1; i >= b; i--)
 
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define mod 1000000007
#define PI 3.1415926535897932384626
#define EXP1 2.718281828459045
#define BIG 1000000000000000000

#define sl(n) scanf("%lld", &n)
#define sll(n,m) scanf("%lld %lld", &n, &m)
#define slll(n,m,k) scanf("%lld %lld %lld", &n, &m, &k)
#define sllll(n,m,k,o) scanf("%lld %lld %lld %lld", &n, &m, &k, &o)
#define sd(n) scanf("%lf", &n)
#define sdd(n,m) scanf("%lf %lf", &n, &m)
#define sddd(n,m,k) scanf("%lf %lf %lf", &n, &m, &k)
#define sc(c) scanf(" %c", &c)
#define ss(s) scanf("%s", s)
#define sal(t,n) fin(iz,n) { scanf("%lld", &t[iz]); }
#define sad(t,n) fin(iz,n) { scanf("%lf", &t[iz]); }
#define gl(t) scanf(" %[^\n]", t);

#define pc(n) printf("%c\n", n)
#define ps(s) printf("%s\n", s)
#define pss(s) printf("%s\n", s.c_str())
#define pl(n) printf("%lld\n", n)
#define pll(n,m) printf("%lld %lld\n", n, m)
#define plll(n,m,k) printf("%lld %lld %lld\n", n, m, k)
#define pd(n) printf("%lf\n", n)
#define pdd(n,m) printf("%lf %lf\n", n, m)
#define pal(t,n) fin(rz,n) { printf("%lld ", t[rz]); } printf("\n")
#define pad(t,n) fin(rz,n) { printf("%lf ", t[rz]); } printf("\n")

#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
 
#define OK ps("OK")
#define OK1 ps("OK1")
#define OK2 ps("OK2")

#define ll int
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>

#define dll pair<ll, ll>
#define vdll vector<dll>
#define vvdll vector<vdll>

#define vb vector<bool>
#define vvb vector<vb>
#define vd vector<double>
#define vvd vector<vd>
#define vc vector<char>
#define vvc vector<vc>

#define all(v) v.begin(), v.end()
#define vlen(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second

string s;
int d;
int c;
const int bm = 10*1000 + 5;
int dp[bm][105][2];

int gdp(int x, int v, int enDessous)
{
    if (x == c) {
        if (v == 0) return 1;
        else return 0;
    }
    if (dp[x][v][enDessous] == -1) {
        dp[x][v][enDessous] = 0;
        int chiffre = s[x] - '0';
        for (int p = 0; p < 10; ++p) {
            if (enDessous == 0 && p > chiffre) break;
            int nv = enDessous | (p < chiffre ? 1:0);
            dp[x][v][enDessous] += gdp(x+1, (v-p+10*d)%d, nv);
            dp[x][v][enDessous] %= mod;
        }
    }
    return dp[x][v][enDessous];
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> s >> d;
    c = s.length();
    fill_n(&dp[0][0][0],bm*105*2,-1);
    cout << (((gdp(0,0,0)-1+mod) % mod)+mod)%mod << endl;
}

Measured memory_bytes: 17408
N,M = map(int,input().split())
H = [0] + list(map(int,input().split()))
G = dict([(i,[]) for i in range(1,N+1)])
for i in range(M):
  A,B = map(int,input().split())
  G[A].append(B)
  G[B].append(A)

cnt = 0
for i in range(1,N+1):
  det = 0
  for v in G[i]:
    if H[i] <= H[v]:
      det = 1
  if det == 0:
    cnt += 1
print(cnt)    

Measured memory_bytes: 45044
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
const int M = 1000005;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  vector<int> cnt(M, 0);
  for(auto x: a){
    if(cnt[x]!=0){
      cnt[x] = 2;
      continue;
    }
    for(int i=x; i<M; i+=x) cnt[i]++;
  }
  int ans = 0;
  for(int x: a){
    if(cnt[x]==1) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7892
# -*- coding: utf-8 -*-
N = int(input())

A, B = [], []
for _ in range(N):
    a, b = map(int, input().split(' '))
    A.append(a)
    B.append(b)

n, ans = 0, 0
for i in range(N-1, -1, -1):
    m = (A[i]+n) % B[i]
    if m > 0:
        ans += B[i] - m
        n += B[i] - m

print(ans)


Measured memory_bytes: 57176
import java.io.*;
import java.util.*;

public class Main {
	static final int MOD = (int)1e9+7;

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

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		String s = sc.next();
		String t = sc.next();
		
		char[] a = s.toCharArray();
		Character[] b = new Character[t.length()];
		
		for(int i = 0; i < t.length(); i++) b[i] = t.charAt(i);
		
		Arrays.sort(a);
		Arrays.sort(b, Collections.reverseOrder());
		
		String as = new String(a);
		String bs = "";
		
		for(int i = 0; i < b.length; i++) bs = bs + b[i];
		
		if(as.compareTo(bs) < 0) {
			out.println("Yes");
		}else{
			out.println("No");
		}
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}
	
	public static long factorial(int n) {
		long a;
		
		if(n > 0) {
			a = n * factorial(n - 1);
		}else{
			a = 1;
		}
		
		return a;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

int A[200005];
int level[200005];

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

    for (int i=1; i<=n; i++)
        cin >> A[i];
    
    if (A[1] == 1)
    {
        cout << 1 << "\n";
        return 0;
    }

    int ptr = 1, lvl = 0, cycleLen = 0, branchLen = 0;

    while (1)
    {
        level[ptr] = ++lvl;

        if (level[ A[ptr] ])
        {
            branchLen = level[ A[ptr] ];
            cycleLen = level[ptr] - level[ A[ptr] ] + 1;
            break;
        }

        ptr = A[ptr];
    }

    int target = 0;

    if (k <= branchLen - 1)
        target = k + 1;
    else
    {
        k -= branchLen - 1;
        target = k % cycleLen + branchLen;
    }

    for (int i = 1; i<=n; i++)
        if (level[i] == target)
        {
            cout << i << "\n";
            return 0;
        }

    return 0;
}


Measured memory_bytes: 5200
function main(input) {
  const lines = input.trim().split("\n");
  let [n, k] = lines[0].split(' ');
  n = +n;
  k = BigInt(k);
  const towns = lines[1].split(' ').map(Number);

  const visited = new Map();
  let pos = 1;
  while (k > 0) {
    const i = visited.get(pos);
    if (i === undefined) {
      visited.set(pos, visited.size);
      pos = towns[pos - 1];
      k--;
    } else {
      const cycle = BigInt(visited.size - i);
      const rest = Number( (k % cycle).toString() );
      for (let [key, value] of visited) {
        if (value == i + rest) {
          pos = key;
          break;
        }
      }
      k = 0;
    }
  }
  
  console.log(pos);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 71144
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

const double pi=acos(-1);

struct point
{
	int x,y;
	
	inline bool operator < (const point t) const
	{
		return atan2(x,y)<atan2(t.x,t.y);
	}
};

point p[120],q[120];
int i,j,n,o;
double l;

int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d%d",&p[i].x,&p[i].y);
	for (i=1;i<=n;i++)
	{
		o=0;
		for (j=1;j<=n;j++)
			if (j!=i)
				o++,q[o].x=p[j].x-p[i].x,q[o].y=p[j].y-p[i].y;
		sort(q+1,q+o+1);
		if (o==1)
			l=pi;
		else
		{
			l=2*pi;
			for (j=2;j<=o;j++)
				l=l-min(pi,atan2(q[j].x,q[j].y)-atan2(q[j-1].x,q[j-1].y));
			l=l-min(pi,atan2(q[1].x,q[1].y)+2*pi-atan2(q[o].x,q[o].y));
		}
		printf("%.15lf\n",l/2/pi);
	}
	return 0;
}

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

using namespace std;

typedef long long int ll;

const ll N=1e6+1;

ll gcd(ll a,ll b){ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

ll fact[N];
bool prime[N];

void sieve(){
    for(ll i=2;i<N;i++){
        if(prime[i]==true){
            for(ll j=i*i;j<=N;j+=i){
                prime[j]=false;
                fact[j]=i;
            }
        }
    }
}

int main(){
    ll n;
    cin>>n;
    ll a[n];
    memset(prime,true,sizeof(prime));
    for(ll i=0;i<n;i++)
        cin>>a[i];
    for(ll i=0;i<N;i++)
        fact[i]=i;
    sieve();

    set<ll>pair;
    ll flag=0;
    for(ll i=0;i<n;i++){
        ll temp=a[i];
        while(temp!=1){
            //cout<<fact[temp]<<" ";
            if(!pair.count(fact[temp]))
                pair.insert(fact[temp]);
            else{
                flag=1;
                break;
            }
            ll j=fact[temp];
            while(temp%j==0)
                temp/=j;
        }
    }
    ll temp=a[0];
    for(int i=1;i<n;i++){
        temp=gcd(temp,a[i]);
    }
    //cout<<temp<<" ";
    if(flag==0) cout<<"pairwise coprime \n";
    else if(temp==1) cout<<"setwise coprime \n";
    else cout<<"not coprime \n";
    return 0;
}


Measured memory_bytes: 23880
#include <stdio.h>

int main(){
    int a, b, n, s;
    
    while(scanf("%d%d%d", &a, &b, &n) != EOF){
        s = 0;
            
        while(n--){
            a %= b;
            a *= 10;
            s += a / b;
        }
        
        printf("%d\n", s);
    }
    
    return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1000000007;
const ll INFLL = 1000000000000000007LL;

void solve() {
  int N, M;
  cin >> N >> M;
  string ans = "";
  vector<bool> mask(N, false);
  for (int i = 0; i < N; i++) {
    ans += 'x';
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (ans[s - 1] == 'x' || ans[s - 1] == c + '0') {
      ans[s - 1] = c + '0';
      mask[s - 1] = true;
    } else {
      cout << -1 << endl;
      return;
    }
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == 'x') {
      ans[i] = '0';
    }
  }
  if (ans[0] == '0' && ans.size() > 1) {
    if (!mask[0]) {
      ans[0] = '1';
    } else {
      cout << -1 << endl;
      return;
    }
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define testcase int t;cin>>t;while(t--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<long long int,long long int>
typedef long long int ll;
typedef unsigned long long int ull;
#define M 1000000007
using namespace std;
int main()
{
    fast
    string str,start,khatam;
cin>>str;
ll q,rev=0;
cin>>q;
int t,f;char c;
while(q--)
{
    cin>>t;
    if(t==1)
        {
            rev++;
            continue;
        }
    cin>>f>>c;
    if(rev%2==0)//original
    {
        if(f==1)
            start+=c;
        else
            khatam+=c;
    }
    else//reversed
        {
        if(f==2)
            start+=c;
        else
            khatam+=c;
        }
} string res;
if(rev%2==0)//original
   {
    reverse(start.begin(), start.end());
   string res1=start.append(str);
   res=res1.append(khatam);
   }
else
   {
    reverse(khatam.begin(), khatam.end());
    reverse(str.begin(), str.end());
   string res1=khatam.append(str);
   res=res1.append(start);
   }
   cout<<res<<endl;
return 0;
}







Measured memory_bytes: 1488
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const scores = arg.slice(1, N + 1).map(n=>parseInt(n)).sort((a,b)=>a-b);
    
    let myScore = scores.reduce((m,n)=>m+n);
    
    if(myScore % 10 === 0) {
        for(let i in scores) {
            if((myScore - scores[i]) % 10 !== 0) {
                console.log(myScore - scores[i]);
                return;
            }
        }
    } else {
        console.log(myScore);
        return;
    }
    
    console.log(0);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7756
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
left,right=-1,10**12+1
a.sort()
f.sort()
# print(a)
while right-left>1:
    mid=(right+left)//2
    tmp=0
    for i in range(n):
        tmp+=max(0,a[i]-mid//f[-1-i])
    
    if tmp<=k:
        right=mid
    else:
        left=mid
print(right)

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

int main(){
    int G[100][100];
    int n,m,s,g1,g2;
    while(cin>>n>>m>>s>>g1>>g2,n){
        s--; g1--; g2--;
        fill(G[0],G[100],1000000);
        for(int i=0;i<m;i++){
            int b1,b2,c;
            cin>>b1>>b2>>c;
            b1--; b2--;
            G[b1][b2]=c;
        }
        for(int i=0;i<n;i++) G[i][i]=0;
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    if(G[i][j]>G[i][k]+G[k][j])G[i][j]=G[i][k]+G[k][j];
                }
            }
        }
        int ans=1000000;
        for(int i=0;i<n;i++){
            ans=min(ans,G[s][i]+G[i][g1]+G[i][g2]);
        }
        cout<<ans<<endl;
    }
    return 0;}

Measured memory_bytes: 3108
N = int(input())
P = [list(map(int,input().split())) for k in range(N)]

for h in range(P[0][2],P[0][2]+201):
    for x in range(101):
        for y in range(101):
            f = 1
            for e in P:
                if e[2] != max(0,h-abs(e[0]-x)-abs(e[1]-y)):
                    f = 0
                    break
            if f == 1:
                print(x,y,h)
                exit(0)


Measured memory_bytes: 46576
n = int(input())
a = []
for i in range(int(n ** 0.5)):
    if n % (i + 1) == 0:
        a.append([i + 1, n // (i + 1)])
ans = float("inf")
for i in a:
    ans = min(ans, i[0] + i[1] - 2)
print(ans)

Measured memory_bytes: 9628
n = int(input())
a,b,c = [0]*n, [0]*n, [0]*n
for i in range(n):
    a[i], b[i],c[i] = map(int,input().split())
dp = [[0]*3 for _ in range(n)]
dp[0] = [a[0],b[0],c[0]]
for i in range(n-1):
    dp[i+1][0] = max(dp[i+1][0], dp[i][1]+a[i+1], dp[i][2]+a[i+1])
    dp[i+1][1] = max(dp[i+1][1], dp[i][0]+b[i+1], dp[i][2]+b[i+1])
    dp[i+1][2] = max(dp[i+1][2], dp[i][0]+c[i+1], dp[i][1]+c[i+1])
print(max(dp[n-1]))

Measured memory_bytes: 34616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    int A = N % 100;
    int B = (N - A)/100;
    bool ao = 0,bo = 0;
    if(1 <= A && A <= 12)ao = 1;
    if(1 <= B && B <= 12)bo = 1;
    if(ao && bo){
        cout << "AMBIGUOUS" << "\n";
    }else if(ao && bo != 1){
        cout << "YYMM" << "\n";
    }else if(ao != 1 && bo){
        cout << "MMYY" << "\n";
    }else{
        cout << "NA" << "\n";
    }
}

Measured memory_bytes: 256
/*  ex9_2
    kento_titech*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 100001
//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){//先頭を示すノードと追加するデータを引数にする
    //追加する分の領域を動的確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) 
        exit(1);
    new->elem = elem;
    new->next = *first;//先頭を示すノードの一つ手前に追加
    *first = new;//追加したノードを先頭を示すノードにする
}

//スタックからデータを取り出す
char pop(node **first){//先頭を示すノードを引数とする
    char elem;
    node *tmp = *first;
    if(tmp == NULL) 
        exit(1);
    elem = tmp->elem;
    *first = tmp->next;//一つ後ろを先頭のノードにする
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}
int main(void){
    char str[SIZE];
    int count=0,i;
    node *first = NULL;//最初のノードの指す先
    scanf("%s",str);
    for(i=0;i<strlen(str);i++){
        if(first!=NULL){
            if(str[i]==first->elem){//スタックにノードを追加
                push(&first,str[i]);
            }
            else{//スタックからデータを取り出す
                pop(&first);
                count+=2;//一回取り出すごとに２つのキューブをとりだしている。
            }
        }else{//初期状態のノードにデータを追加
            push(&first,str[i]);
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 4948
#include "bits/stdc++.h"
 
using namespace std;
 
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int unsigned long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
 
 
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
 
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;
 
const int MOD = 1000*1000*1000 + 7;
const int NMAX = 1000*1000 + 11;
 
int n,m,p,q,k,a,b,c,ans;
string s,str;
vector<int> v;
vector<vector<int> > gr;
int ch[65][200011];
 
void solve()
{
    int x,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>x;
        // par[x] = i;
        ch[0][i] = x;
        // tr(i,ch[0][i]);
    }
 
    for(int j=1;j<64;j++){
        for(int i=1;i<=n;i++)
        ch[j][i] = ch[j-1][ch[j-1][i]];
    }
    int m = 1;
    while(m--){
        int x = 1;
        int ans = x;
        int cur = k;
        // cout<<cur<<" ";
        for(int32_t j=63;j>=0;j--){
            if(cur >= (1LL<<j)){
                // tr(j,ch[j][ans]);
                ans = ch[j][ans];
                cur = cur - (1LL<<j);
            }
        }
        cout<<ans<<" ";
    }
}
 
int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 103668
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <deque>
#include <complex>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
typedef long long int LL;
typedef vector<LL> VI;
typedef pair<LL,LL> pL;
typedef vector<pL> vpL;
typedef pair<LL,pL> ppL;
typedef vector<ppL> vppL;
const LL INF=(LL)1<<60;
VI vx,vy;
vpL vp;
LL find(LL x,LL y){
	LL maxim=0;
	REP(i,vp.size())
		maxim=max(maxim,abs(vp[i].first-x)+abs(vp[i].second-y));
	return maxim;
}
int main() {
	// your code goes here
	
	LL W,H,N;
	cin >> H >> W  >> N;
	REP(i,N){
		LL x,y;
		cin >> x >> y;
		vx.push_back(x);
		vy.push_back(y);
		vp.push_back(pL(x,y));
	}
	sort(vx.begin(),vx.end());
	sort(vy.begin(),vy.end());
	VI useX,useY;
	REP(i,2){
	useX.push_back((vx.size()-i)/2);
	useY.push_back((vy.size()-i)/2);
	}
	vppL anses;
	LL minium=INF;
	REP(k,2)
		REP(j,2){
			LL sumX=0,sumY=0;
			LL ans=0;
			REP(i,N)
				sumX+=abs(vx[i]-vx[useX[k]]);
			REP(i,N)
				sumY+=abs(vy[i]-vy[useY[j]]);
			anses.push_back(ppL(sumX*2+sumY*2-find(vx[useX[k]],vy[useY[j]]),pL(vx[useX[k]],vy[useY[j]])));
		}
	sort(anses.begin(),anses.end());
	cout << anses[0].first << endl << anses[0].second.first << " " << anses[0].second.second << endl;
	return 0;
}

Measured memory_bytes: 4528
# ABD
# AtCoder Beginner Contestが始まってから早数十年。
# コンテストは1回目から順に ABC001,ABC002,...,と名付けられてきましたが、 999回目のコンテスト ABC999 を終え、
# これからのコンテストの名前をどうするかという問題が生じました。
# そこで、1000回目から1998回目のコンテストを順に ABD001,ABD002,...,ABD999 と名付けることとなりました。
# 1以上1998以下の整数Nが与えられるので、N回目のコンテストの名前の最初の3文字を出力してください。

# 1 < N < 1998
# Nは整数

N = int(input())

# N回目のコンテストの最初の三文字を出力せよ。

if 1<= N <= 999:
    print("ABC")
elif 1000 <= N <= 1998:
    print("ABD")

Measured memory_bytes: 9016
import java.util.*;

public class Main{
    
    public static Scanner sc;
    public static int n;
    
    public static void main(String[] args){
        sc = new Scanner(System.in);
        
        final int INF = 1_000_000_000;
        
        n = sc.nextInt();
        
        char[][] grd = new char[n][];
        
        for(int i=0; i<n; i++){
            String line = sc.next();
            grd[i] = line.toCharArray();
        }
        
        int ans = 0;
        for(int i=0; i<n; i++){
            boolean res = check(grd, i);
            ans += (res)? n : 0;
        }
        
        System.out.println(ans);
    }
    
    public static boolean check(char[][] grd, int a){
        char[][] newgrd = new char[n][n];
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                newgrd[i][j] = grd[(i+a)%n][j];
            }
        }
        
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(newgrd[i][j] != newgrd[j][i]){
                    return false;
                }
            }
        }
        
        return true;
    }
}


Measured memory_bytes: 49692
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 200005;

struct Edge { int p, v, r; };
int n, par[2][MAXN], typ[2][MAXN], rt[2], ans[MAXN], cur[MAXN];
vector <int> adj[2][MAXN];
vector <Edge> G[MAXN];

inline void Addedge(int x, int y) { G[x].pb({y, 0, G[y].size()}), G[y].pb({x, 0, G[x].size() - 1}); }

inline void Dfs(int x, int t)
{
	typ[t][x] = 1;
	for (auto y : adj[t][x])
		Dfs(y, t), typ[t][x] ^= 1;
}

inline void Dfs(int x)
{
	while (cur[x] < G[x].size())
		if (G[x][cur[x]].v)
			cur[x] ++;
		else
		{
			int c = cur[x];
			G[x][c].v = 1;
			G[G[x][c].p][G[x][c].r].v = 1;
			if (x && G[x][c].p == x + n)
				ans[x] = -1;
			else if (x - n && G[x][c].p == x - n)
				ans[x - n] = 1;
			Dfs(G[x][c].p);
		}
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 1; i <= n; i ++)
		par[0][i] = Read(), rt[0] = par[0][i] == -1 ? i : rt[0], adj[0][par[0][i]].pb(i);
	for (int i = 1; i <= n; i ++)
		par[1][i] = Read(), rt[1] = par[1][i] == -1 ? i : rt[1], adj[1][par[1][i]].pb(i);
	Dfs(rt[0], 0);
	Dfs(rt[1], 1);
	for (int i = 1; i <= n; i ++)
		if (typ[0][i] ^ typ[1][i])
			return puts("IMPOSSIBLE"), 0;
	puts("POSSIBLE");
	for (int i = 1; i <= n; i ++)
		if (~par[0][i])
			Addedge(par[0][i], i);
		else
			Addedge(0, i);
	for (int i = 1; i <= n; i ++)
		if (~par[1][i])
			Addedge(par[1][i] + n, i + n);
		else
			Addedge(0, i + n);
	for (int i = 1; i <= n; i ++)
		if (typ[0][i])
			Addedge(i, i + n);
	Dfs(0);
	for (int i = 1; i <= n; i ++)
		printf("%d%c", ans[i], i == n ? '\n' : ' ');
	return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int d = n%1000;
    //cout<<d;
    int change=0;

    if(d>0 && d<1000)
    {
        change = 1000 -d;
    }
    else if(d==0)
        change=0;

    cout<<change;
        return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args){
	Scanner stdin = new Scanner(System.in);
	Stack<Integer> stack = new Stack<Integer>();
	while(stdin.hasNextInt()){
	    int i = stdin.nextInt();
	    if(i != 0){
		stack.push(i);
	    } else {
		System.out.println(stack.pop());
	    }
	}
    }
}

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

#define int long long


signed main() {
    
    char s;
    cin >> s;
    switch(s){
        case 'a':
        case 'i':
        case 'u':
        case 'e':
        case 'o':
            cout << "vowel" << endl;
            break;
        default:
            cout << "consonant" << endl;;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

ll d, ans, m, x, q;
ll c[30], s[370][30], lst[30];

int main() {
	ll i, j, re, mx, mj;
	cin >> d;
	for(i=1; i<=26; i++) cin >> c[i];
	for(i=1; i<=d; i++) for(j=1; j<=26; j++) cin >> s[i][j];
	for(i=1; i<=d; i++) {
		mx = -1e9, mj = 0;
		for(j=1; j<=26; j++) {
			re = s[i][j] + c[j] * (i-lst[j]);
			if(re > mx) {
				mx = re;
				mj = j;
			} else if (re==mx && c[j]>c[mj]) mj = j;
		}
		lst[mj] = i;
		cout << mj << endl;
	}
	return 0;
}

Measured memory_bytes: 3696
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

highmax = 0
maxs=0
for i in range(n):
    if highmax < a[i]:
        highmax = a[i]
        maxs = i

for i in range(n):
    max = 0
    if maxs != i:
        print(a[maxs])
    else:
        for j in range(n):
            if i != j:
                if max < a[j]:
                    max = a[j]
        print(max)
            

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

using namespace std;

int main() {
	// your code goes here
	string s;
	cin >> s;
	if (s=="Sunny") cout << "Cloudy";
	else if (s=="Cloudy") cout << "Rainy";
	else if (s=="Rainy") cout << "Sunny";
	return 0;
}

Measured memory_bytes: 256
def c_bridge(N, M, E):
    # N: 頂点の数, M: 辺の数, E: 辺で結ばれる頂点の組
    def dfs(v):
        is_visited[v] = True  # 現在の頂点を訪問済にする
        for v2 in range(N):
            if not graph[v][v2] or is_visited[v2]:
                continue  # 頂点v2に行けないか、行く必要がない
            dfs(v2)

    graph = [[False for _ in range(N)] for _ in range(N)]
    for a, b in E:
        graph[a - 1][b - 1] = True
        graph[b - 1][a - 1] = True

    # 各辺は橋か？ グラフからその辺を取り除いて、グラフが連結かを判定
    ans = 0
    for a, b in E:
        # 辺を取り除く
        graph[a - 1][b - 1] = False
        graph[b - 1][a - 1] = False

        # すべての辺を未訪問として初期化
        is_visited = [False for _ in range(N)]
        # 頂点0からDFS
        dfs(0)
        # すべての頂点が訪問済なら連結、そうでなければ非連結
        if not all(is_visited):
            ans += 1

        # 辺を復元
        graph[a - 1][b - 1] = True
        graph[b - 1][a - 1] = True
    return ans

N,M = [int(i) for i in input().split()]
E = [[int(i) for i in input().split()] for j in range(M)]
print(c_bridge(N, M, E))

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dump(x) cerr << #x " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define endl '\n'

#ifdef _DEBUG27_
    //#define STRESS 1
#endif

typedef long long llong;

const int INF = 2e9 + 999;
const llong LINF = 2e18 + 999;

void inv(bool e);
template<typename T> T sign(T a);
template<typename T> void die(T &a);
template<typename T> void umax(T &a, T b);
template<typename T> void umin(T &a, T b);

bool brute, alter;
int cnt_tests = 1;

// Get + in div1

// Code below

llong n, k;

void inp() {
    cin >> n >> k;
}

void solve() {
    llong res = 1;
    for (llong i = 0; i < n; ++i) {
        if (res * 2ll < res + k) {
            res *= 2ll;
        } else {
            res += k;
        }
    }
    cout << res;
}

void stress() {

}

void naive() {

}

void run();
int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (0) {
            freopen("palindrome.in", "r", stdin);
            freopen("palindrome.out", "w", stdout);
        }
    #endif
    srand(time(0));
    #ifdef STRESS
        brute = true;
    #else
        brute = false;
    #endif

    for (int i = 0; (i < cnt_tests); i++) {
        run();
    }

    #ifdef _DEBUG27_
        cout << endl << "Time: " << clock() / 1000.0 << " ms";
    #endif
    return 0;
}

void run() {
    if (!brute) {
        inp();
    }
    else {
        stress();
    }
    solve();
    cout << endl;
}

template<typename T>
void die(T &a) {
    cout << a;
    exit(0);
}

template<typename T>
T sign(T a) {
    if (a == 0)
        return 0;
    if (a < 0)
        return -1;
    return 1;
}

template<typename T>
void umax(T &a, T b) {
    if (b > a)
        a = b;
}

template<typename T>
void umin(T &a, T b) {
    if (b < a)
        a = b;
}

void inv(bool e) {
    if (!e) {
        vector<int> a;
        a[-1] += 1;
    }
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


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

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  int N; cin >> N;
  vector <ll> A(3 * N);
  for (int i = 0; i < 3 * N; i++){
    cin >> A[i];
  }
  
  priority_queue <ll, vector<ll>, greater<ll> > que1;
  priority_queue <ll> que2;

  ll sum1 = 0, sum2 = 0;
  for (int i = 0; i < N; i++){
    sum1 += A[i];
    que1.push(A[i]);
  }

  for (int i = 2 * N; i < 3 * N; i++){
    sum2 += A[i];
    que2.push(A[i]);
  }
  
  vector <ll> S1(N + 1), S2(N + 1);
  S1[0] = sum1; S2[N] = sum2;

  for (int i = 0; i < N; i++){
    que1.push(A[N + i]);
    sum1 += A[N + i] - que1.top();
    que1.pop();
    S1[i + 1] = sum1;
  }
  
  for (int i = 0; i < N; i++){
    que2.push(A[2 * N - 1 - i]);
    sum2 += A[2 * N - 1 - i] - que2.top();
    que2.pop();
    S2[N - i - 1] = sum2;
  }

  
  ll ans = -1 * 1e18;
  for (int i = 0; i < N + 1; i++){
    if (ans < S1[i] - S2[i]){
      ans = S1[i] - S2[i];
    }
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
using namespace std;
#define INF INT_MAX/3

int main(){
    int N,M,R;cin >> N >> M >> R;
    vector<int> vis;
    vector<vector<int> >dist(N);
    for(int i = 0 ; i < R ; i++){
        int r;cin >> r;r--;
        vis.push_back(r);
    }
    for(int i = 0 ; i < N ; i++){
        dist[i].resize(N);
        for(int j = 0; j < N ; j++){
            if(i == j)dist[i][j] = 0;
            else dist[i][j] = INF;
        }
    }
    for(int i = 0; i < M ; i++){
        int u,v,cost;
        cin >> u >> v >> cost;u--;v--;
        dist[u][v] = cost;
        dist[v][u] = cost;
    }
    //warshall_floyd
    
    for(int k = 0 ; k < N ; k++){
        for(int i = 0 ; i < N ; i++){
            for(int j = 0 ; j < N ; j++){
                dist[i][j] = min(dist[i][j],dist[k][j]+dist[i][k]);
            }
        }
    }
    int res = INF;

    sort(vis.begin(), vis.end());
    do {
        int tmp = 0;
        for (int i = 1; i < vis.size(); ++i) tmp += dist[vis[i]][vis[i-1]];
        res = min(res, tmp);
    } while (next_permutation(vis.begin(), vis.end()));
    

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  int sum=0;
  for(int i=0;i<N;i++)
    sum+=A.at(i);
  int x;
  if(sum%N<=N/2)
    x=sum/N;
  else
    x=(sum/N)+1;
  int ans=0;
  for(int i=0;i<N;i++)
    ans+=pow(x-A.at(i),2);
  cout<<ans<<endl;
   return 0;
}

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

using namespace std;

using int64 = long long;

constexpr int M = 13;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

constexpr int64 P = 1000000007;

// Verified: ABC133E, ABC132D, ABC130E
struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 input_x) : x(input_x) {}
  FiniteField() : x(0) {}
  int64 Value() { return x; }
  inline FiniteField operator+(FiniteField o) {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

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

  string input;
  cin >> input;
  int n = input.length();

  vector<vector<FiniteField>> dp = Make2DVector(n + 1, M, FiniteField(0));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < M; j++) {
      if (input[i] == '?') {
        for (int k = 0; k < 10; k++) {
          int next_j = (j * 10 + k) % M;
          dp[i + 1][next_j] += dp[i][j];
        }
      } else {
        int d = input[i] - '0';
        int next_j = (j * 10 + d) % M;
        dp[i + 1][next_j] += dp[i][j];
      }
    }
  }
  // for (int j = 0; j < M; j++) cout << dp[0][j].Value() << " ";
  // cout << endl;
  // for (int j = 0; j < M; j++) cout << dp[1][j].Value() << " ";
  // cout << endl;
  cout << dp[n][5].Value() << endl;
}


Measured memory_bytes: 13648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int K,X;
    cin >> K >> X;
    int x=(X+499)/500;
    if(K>=x) cout << "Yes" << endl;
    else cout << "No" << endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main(){
	int A, B;
	cin >> A >> B;
	string S = "Yay!";
	if( A > 8 || B > 8 ){
		S = ":(";
	}
	cout << S << endl;
	return 0;
}

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

int main(){
  int a,b; cin >> a >> b;
  string s; cin >> s;
  
  bool check=true;
  for(int i=0; i<s.size(); i++){
    if(i==a){
      if(s[i]!='-'){
        check=false;
        break;
      }
    }else{
      if(s[i]=='-'){
        check=false;
        break;
      }
    }
  }
  cout << (check?"Yes":"No") << endl;
}

Measured memory_bytes: 256