akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define INF 100000000
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define de cout << "debug" << endl;

int H, W;
vector<vector<char>> s;
vector<vector<int>> cost;

int bfs(){
  int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0};
  queue<pair<int,int>> que;
  que.push(make_pair(0,0));
  cost[0][0] = 0;
  
  while(!que.empty()){
    pair<int,int> p = que.front();
    que.pop();
    if(p == make_pair(H-1,W-1)){
      return cost[p.first][p.second];
    }
    REP(i,4){
      int ny = p.first + dy[i], nx = p.second + dx[i];
      if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
      if(s[ny][nx] == '#') continue;
      if(cost[ny][nx] != -1) continue;
      
      cost[ny][nx] =  cost[p.first][p.second] + 1;
      que.push(make_pair(ny,nx));
    }
  }
  return -1;
}

int main() {

  cin >> H >> W;
   s = vector<vector<char>>(H,vector<char>(W));
  int white = 0;
  REP(i,H){
    REP(j,W){
      cin >> s[i][j];
      if(s[i][j] == '.')white++;
    }
  }
  cost = vector<vector<int>>(H,vector<int>(W,-1));
  int min_cost = bfs();
  if(min_cost == -1) cout << -1 << endl;
  else cout << white  - (min_cost+1) << endl;
  
}

Measured memory_bytes: 256
module Main where

import           Data.List

main :: IO ()
main = do
    [h, w] <- (map read . words) <$> getLine :: IO [Int]
    list   <-
        (map (map read . words)) <$> (sequence . take h . repeat) getLine :: IO
            [[Int]]
    let res1    = (map goRight . enumerate2d) list
    let list2   = (map snd) res1
    let result1 = (concatMap fst) res1
    let res2    = (map goRight . transpose) list2
    let result2 = (concatMap fst) res2
    let result  = concat [result1, result2]

    putStr
        $ (unlines . (((show . length) result) :) . map
              (unwords . (\((a, b), (c, d)) -> (map show) [a, b, c, d]))
          )
              result

    return ()
goRight
    :: [((Int, Int), Int)] -> ([((Int, Int), (Int, Int))], [((Int, Int), Int)])
goRight list@[_         ] = ([], list)
goRight (     a : b : xs) = if even (snd a)
    then let res = goRight (b : xs) in (fst res, a : (snd res))
    else
        let res = goRight (mapSnd (+ 1) b : xs)
        in  ((fst a, fst b) : (fst res), mapSnd (subtract 1) a : (snd res))

enumerate :: [a] -> [(Int, a)]
enumerate = zip [1 ..]

enumerate2d :: [[a]] -> [[((Int, Int), a)]]
enumerate2d list =
    (map (\(y, a) -> (map (\(x, b) -> ((y, x), b)) . enumerate) a) . enumerate)
        list

mapTuple f1 f2 (a, b) = (f1 a, f2 b)

mapFst f = mapTuple f id
mapSnd f = mapTuple id f


Measured memory_bytes: 84476
#include<iostream>
#include<map>
#include<string>

int main(void) {
    std::map<std::string,int> dict;
    int n;

    std::cin >> n;
    for(std::string str;n--;dict[str]++){
        std::cin >> str;
    }
    std::cout << dict.size() << std::endl;
    return 0;
}


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

int main() {
    char c;
    cin >> c;

    char vowel[5] = {'a', 'e', 'i', 'o', 'u'};
    bool flag = false;
    for (int i = 0; i < 5; i++) {
        if (c == vowel[i]) flag = true;
    }

    cout << (flag ? "vowel" : "consonant") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.AbstractCollection;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGacha solver = new CGacha();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGacha {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            String[] a = in.nextArrString(n);
            int res = solveMe(n, a);
            out.println(res);

            //out.print("Case #"+ testNumber + ": ");
        }

        private int solveMe(int n, String[] a) {
            HashSet<String> set = new HashSet<>();
            set.addAll(toArrayList(a));
            return set.size();
        }

        public static <T> ArrayList<T> toArrayList(T[] a) {
            ArrayList<T> res = new ArrayList<>(a.length);
            Collections.addAll(res, a);
            return res;
        }

    }

    static class FastReader {
        public BufferedReader br;
        public StringTokenizer st;
        String context = null;

        public FastReader(InputStream in) {
            this(new InputStreamReader(in));
        }

        public FastReader(InputStreamReader input) {
            br = new BufferedReader(input);
        }

        public String next() {
            if (context != null) {
                System.err.print("[" + context + "] Wait for input ...");
            }
            while (st == null || !st.hasMoreElements()) {
                try {
                    String s = br.readLine();
                    if (s == null)
                        return null;
                    st = new StringTokenizer(s);
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new RuntimeException("Could not read");
                }
            }
            String res = st.nextToken();
            if (context != null) {
                System.err.println("[" + context + "] ... received : " + res);
            }
            return res;
        }

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

        public String[] nextArrString(int n) {
            String[] a = new String[n];
            for (int i = 0; i < a.length; i++)
                a[i] = next();
            return a;
        }

    }
}



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

