akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int INF = 1e9;
bool allLess(vector<int> nums, int k){
	for (auto it: nums) {
		if (!(it <= k)){
			return false;
		}
	}
	return true;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int h,w,k;
	int ans = INF;
	char temp;
	cin>>h>>w>>k;
	vector<vector<int>> grid(h, vector<int>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin>>temp;
			grid[i][j] = temp-'0';
		}
	}
	for (int cuts = 0; cuts < 1<<(h-1); cuts++) {
		// cout<<bitset<6>(cuts)<<": ";
		int chunks = __builtin_popcount(cuts)+1;
		vector<int> colChunk(chunks, 0);
		bool ok = true;
		int thisAns = chunks-1;
		for (int j = 0; j < w; j++) {
			vector<int> thisCol(chunks, 0);
			int it = 0;
			for (int i = 0; i < h; i++) {
				thisCol[it] += grid[i][j];
				if (((1<<i)&cuts) > 0){
					it++;
				}
			}
			if (!allLess(thisCol, k)){
				ok = false;
			}
			for (int i = 0; i < chunks; i++) {
				colChunk[i] += thisCol[i];
			}
			if (!allLess(colChunk, k)){
				thisAns ++;
				colChunk = thisCol;
				// cout<<j<<'.';
			}
		}
		if (ok){
			// cout<<thisAns<<'\n';
			ans = min(ans, thisAns);
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]


S = str(input())
if(S=="ABC"):
    print("ARC")
else:
    print("ABC")


Measured memory_bytes: 68660
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <list>
#include <map>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define rep(i,n) for(register int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
//const int MOD=998244353;
//const int N=2e5+10;

inline int read(){
	int ww=1,xx=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') ww=-ww;ch=getchar();}
	while(isdigit(ch)){xx=(xx<<1)+(xx<<3)+(ch^48);ch=getchar();}
	return ww*xx;
}

int m,d;
int ans;

signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	m=read();
	d=read();
	for(int i=1;i<=m;i++){
		for(int j=10;j<=d;j++){
			int d1=j%10;
			int d10=j/10;
			if(d1>1&&d10>1&&d1*d10==i) ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
if N == 1:
    print("Hello World")
else:
    A = int(input())
    B = int(input())
    print(A + B)

Measured memory_bytes: 10792
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;
 
int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> input(n,0);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> input.at(i);
  }
  
  int max = 0;
  for (int i = 0; i < n; i++) {
    if(i < m){
      sum += input[i];
    }else{
      sum = sum - input[i-m] + input[i];
    }
    if(sum > max) max = sum;
  }
  
  cout << setprecision(7) << (max + m)/2.0;
  
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

const lint b1 = 1009;
const lint b2 = 1007;
const lint b3 = 997;
const lint h1 = 1e9 + 7;
const lint h2 = 1e9 + 9;
const lint h3 = 998244353;

lint powmod(lint x, lint n, lint mod){
  lint ret = 1;
  while(n > 0){
    if(n&1) ret *= x, ret %= mod, n -= 1;
    else x *= x, x %= mod, n >>= 1;
  }
  return ret;
}

int d[500010], n, m;
vector<int> G[500010];
    
void scc_dfs(int v, vector<bool> &used, vector<int> &vs){
    used[v] = true;
    for(int nv: G[v])if(!used[nv]) scc_dfs(nv, used, vs);
    vs.push_back(v);
}
    
void scc_rdfs(int v, int k, vector<int> &cmp, vector<bool> &used, vector<vector<int>> &rG){
    used[v] = true;
    cmp[v] = k;
    for(int nv: rG[v])if(!used[nv]) scc_rdfs(nv, k, cmp, used, rG);
}
    
pair<int, vector<int>> scc(){
    vector<vector<int>> rG(n);
    rep(i, n)for(int nv: G[i]) rG[nv].push_back(i);
    vector<bool> used(n, false);
    vector<int> vs;
    vector<int> cmp(n);
    rep(i, n)if(!used[i]) scc_dfs(i, used, vs);
    fill(used.begin(), used.end(), false);
    int k = 0;
    rrep(i, n)if(!used[vs[i]]) scc_rdfs(vs[i], k++, cmp, used, rG);
    return make_pair(k, cmp);
}
    
int longest_path(int v){
    if(d[v] >= 0) return d[v];
    int ret = 0;
    for(int nv: G[v]) ret = max(ret, longest_path(nv) + 1);
    return d[v] = ret;
}

int main(){
    string s, t;
    cin >> s >> t;
    n = s.size();
    m = t.size();
    lint th1 = 0;
    lint th2 = 0;
    lint th3 = 0;
    rep(i, m){
        th1 = (th1 * b1 + (t[i] - 'a')) % h1;
        th2 = (th2 * b2 + (t[i] - 'a')) % h2;
        th3 = (th3 * b3 + (t[i] - 'a')) % h3;
    }
    lint sh1 = 0;
    lint sh2 = 0;
    lint sh3 = 0;
    rep(i, m){
        sh1 = (sh1 * b1 + (s[i%n] - 'a')) % h1;
        sh2 = (sh2 * b2 + (s[i%n] - 'a')) % h2;
        sh3 = (sh3 * b3 + (s[i%n] - 'a')) % h3;
    }
    int num[n];
    rep(i, n) num[i] = 0;
    if(sh1 == th1 && sh2 == th2 && sh3 == th3) ++num[0];
    lint p1 = powmod(b1, m, h1);
    lint p2 = powmod(b2, m, h2);
    lint p3 = powmod(b3, m, h3);
    rep(i, n-1){
        sh1 = (sh1 * b1 % h1 - p1 * (s[i] - 'a') % h1 + (s[(i+m)%n] - 'a') + h1) % h1;
        sh2 = (sh2 * b2 % h2 - p2 * (s[i] - 'a') % h2 + (s[(i+m)%n] - 'a') + h2) % h2;
        sh3 = (sh3 * b3 % h3 - p3 * (s[i] - 'a') % h3 + (s[(i+m)%n] - 'a') + h3) % h3;
        if(sh1 == th1 && sh2 == th2 && sh3 == th3) ++num[i+1];
    }
    rep(i, n){
        if(num[i]) G[i].push_back((i+m)%n);
        if(num[i] &&  i == (i+m)%n){
            printf("-1\n");
            return 0;
        }
        d[i] = -1;
    }
    auto scc_result = scc();
    if(scc_result.fi < n){
        printf("-1");
        return 0;
    }
    int ans = 0;
    rep(i, n) ans = max(ans, longest_path(i));
    printf("%d\n", ans);
}

Measured memory_bytes: 105084
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define ll long long;
#define MAX 200005;

int main(){
    int m,d;
    cin >> m >> d;
    int ans = 0;
    for(int a=2;a<10;a++){
        for(int b=2;b<10;b++){
            for(int i=1;i<=m;i++){
                if(a*b == i && 10*a+b <= d) ans++;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }

void _main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int ans = min(B, D) - max(A, C);
  chmax(ans, 0);

  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long i[300000];
int main(){
  string s,a;
  cin >>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      a.push_back('0');
    }else{
      if(s[i]=='1'){
	a.push_back('1');
      }else{
	if(!a.empty()){
	  a.erase(a.size()-1);
	}
      }
    }
  }
  for(int i=0;i<a.size();i++){
    cout <<a[i];
  }
  cout <<'\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>

using namespace std;
using ll = long long;


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n),b;
    for(ll i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    for(ll i=0;i<n-1;i++){
        if(a[i]==a[i+1]){
                b.push_back(a[i]);
                i++;
        }
    }
    if(b.size()<2)  cout << 0;
    else    cout << b[b.size()-1]*b[b.size()-2];
	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = 2000000000;

int main() {
  long n;
  cin >> n;
  long sum[n+10];
  sum[0] = 0;
  for(int i = 1; i <= n-1; i++) {
    long cnt1 = 0, cnt2 = 0;
    for(int j = 1; j <= sqrt(i); j++) {
      if(i % j == 0 & i / j >= 1) {
        if(i / j == j) cnt2++;
        else cnt1++;
      }
    }
    //cout << cnt1 << " " << cnt2 << endl;
    sum[i] = sum[i-1] + cnt1 * 2 + cnt2;
  }
  cout << sum[n-1] << endl;
}

Measured memory_bytes: 11276
#include<bits/stdc++.h>
using namespace std;
#define MN 1000000000L

int main()
{
	int n,k ;  cin >> n >> k;
	int a[n+1],g = 0;
	int i = 1;
	while(i<=n)
	{
		cin >> a[i] ;
		i ++ ;
	}
	
	
	
	int dp[n+1] = {0};
	dp[1] = a[1];
	dp[2] = abs(a[2] - a[1]);
	

	i = 3;
	while(i<=n )
	{
		int b = MN,c=0;
		g = 1;
		while(g<=k && g < i)
		{
			if(i-g == 1)
			c = abs(a[i] - a[i-g]) ;
			else
			c = abs(a[i] - a[i-g]) + dp[i-g];
			if (b > c)
			b = c;
			g++;
		}
		dp[i] = b;
		i++;
	}
	cout<< dp[n];
}

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

int main() {

    string s;
    cin>>s;

    int count0 = 0;
    int count1 = 0;

    for(int i=0;i<s.size();i++){
        if(s.at(i)=='0'){
            count0 ++;
        }else{
            count1 ++;
        }
    }


    int div = abs(count1-count0);
    int answer = s.size() - div;

    cout<<answer<<endl;


    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

int main(){
  int N, L;
  cin >> N >> L;
  vector<int> apple(N);
  apple[0] = L;
  for(int i=1; i<N; i++){
    apple[i] = apple[i-1]+1;
  }
  int sum=0;
  int mini = 5000000;
  int minidx;
  for(int i=0; i<N; i++){
    sum += apple[i];
    if(mini>abs(apple[i])){
      mini = abs(apple[i]);
      minidx = i;
    }
  }
  int ans = sum-apple[minidx];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
S = input()

# 単転したら分解は一意
S = S[::-1]

while S != "":
    if S[:5] == "maerd":
        S = S[5:]
    elif S[:5] == "esare":
        S = S[5:]
    elif S[:6] == "resare":
        S = S[6:]
    elif S[:7] == "remaerd":
        S = S[7:]
    else:
        print("NO")
        exit()

print("YES")


Measured memory_bytes: 75376
N = int(input())
coord = []
for _ in range(N):
    x, y = map(int, input().split(" "))
    coord.append((x, y))

ans = N

for k in range(N):
    for l in range(N):
        if k == l:
            continue
        p, q = coord[k][0] - coord[l][0], coord[k][1] - coord[l][1]
        tmp = N
        for i in range(N):
            for j in range(N):
                if coord[i][0] - p == coord[j][0] and coord[i][1] - q == coord[j][1]:
                    tmp -= 1
        ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 42860
#include<iostream>
#include<algorithm>

int main(){
    
    size_t n, m;
    long long left = 0, right = 0;

    std::cin >> n >> m;

    for(size_t i = 0; i < m; i++){
        long long l, r;
        std::cin >> l >> r;

        if(i == 0){
            left = l;
            right = r;
        }else{
            left = std::max(left, l);
            right = std::min(right, r);
        }
    }

    if(right - left + 1 <= 0){
        std::cout << 0 << std::endl;
    }else{
        std::cout << right - left + 1 << std::endl;
    }
    
    return 0;
}


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

int main() {
    int n, m;
    int k, count;
    bool allflush;
    int ans = 0;

    cin >> n >> m;

    vector<vector<int>> f(m);
    vector<int> p(m);

    for (int i = 0; i < m; i++) {
        cin >> k;
        f[i].resize(k);

        for (int j = 0; j < k; j++) {
            cin >> f[i][j];
            f[i][j]--;
        }
    }

    for (int i = 0; i < m; i++) {
        cin >> p[i];
    }

    for (int i = 0; i < (1 << n); i++) {
        allflush = true;
        for (int j = 0; j < m; j++) {
            count = 0;

            /*Count num of switch 'on'*/
            for (int id_k : f[j]) {
                if ((i >> id_k) & 1) {
                    count++;
                }
            }

            if (count%2 != p[j]) {
                allflush = false;
            } 
        }

        if (allflush) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}


int vis[N];
int diff[N];
unordered_map<int,vec> fr,en;
void dfs(int u, int cnt) {
    if(vis[u] != 0) {
        return;
    }
    vis[u] = cnt;
    for(auto it : fr[u]) {
        if(vis[it] == 0) {
            dfs(it,cnt);
        }
    }
}


void test_case() {

    
 ll n, i, j;
	cin >> n;
	string s;
	cin >> s;
	set <ll> v[26];
	for(i = 0; i < n; i++) {
		v[s[i] - 'a'].insert(i);
	}
	ll q;
	cin >> q;
	while(q--) {
		ll type;
		cin >> type;
		if(type == 1) {
			ll index;
			char c;
			cin >> index >> c;
			index--;
			if(s[index] != c) {
				v[s[index] - 'a'].erase(index);
				s[index] = c;
				v[c - 'a'].insert(index);
			}
		} else {
			ll l, r;
			cin >> l >> r;
			l--; r--;
			set <ll> :: iterator it;
			int ans = 0;
			for(i = 0; i < 26; i++) {
				it = v[i].lower_bound(l);
				if(it != v[i].end() and *it <= r) {
					ans++;
				}
			}
			cout << ans << endl;
		}
	}



    



}


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

    //    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int t = 1;
   //  cin >> t;
    while(t--)
    {   
        test_case();
    }
}


Measured memory_bytes: 27192
import os
import sys
import numpy as np

def z_algo(S):
    # Z-algoirhm  O(n)
    # Z[i] := S と S[i:] で prefix が何文字一致しているか
    # 検証: https://atcoder.jp/contests/arc055/submissions/14179788
    i, j, n = 1, 0, len(S)
    Z = np.zeros_like(S)
    Z[0] = n
    while i < n:
        while i+j < n and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        Z[i] = j
        d = 1
        while i+d < n and d+Z[d] < j:
            Z[i+d] = Z[d]
            d += 1
        i += d
        j -= d
    return Z

def solve(N, A, B):
    Diff = np.empty(3*N, dtype=np.int64)
    Diff[0] = B[0] ^ B[-1]
    Diff[1:N] = B[1:] ^ B[:-1]
    Diff[N] = Diff[2*N] = A[0] ^ A[-1]
    Diff[N+1:2*N] = Diff[2*N+1:3*N] = A[1:] ^ A[:-1]
    Z = z_algo(Diff)[N:2*N]
    Ans = [(0,0)]*0
    for i in range(N):
        z = Z[i]
        if z >= N:
            Ans.append((i, B[0]^A[i]))
    if len(Ans):
        return np.array(Ans)
    return np.zeros((0, 2), dtype=np.int64)


# >>> numba compile >>>
numba_config = [
    [z_algo, "i8[:](i8[:])"],
    [solve, "i8[:,:](i8,i8[:],i8[:])"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
    from numba import njit
    from numba.pycc import CC
    cc = CC("my_module")
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature)(func)
        cc.export(func.__name__, signature)(func)
    cc.compile()
    exit()
elif os.name == "posix":
    exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
    from numba import njit
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature, cache=True)(func)
    print("compiled!", file=sys.stderr)
# <<< numba compile <<<


def main():
    N = int(input())
    A = np.array(input().split(), dtype=np.int64)
    B = np.array(input().split(), dtype=np.int64)
    Ans = solve(N, A, B).tolist()
    for k, x in Ans:
        print(f"{k} {x}")

main()


Measured memory_bytes: 66844
#include<stdio.h>
#include<stdlib.h>
int main(){
   int n,i,j,k;
   scanf("%d%d%d%d",&n,&i,&j,&k);
   if(n+i<j+k)
       printf("Right\n");
   else if(n+i==j+k){
        printf("Balanced\n");
   }
   else
   {
        printf("Left\n");
   }
    return 0;
}


Measured memory_bytes: 128
use std::io;

// 一行読み込み
fn input() -> u32 {
    let mut buf = String::new();
    let stdin = io::stdin();
    stdin.read_line(&mut buf).unwrap();
    return buf.trim().parse().unwrap();
}

// 三乗して返却
fn cube(x: u32) -> u32 {
    return x * x * x;
}

fn main() {
    let x: u32 = input();
    println!("{}", cube(x));
}



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

using namespace std;

int a;
int c[100010];
bool b[100010];
string s; 
int n,m;
int ans1,ans2;

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&a);
		cin>>s;
		if(b[a]==true)
		{
			continue;
		}
		else
		{
			if(s=="WA")
			{
				c[a]++;
			}
			else
			{
				ans1+=c[a];
				ans2++;
				b[a]=1;
			}
		}
	}
	printf("%d %d\n",ans2,ans1);
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

ll dp[2000][2000];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    for (int i = 0; i < h; i++)
    {
        cin >> g[i];
    }
    dp[0][0] = 1;
    for (int y = 0; y < h; y++)
    {
        for (int x = 0; x < w; x++)
        {
            if (0 <= x + 1 && x + 1 < w && 0 <= y && y < h)
            {
                if (g[y][x + 1] == '.')
                {
                    (dp[y][x + 1] += dp[y][x]) %= MOD;
                }
            }
            if (0 <= x && x < w && 0 <= y + 1 && y + 1 < h)
            {
                if (g[y + 1][x] == '.')
                {
                    (dp[y + 1][x] += dp[y][x]) %= MOD;
                }
            }
        }
    }
    cout << dp[h - 1][w - 1] << endl;
}

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

int main() {
  
  int n;
  cin >> n;
  
  string s;
  int p;
  
  vector<tuple<string,int,int>> a;
  
  for ( int i = 0; i < n; i++){
    cin >> s >> p;
    p *= -1;
    a.push_back(make_tuple(s,p,i));
  }
  
  sort(a.begin(),a.end());
  
  string t;
  int q,r;
  
  for ( int i = 0; i < n; i++){
    tie(t,q,r) = a[i];
    cout << r+1 << endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define pb push_back
#define bp __builtin_popcount
#define sz size()
#define ff first
#define ss second
#define vll vector<ll>
#define vbool vector<bool>
#define vpll vector<pair<ll,ll>>
#define pll pair<ll,ll>
#define vllv vector<vector<ll>>
#define setpri(x) cout<<setprecision(x)<<fixed;
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){if(n%x==0)return n/x; else return (n/x)+1;}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;
}
ll modinv(ll n,ll mod){
    return pow1(n,mod-2,mod);
}
bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
    if(a.ff != b.ff)return a.ff < b.ff;
    return a.ss > b.ss;
}
ll isper(ll n){
	
	ll l,r,mid;
	l=-1e3,r=1e3;
	while(l<=r){
		mid=(l+r)/2;
		ll tt=pow2(mid,5);
		if(tt==n)return mid;
		
		if(tt<n){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	
	return 0;
}
void solve(){
    ll i,j,k,l,n,m,x,y,z,r;
	
	cin>>x;
	for(i=-1e3;;i++){
		ll tt=isper(pow2(i,5)+x);
		if(pow2(tt,5)== (pow2(i,5)+x)){
			cout<<tt<<" "<<i<<endl;
			return;
		}
	}
	
	
	
	
}
int main(){
    FS;
    ll i,j,k,n,m,x,y,z,q;
    q=1;
    // cin>>q;
    while(q--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

const double EPS = 1e-8;
struct P{
	double x, y;
	P(double x_, double y_){ x = x_; y = y_; }
	P(){}
	P operator-(const P& p){
		return P(x - p.x, y - p.y); 
	}
};
bool operator<(const P& a, const P& b){
	return ( a.x < b.x );
}

struct Segment{
	P a, b;
	Segment(P a_, P b_){
		if( b_ < a_ ) swap(a_, b_);
		a = a_; b = b_;
	}
	Segment(){}
};
bool operator<(const Segment& a, const Segment& b){
	return ( a.a < b.a );
}

double dot(P a, P b){
	return a.x * b.x + a.y * b.y;
}
double cross(P a, P b){
	return a.x * b.y - a.y * b.x;
}
double dist(P a){
	return sqrt(a.x * a.x + a.y * a.y);
}
double dist(P a, P b){
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double dist(P a, P b, P x){
	if( dot(b-a, x-a) < EPS ) return dist(x-a);
	if( dot(a-b, x-b) < EPS ) return dist(x-b);
	return abs(cross(b-a, x-a)) / dist(b-a);
}
double dist(Segment a, Segment b){
	return min( min(dist(a.a, a.b, b.a), dist(a.a, a.b, b.b)), min(dist(b.a, b.b, a.a), dist(b.a, b.b, a.b)));
}
bool is_intersect(P a1, P a2, P b1, P b2) {
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}
bool is_parallel(P a1, P a2, P b1, P b2){
	return fabs(cross(a1-a2, b1-b2)) < EPS;
}


Segment v[5101];

int main(){
	int n, h[101][101] = {0};
	
	scanf("%d", &n);
	if( n > 5100 ){
		printf("%.8f\n", 0.0);
		return 0;
	}
	
	for(int i=0 ; i < n ; i++ ){
		int ax, ay, bx, by;
		scanf("%d %d %d %d", &ax, &ay, &bx, &by);
		h[ay][ax]++;
		h[by][bx]++;
		v[i] = Segment(P(ax,ay), P(bx,by));
	}
	
	bool flag = false;
	for(int y=0 ; y < 101 && !flag ; y++ ){
		for(int x=0 ; x < 101 && !flag ; x++ ){
			if( h[y][x] >= 2 ){
				flag = true;
			}
		}
	}
	
	// 解が0のとき
	if( flag ){
		printf("%.8f\n", 0.0);
		return 0;
	}
	
	double ans = 200;
	sort(v, v+n);
	for(int i=0 ; i < n ; i++ ){
		for(int j=i+1 ; j < n ; j++ ){
			//if( i == j ) continue;
			double d = dist(v[i], v[j]);
			ans = min(ans, d);
			if( !is_parallel(v[i].a, v[i].b, v[j].a, v[j].b) && is_intersect(v[i].a, v[i].b, v[j].a, v[j].b) ){
				ans = 0.0;
				break;
			}
			/*if( ans < dist(v[i].b, v[j].a) ){
				break;
			}*/
		}
	}
	printf("%.8f\n", ans);
}

Measured memory_bytes: 1272
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 1<<29

using namespace std;
/*
	二部マッチング

	説明
		二部グラフの最大マッチングを求める Ford-Fulerson like なアルゴリズム
		bipartite_matching がメインルーチン

	引数
		L : 左の頂点集合のサイズ
		R : 右の頂点集合のサイズ
		G : 二部グラフ（表示方法が特殊なので注意）
			G[0],...,G[L-1] まであり、G[u] は u と辺でつながっている右の頂点集合を表す。
			ここで、右の頂点は 0,...,R-1 と番号付けられている。

	戻り値
		最大マッチングのサイズ
	
	制約
		なし
	
	計算量
		O(V*(V+E))

	備考
		V_MAX は max(L,R) 以上であればよい。

		マッチングが具体的にほしいときは match を返すようにする
		match[0][u] := 左の頂点 u とマッチしている右の頂点の番号（存在しなければ -1 ）
		match[1][v] := 右の頂点 v とマッチしている左の頂点の番号（存在しなければ -1 ）

*/
const int V_MAX=500;

bool augment(int u,bool *vis,int match[2][V_MAX], const vector<int> *G ){
	if(u==-1) return true;

	rep(i,G[u].size()){
		int v=G[u][i];
		if(!vis[v]){
			vis[v]=true;
			if(augment(match[1][v],vis,match,G)){
				match[0][u]=v;
				match[1][v]=u;
				return true;
			} // end if
		} // end if
	} // end rep
	return false;
}

int bipartite_matching(int L,int R,const vector<int> *G){
	static int match[2][V_MAX];
	rep(u,L) match[0][u]=-1;
	rep(v,R) match[1][v]=-1;
	
	int res=0;
	static bool vis[V_MAX];
	rep(u,L){
		rep(v,R) vis[v]=false;
		if(augment(u,vis,match,G)) res++;
	} // end rep

	return res;
}
int main()
{
//	cut here before submit 
//	freopen ("testcase.1163", "r", stdin );
	int n, m;
	while (scanf ("%d %d", &n, &m ), n, m ){
		static vector<int> G[V_MAX];
		rep (i, V_MAX ) G[i].clear();
		// 0 〜 n-1: bule card n〜n+m-1: red card
		vector<int> cards (n+m, 0 );
		rep (i, n ){
			scanf ("%d", &cards[i] );
		} // end rep
		rep (j, m ){
			scanf ("%d", &cards[n+j] );
		} // end rep

		rep (i, n ){
			rep (j, m ){
				if (__gcd (cards[i], cards[n+j] ) != 1 ){
					G[i].push_back (j );
				} // end if
			} // end rep
		} // end rep
		int res = bipartite_matching (n, m, G );
		printf ("%d\n", res );
	} // end while
		
	return 0;
}

Measured memory_bytes: 2316
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
#include<stdio.h>
#include<iomanip>
using namespace std;

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=1e9+7;
#define ll long long

ll func(ll a){
    ll ans=1;
    while(a){
        ans*=a;
        a--;
        if(ans>mod){
        ans%=mod;
    }
  } 
  return ans;
}

int main(){
    int n,m;
    cin>>n>>m;
    if(abs(n-m)>1){
        cout<<0<<endl;
        return 0;
    }
    if(n!=m){
        int x=max(n,m);
        int y=m+n-x;
        cout<<func(x)*func(y)%mod<<endl;
    }
    else{
        cout<<func(n)*func(n)*2%mod<<endl;
    }
    return 0;
}


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

int main() {
  int a,b,c; cin >>a >>b >>c;
  vector<int> f = {a,b,c};
  sort(f.begin(), f.end());
  int ans = 10*f.at(2)+f.at(1)+f.at(0);
  cout <<ans;
  cout <<endl;
}


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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  int num = N;
  while (num) {
  	sum += num % 10;
    num /= 10;
  }
  
  if (N % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

}


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

#define max 100050

int main()
{
	int n, i, count = 1, tmp;
	char str[max], *p;

	scanf("%d", &n);
	scanf("%d", &tmp);

	fgets(str, max, stdin);
	p = strrchr(str, '\n');
	*p = '\0';

	for (i = 0; i < n - 1; i++)
	{
		if (str[i + 1] - str[i] != 0)
		{
			count++;
		}
	}

	printf("%d", count);


	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int D,N;
  cin >> D >> N;
  if(N != 100)cout << N*pow(100,D) << endl;
  else if(D != 2) cout << 101*pow(100,D) << endl;
  else cout << 1010000 << endl;
}

Measured memory_bytes: 512
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
import bisect
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**21

def main():
    n = getN()
    print((n+1)//2)

if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Measured memory_bytes: 38484
S = input()
T = input()

ans = 10000
for i in range(len(S) - len(T) + 1):
    subset = S[i:i + len(T)]
    # print(f'{subset=}, {T=}')
    cnt = 0
    for s, t in zip(subset, T):
        # print(f'{s=}, {t=}')
        if s != t:
            cnt += 1
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 9104
import java.util.Scanner;

//Book Arrangement
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			long x = sc.nextLong();
			if(x==0)break;
			boolean sign = x>0;
			String res = "";
			x = Math.abs(x);
			boolean k = true;
			while(x>0){
				int t = (int) (x%10);
				if(sign==k)res = t +res;
				else{
					res = (10-t)%10+res;
					if(t!=0)x+=10;
				}
				k=!k;
				x/=10;
			}
			System.out.println(res);
		}
	}

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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
using VI = vector<int>;
using VII = vector<VI>;

int main() {
  int N, C;
  cin >> N >> C;
  VII Dif(C, VI(C));
  VII Grid(N, VI(N));
  REP(i, C) REP(j, C)
    cin >> Dif.at(i).at(j);
  REP(i, N) REP(j, N)
    cin >> Grid.at(i).at(j);
  
  VII SumDiff(C, VI(3));
  VI sum(3);
  REP(c, C) {
    sum.at(0)=0; sum.at(1)=0; sum.at(2)=0;
    REP(i, N) {
      REP(j, N) {
        sum.at((i+j)%3) += Dif.at(Grid.at(i).at(j)-1).at(c);
      }
    }
    SumDiff.at(c) = sum;
  }
  
  int min = SumDiff.at(0).at(0) + SumDiff.at(1).at(1) + SumDiff.at(2).at(2);
  REP(i, C) {
    REP(j, C) {
      if(j==i) continue;
      REP(k, C) {
        if(k==i || k==j) continue;
        int total = SumDiff.at(i).at(0) + SumDiff.at(j).at(1) + SumDiff.at(k).at(2);
        if(min > total) min = total;
      }
    }
  }
  cout << min << endl;
}

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

template<class T> inline T gcd(T a, T b) {
    if (b == 0) return a;
    return  gcd(b, a % b);
}

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

    int k;
    cin >> k;

    int sum = 0;
    REP(a, k) REP(b, k) REP(c, k) sum += gcd(a, gcd(b, c));

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


Measured memory_bytes: 3624
#include <iostream>
#include <cstring>	// require memset 

using namespace std;

const int N = 50000;
bool prime[N+1];

void make_prime (void)
{
	int i,j;
	memset (prime, true , sizeof(prime) );

	prime[0] = false;
	prime[1] = false;

	for (j = 0; j <= N; ++j ) {
		if (prime[j]){
			int p = j;
			for (i = 2*p; i <= N; i += p ) {
				if (prime[i] ){
					prime[i] = false;
				} // end if
			} // end for
		} // end if	
	} // end for
}

int main()
{
	int n;
	make_prime();

	while (cin >> n && n ) {
		int res = 0;

		for (int i = 2; i <= n/2; ++i ) {
			if (prime[i] && prime[n-i] ){
				++res;
			} // end for
		} // end for
		cout << res << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 912
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long n,val,j = 0,sum = 0;
   cin >> n;
   long long arr[n+2];
   for(long long i = 0; i < n; i++)
   {
       cin >> arr[i];
       arr[i] -= i+1;
   }
   sort(arr,arr+n);
   for(long long i = 0; i < n;i++)
   {
      sum += abs(arr[i] - arr[n/2]);
   }
   cout << sum << endl;
}


Measured memory_bytes: 1792
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n;
  string s;
  cin >> n >> s;
  int ans = 0, x = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'I') x++;
    if (s[i] == 'D') x--;
    if (x >= ans) ans = x;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int h, w, d, q;
  cin >> h >> w >> d;
  vector<vi> a(h, vi(w));
  vi index(h*w);

  rep(i, h) rep(j, w) {
    cin >> a[i][j];
    index[a[i][j]-1] = i*w + j;
  }

  cin >> q;
  vi l(q), r(q);
  rep(i, q) {
    cin >> l[i] >> r[i];
  }

  // 1 indexed
  vector<vi> sum(d, vi(h*w/d+2));
  rep(i, d) {
    for (int j = 0; (j+1)*d+i < h*w; j++) {
      int a = index[j*d+i];
      int b = index[(j+1)*d+i];
      sum[i][j+1] = abs(a/w - b/w) + abs(a%w - b%w);
    }
  }

  rep(i, d) rep(j, h*w/d+1) {
    sum[i][j+1] += sum[i][j];
  }

  rep(i, q) {
    int ll = l[i]-1, rr = r[i]-1;
    cout << sum[ll%d][rr/d] - sum[ll%d][ll/d] << endl;
  }
}


Measured memory_bytes: 6912
import java.util.*;
public class Main{
    
    static final int MOD = (int)1e9 + 7;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        long amin = (long)2e9;
        long amax = (long)-2e9;
        long bmin = (long)2e9;
        long bmax = (long)-2e9;
        for(int i=0; i<n; i++){
            long x = Integer.parseInt(sc.next());
            long y = Integer.parseInt(sc.next());
            amin = Math.min(amin, x+y);
            amax = Math.max(amax, x+y);
            bmin = Math.min(bmin, x-y);
            bmax = Math.max(bmax, x-y);
        }
        
        System.out.println(Math.max(amax-amin, bmax-bmin));
    }
    
}

Measured memory_bytes: 59388
#!/usr/bin/python3
# -*- coding: utf-8 -*-


## Input
N = int(input())
Ln = list(map(int, input().split()))
Ln = sorted(Ln)

## Solve
ret = 0
for a in range(2,N):
  c = 0
  for b in range(a-1,0,-1):
    if c >= b:
      continue
    else:
      while (c<b and Ln[a]>=Ln[b]+Ln[c]):
        c += 1
      ret += max(b-c,0)
print(ret)


Measured memory_bytes: 44124
#include <stdio.h>
int main(){
  int h,w,i,j;
 
  while(1){
    scanf("%d %d",&h,&w);
    if(h==0&&w==0) break;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
    if(i==0||i==h-1||j==0||j==w-1) printf("#");
    else printf(".");
      }
      puts("");
    }
    puts("");
  }
 
  return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;int t;
	
	cin>>s>>t;
	char a,b;
	a=s[0];
	int i;
	for(i=0;s[i]!='\0';i++);
	
	b=s[i-1];
	string s1;
	s1=s;
	long long  ans=0;
	for(i=0;s1[i+1]!='\0';i++)
	{
		//char temp=s1[i];
		if(s1[i]==s1[i+1])
		{
			ans++;
			i++;
		}
	}
	for(i=0;s[i]!='\0';i++);
	int sum1=0,sum2=0;char ch1=s[i-1],ch2=s[0];
	for( i=i-1;i>=0;i--)
	{
		if(s[i]==ch1)
		{
			sum1++;
		}
		else
		break;
	}
	for(int i=0;s[i]!='\0';i++)
	{
		if(s[i]==ch2)
		{
			sum2++;
		}
		else
		break;
	}
	long long d;
	//cout<<sum2<<" "<<s.length()<<endl;
	if(sum2==s.length())
	{
	    d=s.length()*t/2;
	    cout<<d;
	}
	else
	{
		d=ans*t;
	if(sum1%2==1&&sum2%2==1&&ch1==ch2)
	    d=d+t-1;
	cout<<d;
	}
	
}

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

int main(){
  ll n,m; cin >> n >> m;
  vector<ll> vs[m];
  rep(i,m){
    ll k; cin >> k;
    rep(j,k){
      ll s; cin >> s;
      s--;
      vs[i].push_back(s);
    }
  }
  vector<ll> vp;
  rep(i,m){
    ll p; cin >> p;
    vp.push_back(p);
  }
  
  ll ans=0;
  for(ll t=0; t < (1<<n); t++){
    //cout << "t=" << t << endl;
    ll light_on=0;
    rep(i,m){
      ll count_on = 0;
      //cout << "i=" << i << endl;
      
        //cout << "t=" << t << ",i=" << i << endl;
        for(ll e : vs[i]){
          //cout << "e=" << e << ",i=" << i << endl;
          if((t >> e)&1){
            //cout << "e=" << e << endl;
            count_on++;
            
          }
        }
      
      //cout << "count_on=" << count_on << endl;
      if(count_on%2==vp[i]){
        //cout << "t=" << t << ",count=" << count_on << ",vp[" << i << "]=" << vp[i] << endl;
        light_on++;
      }
    }
    // cout << "light_on=" << light_on << endl;
    if(light_on==m) ans++;
    //cout << "ans=" << ans << endl;
  }
  cout << ans;

}

Measured memory_bytes: 256
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bs 1000000007

#define bsize 256

#define ldouble long double

using namespace std;

long long INF = 1e9;
const int N = 700031;

int n,m;

vector<int> g[N];
set<pair<int,pair<int,int> > >S;
set<pair<int,pair<int,int> > >::iterator it;
int alive[N];
int pri[N][15],clr[N][15];
int v[N],d[N],c[N];
int tests;

int main(){
	//freopen("cinema.in","r",stdin);
	//freopen("cinema.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin>>n>>m;
	for (int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	for (int i=1;i<=n;i++)
		alive[i]=1;

	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<=10;j++)
		{
			pri[i][j]=-1;
		}
	}
	cin>>tests;
	for (int i=1;i<=tests;i++)
	{
		cin>>v[i]>>d[i]>>c[i];
		pri[v[i]][d[i]]=i;
		clr[v[i]][d[i]]=c[i];
	}

	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<=10;j++)
		{
			S.insert(make_pair(pri[i][j],make_pair(i,j)));
		}
	}

	while (S.size())
	{
		it=S.end();
		--it;
		pair<int,pair<int,int> > p=(*it);
		S.erase(it);
		int qv=p.second.first;
		int qlev=p.second.second;
		if (qlev==0)
			continue;
		for (int i=0;i<g[qv].size();i++)
		{
			int to=g[qv][i];
			if (pri[to][qlev-1]<pri[qv][qlev])
			{
				clr[to][qlev-1]=clr[qv][qlev];
				S.erase(make_pair(pri[to][qlev-1],make_pair(to,qlev-1)));
				pri[to][qlev-1]=pri[qv][qlev];
				S.insert(make_pair(pri[to][qlev-1],make_pair(to,qlev-1)));
			}
		}
	}

	for (int i=1;i<=n;i++)
	{
		int mp=0;
		for (int j=0;j<=10;j++)
		{
			if (pri[i][j]>=pri[i][mp])
				mp=j;
		}
		cout<<clr[i][mp]<<"\n";
	}

	cin.get(); cin.get();
	return 0;
}


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

