akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) { }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    void merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return;
        if (-par[x] < -par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
};

void solve() {
    int N; cin >> N;
    vector<long long>x(N), y(N);
    using pint = pair<int, int>;
    using Edge = pair<long long, pint>;
    vector<Edge> edges(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }
    vector<int> ids(N);
    //x軸方向でソートして隣接している部分のみ
    iota(ids.begin(), ids.end(), 0);
    sort(ids.begin(), ids.end(), [&](int i, int j){
        return x[i] < x[j];
    });
    for (int i = 0; i + 1 < ids.size(); i++) {
        long long u = ids[i];
        long long v = ids[i + 1];
        edges.push_back(Edge(x[v] - x[u], pint(u, v)));
    }
    //y軸方向でソートして隣接している部分のみ
    sort(ids.begin(), ids.end(), [&](int i, int j){
        return y[i] < y[j];
    });
    for (int i = 0; i + 1 < ids.size(); i++) {
        long long u = ids[i];
        long long v = ids[i + 1];
        edges.push_back(Edge(y[v] - y[u], pint(u, v)));
    } 
    sort(edges.begin(), edges.end());
    UnionFind uf(N);
    int res = 0;
    for (auto e : edges) {
        long long u = e.second.first;
        long long v = e.second.second;
        long long cost = e.first;
        if (uf.issame(u, v)) {
            continue;
        }
        uf.merge(u, v);
        res += cost; 
    }
    cout << res << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 10468
fn main() {
    let mut s = String::new();

    std::io::stdin().read_line(&mut s).unwrap();
    let mut s = s.split_whitespace();

    let a : i32 = s.next().unwrap().parse().unwrap();
    let b : i32 = s.next().unwrap().parse().unwrap();

    println!("{}", if (a * b) % 2 == 1 { "Odd" } else { "Even" } );
}


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

int main(int argc, char *argv[])
{
  int sum;
  char num;
  int i;

  sum = 0;
  while ((num = getchar()) != EOF) {
    if (num != '\n') sum += num - 0x30;
    else {
      if (sum != 0) {
        printf("%d\n", sum);
        sum = 0;
      } else break;
    }
  }

  return 0;
}

Measured memory_bytes: 524
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
n,l = readInts()
S = sorted([input() for _ in range(n)])
print(''.join(S))


Measured memory_bytes: 10352
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc164_d
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000
using umap = unordered_map<int, int>;

const int nax = 200012;
char s[nax];

int main() {
    scanf("%s", s);
    int n = strlen(s);
    map<int, int> mp;
    mp[0]++;
    int sum = 0;
    int pow = 1;
    ll rs = 0;
    int m = 2019;
    for(int i=n-1; i>=0; i--) {
        sum = sum + pow * (s[i]-'0');
        sum %= m;
        pow = (pow*10)%m;
        rs += mp[sum];
        mp[sum]++;
    }
    printf("%lld\n", rs);
}


Measured memory_bytes: 4040
import sys

raw_input = sys.stdin.readline

f = lambda : raw_input().rstrip()    
f1 = lambda : f().split()
f2 = lambda t: map(t,f1())

def main1():
    a,b = f2(int)
    if (a+b)%2 == 0:
       print (a+b)/2
    elif a == b:
       print 0
    else:
       print "IMPOSSIBLE"

def main2():
    n = int(f)
    a = f2(int)
    b = sorted(a)
    m = 0
    for i in xrange(n):
        if a[i] != b[i]:
            m = m + 1
    if m<2:
        print "YES"
    else:
        print "NO"

def main3():
    n = int(f())
    a = f2(int)
    b = f2(int)
    ans = 0
    for k in xrange(n):
        if a[i] >= b[i]:
            ans = ans + b[i]
        elif a[i] < b[i] :
            ans = ans + a[i]
            b[i] = b[i] - a[i]
            ans = ans + min(a[i+1], b[i])
            a[i+1] = a[i+1] - b[i]  
    print ans 
 
def main4():
    pass
    
    
if __name__ == "__main__":
    main1()

Measured memory_bytes: 2696
#include<stdio.h>
int main(void)
{
    int i,j,k,l,h,w,a[25][25],sum,min,sa1,sa2;
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			scanf("%d",&a[i][j]);
		}
	}
	min=99999999;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			sum=0;
			for(k=0;k<h;k++){
				for(l=0;l<w;l++){
					sa1=i-k;
					sa2=j-l;
					if(sa1<0){
						sa1=sa1*-1;
					}
					if(sa2<0){
						sa2=sa2*-1;
					}
					if(sa1<sa2){
						sum+=sa1*a[k][l];
					}
					else{
						sum+=sa2*a[k][l];
					}
				}
			}
		 if(min>sum){
			min=sum;
		 }
		}
	}
	printf("%d\n",min);
	return 0;
}
					


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