typedef long long ll;
const int N = 25020, K = 404, mod = 1000000007;
int n, k, m, a[N], vis[K], fw[K], ft[K], gw[K], gt[K], f[N][K], g[N][K];
int qpow(int b, int p) {
  int r = 1;
  for (; p; p >>= 1, b = (ll) b * b % mod) if (p & 1) r = (ll) r * b % mod;
  return r;
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &a[i]);
  }
  int ans = (ll) (n - m + 1) * qpow(k, n - m) % mod;
  if (m >= k) {
    int ok = 0;
    for (int i = 1; i + k - 1 <= m; i++) {
      for (int j = 1; j <= k; j++) vis[j] = 0;
      for (int j = 1; j <= k; j++) vis[a[i + j - 1]] = 1;
      ok |= *min_element(vis + 1, vis + 1 + k);
    }
    if (ok) return printf("%d\n", ans), 0;
  }
  int tl = 0, tr = 0;
  for (int j = 1; j <= k; j++) vis[j] = 0;
  for (int i = 1; i <= m; i++) {
    if (!tl && vis[a[i]]) tl = i - 1;
    vis[a[i]] = 1;
  }
  for (int j = 1; j <= k; j++) vis[j] = 0;
  for (int i = m; i; i--) {
    if (!tr && vis[a[i]]) tr = m - i;
    vis[a[i]] = 1;
  }
  int ret = 0;
  if (tl) {
    f[0][tl] = 1;
    g[0][tr] = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j < k; j++) {
        f[i][1] = (f[i][1] + f[i - 1][j]) % mod;
        g[i][1] = (g[i][1] + g[i - 1][j]) % mod;
        if (j + 1 < k) f[i][j + 1] = (f[i][j + 1] + (ll) f[i - 1][j] * (k - j - 1)) % mod;
        if (j + 1 < k) g[i][j + 1] = (g[i][j + 1] + (ll) g[i - 1][j] * (k - j - 1)) % mod;
        if (j + 2 < k) f[i][j + 2] = (f[i][j + 2] + (ll) f[i - 1][j] * (mod - k + j)) % mod;
        if (j + 2 < k) g[i][j + 2] = (g[i][j + 2] + (ll) g[i - 1][j] * (mod - k + j)) % mod;
      }
      for (int j = 1; j < k; j++) {
        f[i][j] = (f[i][j] + f[i][j - 1]) % mod;
        g[i][j] = (g[i][j] + g[i][j - 1]) % mod;
      }
    }
    for (int i = 0; i <= n - m; i++) {
      int lt = 0, rt = 0;
      for (int j = 1; j < k; j++) {
        lt = (lt + f[i][j]) % mod;
        rt = (rt + g[n - m - i][j]) % mod;
      }
      ret = (ret + (ll) lt * rt) % mod;
    }
  } else {
    fw[1] = k;
    ft[1] = m == 1 ? k : 0;
    for (int td = 2; td <= n; td++) {
      memset(gw, 0, sizeof gw);
      memset(gt, 0, sizeof gt);
      for (int j = 1; j < k; j++) {
        gw[1] = (gw[1] + fw[j]) % mod;
        gt[1] = (gt[1] + ft[j]) % mod;
        if (j + 1 < k) gw[j + 1] = (gw[j + 1] + (ll) fw[j] * (k - j - 1)) % mod;
        if (j + 1 < k) gt[j + 1] = (gt[j + 1] + (ll) ft[j] * (k - j - 1)) % mod;
        if (j + 2 < k) gw[j + 2] = (gw[j + 2] + (ll) fw[j] * (mod - k + j)) % mod;
        if (j + 2 < k) gt[j + 2] = (gt[j + 2] + (ll) ft[j] * (mod - k + j)) % mod;
      }
      for (int j = 1; j < k; j++) {
        gw[j] = (gw[j] + gw[j - 1]) % mod;
        gt[j] = (gt[j] + gt[j - 1]) % mod;
      }
      for (int j = m; j < k; j++) {
        gt[j] = (gt[j] + gw[j]) % mod;
      }
      memcpy(fw, gw, sizeof fw);
      memcpy(ft, gt, sizeof ft);
    }
    for (int j = 1; j < k; j++) {
      ret = (ret + ft[j]) % mod;
    }
    for (int j = k; j > k - m; j--) {
      ret = (ll) ret * qpow(j, mod - 2) % mod;
    }
  }
  ans = (ans + mod - ret) % mod;
  printf("%d\n", ans);
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
char check(long long int n) {
    if (n==1) {
        return 'a';
    } else if (n==2) {
        return 'b';
    } else if (n==3) {
        return 'c';
    } else if (n==4) {
        return 'd';
    } else if (n==5) {
        return 'e';
    } else if (n==6) {
        return 'f';
    } else if (n==7) {
        return 'g';
    } else if (n==8) {
        return 'h';
    } else if (n==9) {
        return 'i';
    } else if (n==10) {
        return 'j';
    } else if (n==11) {
        return 'k';
    } else if (n==12) {
        return 'l';
    } else if (n==13) {
        return 'm';
    } else if (n==14) {
        return 'n';
    } else if (n==15) {
        return 'o';
    } else if (n==16) {
        return 'p';
    } else if (n==17) {
        return 'q';
    } else if (n==18) {
        return 'r';
    } else if (n==19) {
        return 's';
    } else if (n==20) {
        return 't';
    } else if (n==21) {
        return 'u';
    } else if (n==22) {
        return 'v';
    } else if (n==23) {
        return 'w';
    } else if (n==24) {
        return 'x';
    } else if (n==25) {
        return 'y';
    } else {
        return 'z';
    }
}
int main(void){
    long long int n;
    cin>>n;
    std::deque<long long int> deq;
    if (n<=26) {
        cout<<check(n)<<endl;
    } else {
        while (n>0) {
            n--;
            deq.emplace_back(n%26);
            n/=26;
        }
        for (int i=deq.size()-1;i>=0;i--) {
            char c=deq[i]+97;
            cout<<c;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3516
#include<stdio.h>
int main(){
    int N;
    scanf("%d",&N);
    switch (N%10)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        puts("hon");
        break;
    case 3:
        puts("bon");
        break;
    default:
    puts("pon");
        break;
    }
}

Measured memory_bytes: 1648
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
char p[301000];
int n, C[4], w[301000], Left[301000], Right[301000];
int main() {
	int i;
	scanf("%d", &n);
	scanf("%s", p);
	for (i = 0; i < 3 * n; i++) {
		if (p[i] == 'R')w[i] = 1;
		else if (p[i] == 'G')w[i] = 2;
		else w[i] = 3;
	}
	for (i = 0; i < 3 * n; i++) {
		int t = w[i];
		if (C[t] >= C[1] && C[t] >= C[2] && C[t] >= C[3]) {
			Left[i]++;
		}
		C[t]++;
	}
	for (i = 3 * n - 1; i >= 0; i--) {
		int t = w[i];
		if (C[t] >= C[1] && C[t] >= C[2] && C[t] >= C[3]) {
			Right[i]++;
		}
		C[t]++;
	}
	long long res = 1, Mod = 998244353;
	int c = 0;
	for (i = 0; i < 3 * n; i++) {
		if (Left[i])c++;
		if (!Left[i] && !Right[i]) {
			res = res * c%Mod;
			c--;
		}
	}
	c = 0;
	for (i = 3 * n - 1; i >= 0; i--) {
		if (Right[i])c++;
		if (!Left[i] && !Right[i]) {
			res = res * c%Mod;
			c--;
		}
	}
	for (i = 1; i <= n; i++)res = res * i%Mod;
	printf("%lld\n", res);
}

Measured memory_bytes: 3968
#!/usr/bin/env python3
import math
def main():
    N = int(input())
    tax = 1.08
    price_base = math.floor(N/tax)

    if math.floor((price_base)*tax) == N:
        print(price_base)
        return

    if math.floor((price_base+1)*tax) == N:
        print(price_base+1)
        return
    
    if math.floor((price_base-1)*tax) == N:
        print(price_base-1)
        return
    
    print(':(')
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    int cnt=0;
    int state=0;
    int p;
    cin >> p;
    for(int i=1; i<n; i++){
        int now;
        cin >> now;
        if(state==0){
        if(p<now) state=1;
        else if(p>now) state=2;
    }
    else if(state==1){
        if(p>now){
            cnt++;
            state = 0;
        }
    }
    else if(state==2){
        if(p<now){
            cnt++;
            state = 0;
        }
    }
    p = now;
    }
    cout << cnt+1 << endl;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

for i in range(n):
    v = A[i]
    j = i -1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(' '.join(map(str, A)))


Measured memory_bytes: 5596
from math import gcd
MOD = 10**9+7
N = int(input())
d = {}
zero = 0
for _ in range(N):
    a, b = map(int, input().split())
    if a == b == 0:
        zero += 1
        continue
    # 正規化する
    if b < 0:
        b = -b
        a = -a
    g = gcd(a, b)
    b //= g
    a //= g
    # 入力のbが0の時はaの値を正の1に統一する
    if b == 0 and a == -1:
        a = 1

    # 今bは必ず正
    # aも正，すなわち傾きが正のとき
    if a > 0:
        if (a, b) in d:
            d[(a, b)][0] += 1
        else:
            d[(a, b)] = [1, 0]
    else:
        # aが負，すなわち傾きが負の時
        if (b, -a) in d:
            d[(b, -a)][1] += 1
        else:
            d[(b, -a)] = [0, 1]

ans = 1
for (a, b), (k, l) in d.items():
    ans *= (pow(2, k, MOD)-1 + pow(2, l, MOD)-1 + 1)  # 最後の+1はどちらからも選ばなかったパターン
    ans %= MOD
ans -= 1
ans += zero
ans %= MOD
print(ans)


Measured memory_bytes: 60404
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int main(void){

    int n,count,tmp;
 
    while(true){
        scanf("%d",&n);
        if(n == 0)break;
 
        count = 0;
        for(int i=1;i <= n; i++){
            tmp = i;
            while(tmp >= 5 && tmp%5  == 0){
                count++;
                tmp /= 5;
            }
        }
        printf("%d\n",count);
    }
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int h, n;
    cin >> h >> n;
    int a[n];
    int sum = 0;
    REP(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }
    if (sum - h >= 0)
    {
        Yes(1);
    }
    else
    {
        Yes(0);
    }
}

Measured memory_bytes: 640
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005
ll n,arr[maxi][3],memo[maxi][4];
ll solve(ll pos,ll prev)
{
	if(pos==n)
		return 0;
	if(memo[pos][prev]!=-1)
		return memo[pos][prev];
	ll ans=minf;
	for(ll i=0;i<3;i++)
	{
		if(prev==i)continue;
		ans=max(ans,solve(pos+1,i)+arr[pos][i]);
	}
	memo[pos][prev]=ans;
	return ans;
}
int main()
{
    fastread;
    cin>>n;
    for(ll i=0;i<n;i++)
    	for(ll j=0;j<4;j++)
    		memo[i][j]=-1;
    for(ll i=0;i<n;i++)
    	cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    cout<<solve(0,3)<<endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll N;
    string S,ans;
    cin >>N;
    cin >> S;
    ans += S[0];
    for(int i  = 1; i < N ;i++){
        if(S[i-1] != S[i]){
            ans +=S[i];
        }
    }

    cout << ans.size() << endl;
    
    
    return 0;
    

}

Measured memory_bytes: 3720
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
edges=[[] for i in range(3+3*n)]
o=inputs()
s,T=map(int,o.pop().split())
for i in o:
    _,__=map(int,i.split())
    _*=3;__*=3
    edges[_].append(__+1)
    edges[_+1].append(__+2)
    edges[_+2].append(__)

from collections import deque
dq=deque([])
dq.append((3*s,0))
T*=3
seen=[0]*(3*n+3)
seen[3*s]=1
while dq:
    now,c=dq.popleft()
    if now==T :print(c//3);exit()
    for t in edges[now]:
        if seen[t]==0:
            dq.append((t,c+1))
            seen[t]=1
print("-1")


Measured memory_bytes: 112692
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <climits>
#include <functional>

using namespace std;

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

typedef pair<int, int> P;


int N, H;
int knifea[100000];
int knifeb[100000];




int main() {
	cin >> N >> H;
	rep(i, N) {
		cin >> knifea[i] >> knifeb[i];
	}
	sort(knifea, knifea + N, greater<int>());
	sort(knifeb, knifeb + N, greater<int>());
	int remain = H;
	int nowb = 0, nowa = 0;
	int ans = 0;
	while (remain > 0) {
		if (nowb < N) {
			if (knifea[0] < knifeb[nowb]) {
				remain -= knifeb[nowb];
				ans++;
				nowb++;
			}
			else {
				if (0 == remain % knifea[0]) {
					ans += remain / knifea[0];
				}
				else {
					ans += remain / knifea[0] + 1;
				}
				break;
			}
		}
		else {
			if (0 == remain % knifea[0]) {
				ans += remain / knifea[0];
			}
			else {
				ans += remain / knifea[0] + 1;
			}
			break;
		}
	}
	cout << ans << endl;

	return 0;
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;
using namespace std;

ll x[1000][1000];

signed main() {
  ll N,D,ans=0;
  cin>>N>>D;
  rep(i,0,N){
    rep(k,0,D){
      cin>>x[i][k];
    }
  }
  rep(i,0,N){
    rep(j,i+1,N){
      ll d2 = 0;
      rep(k,0,D){
        d2 += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      }
      ll d = sqrt(d2);
      if (d*d==d2)
        ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}



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

S = [""]*N
P = [0]*N
Q = [0]*N

for i in range(N):
    S[i], P[i] = input().split()
    Q[i] = -int(P[i])


SS, PP, ans = zip(*sorted(zip(S, Q, range(N))))

for i in range(N):
    print(ans[i]+1)


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
    int n,k;
    char s[50];
    scanf("%d %d",&n,&k);
    scanf("%s",s);
    if(s[k-1]=='A') s[k-1]='a';
    else if(s[k-1]=='B') s[k-1]='b';
    else if(s[k-1]=='C') s[k-1]='c';

    printf("%s\n",s);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))

money = 1000
max_money = money

open_price = a[0]
close_price = a[0]

for i in range(1, n):
	if a[i] >= a[i - 1]:
		close_price = a[i]
	else:			
		#print(i, a[i])
		#print(open_price, close_price)
		if close_price > open_price:
			num = money // open_price
			left = money - num * open_price
			money = left + num * close_price
			max_money = max(money, max_money)
		open_price = a[i]
		close_price = 0
		#print(money)

if close_price > open_price:
	num = money // open_price
	left = money - num * open_price
	money = left + num * close_price
	max_money = max(money, max_money)

print(max_money)

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

	vector<int> parent, grpsize;

	void init(int n){
		parent.clear();
		for(int i = 0; i < n; i++) parent.push_back(i);
		grpsize.clear();
		for(int i = 0; i < n; i++) grpsize.push_back(1);
	}

	int getRoot(int a) {
		int p = a;
		while(p != parent[p]) p = parent[p];
		while(a != parent[a]) {
			int next = parent[p];
			parent[p] = p;
			a = next;
		}
		return p;
	}

	void merge(int a, int b) {
		a = getRoot(a), b = getRoot(b);
        if(a==b){return;}
		if (grpsize[a] > grpsize[b]) {
			swap(a,b);
		}
		grpsize[b] += grpsize[a];
		parent[a] = b;
	}
}

namespace UF2{
	vector<int> parent, grpsize;

	void init(int n){
		parent.clear();
		for(int i = 0; i < n; i++) parent.push_back(i);
		grpsize.clear();
		for(int i = 0; i < n; i++) grpsize.push_back(1);
	}

	int getRoot(int a) {
		int p = a;
		while(p != parent[p]) p = parent[p];
		while(a != parent[a]) {
			int next = parent[p];
			parent[p] = p;
			a = next;
		}
		return p;
	}

	void merge(int a, int b) {
		a = getRoot(a), b = getRoot(b);
        if(a==b){return;}
		if (grpsize[a] > grpsize[b]) {
			swap(a,b);
		}
		grpsize[b] += grpsize[a];
		parent[a] = b;
	}
}
map<int,map<int,int>>mmp;
int N,K,L;
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin>>N>>K>>L;
    UF::init(N);
    while(K--){
        int a,b;
        cin>>a>>b;
        a--;b--;
        UF::merge(a,b);
    }
    UF2::init(N);
    while(L--){
        int a,b;
        cin>>a>>b;
        a--;b--;
        UF2::merge(a,b);
    }
    for(int i=0;i<N;i++)mmp[UF::getRoot(i)][UF2::getRoot(i)]++;
    for(int i=0;i<N;i++)printf("%d ",mmp[UF::getRoot(i)][UF2::getRoot(i)]);
    return 0;
}


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

int main() {
  int ans = 0, iq = 0;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size() - t.size() + 1; ++i) {
      iq = 0;
      for(int j = 0; j < t.size(); ++j) {
        if(s[i+j] == t[j]) iq++;
      }
      if(ans < iq) ans = iq;
    }
    cout << (t.size() - ans) << '\n';
}


Measured memory_bytes: 3628
from collections import deque

n=int(input())
a=[0]+list(map(int, input().split()))

b=deque()

for i in range(1, n+1):
    if n%2==i%2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

ans=[]

for elem in b:
    ans.append(elem)

print(*ans)

Measured memory_bytes: 118668
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7')cout << "Yes";
    else cout << "No";
}   

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

