akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

void d()
{
	int N;
	cin >> N;
	vector<pair<int, int> > ab(N-1);
	for (int i = 0; i < N-1; i++) {
		int a, b;
		cin >> a >> b;
		ab[i] = pair<int, int>(a-1, b-1);
	}
	vector<int> c(N);
	for (int i = 0; i < N; i++) {
		cin >> c[i];
	}
	sort(c.begin(), c.end(), greater<int>());

	int count = 0;
	vector<int> res(N);
	queue<int> queue;
	queue.push(0);
	vector<bool> reach(N); // そのノードを処理したかどうかを覚える
	for (int i = 0; i < N; i++) {
		reach[i] = false;
	}
	reach[0] = true;
	while (queue.size() > 0) {
		int current = queue.front();
		queue.pop();

		res[current] = c[count++];
		
		// 現在のnodeとの間にedgeがあるnodeを抽出
		for (int i = 0; i < N - 1; i++) {
			pair<int, int> t = ab[i];
			if (t.first == current && ! reach[t.second]) {
				queue.push(t.second);
				reach[t.second] = true;
			}
			if (t.second == current && ! reach[t.first]) {
				queue.push(t.first);
				reach[t.first] = true;
			}
		}
	}

	long long int sum = 0;
	for (int i = 1; i < N; i++) {
		sum += c[i];
	}

	cout << sum << endl;
	cout << res[0];
	for (int i = 1; i < N; i++) {
		cout << " " << res[i];
	}
	cout << endl;
}

int main()
{
	d();
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int inf = -1000;

int main() {

    int n;
    cin>>n;

    int arr[n][3];

    for(int i=0;i<n;++i)
        for(int j=0;j<3;++j)
            cin>>arr[i][j];

    int dp[n][3];
   for(int i=0;i<n;++i)
    for(int j=0;j<3;++j)
       dp[i][j] = inf;

    dp[0][0] = arr[0][0],dp[0][1] = arr[0][1],dp[0][2] = arr[0][2];

    for(int i=1;i<n;++i){
        for(int j=0;j<3;++j){
            if(j==0){
                dp[i][j] = arr[i][j] + max(dp[i-1][j+1],dp[i-1][j+2]);

            }
             if(j==1){
                dp[i][j] = arr[i][j] + max(dp[i-1][j-1],dp[i-1][j+1]);

            }
             if(j==2){
                dp[i][j] = arr[i][j] + max(dp[i-1][j-1],dp[i-1][j-2]);

            }
        }
    }
    int ans ;
    ans = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

    cout<<ans;
    return 0;
      }


Measured memory_bytes: 2560
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  auto make_grid = [&] (int n) {
    auto ret = std::vector<std::vector<int>>(n, std::vector<int>(n));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        ret.at(i).at(j) = (i + j) % n;
      }
    }
    return ret;
  };
  int k; std::cin >> k;
  constexpr int max = 500;
  auto ret = make_grid(std::min(k, max));
  int n = ret.size();
  if (k > max) {
    assert(max == n);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        auto& crr = ret.at(i).at(j);
        if (crr + n < k && (i % 2 == 1)) crr += n;
      }
    }
  }
  std::cout << n << std::endl;
  std::for_each(ret.begin(), ret.end(), [n](auto&& v){
    for (int i = 0; i < n; i++)
      std::cout << (i == 0 ? "" : " ") << v.at(i) + 1;
    std::cout << std::endl;
  });
  return 0;
}