int main(){
    int N,M; cin >> N >> M;
    int imos[N+1];
    memset(imos,0,sizeof(imos));
    for(int i=0;i<M;i++){
        int a,b; cin >> a >> b;
        if(a>b) swap(a,b);
        a--; b--;
        imos[a]++;
        imos[b]--;
    }
    for(int i=0;i<N;i++){
        imos[i+1]+=imos[i];
    }
    for(int i=0;i<N;i++){
        //cout << imos[i] << endl;
        if(imos[i]%2==0) continue;
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(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 main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll cnt;
    rep1(i, s.size()){
        cnt = s[i] - 'A';
        cnt = (cnt + n) % 26;
        s[i] = 'A' + cnt;
    }
    cout << s << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 3616
import java.util.*;

public class Main {
    static int[] array;
    static int n;
    static int h;
    static int w;
    static int k;
    static char[][] board;
    static int ans = 0;
    
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        
        // 全探索する時のデータを取得
        h = sc.nextInt();
        w = sc.nextInt();
        k = sc.nextInt();
        
        // board[i][j]: 迷路
        board = new char[h][w];
        for (int i = 0; i < h; i++) {
            String str = sc.next();
            for (int j = 0; j < w; j++) {
                board[i][j] = str.charAt(j);
            }
        }
        
        n = h + w;
        // array: 長さnのbit列
        array = new int[n];
        
        // arrayのパターンを全探索
        // ex.[1, 1, 1], [1, 1, 2], ... , [m, m, m]
        dfs(0, 0);
        
        // ans: costの最小値
        System.out.println(ans);
    }
    
    public static void dfs(int index, int now) {
        // 終了条件
        if (index == n) {
            // できあがったarrayで計算
            
            char[][] tmpboard = new char[h][w];
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    tmpboard[i][j] = board[i][j];
                }
            }
            
            for (int i = 0; i < h; i++) {
                if (array[i] == 1) {
                    for (int j = 0; j < w; j++) {
                        tmpboard[i][j] = 'x';
                    }
                }
            }
            
            for (int i = h; i < n; i++) {
                if (array[i] == 1) {
                    for (int j = 0; j < h; j++) {
                        tmpboard[j][i-h] = 'x';
                    }
                }
            }
            
            int count = 0;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (tmpboard[i][j] == '#') count++;
                }
            }
            
            if (count == k) ans++;
            return;
        }
        
        // 次項の取る値: 0 or 1
        for (int i = 0; i < 2; i++) {
            array[index] = i;
            dfs(index + 1, i);
        }
    }
}

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

const int INF = 1 << 30;

int main()
{
  int n, m;
  while (cin >> n >> m) {
    if ((n|m) == 0)
      break;

    vector<vector<int> > scene(n, vector<int>(n));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j)
	cin >> scene[i][j];
    }

    vector<vector<int> > pic(m, vector<int>(m));
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < m; ++j)
	cin >> pic[i][j];
    }

    int ans_x = INF, ans_y = INF;
    for (int r = 0; r < 4; ++r) {
      for (int i = 0; i <= n-m; ++i) {
	for (int j = 0; j <= n-m; ++j) {
	  
	  bool valid = true;
	  int vx = INF, vy = INF;
	  for (int y = 0; y < m && valid; ++y) {
	    for (int x = 0; x < m && valid; ++x) {
	      if (pic[y][x] != -1) {
		if (vx == INF) {
		  vx = x+j;
		  vy = y+i;
		}
		if (pic[y][x] != scene[i+y][j+x])
		  valid = false;
	      }
	    }
	  }

	  if (valid) {
	    if (ans_y > vy) {
	      ans_y = vy;
	      ans_x = vx;
	    } else if (ans_y == vy && ans_x > vx) {
	      ans_x = vx;
	    }
	  }	  
	}
      }

      vector<vector<int> > tmp = pic;
      for (int i = 0; i < m; ++i) {
	for (int j = 0; j < m; ++j)
	  pic[i][j] = tmp[j][m-i-1];
      }
    }

    if (ans_x != INF)
      cout << ans_x+1 << " " << ans_y+1 << endl;
    else
      cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 964
#include<iostream>
#include<vector>
#include<cstdlib> //abs
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> t(n+1,0),x(n+1,0),y(n+1,0);
  for(int i=1;i<n+1;i++){
    cin >> t[i] >> x[i] >> y[i];
  }
  int dis,cnt=0;
  for(int i=1;i<n+1;i++){
    dis=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
    if(dis<=t[i]-t[i-1]&&dis%2==(t[i]-t[i-1])%2) cnt++;
  }
  if(cnt==n) cout << "Yes\n";
  else  cout << "No\n";
  return 0;
}


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