int main() {
    while (true) {
        int a, b; cin >> a >> b;
        if (a == 0 && b == 0) break;
        if (a <= b)
            cout << a << " " << b << endl;
        else
            cout << b << " " << a << endl;
    }
}


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル

	int a,b;
	cin >> a >> b;
	cout << a * b << endl;

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

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

int main() {
  long long n, k;
  cin >> n >> k;
  long long ans = 0;
  for (int ni = k + 1; ni <= n; ni++) {
    ans += n / ni * (ni - k);
    if (n % ni >= k) ans += n % ni - k + 1;
  }
  if (k == 0) ans -= n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
standard = input("")
standard = standard.split()
dis2 = int(standard[1])**2
count = int(standard[0])

near_count = 0

for i in range(count):
  point = input("")
  point = point.split()
  if int(point[0])**2 + int(point[1])**2 <= dis2:
    near_count += 1

print(str(near_count))
  


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine())+1;
            var memo = new List<int>(Enumerable.Range(0, N).Select(s => int.MaxValue));
            var t6 = new List<int>();
            var t9 = new List<int>();
            for (var i = 1; i < N; i++)
            {
                var tmp = (int)Math.Pow(6, i);
                if (N < tmp) break;
                t6.Add(tmp);
            }
            for (var i = 1; i < N; i++)
            {
                var tmp = (int)Math.Pow(9, i);
                if (N < tmp) break;
                t9.Add(tmp);
            }
            Action<List<int>, int, int> chmin =
                (ls, index, val) =>
                {
                    if (val < ls[index]) ls[index] = val;
                };
            memo[0] = 0;
            for (var i = 1; i < N; i++)
            {
                chmin(memo, i, memo[i-1]+1);
                for (var k = 0; k<t6.Count; k++)
                {
                    if (i - t6[k] < 0) continue;
                    chmin(memo, i, memo[i - t6[k]] + 1);
                }
                for (var k = 0; k < t9.Count; k++)
                {
                    if (i - t9[k] < 0) continue;
                    chmin(memo, i, memo[i - t9[k]] + 1);
                }
            }
            Console.WriteLine(memo[N - 1]);
        }
    }
}