Measured memory_bytes: 2176
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String string = in.next();
            for (int i = 0; i < string.length(); i += 2) out.print(string.charAt(i));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

    }
}



Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define pi 3.141592653897932384626
//freopen("std.in","r",stdin);freopen("std.out","w",stdout);
using namespace std;
int main()
{
    long a,b,c;
    cin>>a>>b>>c;
    long x,y,z;
    long k=0;
    if(a%2==1||b%2==1||c%2==1){cout<<k<<endl;return 0;}
    while(k<10000000){
        k++;
        x=(a+b)/2;
        y=(a+c)/2;
        z=(b+c)/2;
        if(x%2==1||y%2==1||z%2==1){cout<<k<<endl;return 0;}
        a=x;b=y;c=z;
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
s = input()
if len(s)==2:
    if s[0]==s[1]:
        print(1,2)
    else:
        print(-1,-1)
else:
    for i in range(len(s)-2):
        
        if len(set(s[i:i+3])) < 3:
            print(i+1,i+3)
            exit()
    print(-1,-1)

Measured memory_bytes: 3188
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n: Int = sc.nextInt()
    val s: String = sc.next()
    var max: Int = 0
    var x: Int = 0
    for (i in 0 until n){
        if (s[i] == 'I') {
            x++
        } else {
            x--
        }
        max = Math.max(x, max)
    }
    println(max)
}

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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

struct Counter {
  map<int,int> acc;
  priority_queue<pair<int,int>> pq;
  void add(int a) {
    acc[a]++;
  }
  void collect() {
    for (auto p : acc) pq.push(make_pair(p.second,p.first));
  }
  int cnt() {
    return pq.empty() ? 0 : pq.top().first;
  }
  int num() {
    return pq.top().second;
  }
};

int be_fixed(Counter &a, Counter &b) {
  int a1,b1,a2,b2;
  a1 = a.cnt(); b1 = b.cnt();
  if (a.num() != b.num()) return a1+b1;

  a.pq.pop(); b.pq.pop();
  a2 = a.cnt(); b2 = b.cnt();
  return max(a1+b2,a2+b1);
}

int main() {
  int n;cin>>n;
  Counter a,b;
  rep(i,n/2) {
    int x,y;cin>>x>>y;
    a.add(x); b.add(y);
  }
  a.collect(); b.collect();
  int d = be_fixed(a,b);
  int ans = n - d;
  cout << ans << endl;
}


Measured memory_bytes: 6136
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 3005;
const double Pi = acos(- 1.0);
int n, t[N], L;
double ansx, ansy;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); L = read();
	for(int i = 1; i <= n; i ++) t[i] = read();
	for(int i = 1; i <= n; i ++)
		for(int j = i + 1; j <= n; j ++)
		{
			int cnt = j - i - 1;
			double tmp = Pi * (double)(t[i] + t[j]) / L;
			ansx += cos(tmp) * (double)(n - 2 * cnt - 2);
			ansy += sin(tmp) * (double)(n - 2 * cnt - 2);
		}
	ansx /= (double)n * (n - 1) * (n - 2) / 6.0;
	ansy /= (double)n * (n - 1) * (n - 2) / 6.0;
	printf("%.12f %.12f\n", ansx, ansy);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 640
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n = II()
k = II()
ans = INF
for i in range(2 ** n):
    tmp = [0] * n 
    for j in range(n):
        if (i >> j & 1):
            tmp[j] = 1
    num = 1
    for ope in tmp:
        if ope == 1:
            num *= 2
        else:
            num += k
    ans = min(ans, num)
print(ans)
            



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

