akhauriyash/Code-Regression huggingface dataset:
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		String S = sc.next();
		String T = sc.next();
		HashMap<String, String> mapS = new HashMap<String, String>();
		HashMap<String, String> mapT = new HashMap<String, String>();
		boolean ans = true;
		
		for(int i = 0; i < S.length(); i++){
			String cs = "" + S.charAt(i);
			String ct = "" + T.charAt(i);
			
			if(mapS.containsKey(cs)){
				if(!ct.equals(mapS.get(cs))){
					ans = false;
					break;
				}
			}else mapS.put(cs, ct);
			
			if(mapT.containsKey(ct)){
				if(!cs.equals(mapT.get(ct))){
					ans = false;
					break;
				}
			}else mapT.put(ct, cs);
		}
		
		System.out.println(ans?"Yes":"No");
	}
}

Measured memory_bytes: 46444
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<ll> A(7);
  rep(i, 7) cin >> A[i];
  ll ans = 0;
  ans = A[1] + A[0]/2*2 + A[3]/2*2 + A[4]/2*2;
  if(A[0] && A[3] && A[4]) {
    ll tmp = 3 + A[1] + (A[0]-1)/2*2 + (A[3]-1)/2*2 + (A[4]-1)/2*2;
    ans = max(tmp, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3656
N = int(input())
INF = 1000000
B = [INF]*(N+1)
tmp = list(map(int, input().split()))
for i in range(1, N):
    B[i] = tmp[i-1]
A = []
for i in range(N):
    A.append(min(B[i], B[i+1]))
print(sum(A))

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

int main(void){
    int N,M;
    cin >> N >> M;
    int aM[M];
    int bM[M];
    for(int i = 0 ; i < M ; i++){
        cin >> aM[i] >> bM[i];
    }
    
    vector<int> counter(N+1);
    for(int i = 1 ; i <= N ; i++){
        counter[i] = 0;
        for(int j = 0 ; j < M ; j++){
            if( i == aM[j] || i == bM[j] ) counter[i]++;
            
        }
    }
    
    for(int i = 1 ; i <= N ; i++){
        cout << counter[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
char s[N];
int cur[N], fin[N], X[N], pref[N], lst[13][N];

int pw(int x, int y) {
  int r = 1;
  for (; y; y /= 2, x *= x)
    if (y & 1)
      r *= x;
  return r;
}

int main() {
  int n; scanf("%d", &n); int nn = pw(3, n);
  scanf("%s", s+1);
  int m = strlen(s+1);
  for (int i = 1; i <= m; i++) {
    lst[0][i] = 0;
    pref[i] = pref[i-1] + (s[i] == 'S');
  }
  auto get = [&](int i, int j) {
    int cnt = (pref[j] - pref[X[i]]) % 2; X[i] = j;
    return cur[i] = (cur[i] ^ (3 * cnt)) % 3;
  };
  for (int i = 3, it = 1; i <= nn; i *= 3, it++) {
    for (int j = 0; j < i; j++)
      cur[j] = j / (i / 3), X[j] = 0;
    lst[it][0] = i-1;
    for (int j = 1; j <= m; j++) {
      for (int u = lst[it-1][j-1]; u < i; X[u] = j, u += i / 3) {
        get(u, j-1);
        if (s[j] == 'R')
          (cur[u] += 1) %= 3;
        else
          (cur[u] ^= 3) %= 3;
      }
      for (int u = lst[it-1][j]; u < i; u += i / 3)
        if (get(u, j) == 2)
          lst[it][j] = u;
    }
    for (int j = 0; j < nn; j++)
      fin[j] += get(j % i, m) * (i / 3);
  }
  for (int i = 0; i < nn; i++)
    printf("%d ", fin[i]);
  enl;
  return 0;
}

Measured memory_bytes: 21588
import java.util.Arrays;
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int K = sc.nextInt();
		int T = sc.nextInt();
		int[] A = new int[T];
		for (int i = 0; i < T; i++) {
			A[i] = sc.nextInt();
		}
		if (T == 1) {
			System.out.println(A[0] - 1);
			return;
		}
		Arrays.sort(A);
		System.out.println(Math.max((K - 1) - (K - A[T - 1]) * 2, 0));
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 21972
# C - Inserting 'x'
s = input()

cnt = 0
l = 0
r = len(s)-1
while r>l:
    if ( s[l]==s[r] ):
        l+=1
        r-=1
        #print("same")
    else:
        if ( s[r]=="x" ):
            cnt+=1
            r-=1
            #print("r")
        elif ( s[l]=="x" ):
            cnt+=1
            l+=1
            #print("l")
        else:
            cnt=-1
            break

print(cnt)

Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def f(n):
    r = 2
    ret = 1
    for i in range(n, n-r, -1):
        ret *= i
    for i in range(1, r+1):
        ret //= i
    return ret * 2 + n


class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo

@mt
def slv(N, M, A):
    A.sort(reverse=True)
    print(A)
    b = Bisect(f)

    i = b.bisect_left(M, 1, N)
    if f(i) != M:
        i -= 1
    l = f(i)

    ans = 0
    for j in range(i):
        ans += A[j] * 2
        ans += A[j] * (i-1)

    rem = M - l
    print(i, l, rem)
    j = 0
    while rem != 0:
        ans += A[j] + A[i]
        rem -= 1
        if rem == 0:
            break
        ans += A[j] + A[i]
        rem -= 1
        if rem == 0:
            break
        j += 1


    return ans

import numpy as np
def slv2(N, M, A):
    C = Counter(A)
    B = [C[i] for i in range(2**18)]
    D = np.fft.rfft(B)
    D *= D
    E = list(np.fft.irfft(D).real)
    ans = 0
    c = 0
    i = 2**18 - 1
    while c != M:
        n = int(round(E[i]))
        if n != 0:
            if c + n > M:
                n = M-c
            c += n
            ans += i * n
        i -= 1
        assert i != -1

    return ans

def main():
    N, M = read_int_n()
    A = read_int_n()
    print(slv2(N, M,A))

    # N = 10**5
    # M = random.randint(1, N**2)
    # A = [random.randint(1, 10**5) for _ in range(N)]
    # print(slv(N, M, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 44256
#D
s_list=list(input())
q=int(input())
r=0
sl_list=[]
for i in range(q):
    ope=input().split()
    if ope[0]=='1':
        r+=1
    else:
        if (int(ope[1])+r)%2 == 1:
            sl_list.append(ope[2])
        else:
            s_list.append(ope[2])
sl_list.reverse()
s_list=sl_list + s_list
if r%2 !=0:
    s_list.reverse()
print(''.join(s_list))

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long X, long long Y, long long Z, long long K, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    VLL memo;
    sort(ALL(A), greater<LL>());
    sort(ALL(B), greater<LL>());
    sort(ALL(C), greater<LL>());
    REP(i, X) REP(j, Y) REP(k, Z) {
        if(i*j*k > K) continue;

        memo.PB(A[i]+B[j]+C[k]);
    }

    sort(ALL(memo), greater<LL>());
    REP(i, K) {
        cout << memo[i] << endl;
    }
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(X);
    for(int i = 0 ; i < X ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(Y);
    for(int i = 0 ; i < Y ; i++){
        scanf("%lld",&B[i]);
    }
    std::vector<long long> C(Z);
    for(int i = 0 ; i < Z ; i++){
        scanf("%lld",&C[i]);
    }
    solve(X, Y, Z, K, std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 34920
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

/* 二項係数 C(n,k) mod p を計算 */
const int MOD = 1000000007;
const int MAX = 201000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll H,W,A,B;
  cin >> H >> W >> A >> B;
  COMinit();

  ll x = H-A;
  ll y = B+1;
  ll ans = 0;
  REP(i, min(H-A,W-B)){
    (ans += (COM(x+y-2,x-1) * COM(H+W-x-y,H-x))%MOD ) %= MOD;
    x--; y++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 4992
#include <iostream>

int main() {
  std::string s;
  unsigned long long k;

  std::cin >> s >> k;
  
  k--;
  
  unsigned long long i = 0;
  while (s[i] == '1' && i < k) i++;
  if (s[i] == '\0') std::cout << '1' << std::endl;
  else std::cout << s[i] << std::endl;
  return 0;
}


Measured memory_bytes: 384
from itertools import product

h, w, k = map(int, input().split())
table = [list(input()) for _ in range(h)]

ans = 0

for row_bit in product(range(2), repeat=h):
    for col_bit in product(range(2), repeat=w):
        tmp = 0
        for row in range(h):
            for col in range(w):
                if table[row][col] == "#" and (row_bit[row] and col_bit[col]):
                    tmp += 1
        if tmp == k:
            ans += 1

print(ans)


Measured memory_bytes: 9128
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    int n, m;
    cin >> n >> m;

    int a[m];
    REP(i, m) a[i] = 0;

    REP(i, n) {
        int k;
        cin >> k;
        REP(j, k) {
            int tmp;
            cin >> tmp;
            a[tmp - 1]++;
        }
    }

    int count = 0;
    REP(i, m)
        if (a[i] == n) count++;

    cout << count << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	long long a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	//cout<<a[0]<<" "<<a[2]<<" "<<a[3]<<endl;
	if(a[2]%2==0 || a[1]%2==0 || a[0]%2==0)  cout<<0<<endl;
	else cout<<a[0]*a[1]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

const int MAXN = 500050;
int n, m, k;
vector<int> fr[MAXN];
int bl[MAXN];
int repr[MAXN];
bool vis[MAXN];
map<int, int> nic;

int dfs(int i, int r) {
    vis[i] = 1;
    repr[i] = r;
    int ans = 1;
    for (int next: fr[i]) {
        if (!vis[next]) ans += dfs(next, r);
    }
    return ans;
}

void solve() {
    // read input
    sc(n); sc(m); sc(k);
    int u, v;
    fo(i, m) {
        sc(u); sc(v);
        fr[u].pb(v);
        fr[v].pb(u);
    }
    //set vis to 0, run dfs on nonvisited
    fo1(i, n) vis[i] = 0;
    fo1(i, n) {
        if (!vis[i]) nic[i] = dfs(i, i);
    }
    // block people in the same component
    fo1(i, n) bl[i] = 0;
    fo(i, k) {
        sc(u); sc(v);
        if (repr[u] == repr[v]) {
            bl[u]++;
            bl[v]++;
        }
    }
    //for each node, get # in component - fr - bl - 1 (self)
    fo1(i, n) {
        pd(nic[repr[i]]-fr[i].size()-bl[i]-1);
    }
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 20992
import java.util.*;

public class Main {
	void doIt() {
		new Pollocks_conjecture().main();
	}

	class Pollocks_conjecture{
		final int MAX = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		final int LEN = 1000000;
		void main() {
			List<Integer> li = new ArrayList<>();
			for(int i = 1; i < LEN; i++) {
				int val = cul(i);
				if(val <= LEN) {
					li.add(val);
				}
				else {
					break;
				}
			}
			int dp[] = new int[LEN];
			int dpe[] = new int[LEN];
			Arrays.fill(dp, MAX);
			Arrays.fill(dpe, MAX);
			dp[0] = 0;
			dpe[0] = 0;
			for(int i = 1; i <= li.size(); i++) {
				int w = li.get(i - 1);
				for(int j = w; j < LEN; j ++) {
					dp[j] = Math.min(dp[j], dp[j - w] + 1);
				}
				if(w % 2 != 0) {
					for(int j = w; j < LEN; j ++) {
						dpe[j] = Math.min(dpe[j], dpe[j - w] + 1);
					}
				}

			}

			while(true) {
				int n = sc.nextInt();
				int len = 0;
				if(n == 0) return;		
				System.out.println(dp[n] + " " + dpe[n]);
			}
		}

		int cul(int n) {
			return (n) * (n + 1) * (n + 2) / 6;
		}
	}

	public static void main(String[] args) {
		new Main().doIt();
	}

}


Measured memory_bytes: 35412
###SPEED TEST###
#import sys
#input=sys.stdin.readline
n,c,k=map(int,input().split())
t=[int(input()) for _ in range(n)]
t.sort()
p=1
dt=t[0]+k
ans=0
for i in range(1,n):
    if p==c:
        p=1
        ans+=1
        dt=t[i]+k
    elif dt<t[i]:
        p=1
        ans+=1
        dt=t[i]+k
    else:
        p+=1
print(ans+1)

Measured memory_bytes: 7388
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define NFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); --i)
#define endl "\n"
#define mp make_pair
#define X first
#define Y second
#define inf 1e18
#define mod 1000000007
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()
#define sz(x) int(x.size())
// #define lli int
typedef long long int lli;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<lli,lli> pll;
typedef vector<lli> vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

const int N = 100010;

int val1[N];
bool isPresent[N];
int dp[(1<<16) + 1];
bool good[(1<<16) + 1];

int main() {
	int n; cin >> n;
	FOR(i, 1, n-1) {
		int a1, b1, c1; cin >> a1 >> b1 >> c1; a1++, b1++;
		val1[a1] ^= c1, val1[b1] ^= c1;
	}
	int answer1 = 0;
	int remain = 0;
	FOR(i, 1, n) {
		if (val1[i] == 0) {
			answer1++; continue;
		}
		if (isPresent[val1[i]]) {
			answer1++, isPresent[val1[i]] = false;
		} else {
			isPresent[val1[i]] = true;
		}
		remain ^= (1<<val1[i]);
	}
	FOR(i, 0, (1<<16)-1) {
		int currentMask = 0;
		FOR(j, 0, 16) {
			if (i & (1<<j)) {
				currentMask ^= j;
			}
		}
		if (currentMask == 0) {
			good[i] = true;
		}
	}
	FOR(i, 0, (1<<16)-1) {
		for (int j = i; j > 0; j = (j -1) & i) {
			if (good[i ^ j]) {
				dp[i] = max(dp[i], dp[j] + 1);
			}
		}
	}
	cout << n - (answer1 + dp[remain]) << "\n";
return 0;}

Measured memory_bytes: 1024
h,w,k=map(int,input().split())
def amida_h1_total(w):
    if w<0:
        return 0
    if w==0:
        return 1
    return amida_h1_total(w-1)+amida_h1_total(w-2)
def amida(h,w,k):
    memo=[[-1 for _ in range(w)] for _ in range(h)]
    memo[0][0]=amida_h1_total(w-1)
    if w>1:
        memo[0][1]=amida_h1_total(w-2)
    for i in range(2,w):
        memo[0][i]=0
    def _amida(h,k):
        if k<=0 or k>w:
            return 0
        if memo[h-1][k-1]>=0:
            return memo[h-1][k-1]
        memo[h-1][k-1]=sum((_amida(h-1,k-1)*amida_h1_total(k-2)*amida_h1_total(w-k),
                            _amida(h-1,k)  *amida_h1_total(k-1)*amida_h1_total(w-k),
                            _amida(h-1,k+1)*amida_h1_total(k-1)*amida_h1_total(w-k-1)))%1000000007
        return memo[h-1][k-1]
    return _amida(h,k)
print(amida(h,w,k))


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

int main(){
  int N,M;
  int ju = 1;            //条件を満たす値が存在するかどうか
  cin >> N >> M;
  vector<int> ans(N,0);  //N桁で各桁が0で初期化された整数
  if(N != 1){
    ans.at(0) = 1;
  }
  
  for(int i = 0;i < M;i++){
    int s,c;
    cin >> s >> c;
    s--;
    //一番左の桁が0で答えが0でないとき
    if(s == 0 && c == 0 && N != 1){
      ju = 0;
      break;
    }
    if((ans.at(s) == 0)||(s == 0 && N != 1 && ans.at(s) == 1)){
      ans.at(s) = c;
    }else if(ans.at(s) != c){
      ju = 0;
      break;
    }
  }
  
  if(!ju){
    cout << -1;
  }else{
    for(int i = 0;i < N;i++){
      cout << ans.at(i);
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
    int n;
    cin>>n;
    int a[n/2]; 
    int b[n/2];
    vector <pair<int,int> > an(100001);
    vector <pair<int,int> > bn(100001); 

    for(int i = 0; i<100001; i++){
        an[i].first=0;
        an[i].second=i;
        bn[i].first=0;
        bn[i].second=i;
    }

    for(int i = 0; i<n/2; i++){
        cin>>a[i];
        an[a[i]].first++;
        cin>>b[i];
        bn[b[i]].first++;
    }
    sort(an.begin(),an.end());
    sort(bn.begin(),bn.end());
    

    if(an[100000].second!=bn[100000].second) cout<<n-an[100000].first-bn[100000].first<<endl;
    else if(an[100000].second==bn[100000].second){
        if(an[100000].first+bn[99999].first>an[99999].first+bn[100000].first){
            cout<<n-an[100000].first-bn[99999].first<<endl;
        }
        else{
            cout<<n-bn[100000].first-an[99999].first<<endl;
        }
    }

    return 0;
}




Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    vector<int>s(M),c(M),ans(N,0),ch(N,0);
    for(int i=0;i<M;i++){
        cin >> s[i] >> c[i];
    }
    for(int i=0;i<M;i++){
        if(ch[s[i]-1]==0){
            ans[s[i]-1]=c[i];
            ch[s[i]-1]=1;
        }else{
            if(ans[s[i]-1]!=c[i]){
                cout << "-1";
                break;
            }
        }
        if(i==M-1){
            if(N==1 && ans[0]==0){
                for(int i=0;i<N;i++){
                    cout << ans[i];
                }
            }else if(ans[0]==0 && ch[0]==1){
                cout << "-1";
            }else if(ch[0]==0){
                ans[0]=1;
                for(int i=0;i<N;i++){
                    cout << ans[i];
                }
            }else{
                for(int i=0;i<N;i++){
                    cout << ans[i];
                }
            }
        }
    }
    if(M==0 && N==1){
        for(int i=0;i<N;i++){
            cout << ans[i];
        }
    }else if(M==0){
        ans[0]=1;
        for(int i=0;i<N;i++){
            cout << ans[i];
        }    
    }
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n,W;
  int cnt=1;
  while(cin>>W,W){
    cin>>n;
    vector<int>v(n);
    vector<int>w(n);
    for(int i=0;i<n;i++)
      scanf("%d,%d",&v[i],&w[i]);
    int dp[n+1][W+1]={};
    for(int i=n-1;i>=0;i--){
      for(int j=0;j<=W;j++){
	if(j-w[i]<0)dp[i][j]=dp[i+1][j];
	else if(j-w[i]>=0)dp[i][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
      }
    }
    int ma=dp[0][W];
    int weight=W;
    for(int i=W;i>=0;i--){
      if(ma==dp[0][i]){
      weight=i;
      }else
	break;
    }
    cout<<"Case"<<" "<<cnt<<':'<<endl;
    cout<<dp[0][W]<<endl;
    cout<<weight<<endl;
    cnt++;
  }
  return 0;
}



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

string a;
long long x,y,z;

int main(){
	cin>>a;
  for (int i=0;i<a.size(); ++i){
  	if (a[i] == 'W'){
    	x += i;
        y++;
    }
  }
  x -= (y*(y-1))/2;
  cout<<x;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first

const int N=102000;
ll dp[N];
int n;
int a[N];
int k;
ll go(int idx){
    if(idx==n-1)
        return 0;
    if(idx>=n)
        return 2e18;
    ll &ret=dp[idx];
    if(ret != -1)
        return ret;
    ret=2e18;
    for(int i=1;i<=k;i++)
    ret = min(ret, go(idx+i)+abs(a[idx+i]-a[idx]) );
    //ret = min(ret, go(idx+2)+abs(a[idx+2]-a[idx]) );
    //cout<<idx<<' '<<dp[idx]<<endl;
    return ret;
}

int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    memset(dp,-1,sizeof dp);
    cout<<go(0);

}


Measured memory_bytes: 6144
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors


def solve():
    N = int(input())
    
    ans = 0
    for i in range(1, N + 1, 2):
        divisors = make_divisors(i)
        if len(divisors) == 8:
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()


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

int main() {

    //int n;
    //scanf("%d",&n);

    char s[2];
    scanf("%s", s);

    if(s[1]=='5'){
        printf("Christmas");
    }else if(s[1]=='4'){
        printf("Christmas Eve");
    } else if (s[1] == '3') {
        printf("Christmas Eve Eve");
    } else if (s[1] == '2') {
        printf("Christmas Eve Eve Eve");
    }


    return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef struct {
    int a; int b; int c; int d;
}Data;
vector<Data> ans;
priority_queue< int, std::vector<int>, std::greater<int> >
find_(priority_queue< int, std::vector<int>, std::greater<int> > y, int f) {
    priority_queue< int, std::vector<int>, std::greater<int> > ret;
    bool ok = true;
    while(!y.empty()) {
        int tmp = y.top();
        y.pop();
        if(tmp == f) {
            ok = false;
            continue;
        }
        ret.push(tmp);
    }
    if(ok) ret.push(f);
    return ret;
}
int main() {
    int h, w; cin >> h >> w;
    priority_queue< int, std::vector<int>, std::greater<int> > x[h];
    int a[h][w];
    rep(i, h) rep(j, w) {
        cin >> a[i][j];
        if(a[i][j] % 2) x[i].push(j);
    }
    rep(i, h-1) {
        while(x[i].size() > 1) {
            int first = x[i].top(); x[i].pop();
            int second = x[i].top(); x[i].pop();
            //printf("%d %d\n",first,second);
            rep(j, second-first) {
                ans.push_back(Data{i,first+j,i,first+j+1});
            }
        }
        if(x[i].size()==1) {
            x[i+1] = find_(x[i+1], x[i].top());
            ans.push_back(Data{i,x[i].top(),i+1,x[i].top()});
        }
    }
    while(x[h-1].size() > 1) {
        int first = x[h-1].top(); x[h-1].pop();
        int second = x[h-1].top(); x[h-1].pop();
        rep(j, second-first) {
            ans.push_back(Data{h-1,first+j,h-1,first+j+1});
        }
        
    }
    cout << ans.size() << endl;
    rep(i, ans.size()) {
        printf("%d %d %d %d\n",ans[i].a+1,ans[i].b+1,ans[i].c+1,ans[i].d+1);
    }
}          


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int r, g, b;
    cin >> r >> g >> b;
    if ( (r * 100 + g * 10 + b) % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a[33]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
	int n;cin>>n;
	cout<<a[n-1]<<"\n";
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 2e5 + 10;
vector<ll> graph[MAXN];

ll level[MAXN];
ll k,dist = 0;
void dfs(ll u,ll p){
    level[u] = level[p] + 1;
    if(level[u] > dist){
        dist = level[u],k = u;
    }

    for(ll v:graph[u]){
        if(v == p) continue;
        dfs(v,u);
    }
}

ll win[MAXN];

void solve(){

    ll n; cin>>n;    
    FOR(i,1,n-1){
        ll u,v; cin>>u>>v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(1,0);

    ZERO(level);
    dist = 0;
    dfs(k,0);

    win[1] = true;
    win[2] = false;

    FOR(i,3,dist){
        win[i] = (!win[i-1]) or (!win[i-2]);
    }
    if(win[dist]) cout<<"First\n";
    else cout<<"Second\n";
}

signed main(){

   FastRead;    


    ll t,w;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        solve();
    }
}



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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

#include <bits/stdc++.h>
#define rep(i,a,n) for(ll i = a;i < n;i++)
typedef long long ll;
using namespace std;

int main(){
    ll m,k;
    cin >> m >> k;
    if(pow(2,m) <= k){
        cout << -1 << endl;
    }
    else if(m == 1){
        if(k == 0) cout << "0 0 1 1" << endl;
        else cout << "-1" << endl;
    }
    else{
        cout << k << " ";
        rep(i,0,pow(2,m)){
            if(i == k) continue;
            cout << i << " ";
        }
        cout << k << " ";
        rep(i,0,pow(2,m)){
            if(pow(2,m) - i - 1 == k) continue;
            cout << pow(2,m) - i - 1 << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll x, y;
  cin >> x >> y;
  ll ans = max(400000 - x * 100000, 0ll) + max(0ll, 400000 - y * 100000);
  if (x == 1 && y == 1) ans += 400000;
  cout << ans << endl;
}

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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef double db;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;

const int INF=0x3f3f3f3f;
const int N=303;

int n;
double dp[N][N][N];

double rek(int jed, int dva, int tri) {
    if (jed<0 || dva<0 || tri<0) return 0;
    if (jed==0 && dva==0 && tri==0) return 0;
    double &ret=dp[jed][dva][tri];
    //printf("jed == %d, dva == %d, tri == %d\n", jed, dva, tri);
    if (ret!=0) return ret;
    ret=((db)jed*rek(jed-1, dva, tri)+(db)dva*rek(jed+1, dva-1, tri)+(db)tri*rek(jed, dva+1, tri-1)+n)/(db)(jed+dva+tri);
    //cout <<fixed<<setprecision(10)<<ret<<"\n";
    return ret;
}

int main() {
    int j=0, d=0, t=0;
    scanf("%d", &n);
    for (int i=0; i<n; ++i) {
        int x;
        scanf("%d", &x);
        if (x==1) ++j;
        else if (x==2) ++d;
        else ++t;
    }
    double sol=rek(j, d, t);
    cout <<fixed<<setprecision(12)<<sol<<"\n";
    return 0;
}


Measured memory_bytes: 217344
#include <iostream>
#include <list>
#include <algorithm>
#include <vector>
#include <memory>

int main()
{
    int a, b;
    std::cin >> a >> b;
    if (a <= 5) {
        std::cout << 0 << std::endl;
    } else if (a <= 12) {
        std::cout << b / 2 << std::endl;
    } else {
        std::cout << b << std::endl;
    }
    return 0;
}


Measured memory_bytes: 888
s = input()
n = len(s)

boundary = []
ans = [0] * n

for i in range(n-1):
    if s[i] == "L" and s[i+1] == "R":
        boundary.append(i)

boundary.append(n-1)

l = 0
for r in boundary:
    ## s[l ~~ r]
    middle = 0
    cnt = [0, 0]
    for x in range(l, r+1):
        cnt[x % 2] += 1
        if x < r and s[x] == "R" and s[x+1] == "L":
            middle = x

    ans[middle] = cnt[middle % 2]
    ans[middle + 1] = cnt[1 - (middle % 2)]
    l = r+1

print(" ".join(map(str, ans)))
    

Measured memory_bytes: 12540
'use strict'

const main = (input) => {

  const lines = input.split('\n');
  const [n, m] = lines[0].split(' ').map(e => parseInt(e));
  const pairs = lines.slice(1, 1 + m).map(line => line.split(' ').map(e => parseInt(e)));
  
  const parent = Array.from({length: n}).fill(-1);
  
  function union(a, b) {
      const fa = find(a);
      const fb = find(b);
      // console.log({a,b,fa,fb});
      if (fa === fb) {
          return;
      }
      if (fa === b) {
          return;
      }
      if (fb === a) {
          return;
      }
      
      if (parent[fa] < parent[fb]) {
          parent[fa] += parent[fb];
          parent[fb] = fa;
      } else {
          parent[fb] += parent[fa];
          parent[fa] = fb;
      }
  }
  
  function find(a) {
      if (parent[a] < 0) {
          return a;
      }
      
      const result = find(parent[a]);
      parent[a] = result;
      
      return result;
  }

  for (const pair of pairs) {
      union(pair[0] - 1, pair[1] - 1);
  }

  let result = 0;
  const map = {};
  for (let i = 0; i < n; ++i) {
      if (find(i) in map) {
          map[find(i)] += 1;
      } else {
          map[find(i)] = 1;
      }
  }
  for (const key in map) {
      result = Math.max(result, map[key]);
  }
  // console.log(parent);
  
  console.log(result);
};



main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 103356
// AOJ 1001: Binary Tree Intersection And Union
// 2017.12.14 bal4u@uu

#include <stdio.h>
#include <string.h>

typedef struct { int l, r, c; } T;
T node[210]; int sz;
char buf[1210], *p;
char ans[610], *q;

char *parse(char *p, int i)
{
	node[i].c++; p++;
	if (*p != ',') {
	    if (node[i].l == 0) node[i].l = sz++;
		p = parse(p, node[i].l);
	}
	p++;
	if (*p != ')') {
		if (node[i].r == 0) node[i].r = sz++;
	    p = parse(p, node[i].r);
	}
	return p+1;
}

char *act(char *q, int i, int k)
{
	if (node[i].c < k) return q;
	*q++ = '(';
	if (node[i].l > 0) q = act(q, node[i].l, k);
	*q++ = ',';
	if (node[i].r > 0) q = act(q, node[i].r, k);
	*q++ = ')';
	return q;
}

int main()
{
	int op;
	char *a, *b;

	while (fgets(p=buf, 1210, stdin) != NULL) {
		memset(node, 0, sizeof(node));

		op = *p, p+=2;
		a = p; while (*p != ' ') p++; *p++ = 0;
		b = p;
		sz = 1;
		parse(a, 0);
		parse(b, 0);

		q = act(ans, 0, op == 'i' ? 2 : 1), *q = 0;
		puts(ans);
	}
	return 0;
}

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

using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }

    mint &operator/=(const mint a) { return *this *= a.inv(); }

    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

struct UnionFind {
    vector<int> d;

    UnionFind(int n = 0) : d(n, -1) {}

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int size(int x) { return -d[find(x)]; }
};

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 dfs(int l, char c, string s) {
    if (l == 0 || s == string(l + 1, c))return l;

    string t = "";
    for (int i = 0; i < l; ++i) {
        if (s[i] == c || s[i + 1] == c)t += c;
        else t += s[i];
    }
    return dfs(l - 1, c, t);
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<bool> A(10);
    for (int i = 0; i < k; ++i) {
        int a;
        cin >> a;
        A[a] = true;
    }
    for (int i = n; i < n * 20; ++i) {
        string t = to_string(i);
        bool b = true;
        for (int j = 0; j < t.size(); ++j) {
            if (A[t[j] - '0']) {
                b = false;
                break;
            }
        }
        if (b) {
            cout << t << endl;
            return 0;
        }
    }
    return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, s);
  set<int> seen;
  for (int i = 1; i <= 1000000; ++i) {
    if (!seen.insert(s).second) {
      out(i);
      return 0;
    }
    s = (s & 1) ? (s * 3 + 1) : (s / 2);
  }
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=3e4;
int n;
ll a[maxn+10];
int main()
{
    while(cin>>n)
    {
        ll sum=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            sum+=a[i]-1;
        }
        cout<<sum<<endl;

    }
    return 0;
}

Measured memory_bytes: 256
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
  string N;
  cin >> N;
  REP(i,3) if(N[i] == '1') N[i] = '9';
  else if(N[i] == '9') N[i] = '1';
  cout << N << endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <cstdio>
using namespace std;
const long long mod = 998244353;
const int N = 3e5 + 12;
long long n,k,a,b,g,t1,t2,ans,fac[N],inv[N];
long long qpow(long long x,long long y){long long ret = 1;while(y){if(y & 1)ret = ret * x % mod;x = x * x % mod;y >>= 1;}return ret;}
long long gcd(long long a,long long b){return b ? gcd(b,a % b) : a;}
long long C(int n,int m){return fac[n] * inv[m] % mod * inv[n - m] % mod;}
int main()
{
	if(a > b)swap(a,b);
	scanf("%lld %lld %lld %lld",&n,&a,&b,&k);g = a / gcd(a,b) * b;
	fac[0] = 1;for(int i = 1;i <= n;i++)fac[i] = 1LL * fac[i - 1] * i % mod;
	inv[n] = qpow(fac[n],mod - 2);for(int i = n - 1;~i;i--)inv[i] = 1LL * inv[i + 1] * (i + 1) % mod;
    while((k - t2 * b) % a && t2 <= n)t2++;t1 = (k - t2 * b) / a;
    if(t2 > n){puts("0");return 0;}
    while(t1 >= 0 && t2 <= n)
    {
       if(t1 <= n)(ans += C(n,t1) * C(n,t2) % mod) %= mod;
       t2 += (g / b);t1 -= (g / a);
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

template <typename T>
class Seg_Tree{
public: // 0-index
	vector<T> dat;
	T initial,M;
	int n;
	T unite(T a,T b){//
		return (a*b) % M;
	}
	Seg_Tree(int n0_=1,T initial_=1,T M_=1){
		initsize(n0_,initial_,M_);
	}
	void initsize(int n0,T initial_,T M_){
		M = M_;
		initial = initial_;
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++)dat[i]=initial;
				break;
			}
			k*=2;
		}
	}

	//i banme wo x nisuru
	void update(int i,T x){
		i += n-1;
		dat[i] = x;
		while(i>0){
			i = (i-1) / 2;
			dat[i] = unite(dat[i*2+1],dat[i*2+2]);
		}
	}

	//[a,b)
	T query0(int a,int b,int k,int l,int r){
		if(r<=a || b<=l)return initial;
		if(a<=l && r<=b)return dat[k];
		else{
			T vl = query0(a,b,k*2+1,l,(l+r)/2);
			T vr = query0(a,b,k*2+2,(l+r)/2,r);
			return unite(vl,vr);
		}
	}

	//return [a,b)
	T query(int a,int b){
		return query0(a,b,0,0,n);
	}

	T get_except(int ind){
		T vl = query(0,ind);
		T vr = query(ind+1,n);
		return unite(vl,vr);
	}

	T get_all(){
		return query(0,n);
	}
};

vector<int> leaf(const vector<int> &u,const vector<int> &v){
	int N = u.size() + 1;
	vector<int> G(N,0),res;
	for(int i=0;i<N-1;i++){
		G[u[i]]++;
		G[v[i]]++;
	}
	for(int i=0;i<N;i++){
		if(G[i] == 1){
			res.push_back(i);
		}
	}
	return res;
}

vector< pair<int,int> > leaf_to_root(const vector<int> &u,const vector<int> &v,const int root){
	// return <parent,child>
	int yet = 1000000000;
	vector<int> d(u.size()+1,yet);
	vector< pair<int,int> > res;
	queue<int> Q;
	Q.push(root);
	d[root] = 0;
	vector< vector<int> > G(u.size()+1);
	for(int i=0;i<u.size();i++){
		G[u[i]].push_back(v[i]);
		G[v[i]].push_back(u[i]);
	}
	while( Q.size() ){
		int now = Q.front();
		Q.pop();
		for(auto nex:G[now]){
			if(d[nex]!=yet)continue;
			d[nex] = d[now] + 1;
			Q.push(nex);
			res.push_back( make_pair(now,nex) );
		}
	}
	reverse(res.begin(), res.end());
	return res;
}


int main(){


	int N,M;
	cin >> N >> M;
	vector<int> x(N-1),y(N-1);
	FOR(i,0,N-1) cin >> x[i] >> y[i];
	FOR(i,0,N-1) x[i]--,y[i]--;

	vector< vector<int> > G(N);
	for(int i=0;i<N-1;i++){
		G[x[i]].push_back(y[i]);
		G[y[i]].push_back(x[i]);
	}
	vector< map<int,int> > ma(N);
	for(int i=0;i<N;i++){
		for(int j=0;j<G[i].size();j++){
			ma[ i ][ G[i][j] ] = j;
		}
	}

	vector< Seg_Tree<ll> > dp(N);
	for(int i=0;i<N;i++){
		dp[i].initsize(G[i].size(),1,M);
	}

	auto route = leaf_to_root(x,y,0);
	for(auto a:route){
		int p = a.first;
		int c = a.second;
		dp[p].update(ma[p][c],(dp[c].get_all()+1LL)%M );
	}

	reverse(route.begin(),route.end());
	for(auto a:route){
		int c = a.second;
		int p = a.first;
		ll v = dp[p].get_except(ma[p][c]);
		dp[c].update(ma[c][p],(v+1LL)%M);
	}

	for(int i=0;i<N;i++){
		cout << dp[i].get_all() << endl;
	}


}


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

#define rep(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 all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define MOD 1000000007

const int MAX_M = 100000;


int main(){
  ll k, a, b;
  //string s;
  cin >> k >> a >> b;
  bool ok = false;
  
  //vector<ll> a(n);
  //queue<ll> q;
  //map<string,ll> d{};
  
  rep(i,a,b+1){
    if(i%k == 0){
      ok = true;
      break;
    }
  }
  
  cout << ((ok)? "OK" : "NG") << endl;
}

Measured memory_bytes: 3632
abc = input()
list_abc = abc.split(" ")
min = int(list_abc[0])
mid = int(list_abc[1])
max = int(list_abc[2])

for index in range(3):
    cur_num = int(list_abc[index])
    if max < cur_num:
        list_abc[2] = str(cur_num)
        list_abc[index] = str(max)
        max = cur_num
min = int(list_abc[0])
mid = int(list_abc[1])
if mid < min :
    list_abc[0] = str(mid)
    list_abc[1] = str(min)
min = int(list_abc[0])
mid = int(list_abc[1])
print(str(min) + " " + str(mid) + " " + str(max))
max = int(list_abc[2])


Measured memory_bytes: 5596