vector<int> dp;

int length(int u, vector<vector<int>> &adj)
{
    if(dp[u] != -1)
        return dp[u];
    int len = 0;
    for(int j = 0; j < adj[u].size(); j++)
    {
        int v = adj[u][j];
        len = max(len, 1 + length(v, adj));
    }
    dp[u] = len;
    return len;    
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> adj(n);
    for(int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        adj[x - 1].push_back(y - 1);
    }

    dp = vector<int> (n, -1);
    int maxc = 0;
    for(int i = 0; i < n; i++)
        maxc = max(maxc, length(i, adj));
    cout << maxc;
    return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using ld = long double;
#include<bits/extc++.h>
using namespace __gnu_pbds;
using oset = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn = 1<<21, mod = 1e9 + 7;
int n, k, c;
string s;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k >> c >> s;
	vi pref(n), suf(n);
	map<int, int> cnt;
	for(int fp = -1, lft = 0, i = 0; i < n; i++) {
		if(i > fp && s[i] == 'o') {
			cnt[i]++;
			lft++;
			fp = i + c;
		}
		pref[i] = lft;
		//cout << i << " "<<fp<<" "<< s[i] << " " << lft << '\n';
	}
	//cout << '\n';
	for(int lu = 1<<30, lft = 0, i = n; i--;) {
		if(i+c < lu && s[i] == 'o') {
			cnt[i]++;
			lft++;
			lu = i;
			//cout << i << " ";
		}
		suf[i] = lft;
	}
	for(int i = 0; i < n; i++) {
		int x = 0;
		if(i) x += pref[i-1];
		if(i+1<n) x += suf[i+1];
		if(x<k) cout << i+1 << '\n';
	}
}