Measured memory_bytes: 13664
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>

using namespace std;

int main(){
	int N, ans = 0;
	cin >> N;

	for (int i = 1; i <= N; i += 2){
		int c = 0;
		for (int j = 1; j <= N; ++j){
			if (i % j == 0)
				++c;
		}
		if (c == 8)
			++ans;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

struct UnionFind {
  vector<int> parent;
  UnionFind (int n) : parent(n, -1) {}
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (parent[y] < parent[x]) swap(x, y);
    if (parent[x] == parent[y]) --parent[x];
    parent[y] = x;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k,l;
  cin>>n>>k>>l;
  UnionFind uf0(n), uf1(n);
  REP(i,k) {
    int a,b;
    cin>>a>>b;
    --a;--b;
    uf0.merge(a,b);
  }
  REP(i,l) {
    int a,b;
    cin>>a>>b;
    --a;--b;
    uf1.merge(a,b);
  }
  map<tuple<int,int>, int> m;
  REP(i,n) {
    ++m[make_tuple(uf0.root(i), uf1.root(i))];
  }
  REP(i,n) {
    if(i)cout<<" ";
    cout<<m.at(make_tuple(uf0.root(i), uf1.root(i)));
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 13568
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[110],n;
ll sum,ans;
int main(){
	scanf("%lld",&n);
	rep(i,0,n){
		scanf("%lld",a+i);
		sum+=a[i];
	}
	ll ans=INF;
	ll temp=0;
	rep(i,0,n){
		temp+=a[i];
		ans=min(ans,llabs(sum-temp*2));
	}
    printf("%lld",ans);
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
    int max;
    int min;
    int sa;
        
    public void solve(){
        Scanner sc = new Scanner(System.in);
         for(int i=1; i<=7; i++){
            max = sc.nextInt();
            min = sc.nextInt();
            sa = max-min;
            System.out.println(sa);
         }
    }
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

            
        

Measured memory_bytes: 17304
#include<iostream>

using namespace std;

int main()
{
    int n, m, d;
    int count = 0;
 
    cin >> n >> m;
    
    for( int i = 0; i < m; i++ )
    {
        cin >> d;
        if( d <= m )
            count++;
    }
 
    cout << m - count << endl;
}



Measured memory_bytes: 3108
module m1
  implicit none
  integer(8) :: u(100000) = -1
contains
  recursive integer(8) function root(i) result(res)
    integer(8), intent(in) :: i
    if (u(i) < 0) then
       res = i
    else
       u(i) = root(u(i))
       res = u(i)
    end if
  end function root
end module m1
program abc120d
  use m1
  implicit none
  integer(8) n, m, i, ra, rb
  integer(8), dimension(:), allocatable :: a, b, ans
  read *, n, m
  allocate(a(m), b(m), ans(m))
  do i = 1, m
     read *, a(i), b(i)
  end do
  ans(m) = n * (n - 1) / 2
  do i = m, 2, -1
     ans(i - 1) = ans(i)
     ra = root(a(i))
     rb = root(b(i))
     if (ra /= rb) then
        ans(i - 1) = ans(i - 1) - u(ra) * u(rb)
        if (u(ra) < u(rb)) then
           u(ra) = u(ra) + u(rb)
           u(rb) = ra
        else
           u(rb) = u(rb) + u(ra)
           u(ra) = rb
        end if
     end if
  end do
  do i = 1, m
     print '(i0)', ans(i)
  end do
end program abc120d


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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

int main(int argc, const char* argv[]) {
	ll n;
	cin >> n;
	vector<ll> d(n);
	rep(i, n) cin >> d[i];
	sort(d.begin(), d.end());
	cout << d[n/2] - d[n/2-1] << endl;

	return 0;
}


Measured memory_bytes: 1024
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()

    print(700 + 100 * S.count('o'))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9048
#include<algorithm>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<numeric>
#include<string>
#include<deque>
#include<vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
const double PI = acos(-1);  // PI = 3.141593...

int main() {
    int n, ans;
    cin >> n;
    
    vector<vector<int>> dp(10, vector<int>(10, 0));
    int d = 1;
    for(int i=1; i <= n; ++i) {
        if(i/d == 10) {
            d *= 10;
            continue;
        }
        ++dp[i/d][i%10];
    }
    for(int i=1; i<10; ++i) {
        for(int j=1; j<10; ++j) {
            ans += dp[i][j] * dp[j][i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)

signed main() {
  int x; cin >> x;
  if(x >= 30) puts("Yes");
  else puts("No");
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	string S;
	cin >> S;

	ll a = stoi(S.substr(0, 2));
	ll b = stoi(S.substr(2, 2));

	string ans = "NA";
	
	if (a >= 13 && 1 <= b && b <= 12)
	{
		ans = "YYMM";
	}

	if (b >= 13 && 1 <= a && a <= 12)
	{
		ans = "MMYY";
	}

	if (a == 0 && 1 <= b && b <= 12)
	{
		ans = "YYMM";
	}

	if (b == 0 && 1 <= a && a <= 12)
	{
		ans = "MMYY";
	}

	if (1 <= a && a <= 12 && 1 <= b && b <= 12)
	{
		ans = "AMBIGUOUS";
	}

	cout << ans << endl;

	//system("pause");
}

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

int main()
{
  int a,b,c;
  int i;

  scanf("%d%d%d",&a,&b,&c);
  
 for(i=1;i<=b;i++)
 {
   if(a*i%b==c)
   {
     printf("YES\n");
     return 0;
   }
 }
  
  printf("NO\n");
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

typedef struct R{
  int h, w;
} Rect;

int solve(){
  Rect D[6], F[3], rtmp;
  int i, tmp, j, minj;
  for ( i = 0; i < 6; i++ ) {
    scanf("%d %d", &D[i].h, &D[i].w);
    if ( D[i].h > D[i].w) {
      tmp = D[i].h; D[i].h = D[i].w; D[i].w = tmp;
    }
  }
  for ( i = 0; i < 6; i++ ){
    minj = i;
    for ( j = i; j < 6; j++ ){
      if ( D[j].h <= D[minj].h ){
        if (D[j].h == D[minj].h ){
          if ( D[j].w < D[minj].w ) minj = j;
        } else minj = j;
      }
    }
    rtmp = D[minj]; D[minj] = D[i]; D[i] = rtmp;
  }


  for ( i = 0; i < 6; i+=2){
    if ( D[i].h == D[i+1].h && D[i].w == D[i+1].w ) D[i/2] = D[i];
    else return 0;
  }

  return D[0].h == D[1].h && D[0].w == D[2].h && D[1].w == D[2].w;
}

int main(){
  if ( solve() ) printf("yes\n");
  else printf("no\n");
  return 0;
}



Measured memory_bytes: 2112
// #include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
	string s;
	cin >> s;
	int len = s.length();
	bool t = 0;
	for (int i = 0; i < len; i++) {
		if (t == 0 && s[i] == 'C') {
			t = 1;
		}
		if (t == 1 && s[i] == 'F') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


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

int main() {
  int a,b;
  char op;
  while(1){
    
  cin >> a >> op >> b;
    if(op=='?')
      break;
  else if(op=='+'){
    cout << a+b << endl;
  }
    else if(op=='-'){
      cout << a-b << endl;
    }
    else if(op=='*'){
      cout << a*b << endl;
    }
    else if(op=='/'){
      cout << a/b << endl;
    }
  
  
  }
}
 


Measured memory_bytes: 3088
#include "bits/stdc++.h"

#define pb push_back
#define f first
#define s second

using namespace std;

int n, m;
vector<pair<int, bool>> v;
vector<int> pr, ac;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int x;
        string y;
        cin >> x >> y;
        x--;
        if(y == "AC"){
            v.pb({x, true});
        }
        else{
            v.pb({x, false});
        }
    }
    pr.assign(n, 0);
    ac.assign(n, 0);
    for(auto i : v){
        if(ac[i.f] == 0 && !i.s){
            pr[i.f]++;
        }
        else if(i.s){
            ac[i.f]++;
        }
    }
    int res1 = 0, res2 = 0;
    for(auto i : ac) res1 += (i > 0);
    for(int i = 0; i < n; ++i){
        if(ac[i]) res2 += pr[i];
    }
    cout << res1 << " " << res2;
    return 0;
}


Measured memory_bytes: 1780
import itertools
n = int(input())
l = list(map(int,input().split()))
if n<3:
  print(0)
  quit()

cmb = list(itertools.combinations(l,3))
count = 0
for a,b,c in cmb:
  if (a!=b and b!=c and c!=a) and (a+b>c and b+c>a and c+a>b):
    count += 1
print(count)

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

typedef long long ll;
const int maxn=1e5+10,mod=1e9+7;
int n;
ll ans,inv[maxn];

int main(){
	inv[1]=1;
	for(int i=2;i<maxn;++i)
		inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1;i<maxn;++i)
		inv[i]=(inv[i-1]+inv[i])%mod;
	cin>>n;
	for(int i=1,a;i<=n;++i){
		cin>>a;
		(ans+=a*(inv[i]+inv[n-i+1]-inv[1]+mod))%=mod;
	}
	for(int i=1;i<=n;++i)
		ans=ans*i%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int count[100];
  string s;
  int ans = 1;
  cin >> s;
  for(int i=0; i<100; i++) count[i] = 0;
  for(int i=0; i<s.length(); i++){
    count[s[i] - 97]++;
  }
  for(int i=0; i<26; i++){
    if(1 < count[i]) ans = 0;
  }
  if(ans) cout << "yes" << endl;
  else cout << "no" << endl;
  return 0;
}


Measured memory_bytes: 256
// 🐋💭 Walk on Multiplication Table
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}
// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

func main() {
    let n = readInt()
    let aryA = readLine()!.split(separator: " ").map { String($0) }
    var ans = [String](repeating: String(), count: n)
    
    for i in 0..<n {
        let a = aryA[i]
        ans[Int(a)! - 1] = String(i + 1)
    }
    print(ans.joined(separator: " "))
}
main()


Measured memory_bytes: 17504
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    long long a, b ,c;
    cin >> a >> b >> c;

    long long d = c - a - b;

    if (d > 0 && d * d > 4 * a * b) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 40;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> a(n+1);
  rep(i, n+1) cin >> a[i];

  if(n == 0) {
    if(a[0] == 1) cout << 1 << endl;
    else cout << -1 << endl;
    return 0;
  }

  if(a[0] > 0) {
    cout << -1 << endl;
    return 0;
  }

  vector<ll> del(n+1);
  del = a;
  for(int i = n-1; i >= 0; --i) del[i] += del[i+1];

  vector<ll> node(n+1, 0);
  node[0] = 1;
  for(int i = 1; i < n; ++i) {
    if(min(node[i-1]*2, del[i]) - a[i] <= 0) {
      cout << -1 << endl;
      return 0;
    }
    node[i] = min(node[i-1]*2, del[i]) - a[i];
  }
  if(node[n-1] * 2 < a[n]) {
    cout << -1 << endl;
    return 0;
  }

  ll ans = 0;
  for(int i = 0; i <= n; ++i) ans += a[i] + node[i];
  cout << ans << endl;
}


Measured memory_bytes: 5636
S=list(input())
ki=[]
gu=[]
for i in range(len(S)):
    if i%2==0:
        ki.append(S[i])
    else:
        gu.append(S[i])
if ("L" not in ki) and ("R" not in gu):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9108
n = int(input())
a = list(input().split())

r = 0
c = 1
h = a[0]
for i in range(1, n):
    if h == a[i]:
        c += 1
        if c%2==0:
            r += 1
    else:
        c = 1
        h = a[i]
print(r)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  n %= 10;
  if (n==2 || n==4 || n==5 || n==7 || n==9) {
    cout << "hon" << endl;
  } else if (n == 3) {
    cout << "bon" << endl;
  } else {
    cout << "pon" << endl;
  }
}

Measured memory_bytes: 3632
#if 0
date +%Y.%m.%d

问题等价于求长为 n 的满足一下三个条件的数列的个数：

1. 所有值的和为 s1 = 3m
2. 奇数的个数不超过 s2 = m
3. 最大的数不超过 s3 = 2m

先考虑第一个限制，相当于把 s1 个球放进 n 个盒子，方案数为 f1(s1, n) = C(n + s1, s1)。

再考虑第二个限制，设 f2(n, m, k) 为长度为 n ，和为 m ，奇数不超过 k 个的方案数，
枚举奇数个数 i ，然后把这 i 个奇数减 1 弄成偶数，
那么 i 的贡献就是 C(n, i) * f1((m - i) / 2, n - 1) 。

最后考虑第三个限制，由于和为 3m ，超过 2m 的数最多只有一个，
简单容斥，钦定一个数大于 2m ，那么贡献就是 - n * f2(n, m, m) ，
但事实上这也算进去了该数恰好为 2m 的情况，继续容斥，贡献为 n * f2(n - 1, m, m) ，
那么答案 f3(n, m) = f2(n, 3m, m) - n * (f2(n, m, m) - f2(n - 1, m, m)) 。
#endif
#include <cstdio>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;

inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 3000005, mod = 998244353;
lolong fac[maxn];
lolong inv[maxn];
lolong ifac[maxn];

inline lolong c(int n, int m) {
	return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}

lolong f(int n, int m, int k) {
	lolong res = 0;
	for(int i = 0; i <= k and i <= n; i ++)
		if(!((m - i) & 1))
			res += c(n, i) * c((m - i) / 2 + n - 1, (m - i) >> 1) % mod;
	return res % mod;
}

int main() {
	fac[0] = 1;
	for(int i = 1; i < maxn; i ++)
		fac[i] = fac[i - 1] * i % mod;

	inv[1] = 1;
	for(int i = 2; i < maxn; i ++)
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;

	ifac[0] = 1;
	for(int i = 1; i < maxn; i ++)
		ifac[i] = ifac[i - 1] * inv[i] % mod;

	int n = input(), m = input();
	printf("%lld\n",
			(f(n, m * 3, m) + mod -
			 n * (f(n, m, m) + mod -
				 f(n - 1, m, m)) % mod) % mod);
}


Measured memory_bytes: 70656
x=int(input())
# an = n^5 - (n - 1)^5
# a -> 120~-119 -> -118~119
# b -> 119~-120 -> -119~118
for i in range(-118,120):
  for j in range(-119,119):
    if i**5-j**5==x:
      print(i,j)
      exit()


Measured memory_bytes: 9020
#include<iostream>
#include<cstring>
using namespace std;
const int N = 310;
char s[N][N];
int id[N][N];
bool isempty[N];	
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	memset(id,0,sizeof(id));
	memset(isempty,true,sizeof(isempty));
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>s[i][j];
			if(s[i][j]=='#'){
				isempty[i]=false;
			}
		}
	}

	int cnt=1;
	for(int i=1;i<=n;i++){
		if(!isempty[i]){
			for(int j=1;j<=m;j++){
				if(s[i][j]=='#'){
					id[i][j]=cnt++;
				}
			}
			
			int last=0;
			for(int j=1;j<=m;j++){
				if(s[i][j]=='#'){
					last=id[i][j];
				}
				else{
					id[i][j]=last;
				}
			}
			
			last=id[i][m];
			for(int j=m;j>=1;j--){
				if(s[i][j]=='#'){
					last=id[i][j];
				}
				else{
					id[i][j]=last;
				}
			}
		}
	}
	
	for(int i=2;i<=n;i++){
		if(isempty[i] && !isempty[i-1]){
			isempty[i]=false;
			for(int j=1;j<=m;j++){
				id[i][j]=id[i-1][j];
			}
		}
	}
	
	for(int i=n-1;i>=1;i--){
		if(isempty[i] && !isempty[i+1]){
			isempty[i]=false;
			for(int j=1;j<=m;j++){
				id[i][j]=id[i+1][j];
			}
		}
	}
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<id[i][j]<<' ';
		}
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1280