int main()
{
    int card_num;
    int shuffle_num;
    int p, c;
    while(1){
        cin >> card_num;
        cin >> shuffle_num;
        if(card_num * shuffle_num == 0){
            break;
        }
        int card[card_num];
        for(int i = 0; i < card_num; i++){
            card[i] = card_num - i;
        }
        for(int i = 0; i < shuffle_num; i++){
            cin >> p;
            cin >> c;
            rotate(card, card + p - 1, card + c + p - 1);
        }
        cout << card[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "YES" << endl; exit(0); }
void no() { cout << "NO" << endl; exit(0); }

int main() {
    int cnt[4]; rep(i, 4) cnt[i] = 0;
    rep(i, 3) {
        int a, b; cin >> a >> b;
        cnt[a-1]++; cnt[b-1]++;
    }
    rep(i, 4) {
        if(cnt[i] == 3) no();
    }
    yes();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

using namespace std;

int main(){
    string s;
    cin >> s;
    for(int i=1;i<s.length();i++){
        if ((s.length()-i)%2 != 0) {
            continue;
        }
        bool ok = true;
        for(int j=0;j<(s.length()-i)/2;j++){
            if (s[j] != s[j+(s.length()-i)/2]) {
                ok = false;
            }
        }
        if (ok) {
            cout << s.length()-i << endl;
            return 0;
        }
       
    }
    
}

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

class Main{
    static int[][] A;
    static int[] B;
    static int i, j, k, n;
    
    public static void main(String[] args){
	try{
	    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 	    String s;
	    s = bf.readLine();
	    n = Integer.parseInt(s);
	    A = new int[n][n];
	    B = new int[n+1];
	    //初期化
	    for(i=0 ; i<n ; i++){
		for(j=0 ; j<n ; j++){
		    A[i][j] = 0;
		}
	    }
	    //データ入力
	    
	    for(i=0 ; i<n ; i++){
		StringTokenizer S = new StringTokenizer(bf.readLine());
		B[0] = Integer.parseInt(S.nextToken());
		B[1] = Integer.parseInt(S.nextToken());
		if(B[1] == 0)continue;
		for(j=0 ; j<B[1] ; j++){
		    B[j+2] = Integer.parseInt(S.nextToken());
		}
		for(k=0 ; k<B[1] ; k++){
		    A[i][B[k+2]-1]++;
		}
	    }
	}
	catch(IOException e){
	    System.out.println(e);
	}

	
	for(i=0 ; i<n ; i++){
	    for(j=0 ; j<n-1 ; j++){
		System.out.print(A[i][j]+" ");
	    }
	    System.out.println(A[i][j]);
	}
	
    }
}



Measured memory_bytes: 29704
# Surrounded Nodes
from collections import deque
import sys
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
N = int(input())
G = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
S = -1
for i in range(1, N+1):
    if len(G[i]) == 1:
        S = i
        break
visited = [False for i in range(N+1)]
parent = [-1 for i in range(N+1)]
count = [1 for i in range(N+1)]

ans = N*pow(2, N-1, mod)
stack = deque()


def dfs(node):
    visited[node] = True
    for child in G[node]:
        if visited[child] == False:
            parent[child] = node
            stack.append((node, child))
            dfs(child)


powers = [1 for i in range(2*10**5+1)]
for i in range(1, 2*10**5+1):
    powers[i] = powers[i-1]*2 % mod

dfs(S)
while stack:
    mom, child = stack.pop()
    count[mom] += count[child]
ans = 0
for i in range(1, N+1):
    if len(G[i]) > 1:
        ans += powers[N-1]
        for x in G[i]:
            if x != parent[i]:
                ans -= powers[count[x]]
        ans -= powers[N-count[i]]
        ans += len(G[i]) - 1
        ans %= mod
D = pow(2, N, mod)
print(ans*pow(D, mod-2, mod) % mod)

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define insum(a, b)  a = modsum(a, (b))
#define insubtract(a, b) a = modsubtract(a, (b))
#define inmultiply(a, b) a = modmultiply(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < (int)(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#ifdef MAX_HOME
#define watch(x) cout << (#x) << " = " << x << endl;
#else
#define watch(x) cerr << (#x) << " = " << x << endl;
#endif

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T>
ostream & operator << (ostream &out, vector<T> &a) {
    out << "{";
    for (auto x : a) out << x << " ";
    return out << "}";
}

template<class T>
ostream & operator << (ostream &out, pair<T, T> &a) {
    out << "{";
    cout << a.first << ", " << a.second;
    return out << "}";
}

void smain();

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

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
#endif

    cout << setprecision(12) << fixed;

    smain();
}
/* END OF TEMPLATE ========================================================================================================================================== */;

const int N = 309;

int n, m;

bool check(vvi a, int bound) {
    vector<vector<char>> used(n, vector<char>(m, 0));

    fori (iter, m) {
        vi cnt(m + 1, 0);
        fori (i, n) {
            fori (j, m) {
                if (!used[i][j]) {
                    cnt[a[i][j]]++;
                    break;
                }
            }
        }
        if (*max_element(ALL(cnt)) <= bound) return 1;
        int del = max_element(ALL(cnt)) - cnt.begin();
        fori (i, n) fori (j, m) if (a[i][j] == del) used[i][j] = 1;
    }
    return 0;
}

void smain() {

    cin >> n >> m;
    vvi a(n, vi(m));
    fori (i, n) fori (j, m) cin >> a[i][j];
    int l = 0, r = n;
    while (r - l > 1) {
        int m = r + l >> 1;
        if (check(a, m)) r = m;
        else l = m;
    }
    cout << r;
}



Measured memory_bytes: 1156
#include<iostream>
#include <string>
#include <set>
#include <cstdlib> 
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
  int N;
  int p[11];
  cin >>N;
  for (int i=0;i<N;i++){
    cin >>p[i];
  }
  sort(p,p+N);
  int sum=accumulate(p,p+N-1,0)+(p[N-1]/2);
  cout << sum<<endl;
}  
  

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	vector<double>a(3);
	while(cin>>a[0]>>a[1]>>a[2],a[0]){
		sort(all(a));
		double r=hypot(a[0],a[1])/2;
		int n;
		cin>>n;
		rp(n){
			int m;cin>>m;
			if(m>r)cout<<"OK"<<endl;
			else cout<<"NA"<<endl;
		}
	}
}

Measured memory_bytes: 1252
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
cnt = 0

for i in b:
	x = bisect.bisect_left(a,i)
	y = bisect.bisect_right(c,i)
	cnt += x*(n-y)
print (cnt)


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

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

long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}

int main() {
    int A, B;
    cin >> A >> B;
    cout << LCM(A,B) << endl;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5)
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
a,b,k = li()
ans = set()
for i in range(k):
    if a+i > b:
        break
    
    ans.add(a+i)
    