using ll = long long;
const ll MOD = 1e9 + 7;

// 繰り返し自乗法(x^nをmで割った余り) O(logn)
ll power(ll x, ll n, ll m) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, m);
    if (n % 2 == 0) res = (res * res) % m;
    else res = (((res * res) % m) * x) % m;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  ll a_0 = 0, b_0 = 0, ab_0 = 0;
  map<pair<ll, ll>, ll> mp;
  for (int i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      ab_0++;
    }
    else if (a == 0) {
      a_0++;
    }
    else if (b == 0) {
      b_0++;
    }
    else {
      if (b < 0) {
        a *= -1;
        b *= -1;
      }
      mp[make_pair(a / gcd(abs(a), abs(b)), b / gcd(abs(a), abs(b)))]++;
    }
  }
  
  ll ans = 1;
  ans *= (power(2, a_0, MOD) + power(2, b_0, MOD) - 1) % MOD;
  
  for (auto i : mp) {
    auto [x, y] = i.first;
    auto z = i.second;
    if (z == 0) continue;
    
    ll keep = 0;
    if (x < 0) {
      if (mp[make_pair(y, -x)] > 0) {
        keep = (power(2, z, MOD) + power(2, mp[make_pair(y, -x)], MOD) - 1) % MOD;
        mp[make_pair(y, -x)] = 0;
      }
      else {
        keep = power(2, z, MOD);
      }
    }
    else {
      keep = power(2, z, MOD);
    }
    
    ans *= (keep % MOD);
    ans %= MOD;
    mp[make_pair(x, y)] = 0;
  }
  
  ans += ab_0;
  
  cout << (ans + MOD - 1) % MOD << '\n';
}