Measured memory_bytes: 14228
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int k=m/n;
	for(int i=k;i>=1;i--)
	if(m%i==0){
		cout<<i;
		return 0;
	}
}

Measured memory_bytes: 256
N=gets.to_i
as=gets.split.map(&:to_i)
cnts=Array.new(9,0)
as.each do |i|
    judge=true
    for j in 0..7
        if 400*j <= i && i < 400*(j+1)
            cnts[j]=1
            judge=false
        end
    end
    cnts[8]+=1 if judge
end
puts [[1,cnts[0..7].inject(:+)].max,cnts.inject(:+)].join(" ")


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

long N, P, i, j, n;

long long pow2(long a, long b) {
    if (b == 0) {
        return 1;
    } else if (b == 1) {
        return a;
    } else if (b % 2 == 0) { //b偶数
        long long tmp = pow2(a, b / 2);
        return tmp * tmp;
    } else {
        long long tmp = pow2(a, (b-1) / 2);
        return tmp * tmp * a;
    }
}

int main(void) {
    cin >> N >> P;
    if (N == 1) {
        cout << P << endl;
        return 0;
    }
    long sqrt_P = sqrt(P);
    long ans = 1;
    //Pを素因数分解
    for (i=2; i<=sqrt_P; i++) {
        n = 0;
        while (P % i == 0) {
            P /= i;
            n++;
        }
        if (n >= N) {
            ans *= pow2(i, n / N);
        }
    }
    
    cout << ans << endl;
    return 0;
}




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