for i in range(k):
    if b-i < a:
        break
    
    ans.add(b-i)
    
ansl = sorted(list(ans))
 
for ans in ansl:
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    int n, k;
    cin >> n >> k;
    vector<ll> num(n);
    for(auto &i : num){
        cin >> i;
    }
    for(int i = k; i < n; ++i){
        if(num[i] > num[i-k]){
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}

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

    solve();
}


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

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

    int x, y;
    cin >> x >> y;

    int n = 100;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i + j != x) continue;
            if(i * 2 + j * 4 != y) continue;
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3620
class Chokudai
    def initialize(n)
        @root_size = []
        (n + 1).times do |i|
            @root_size.push([i, 1])
        end
        @usage_list = [n * (n - 1) / 2]
    end

    def connect(a, b)
        ret_size = 0
        ua = self.search(a)
        ub = self.search(b)
        ra = ua[0]
        rb = ub[0]
        if @root_size[ra][0] != @root_size[rb][0] then
            ret_size = @root_size[ra][1] * @root_size[rb][1]
            if @root_size[ra][1] > @root_size[rb][1] then
                self.update(ra, ub)
            else
                self.update(rb, ua)
            end

        end
        @usage_list.unshift(@usage_list[0] - ret_size)
    end

    def update(root, joined)
        @root_size[root][1] += @root_size[joined[0]][1]
        while joined.size > 0
            s = joined.pop
            @root_size[s][0] = root
            @root_size[s][1] = 0
        end
    end

    def search(x)
        temp = x
        union = [x]
        while @root_size[temp][0] != temp
            temp = @root_size[temp][0]
            union.unshift(temp)
        end
        return union
    end

    def answer
        @usage_list.shift
        @usage_list.each do |usage|
            puts(usage)
        end
    end
end
inputs = STDIN.readlines.map{|line|line.strip.split()}
line = inputs.shift

n = line[0].to_i
m = line[1].to_i

chokudai = Chokudai.new(n)
inputs.reverse.each do |input|
    a = input[0].to_i
    b = input[1].to_i

    chokudai.connect(a, b)
end
chokudai.answer

Measured memory_bytes: 45564
n = str(input())

hon = {2, 4, 5, 7, 9}
pon = {0, 1, 6, 8}
bon = {3}

f = int(n[len(n)-1])


if f in hon:
    print('hon')
if f in pon:
    print('pon')
if f in bon:
    print('bon')


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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}
ll f[5]={0};
int n;
char s[20];

int main(){
  scanf("%d",&n);
  REP(i,n){
    scanf("%s",s);
    if(s[0]=='M') f[0]++;
    if(s[0]=='A') f[1]++;
    if(s[0]=='R') f[2]++;
    if(s[0]=='C') f[3]++;
    if(s[0]=='H') f[4]++;
  }
  ll sum = 0;
  REP(i,5)FOR(j,i+1,5)FOR(k,j+1,5){
    sum += f[i]*f[j]*f[k];
  }
  printf("%lld\n",sum);
}


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

typedef long long ll;
typedef long double ld;
const ll M=1e9+7;
const ll MAXN=1e6+7;
const ld pi=acos(-1);

#define gi(n) ll n=read()
#define endl '\n'
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define per(i,a,b) for(ll i=b-1; i>=a; --i)

typedef vector<ll> V;
typedef vector<V> VV;
typedef set<ll> S;
typedef pair<ll,ll> pl;
typedef vector<pl> Vp;

#define all(v) v.begin(),v.end()
#define pb push_back
#define fs first
#define sc second