Measured memory_bytes: 22224
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
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 main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> Q(100100);
  REP(i, N) {
    int A, B;
    cin >> A >> B;
    Q[A].push_back(B);
  }
  int ans = 0;
  priority_queue<int> pq;
  for(int i = 1; i <= M; i++) {
    REP(j, Q[i].size()) {
      pq.push(Q[i][j]);
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
    
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5632
H, W = 2, 4
ARR = [
    [0, 9, 9, 9, 9, 9, 9, 9, 9, 9],
    [9, 0, 9, 9, 9, 9, 9, 9, 9, 9],
    [9, 9, 0, 9, 9, 9, 9, 9, 9, 9],
    [9, 9, 9, 0, 9, 9, 9, 9, 9, 9],
    [9, 9, 9, 9, 0, 9, 9, 9, 9, 2],
    [9, 9, 9, 9, 9, 0, 9, 9, 9, 9],
    [9, 9, 9, 9, 9, 9, 0, 9, 9, 9],
    [9, 9, 9, 9, 9, 9, 9, 0, 9, 9],
    [9, 9, 9, 9, 2, 9, 9, 9, 0, 9],
    [9, 2, 9, 9, 9, 9, 9, 9, 9, 0]
]

CRR = [
    [-1, -1, -1, -1],
    [8, 1, 1, 8],
]


H, W = map(int,input().split())

ARR = []

for i in range(10):
    res = list(map(int, input().split()))
    ARR.append(res)

CRR = []

for i in range(H):
    CRR.append(list(map(int, input().split())))


def calculate(h, w, arr, crr):
    for i in range(0, 10):
        for j in range(0, 10):
            for k in range(0, 10):
                s1 = arr[j][i] + arr[i][k]
                s2 = arr[j][k]
                arr[j][k] = min(s1, s2)

    result = 0
    for cr in crr:
        for c in cr:
            if c == -1:
                continue
            else:
                result += arr[c][1]

    print(result)


calculate(H, W, ARR, CRR)


Measured memory_bytes: 3444
n = int(input())
d = [[0] * 10 for _ in range(10)]

for i in range(1, n + 1):
  s = str(i)
  if s[-1] == '0':
    continue
  d[int(s[0])][int(s[-1])] += 1

result = 0
for i in range(1, 10):
  for j in range(1, 10):
    result += d[i][j] * d[j][i]
print(result)


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

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    long long count = 0;
    int xxx=min(x,y);
    if (a + b >= c + c)
    {
        count += (c + c) * xxx;
        x -= xxx;
        y -= xxx;
    }
    else
    {
        count += (a + b) * xxx;
        x -= xxx;
        y -= xxx;
    }

    if (x > 0)
    {
        count += min(c + c, a) * x;
    }
    if (y > 0)
    {
        count += min(c + c, b) * y;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())

l = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')

a = 0
for i in range(H):
    s = input()
    s = s.split(' ')
    a += 1
    if 'snuke' in s:
        w = s.index('snuke')
        h = a

print(l[w]+str(h))




Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define pf printf
#define sf scanf
#define ll long long
int main(){
	int a,b,c,ans=0;
	sf("%d%d%d",&a,&b,&c);
	if(a==b & a!=c){
    	pf("Yes");
    }else if(a==c & a!=b){
    	pf("Yes");
    }else if(b==c && a!=b){
    	pf("Yes");
    }else{
        pf("No");
    }
	return 0;
}


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

#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define debug(x) cerr << #x << " = " << x << endl;
#define SET(c, v) memset(c, v, sizeof c)
#define pi 3.14159265358979323846264338
#define all(S) (S).begin(), (S).end()
#define mod 1000000007LL
#define INF 0x3f3f3f3f
#define pf push_front
#define pb push_back
#define mk make_pair
#define MAX 10010
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
typedef unsigned long long int ull;
ll pd[MAX][101][2], n, cnt;
string s;

ll solve(int k, int p, int sum) {
	if(k == (int)s.size() && !(sum % n)) return 1;
	if(k == (int)s.size()) return 0;
	ll &ans = pd[k][sum][p];
	if(ans != -1) return ans;
	int v = s[k] - '0';
	ans = 0;
	if(p) {
		for(int i = 0; i < v; i++)
			ans = (ans + solve(k+1, 0, (sum+i)%n)) % mod;
		ans = (ans + solve(k+1, 1, (sum+v)%n)) % mod;
	}
	else {
		for(int i = 0; i < 10; i++)
			ans = (ans + solve(k+1, 0, (sum+i)%n)) % mod;
	}
	return ans;
}

int main(int argc, char** argv) {
	cin >> s >> n;
	memset(pd, -1, sizeof pd);
	cout << ((solve(0, 1, 0) - 1) + mod) % mod << endl;
	return 0;
}


Measured memory_bytes: 16896
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int mo=1e9+7;
int i,j,n,k,f[2005],fac[2005],cnt,ans;
int qs(int x,int y){
	int s=1;
	for(;y;y>>=1,x=(ll)x*x%mo) if (y&1) s=(ll)s*x%mo;
	return s;
}
int main(){
	scanf("%d%d",&n,&k);
	fo(i,1,n){
		if (i*i>n) break;
		if (n%i==0){
			fac[++cnt]=i,fac[++cnt]=n/i;
			if (fac[cnt]==fac[cnt-1]) cnt--;
		}
	}
	sort(fac+1,fac+1+cnt);
	fo(i,1,cnt){
		f[i]=qs(k,(fac[i]+1)>>1);
		fo(j,1,i-1) if (fac[i]%fac[j]==0) (f[i]-=f[j])%=mo;
	}
	fo(i,1,cnt) {
		if (!(fac[i]&1)) fac[i]>>=1;
		(ans+=(ll)f[i]*fac[i]%mo)%=mo;
	}
	printf("%d\n",(ans+mo)%mo);
}

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

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

#define F first
#define S second

int main(void){
    for(int n; cin >> n, n;){
        vector<pii> rw(n);
        rep(i, n) cin >> rw[i].F >> rw[i].S;

        sort(all(rw));

        int sum_r = 0, sum_rw = 0; //sum_r??????1??????-1
        rep(i, n - 1) sum_r += rw[i].F;
        rep(i, n) sum_rw += rw[i].F + rw[i].S;

        int res;
        if(sum_r >= rw[n - 1].F){
            res = sum_rw;
        }
        else{
            int rest = rw[n - 1].F - sum_r;

            vi dp(rest + 1);
            dp[0] = true;

            int time_w = 0;
            rep(i, n - 1){
                for(int j = rest; j >= rw[i].S; j--){
                    if(dp[j - rw[i].S]){
                        dp[j] = true;
                        time_w = max(time_w, j);
                    }
                }
            }

            res = sum_rw + rw[n - 1].F - sum_r - time_w;
        }

        cout << res << endl;
    }

	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <tuple>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;
#define Nmax 100005

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	char s[Nmax];
	cin >> s;
	int n = strlen(s);
	int sum[Nmax] = {};
	rep(i,0,n){
		int locate = i;
		int cnt=0;
		if(s[i] == 'R'){
			while(s[i] == 'R'){
				cnt++;
				i++;
			}
			i--;
			sum[i] += (cnt+((cnt)%2))/2;
			sum[i+1] += (cnt+((cnt+1)%2))/2;
		}else{
			while(s[i] == 'L'){
				cnt++;
				i++;
			}
			i--;
			sum[locate] += (cnt+((cnt)%2))/2;
			sum[locate-1] += (cnt+((cnt+1)%2))/2;
		}
	}
	rep(i,0,n) cout << sum[i] << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

const long long INF = 1LL << 60;

const long long MOD = 1000000007;

int N;
int M;
long long dp[100010];
long long  a[100010];



int main()
{
  cin >> N >> M;
  for(int i=0; i<M; i++)
    {
      cin >> a[i];
      if(i!=0 && a[i]==a[i+1]-1)
	{
	  cout << 0 << endl;
	  return 0;
	}
    }
  a[M] = INF;

  dp[0] = 1;
  for(int i=1; i<N+1; i++)
    dp[i] = 0;

  int j=0;
  int k=0;
  if(a[k]==1)
    k++;
  for(int i=0; i<N; i++)
    {
      if(i+1!=a[j])
	{
	  dp[i+1] += dp[i];
	  dp[i+1] %= MOD;
	}
      else
	{
	  //	  cout << i+1 << "i+1 broken" <<endl;
	  j++;
	}
      if(i+2!=a[k])
	{
	  dp[i+2] += dp[i];
	  dp[i+2] %= MOD;
	  //cout<<"k:"<<k<<" a[k]:"<<a[k]<<endl;
	}
      else
	{
	  //cout <<i+2 << "+2 step was broken" <<endl;
	  k++;
	}
    }

      cout << dp[N] << endl;


  return 0;
}



Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
  int i;
  int t[4];
  int sum = 0;

  for (i = 0; i < 4; i++){
    scanf("%d", &t[i]);
    sum += t[i];
  }

  printf("%d\n%d\n", sum / 60, sum % 60);

  return (0);
}

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

int main() {
    int N;
    cin >> N ;
    int p[N+10];
    int count=0;
    for(int i=0;i<N;i++){
      cin>>p[i];
    }

    for(int i=1;i<N-1;i++){
      if(p[i-1]<p[i] && p[i]<p[i+1]){
        count++;
      }
      else if(p[i-1]>p[i] && p[i]>p[i+1]){
        count++;
      }
    }
   cout << count << endl;
   return 0;
 }


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int minj,i,j,a=0,count=0;
  int N,A[100],c=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<=N-1;i++){
    minj=i;
    for(j=i;j<=N-1;j++){
      if(A[j]<A[minj]){
	minj=j;
	c=1;
      }
    }
    
    a=A[i];
    A[i]=A[minj];
    A[minj]=a;
    if(c==1){
      count++;
      c=0;
    }
    
  }
  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
}
  printf("%d\n",A[N-1]);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 2744
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

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