int main(void){
	string S;
	cin >> S;
	int ans = 0;
	int l = 0;
	rep(i,3) {
		if (S[i] == 'R') l++;
		else l = 0;
		ans = max(ans,l);
	}
	cout << ans << endl;
return 0;
}


Measured memory_bytes: 3616
s = input()

na = nb = nc = 0
for c in s:
  if c == 'a':
    na += 1
  if c == 'b':
    nb += 1
  if c == 'c':
    nc += 1

if max(abs(na-nb), max( abs(na - nc), abs(nb - nc))) > 1:
  print("NO")
else:
  print("YES")


Measured memory_bytes: 67536
# -*- coding: utf-8 -*-
"""
Created on Fri Mar  1 00:32:34 2019

@author: yuta
"""

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

def main(n,a):
    b = sorted(a,reverse = True)
    c = b[:(2*n+1)]
    d = c[1::2]
    max_sum = sum(d)
    print(max_sum)
main(N,a)

Measured memory_bytes: 37084
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int n, k;
long long F[8000001];
long long inv[8000001];
long long invF[8000001];

long long mod = 1000000007LL;

long long C(int a, int b)
{
	if(b < 0 || b > a) return 0;
	long long ret = F[a];
	ret *= invF[b];
	ret %= mod;
	ret *= invF[a-b];
	ret %= mod;
	return ret;
}