inline ll read(){
	ll x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll pow1(ll p,ll d, ll P){return d?(pow1(p*p%P,d>>1,P)*(d&1?p:1))%P:1;}

V prime;
bool is_composite[MAXN];
void sieve (ll n){
	std::fill (is_composite, is_composite + n, false);
	rep(i,2,n){
		if(!is_composite[i]) prime.pb(i);
		for(ll j = 0; j < prime.size() && i*prime[j] < n; ++j){
			is_composite[i*prime[j]] = true;
			if(i % prime[j] == 0) break;
		}
	}
}
ll modInverse(ll a, ll m){
	ll m0=m,y=0,x=1;
	if(m==1) return 0;
	while(a>1){
		ll q=a/m,t=m;
		m=a%m;
		a=t; 
		t=y;

		y = x-q*y; 
		x = t;
	}
	if(x<0) x += m0;
	return x; 
}

ll f(ll a,ll b){return (a/b)*(b/2)+max(a%b-b/2+1,0LL);}

void doit(){
	gi(a); gi(b);
	V v;
	ll c=2,p=1,ans=0;
	for(;c/2<=b;c*=2)v.pb(f(b,c)-f(a-1,c));
	for(auto i:v) ans+=(i&1?1:0)*p, p*=2;
	cout<<ans;
}
int main(){
//	for(gi(t);t--;cout<<endl)
		doit();
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>

using namespace std;

int sqr[200005];

int main(){

    int N, A, B, C, D;
    bool doubleRock = false, tripleSqr = false;
    char S[200005];

    cin >> N >> A >> B >> C >> D ;

    for(int i=1; i<=N; i++){
        cin >> S[i] ;
    }

    sqr[0] = 1;
    for(int i=1; i<=N; i++){
        if(S[i] == '.') sqr[i] = 0;
        else sqr[i] = 1;

        if(((i < D) || (i < C)) && (i > A)){
            if((sqr[i] == 1 && sqr[i-1] == 1)){
                doubleRock = true;
            }
        }
        if(C > D){
            if((i > B) && (i <= D+1) ){
                if(sqr[i] == 0 && sqr[i-1] == 0 && sqr[i-2] == 0){
                    tripleSqr = true;
                }
            }
        }
    }

    if(doubleRock){
        cout << "No" << endl;
    } else{
        if(C < D){
            cout << "Yes" << endl;
        } else{
            if(tripleSqr == true){
                cout << "Yes" << endl;
            } else{
                cout << "No" << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4552
#include "bits/stdc++.h"
using namespace std;

int main(void) {
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	for(int i=0;i<n;i++) cin >> l[i];

	sort(l.begin(), l.end());
	reverse(l.begin(), l.end());

	int sum=0;

	for(int i=0;i<k;i++) sum += l[i];

	cout << sum << endl;
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val F = mutableListOf<IntArray>()
    val P = mutableListOf<IntArray>()
    (1..N).forEach {
        F.add(readLine()!!.split(" ").map { it.toInt() }.toIntArray())
    }
    (1..N).forEach {
        P.add(readLine()!!.split(" ").map { it.toInt() }.toIntArray())
    }


    var benefit = Int.MIN_VALUE
    (1..(1.shl(10) - 1)).forEach { bit ->
        var localBenefit = 0
        val myOpenInfo = (0..9).map {
            val isIthOpen = bit.shr(it).and(1)
            isIthOpen
        }

        (0..(N-1)).forEach { shopIndex ->
            val shopOpenInfo = F[shopIndex]
            var c = 0
            (0..9).forEach {
                if (myOpenInfo[it] == 1 && shopOpenInfo[it] == 1) {
                    c++
                }
            }

            localBenefit += P[shopIndex][c]
        }
        benefit = Math.max(benefit, localBenefit)
    }

    println(benefit)
}

Measured memory_bytes: 41568
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> p(A);
    vector<int> q(B);
    vector<int> r(C);
    rep(i, A) cin >> p[i];
    rep(i, B) cin >> q[i];
    rep(i, C) cin >> r[i];
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end(), greater<int>());

    LL ans = 0;
    int a = 0;
    int b = 0;
    int c = 0;
    while (c < X+Y) {
        int red = a < A ? p[a] : 0;
        int green = b < B ? q[b] : 0;
        int white = c < C ? r[c] : 0;
        if (0 < X) {
            // it is allowed to eat more red apple
            if (green <= red && white <= red) {
                //! red apple is the best apple
                ans += red;
                ++a;        
                --X;
            } else if (red <= green && white <= green) {
                //! green apple is the best apple
                if (0 < Y) {
                    //! it is allowed to eat more green apple
                    ans += green;
                    ++b;
                    --Y;
                } else {
                    //! must eat red apple
                    if (white <= red) {
                         ans += red;
                         ++a;
                         --X;
                    } else {
                        ans += white;
                        ++c;
                    }
                }
            } else {
                //! white apple is the best apple
                ans += white;
                ++c;
            }
        } else {
            //! must eat green apple
            if (white <= green) {
                ans += green;
                ++b;
                --Y;
            } else {
                ans += white;
                ++c;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
template<class T>void sort(vec<T> &v){sort(v.begin(),v.end());}
template<class T>void rsort(vec<T> &v){sort(v.rbegin(),v.rend());}
const ll mod = 1e9+7;

ll powmod(ll x,ll n){
    if(n == 0)return 1;
    if(n%2)return x*powmod(x*x%mod,n/2)%mod;
    return powmod(x*x%mod,n/2)%mod;
}
ll frac[2020],ifrac[2020];
ll conbi(ll n,ll k){
    return (((frac[n]*ifrac[n-k]%mod)*ifrac[k])%mod+mod)%mod;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    rep(i,2020)i == 0 ? frac[i] = 1:frac[i] = (frac[i-1]*i%mod+mod)%mod;
    rep(i,2020)ifrac[i] = powmod(frac[i],mod-2)%mod;
    ll n,k; cin >> n >> k;
    rep(i,k){
        if(i>n-k){
            cout << 0 << endl;
            continue;
        } 
        cout << conbi(n-k+1,i+1)*conbi(k-1,i)%mod << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  if(A >= K){
    cout << K << endl;
  }
  else if(A + B >= K){
    cout << A << endl;
  }
  else{
    cout << A - (K - A - B) << endl;
  }
}


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

string input;
long long result = 0;

void solve(long long num, int idx, long long sum) {
    if (idx == input.size()) {
        result += num + sum;
        return;
    }

    solve(num * 10 + int(input[idx] - '0'), idx + 1, sum);
    solve(0, idx + 1, sum + num);
}

int main(void) {
    getline(cin, input);

    solve(0, 0, 0);

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define size(a) int((a).size())
#define present(c, x) (c.find(x) != c.end()) 
#define printVerdict(verdict) cout << (verdict ? "Yes": "No") << '\n'
#define printDecimal(d) printf("%.9f\n", d)
#define inrange(val, start, end) (val >= start && val <= end)
 
const int mod = 1e9 + 7; 
 
template <class T1, class T2, class T3> 
void printTuple(tuple<T1, T2, T3> t) { cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n'; }
template <class T1, class T2>
void printPair(pair<T1, T2> p) { cout << p.first << " " << p.second  << '\n'; }
template <class T>
void printArray(vector<T> arr) { for (int i = 0; i<size(arr); i++) {cout << arr[i] << " ";} cout << '\n'; } 

map<int, int> comp_size;

void dfs (int curr, int curr_comp, vector<bool> &visited, vector<vector<int>> &graph) {
	visited[curr] = true;
	comp_size[curr_comp]++;
	for (int neighbor : graph[curr]) {
		if (!visited[neighbor]) dfs(neighbor, curr_comp, visited, graph);
	}
} 

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,m; cin >> n >> m;
	vector<bool> visited(n+1, false);
	vector<vector<int>> graph(n+1, vector<int>());
	for (int i = 0; i<m; i++) {
		int u,v; cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	
	int curr_comp = 0, ret = -1;
	
	for (int i = 1; i<=n; i++) {
		comp_size[curr_comp] = 0;
		if (!visited[i]) dfs(i, curr_comp, visited, graph);
		ret = max(ret, comp_size[curr_comp]);
		curr_comp++;
	}
	
	cout << ret << '\n';
}


Measured memory_bytes: 42212
#include <stdio.h>
int main(void){
    int H, W, i, j;
    for (;;){
        scanf("%d",&H);
        scanf("%d",&W);
        if (H==0 && W==0)break;

        else{
            for ( i = 0; i < H; i++ ){
                for ( j = 0; j < W; j++ ){
                    if ( i == 0 || i == H-1 ){
                        printf("#");
                    } else {
                        if (j==0 || j == W-1){
                        printf("#");
                        }else{
                        printf(".");
                        }
                    }
                }
            printf("\n");
            }
        }
        printf("\n");
    }
    return 0;
    
}



Measured memory_bytes: 2024
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>

#define int long long
#define rr register

#define inf 1e9
#define MAXN 1010

using namespace std;

inline int read() {
	int s = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) f |= ch == '-', ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

void print(int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) print(x / 10);
	putchar(x % 10 + 48);
}

int n;

void work(int x) {
	if (x > 26) {
		if (x % 26 == 0) work(x / 26 - 1);
		else work(x / 26);
	}
	if (x % 26 == 0) cout << char('z');
	else cout << char(x % 26 + 'a' - 1);
}

signed main() {
	n = read();
	work(n);
	cout << "\n";
}

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

int main() {
  int A,B;
  cin >> A >> B;

  if(A<=5){
    cout << 0 << endl;
  }else if(A<=12){
    cout << B/2 << endl;
  }else{
    cout << B << endl;
  }
}


Measured memory_bytes: 764
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n,m;
int a[200100],b[200100];

vector<int> t;

int main(){
	cin>>n>>m;
	REP(i,m){
		cin>>a[i]>>b[i];
		if(a[i]==1){
			t.push_back(b[i]);
		}else if(b[i]==n){
			t.push_back(a[i]);
		}
	}
	sort(t.begin(),t.end());
	for(int i=0;i<t.size()-1;i++){
		if(t[i]==t[i+1]){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

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

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

struct Out{
    int x, y, nx, ny;
};

int G[510][510];

int main(){
    int H, W; cin >> H >> W;
    REP( i, H ){
        REP( j, W ){
            int a; cin >> a;
            G[i][j] = a;
        }
    }

    int n = 0;
    vector<Out> ans;
    REP( i, H ){
        if( i % 2 == 0 ){
            REP( j, W ){
                if( G[i][j] % 2 == 1 ){
                    if( j != W - 1 ){
                        n++;
                        ans.emplace_back( Out{ i + 1, j + 1, i + 1, j + 2 } );
                        G[i][j + 1]++;
                    }else if( i != H - 1 ){
                        n++;
                        ans.emplace_back( Out{ i + 1, j + 1, i + 2, j + 1 } );
                        G[i + 1][j]++;
                    }
                }
            }
        }else{
            for( int j = W - 1; j >= 0; j-- ){
                if( G[i][j] % 2 == 1 ){
                    if( j != 0 ){
                        n++;
                        ans.emplace_back( Out{ i + 1, j + 1, i + 1, j } );
                        G[i][j - 1]++;
                    }else if( i != H - 1 ){
                        n++;
                        ans.emplace_back( Out{ i + 1, j + 1, i + 2, j + 1 } );
                        G[i + 1][j]++;
                    }
                }
            }
        }
    }

    cout << n << endl;
    REP( i, ans.size() ){
        cout << ans[i].x << " " << ans[i].y << " " << ans[i].nx << " " << ans[i].ny << endl;
    }
}


Measured memory_bytes: 5232
while True:
  dice = [1,2,3,5,4,6]
  n = int(input())
  if n == 0:
    break
  a = 1
  while n>0:
    s = input()
    if s == 'North':
      dice[0],dice[1],dice[3],dice[5] = dice[1],dice[5],dice[0],dice[3]
    elif s == 'South':
      dice[1],dice[5],dice[0],dice[3] = dice[0],dice[1],dice[3],dice[5]
    elif s == 'East':
      dice[0],dice[2],dice[4],dice[5] = dice[4],dice[0],dice[5],dice[2]
    elif s == 'West':
      dice[4],dice[0],dice[5],dice[2] = dice[0],dice[2],dice[4],dice[5]
    elif s == 'Right':
      dice[1],dice[2],dice[3],dice[4] = dice[2],dice[3],dice[4],dice[1]
    else:
      dice[2],dice[3],dice[4],dice[1] = dice[1],dice[2],dice[3],dice[4]
    a += dice[0]
    n -= 1
  print(a)


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    Int A, B; cin >> A >> B;
    Int g = __gcd(A, B);
    int ans = 1;
    for (Int i = 2; i * i <= g; i++) {
        int cnt = 0;
        while (g % i == 0) g /= i, cnt++;
        if (cnt) ans++;
    }
    if (g != 1) ans++;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n;
  LL a, b;
  cin>>n>>a>>b;
  vl x(n);
  REP(i, n)cin>>x[i];

  LL ans=0;
  REP(i, n-1){
    ans += min(a*(x[i+1]-x[i]), b);
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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; }

using ll = long long;

ll N, K, C;
std::string S;
std::vector<ll> L, R;
ll sz;

int main()
{
  std::cin >> N >> K >> C >> S;

  ll p = 0, cnt = 0;

  L.emplace_back( 0 );

  while( p < N )
  {
    p += C+1;

    while( p < N-1 && S[p] == 'x' )
      ++p;

    if( p < N && S[p] == 'o' )
      L.emplace_back( p );
  }

  if( L.size() > K )
    return 0;

  p = N-1, cnt = 0;

  R.emplace_back( N-1 );

  while( p > 0 )
  {
    p -= C+1;

    while( p > 0 && S[p] == 'x' )
      --p;

    if( p >= 0 && S[p] == 'o' )
      R.emplace_back( p );
  }

  if( R.size() > K )
    return 0;

  std::reverse( all(R) );

  ll ans = 0;

  rep( i, std::min(L.size(), R.size()) ) if( L[i] == R[i] )
    std::cout << L[i]+1 << std::endl;

  return 0;
}

Measured memory_bytes: 5104
#include <bits/stdc++.h>
#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, Q;
    cin >> N >> Q;
    atcoder::fenwick_tree<ll> fw(N);
    for(int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        fw.add(i, a);
    }
    for(int q = 0; q < Q; q++) {
        ll t, a, b;
        cin >> t >> a >> b;
        if(t == 0) {
            fw.add(a, b);
        } else {
            ll ans = fw.sum(a, b);
            cout << ans << endl;
        }
    }
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll N;
vector<string> ans;

void dfs(string s, char nxt) {
    if (s.length() == N) {
        ans.push_back(s);
        return;
    }
    for (char c = 'a'; c <= nxt; ++c) {
        s.push_back(c);
        dfs(s, c == nxt ? nxt + 1 : nxt);
        s.pop_back();
    }
}

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

    cin >> N;
    ans.clear();
    dfs("", 'a');

    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    REP(i, ans.size()) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 9332
#include<iostream>
using namespace std;
int main(){
int pas,jui,pasta=2000,juice=2000,i;
for(i=0;i<3;i++){
cin>>pas;
if(pas<=pasta)pasta=pas;
}
for(i=0;i<2;i++){
cin>>jui;
if(jui<=juice)juice=jui;
}
cout<<(pasta+juice)-50<<endl;
return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		int five = 0;
		int seven = 0;
		Scanner sc = new Scanner(System.in);
		for(int i = 0; i < 3; i++) {

			int num = Integer.parseInt(sc.next());
			
			switch(num) {
			case 5:
				five++;
				break;
			case 7:
				seven++;
				break;
			}
		}
		if(five == 2 && seven == 1) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,ma = 0,rmi = INF,lma = 0;
	vector<P> vec;
	cin >> n;
	for(int i = 0;i < n;i++){
		int l,r;
		cin >> l >> r; l--;
		vec.emplace_back(l,r);
		ma = max(ma,r - l);
		chmin(rmi,r);
		chmax(lma,l);
	}
	sort(all(vec),[](const P &p1,const P &p2){
		return p1.second < p2.second;
	});
	int l1max = vec[0].first;
	for(int i = 1;i < n;i++){
		chmax(ma,rmi - lma + vec[i].second - min(vec[i].first,l1max));
		chmax(l1max,vec[i].first);
	}
	cout << ma << endl;
}

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

int main(){
  int s;
  cin >> s;
  vector<int> a(1000000, 0);
  a.at(s)++;
  for(int i=2; i<1000000; i++){
    if(s%2 == 0){
      s /= 2;
      a.at(s)++;
    }else{
      s *= 3;
      s++;
      a.at(s)++;
    }
    if(a.at(s) == 2){
      cout << i << endl;
      break;
    }
  }
  return 0;
}


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

int main(){
	int n;
	cin>>n;
	int a,b[n+1];
	for(int i=0; i<=n; i++){
		b[i]=0;
	}
	for(int i=2; i<=n; i++){
		cin>>a;
				b[a]++;
				
	}
	for(int i=1; i<=n; i++){
		cout<<b[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4416
# -*- coding: utf-8 -*-
"""
A - Biscuit Generator
https://atcoder.jp/contests/abc125/tasks/abc125_a

"""
import sys


def solve(A, B, T):
    gen = [t for t in range(1, T+1) if t % A == 0]
    return B * len(gen)


def main(args):
    A, B, T = map(int, input().split())
    ans = solve(A, B, T)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,m,k,i,j,s;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	fo(i,0,n)//1..n
		fo(j,0,m){//1..m
			s=i*m+j*n-i*j*2;//-i*j
			if (s==k){
				printf("Yes\n");
				return 0;
			}
		}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <map>
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<long,long>
using namespace std;
ifstream fin("f.in");
ofstream fout("f.out");
multiset<int,greater<int> > s,ans;
vector<int> v;
int n,nr,i,j;
int main()
{
	cin>>n;
	for(i=0;i<(1<<n);i++)
	{
		cin>>nr;
		s.insert(nr);
	}
	ans.insert(*s.begin());
	s.erase(s.begin());
	bool ok=true;
	for(i=0;i<n;i++)
	{
	    if(ok==true)
        {
            for(int x:ans)
            {
                auto it=s.upper_bound(x);
                if(it==s.end() && ok==true)
                {
                    cout<<"No";
                    ok=false;
                    break;
                }
                v.push_back(*it);
                s.erase(it);
            }
            int siz=v.size();
            for(j=0;j<siz;j++)
            {
                ans.insert(v[j]);
            }
        }
        v.clear();
	}
	if(ok==true)
        cout<<"Yes";
	return 0;
}


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

int main(){
  int H, W;

  while(1){
    cin>>H>>W;
    if(H==0 && W==0){
      break;
    }
    for(int i=0; i<H; i++){
      for(int j=0; j<W; j++){
        if(i==0 || i==H-1 || j==0 || j==W-1){
          cout<<"#";
        }else{
          cout<<".";
        }
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
import math
import calendar
import fractions
import itertools
from fractions import gcd
n = int(input())
t = [int(input()) for _ in range(n)]

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

print(lcm(t))

Measured memory_bytes: 72172