const int MAX=1<<18;
const int INF=0x3f3f3f3f;
int n,a[MAX],sum;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]),sum+=a[i];
    if(sum%10!=0){
        printf("%d\n",sum);
        return 0;
    }
    else{
        sort(a,a+n);
        for(int i=0;i<n;i++) if(a[i]%10!=0){
            printf("%d\n",sum-a[i]);
            return 0;
        }
        printf("0\n");
    }
    return 0;
}


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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e9;
const int MB = 30;
const int MOD = 1e9 + 7;

void solve() {
	int k;
	cin >> k;
	int now = 0;
	for (int i = 1; i <= k; i++) {
		now = (now * 10 + 7) % k;
		if (!now) {
			cout << i;
			return;
		}
	}
	cout << -1;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, d[100005] = {};
    cin >> n;
    for (int i = 1; i <= n; i++) {
        d[i] = d[i - 1] + 1;
        for (int j = 1; j <= 100000; j *= 6) if (j <= i) d[i] = min(d[i], d[i - j] + 1);
        for (int j = 1; j <= 100000; j *= 9) if (j <= i) d[i] = min(d[i], d[i - j] + 1);
    }
    cout << d[n];
}


Measured memory_bytes: 640
//
//  main.cpp
//  atcoderX
//
//  Created by 村井真奈美 on 2018/06/16.
//  Copyright © 2018年 村井真奈美. All rights reserved.
//


#include <bits/stdc++.h>
using namespace std;



int main() {

    int pl[999];
    int sum = 0 ;
    
    for(int i=0 ; i<999 ; i++){
        sum  += i + 1;
        pl[i]=sum;
    }
    
    int a,b;
    cin >> a >> b;
    
    for(int i=0 ; i<999 ; i++){
        for(int j=1 ; j<pl[i] ; j++){
            if(a+j == pl[i] && b+j == pl[i+1]) cout << j << endl;
        }
    }
    
}


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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}




int main()
{
    ll N,ans=0,i=1;

    cin >> N;

   while(i<=N){
       if(i%3!=0 && i%5!=0){
           ans += i;
       }
        i++;

   }

   cout << ans << endl;

 
    return 0;

}