long long ways(int nLocation, int nObject)
{
	return C(nLocation + nObject - 1, nLocation - 1);
}

long long DP[2001][2001];

long long dp(int nZero, int nColor)
{
	if(nZero > n || nColor > n) return 0;
	if(nZero == n && nColor == n) return 1;
	long long &ret = DP[nZero][nColor];
	if(ret != -1) return ret;
	ret = 0;
	if(nZero <= nColor)
		ret += dp(nZero + 1, nColor);
	long long mul = ways(
			nZero + nColor * (k - 1),
			k - 2
		);
	
	ret += dp(nZero, nColor + 1) * mul;
	ret %= mod;
	//cout << nZero << " " << nColor << " : " << ret << endl;
	return ret;
}

int MAIN()
{
	cin >> n >> k;
	F[0] = invF[0] = 1;
	inv[1] = 1;
	for(int i = 2; i <= 8000000; i++)
		inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;

	for(int i = 1; i <= 8000000; i++)
	{
		F[i] = (F[i-1] * i) % mod;
		invF[i] = (invF[i-1] * inv[i] % mod);
	}
	memset(DP, 0xff, sizeof(DP));
	long long ans = 1;
	if(k > 1)
	{
		ans = dp(1, 0);
		for(int i = 1; i <= n; i++)
			ans = (ans * i) % mod;
	}
	cout << ans << endl;
	return 0;
}