Measured memory_bytes: 3624
<?php
  fscanf(STDIN,"%d%d", $n , $y);
  const MAN = 10000;
  const SEN = 1000;
  const GO = 5000;
  for($i=0; $i<=$n; $i++){
      for($j=0; $j<=$n; $j++){
          if($i+$j<=$n){
              $man = $y - ($i*SEN + $j*GO);
              if($man%MAN == 0 && $i+$j+($man/MAN) == $n){
                  echo ($man/MAN)." ".$j." ".$i;
                  exit;
              }
          }else{
              break;
          }
      }
  }
  echo "-1 -1 -1";

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
// sort(v.rbegin(),v.rend());
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	string s;
	cin>>s;
	int maxi = 0;
	int curr = 0;
	for(int i=0;i<s.size;i++)
	{
		if(s[i]=='R' && curr==0)
		{
			curr=1;
			maxi = max(curr,maxi);
		}
		else if(curr!=0)
		{
			if(s[i]=='R')
			{
				curr++;
				maxi=max(curr,maxi);
			}
			else
			{
				curr=0;
			}
		}
	}	
	cout<<maxi<<endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
unsigned long factorialMethod(unsigned long k);
int main(){
    unsigned long long N, ans;
    cin >> N;
    ans = 1;
    for(int i = 1; i <= N; ++i){
        ans*= i;
        ans %= 1000000007;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
//ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
//constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

using ll = long long;

ll solve(ll dongri, vector<ll>& a,vector<ll>& b){
    vector<ll> dp(dongri+1,0);
    for(int i=0;i<=dongri;i++) dp[i] = i;

    for(int i=0;i<3;i++){
        if(a[i] >= b[i]) continue;
        for(int j=0;j<=dongri;j++){
            if(j-a[i]>=0) dp[j] = max(dp[j],dp[j-a[i]]+b[i]);
        }
    }
    return dp[dongri];
}

int main(){
    ll N; cin >> N;
    vector<ll> a(3),b(3);
    rep(i,3) cin >> a[i];
    rep(i,3) cin >> b[i];

    ll tmp = solve(N,a,b);
    tmp = solve(tmp,b,a);
    cout << tmp << endl;
}


Measured memory_bytes: 195584
from itertools import accumulate

N = int(input())
As = list(map(int, input().split()))

csum = list(accumulate(As, initial=0))

P_end = 1
R_end = 3
ans = 10 ** 18
for Q_end in range(2, N - 1):
    former_half = csum[Q_end] / 2
    latter_half = (csum[-1] - csum[Q_end]) / 2
    while P_end + 1 <= Q_end and csum[P_end + 1] < former_half:
        P_end += 1
    while R_end + 1 < N and csum[R_end + 1] - csum[Q_end] < latter_half:
        R_end += 1
    
    if abs(csum[P_end] - former_half) > abs(csum[P_end + 1] - former_half):
        P = csum[P_end + 1]
    else:
        P = csum[P_end]
    Q = csum[Q_end] - P

    if abs(csum[R_end] - csum[Q_end] - latter_half) > abs(csum[R_end + 1] - csum[Q_end] - latter_half):
        R = csum[R_end + 1] - csum[Q_end]
        S = csum[-1] - csum[R_end + 1]
    else:
        R = csum[R_end] - csum[Q_end]
        S = csum[-1] - csum[R_end]

    # print(P, Q, R, S)
    diff = max(P, Q, R, S) - min(P, Q, R, S)
    ans = min(diff, ans)
    

print(ans)

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

int main() {
	int n,i,j,g,w,l,a[10];
	char t[10];
	while(cin >>n) {
		if (n==0) break;
		for (i=0;i<n;i++) {
			cin >> t[i]; w=0; l=10;
			for (j=0; j<n-1 ; j++) { cin >> g; w+=(g==0); l-=(g==1);}
			a[i]=w*10000+l*100+(10-i);
		}
		sort(a,a+n,greater<int>());
		for (i=0;i<n;i++) cout << t[10-(a[i] % 100)] << endl;
	}  
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N,K;
    cin >> N >> K;
    ld ans = 0;
    REPS(i,N){
        ll po = max(ceil(log2((ld)K/(ld)i)),(ld)0);
        ans += (ld)1/(ld)N*pow((ld)0.5,po);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  int n;
  cin >> n;
  vi prv(n);
  map<int, int> last;
  rep(i,n) {
    int x;
    cin >> x;
    if (last.count(x)) {
      prv[i] = last[x];
    } else {
      prv[i] = -1;
    }
    last[x] = i;
  }

  vl dp(n+1, 0);
  dp[0] = 1;
  rep(i, n) {
    dp[i+1] += dp[i];
    dp[i+1] %= MOD;

    if (prv[i] != -1 and prv[i] != i-1) {
      dp[i+1] += dp[prv[i] + 1];
      dp[i+1] %= MOD;
    }
    //cerr << dp[i+1] << " ";
  }
  //cerr << endl;

  cout << dp[n] << endl;
}


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

int main(){
	int n;
	int b = 0, f = 0,r = 0,v = 0;
	int count[4][3][10] ={0};
	
	cin >> n;
	
	for( int i = 0; i < n; i++ ){	
		cin >> b >> f >> r >> v;
		count[b-1][f-1][r-1] += v;
	}
	
	for( int b = 0; b < 4; b++ ){
		for ( int f = 0; f < 3; f++ ){
			for ( int r = 0; r < 10; r++ ){
					cout << " " << count[b][f][r];
			}
			cout << endl;
		}
		if (b < 3)
			cout << "####################" << endl;
	}
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,n) for(ll i=0;i<n;i++)
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

int main(){
    fast;
    ll n,k,i,ans=0;
    cin>>n>>k;
    ll a[n];
    forn(i,n)cin>>a[i];
    sort(a,a+n);
    forn(i,k){
        ans+=a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
S = list(map(int, input().split()))
N = S[0]
M = S[1]
C = S[2]
AB = [list(map(int, input().split())) for i in range(N+1)]

B = AB[0]
Sum = 0
cnt = 0
for i in range(N):
    for j in range(M):
        Sum += AB[i+1][j] * B[j]
    if(Sum+C>0):
        cnt+=1
    Sum=0
print(cnt)
1

Measured memory_bytes: 38256
from collections import Counter
n = int(input())
lst = [int(i) for i in input().split()]
mod = 10**9 + 7
lst_c = Counter(lst)
lst_c = sorted(lst_c.items(),key = lambda x:x[0])

ideal = []

if n%2!=0:
    ideal.append((0,1))
    for i in range(1,n//2+1):
        ideal.append((2*i,2))
else:
    for i in range(n//2):
        ideal.append((2*i+1,2))

if lst_c != ideal:
    print(0)
else:
    l = len(ideal)
    if n%2!=0:
        l -= 1
    print(2**l % mod)

Measured memory_bytes: 17756
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k,q = list(map(int, input().split()))
a = list(map(int, input().split()))
arg = [(num,i) for i,num in enumerate(a)]
arg.sort()
def sub(x):
    """0,1,...,x-1番目は使わない場合において、X-Yの値
    """
    index = [item[1] for item in arg[:x]]
    index.sort()
    index.append(n)
    vals = []
    prv = 0
    for ind in index:
        if ind-prv>=k:
            vals.extend(sorted(a[prv:ind])[:(ind-prv)-k+1])
        prv = ind+1
        if prv>=n:
            break
    if len(vals)<q:
        return None
    else:
        vals.sort()
        return vals[q-1] - arg[x][0]
ans = float("inf")
for i in range(n):
    res = sub(i)
    if res is not None:
        ans = min(ans, res)
print(ans)

Measured memory_bytes: 74572
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            (long A, long B) = Slice2<long>();
            WriteLine(Max(Max(A + B, A - B), A * B));
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int64_t N, K;
    cin >> N >> K;
    vector<pair<int, int>> list;
    for (int i = 0; i < N; i++)
    {
        int64_t p, q;
        cin >> p >> q;
        list.push_back(make_pair(p, q));
    }
    sort(list.begin(), list.end());
    int64_t sum = 0;
    for (int64_t i = 0; i < N; i++)
    {
        sum += list[i].second;
        if (sum >= K)
        {
            cout << list[i].first;
            break;
        }
    }
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

pair<int, int> E[100001];
int H[100001];
int memo[100001];
int sagasu(int A) {
	if (memo[A]) return memo[A];
	ce(A);
	vector<int> kari;
	for (int i = H[A]; i; i = E[i].second) kari.pb(sagasu(E[i].first));
	sort(kari.begin(), kari.end(), greater<int>());
	int ret = 1;
	rep(i, kari.size()) ret = max(ret, i + kari[i] + 1);
	return memo[A] = ret;
}

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


	int N = getint();

	for (int i = 2; i <= N; i++) {
		int a = getint();
		E[i] = mp(i, H[a]);
		H[a] = i;
	}

	co(sagasu(1) - 1);

	Would you please return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int funcovf(int *Ax, int i,int M){
    if(i==0){
        Ax[0] =2;    
        return 0;
    }

    Ax[i]++;

    if(Ax[i]> M){
        funcovf(Ax,i-1,M);
        Ax[i] = Ax[i-1];
    }
    return 0;
}

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

    int ai[50];
    int bi[50];
    int ci[50];
    int di[50];

    for (int i=0;i<Q;i++){
        cin>> ai[i] >> bi[i]>>ci[i]>>di[i];
    }
    
    int Ax[10];
    for(int i=0;i<10;i++){
        Ax[i] =1;
    }

    int maxnum=0;

    while(1){
        //check
        int tempnum =0;
        for(int i=0;i<Q;i++){
            if((Ax[ bi[i]-1 ]-Ax[ ai[i]-1 ]) == ci[i]){
                tempnum= tempnum + di[i];
            }
        }
        if(tempnum > maxnum){
            maxnum = tempnum;
        }

        //Ax[i] change
        funcovf(Ax,N-1,M);
        if(Ax[0] > 1){
            break;
        }
    }
    cout<< maxnum<<std::endl;
}



Measured memory_bytes: 3588
N, P = map(int, input().split())
p = P
import math

MAX = 1000000   # MAX is max number
prime = [True]*(MAX+1)
prime[0] = False
prime[1] = False

R = int(math.sqrt(MAX))

for i in range(2, R+1):
    if prime[i]:
        cnt = 2
        while i * cnt <= MAX:
            prime[i * cnt] = False
            cnt += 1

dp = [0]*(MAX+1)

for i in range(2, MAX+1):
    if prime[i]:
        while P % i == 0:
            dp[i] += 1
            P //= i

ans = 1
for i in range(2, MAX+1):
    if dp[i] >= N:
        ans *= i ** (dp[i] // N)

if N == 1:
    print(p)
else:
    print(ans)


Measured memory_bytes: 57948
# 141A
# 天気予報
# 入力値　Sunny, Cloudy, Rainy

# 入力
s = str(input())

# 処理
if s == "Sunny":
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
elif s == "Rainy":
    print("Sunny")


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

int main() {
    ll a,b,x; cin >> a >> b >> x;

    ll ans = 0;

    if (a%x == 0)ans = (b-a)/x +1;
    else if (((a%x) + (b-a)%x) >= x)ans = (b-a)/x +1;
    else ans = (b-a)/x;

    cout << ans << endl;
}

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

typedef long long LL;

char a[233];

int main()
{
    LL n;
    int t = 0;
    cin >> n;
    while (n)
    {
        a[++t] = 'a' + (n - 1) % 26;
        n--;
        n /= 26;
    }
    for (int i = t; i >= 1; i--)
        printf("%c", a[i]);
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

#define MOD 1000000007 

int main(void){
    int N;
    scanf("%d",&N);

    int* prime_factor;
    NEW(prime_factor,N+1);
    for(int i=1;i<=N;i++) prime_factor[i]=0;

    //素因数をかぞえあげる
    for(int i=1;i<=N;i++){
        int tmp=i;
        int q=2;
        while(tmp!=1){
            if(tmp%q==0){
                prime_factor[q]++;
                tmp/=q;
            }
            else q++;
        }
    }

    long ans=1;
    for(int i=1;i<=N;i++){
        ans=(ans*(prime_factor[i]+1))%MOD;
    }
    printf("%ld\n",ans);

    return 0;
}

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

#define int long long
#define double long double

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

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

constexpr int MOD = 1e9+7;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    vector<int> ans(n,0);
    rep(x,1,101){
        rep(y,1,101){
            rep(z,1,101){
                int memo=x*x+y*y+z*z+x*y+y*z+z*x;
                if(0<memo&&memo<=n){
                    ans[memo-1]++;
                }
            }
        }
    }
    rep(i,n){
        cout<<ans[i]<<endl;
    }
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, ma, mb;
	cin >>n >>ma >>mb;
	VI a(n), b(n), c(n);
	rep(i, n) cin >>a[i] >>b[i] >>c[i];
	
	const int jmx = n*11;
	vector<VL> dp(jmx+11, VL(jmx+11, MD));
	dp[0][0] = 0;
	rep(i, n){
		vector<VL> np(jmx+10, VL(jmx+10, MD));
		rep(j, jmx) rep(k, jmx) if(dp[j][k] < MD){
			amin(np[j+a[i]][k+b[i]] , dp[j][k] + c[i]);
			amin(np[j][k], dp[j][k]);
		}
		swap(dp, np);
	}
	//for(auto xl: dp){for(auto x :xl) cerr<<x<<" ";dbg("");}
	ll ans = MD;
	rep2(j, 1, jmx){
		if( j*mb % ma) continue;
		ll tk = (ll)j * mb / ma;
		if( tk > jmx) continue;
		if(dp[j][tk] < MD) ans = min(ans, dp[j][tk]);
	}
	cout << (ans !=MD? ans: -1) <<"\n";
	return 0;
}


Measured memory_bytes: 3516