int main()
{
	int start = clock();
	#ifdef LOCAL_TEST
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios :: sync_with_stdio(false);
	cout << fixed << setprecision(16);
	int ret = MAIN();
	#ifdef LOCAL_TEST
		cout << "[Finished in " << clock() - start << " ms]" << endl;
	#endif
	return ret;
}


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

int main(void){
  ll K;
  cin >> K;
  vector<ll> A;
  for(int i=1;i<10;i++){
    A.push_back(i);
  }
  
  ll cnt=0;
  while(1){
    if(K < A.size()){
      cout << A.at(K-1) << endl;
      return(0);
    }
    ll x = A.at(cnt);
    ll d = x%10;
    for(int i=-1;i<=1;i++){
      if(d+i>=0 && d+i<=9){
        A.push_back(x*10+(d+i));
      }
    }
    cnt++;
  }
  return(0);
}

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

const int L = 31;

vector<int> v[L][2][2];
int n, r;

void g(int t){
    for(int i = 0, x; i < n; i++){
        scanf("%d", &x);
        for(int j = 0, k = 0; j < L; j++){
            int y = x & (1 << j);
            v[j][t][!!y].push_back(k);
            k |= y;
        }
    }
}

int f(int x, int y, int z){
    auto &w = v[x][0][y], &u = v[x][1][z];
    int r = ~(y ^ z) & w.size() & u.size() & 1;
    for(int i = 0, j = int(u.size()) - 1; i < w.size(); i++){
        for(; j >= 0 && w[i] + u[j] >= (1 << x); j--);
        if(j < 0) return r & 1;
        r ^= ~j;
    }
    return r & 1;
}

int main(){
    scanf("%d", &n);
    g(0);
    g(1);
    for(int i = 0; i < L; i++){
        for(int j = 0; j < 2; j++) for(int k = 0; k < 2; k++)
            sort(v[i][j][k].begin(), v[i][j][k].end());
        r |= (f(i, 0, 0) ^ f(i, 0, 1) ^ f(i, 1, 0) ^ f(i, 1, 1)) << i;
    }
    printf("%d\n", r);
}

Measured memory_bytes: 58680
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF 1<<28

using namespace std;

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

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

	int N, x; cin >> N >> x;
	vector<int> a(N, 0);
	rep (i, N){
		cin >> a[i];
	} // end rep

	sort(ALL(a));

	int res = 0;
	rep (i, N){
		x -= a[i];
		if (x >= 0){
			++res;
		}else{
			break;
		} // end if
	} // end rep

	if (x > 0){
		--res;
	} // end if

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256