akhauriyash/Code-Regression huggingface dataset:
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
const int N = 2e5+ 10;



int main(){
   IOS

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

   vector<ll> a(n), b(m);
   for(ll &x : a)cin>>x;
   for(ll &x : b)cin>>x;
	
	
	for(int i = 1; i < n; i++){
		a[i] += a[i-1];
	}

	for(int i = 1; i < m; i++){
		b[i] += b[i-1];
	}

	int ans = 0;		
	for(int i = 0; i < n; i++){
		int idx = upper_bound(all(b), k - a[i]) - b.begin() - 1; 	
		if(a[i] <= k)
			ans = max(ans, i + 1 + idx + 1);
	}

	for(int i = 0; i < m; i++){
		int idx = upper_bound(all(a), k - b[i]) - a.begin() - 1;
		if(b[i] <= k){
			ans = max(ans, i + 1 + idx + 1);
		}
	}
	cout<<ans<<"\n";



}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
	if(b&1) res = res * a % mod;
		a = a * a % mod;
	b >>= 1;
	}

	return res;
}



Measured memory_bytes: 6344
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Map<String, Integer> sales = new HashMap<>();
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a == 0) {
				String k = sc.next();
				int x = sc.nextInt();
				sales.put(k, x);
			}
			if (a == 1) {
				String y = sc.next();
				if (sales.get(y) == null) {
					System.out.println(0);
				} else {
					System.out.println(sales.get(y));
				}

			}
			if(a==2) {
				String z=sc.next();
				sales.remove(z);
			}
		}
	}
}


Measured memory_bytes: 192580
#include <bits/stdc++.h>
using namespace std;
int main() 
{
  ios::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int n;
  cin >> n;
  int ret = 0;
  for (int i = 0; i < n; i ++)
	{
    int t;
    cin >> t;
    ret ^= t;
  }
  if (ret == 0) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

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

  if((n == 1 && a != b) || a > b)
  {
	cout << 0 << endl;
  }
  else
  {
	cout << (n - 2) * (b - a) + 1 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream> 
#include<vector>
#include<algorithm>
using namespace std; 
int main() {
	vector <int> vec(4);
	for (int i = 0; i < 4; i++) {
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	if (vec.at(0) == vec.at(1) && vec.at(2) == vec.at(3)) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}
}
	


Measured memory_bytes: 3136
#include <iostream>
#include <cstdio>
#include <vector>
#include <deque>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <string>

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

int main(){
    int A,B,K;
    int tmp;

    scanf("%d %d %d",&A,&B,&K);

    for(int i=0;i<K && A+i<=B;i++){
        tmp = A+i;
        printf("%d\n",tmp);
    }

    for(int i= ((B-K+1 <= tmp) ? tmp+1 : B-K+1) ; i<=B ; i++){
        printf("%d\n",i);
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  char s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  int count;
  if (s1 == '1'){
    count++;
  }
  if (s2 == '1'){
    count++;
  }
  if (s3 == '1'){
    count++;
  }
  cout << count;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a,b;
    char c;
    int f = 1;
    
    while(f){
        scanf("%d %c %d", &a, &c, &b);
        int ans;
        
        switch (c){
            case '+':
                ans = a+b;
                printf("%d\n", ans);
                break;
                
            case '-':
                ans = a-b;
                printf("%d\n", ans);
                break;
            
            case '*':
                ans = a*b;
                printf("%d\n", ans);
                break;
            
            case '/':
                ans = a/b;
                printf("%d\n", ans);
                break;
            
            case '?':
                f = 0;
                break;
            
        }
        
    }
    
    return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	string s;
	cin >> s;

	string r;
	for (int i = 0; i < s.size() - 1; ++i)
		if (s[i] == s[i + 1])
			r += "0";
		else
			r += "1";

	int res = s.size();
	for (int i = 0; i < r.size(); ++i) {
		if (r[i] == '1') {
			int distance = max(i + 1, (int)r.size() - i);
			res = min(res, distance);
		}
	}

	cout << res << "\n";

	return 0;
}

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

typedef long long lli;
typedef pair<lli,lli> pll;
typedef vector<lli> vcL;

void solve() {
	int n = 3;
//	cin >> n;
	int s[ n+5 ];
	for (int i = 0; i < n; ++i) cin >> s[i];
	
	cout << s[2]/s[0]*s[1] << '\n';
	
}

int main() {
	int t = 1;
//	cin >> t;
	while ( t-- ) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define removeDuplicate(a) sort(a.begin(), a.end()); a.resize(distance(a.begin(), unique(a.begin(), a.end())));


const int LimitN = 1e5 + 10; 
const long long oo = 1e18 + 10; 
struct TEdge {
	int foo, bar, cost; 
	TEdge (int foo = 0, int bar = 0, int cost = 0) : foo(foo), bar(bar), cost(cost) {}
	int getAdj (int u) { if (foo == u) return bar; return foo; }
} e[LimitN]; 

int n; 
int subSize[LimitN]; 
long long lenCycle = 0; 
long long minElimition = 0; 
vector<int> g[LimitN]; 

void dfs (int foo, int parent = 0) {
	subSize[foo] = 1;
	bool isCentroid = true;   
	for (int iEdge : g[foo]) {
		int bar = e[iEdge].getAdj(foo); 
		if (bar == parent) continue; 
		dfs(bar, foo); 
		lenCycle += 2LL * min(n - subSize[bar], subSize[bar]) * e[iEdge].cost; 
		subSize[foo] += subSize[bar]; 
		if (2 * subSize[bar] == n) {
			minElimition = min(minElimition, (long long) e[iEdge].cost); 
		}	
		if (subSize[bar] > (n - 1) / 2) 
			isCentroid = false; 
	}
	if ((n - subSize[foo]) > (n - 1) / 2) isCentroid = false; 
	if (isCentroid) {
		for (int iEdge : g[foo]) {
			minElimition = min(minElimition, (long long)e[iEdge].cost); 
		}
	}
}


int main() {
    #define file "in"
    //freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);

    scanf("%d", &n); 
    for (int iEdge = 1; iEdge < n; ++iEdge) {
    	int foo, bar, cost; 
    	scanf("%d %d %d", &foo, &bar, &cost); 
    	e[iEdge] = TEdge (foo, bar, cost); 
    	g[foo].push_back(iEdge); 
    	g[bar].push_back(iEdge); 
    }
    minElimition = oo; 
    dfs(1); 
    //printf("%lld %lld\n", lenCycle, minElimition);
    printf("%lld", lenCycle - max(0LL, minElimition)); 
    return 0;
}

Measured memory_bytes: 15232
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    string s; cin >> s; SORT(s);
    Yn(s=="abc");

    return 0;
}

Measured memory_bytes: 256
N,K=map(int, input().split(" "))
d=[0]*K
A=[0]*K
dic={}
for i in range(K):
    d[i]=int(input())
    A[i]=input().split()
for j in range(K):
    if d[j]==1:
        if A[j][0] not in dic:
                dic[A[j][0]]=1
    if d[j]!=1:
        for k in range(d[j]):
            if A[j][k] not in dic:
                dic[A[j][k]]=1
print(N-len(dic))

Measured memory_bytes: 9324
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1
d = {0}
p = 0
while not a[p] in d:
    d.add(a[p])
    p = a[p]
#print(d)
val = [0]
p = 0
for i in range(len(d)):
    val.append(a[p])
    p = a[p]
#print(val)
cnt = 0
p = 0
while val[p] != val[-1]:
    cnt += 1
    p += 1
del val[-1]
if cnt > k:
    print(val[k]+1)
    exit()
k -= cnt
k2 = k % (len(d)-cnt)
#print(k2)
#print(cnt)
print(val[cnt + k2]+1)


Measured memory_bytes: 124776
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int a[100000], b[100000];

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
ll Max(ll a, ll b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}
void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[],int y[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		hSwap(y, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x,y, left, i - 1, n);
	if (j + 1 <  right)QSort(x,y, j + 1, right, n);
}

int main() {
	int n, m;
	//*
	scanf("%d %d", &n, &m);
	REP(i, m) {
		scanf("%d %d", &a[i], &b[i]);
	}
	/*/
	n = 1e5, m = 1e5;
	a[0] = 1, b[0] = 2;
	REPS(i, n-1) {
		a[i] = i;
		b[i] = i + 1;
	}
	//*/
	QSort(b, a, 0, m - 1,1);
	//ShowData(a, 0, m - 1);
	//ShowData(b, 0, m - 1);
	int l = 0, r = 0;
	int ans = 0;
	//*
	while(1) {
		int flag = 0;
		while (a[l] < b[r]) {
			flag = 1;
			l++;
			if (l == m)break;
		}
		if(flag)ans++;
		if (r == l || l == m)break;
		r=l;
	}
	//*/
	PRINTD(ans);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=5e5+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
char s[N];
int len,ch[N][26],nxt[N],T;
ll gao(ll x,int c){
	if(x<=len)return ch[x][c];
	ll n1=ch[len/2][c],n2=ch[T][c],l1=len/2,l2=T;
	while(l1+l2<=x){
		swap(l1,l2);l1+=l2;
		swap(n1,n2);n1+=n2;
	}return n1+gao(x-l1,c);
}
int main(){
	scanf("%s",s+1);len=strlen(s+1);
	rep(i,1,len){
		re(j,0,26)ch[i][j]=ch[i-1][j];
		ch[i][s[i]-'a']++;
	}
	ll l,r;read(l,r);int j=0;
	rep(i,2,len){
		while(j&&s[j+1]!=s[i])j=nxt[j];
		if(s[j+1]==s[i])j++;
		nxt[i]=j;
	}
	T=nxt[len];while(T>=len/2)T=nxt[T];
	T=len/2-T;
	re(i,0,26)cout<<gao(r,i)-gao(l-1,i)<<" ";
}

Measured memory_bytes: 21760
point = [0,0]

n = int(input())

for i in range(n):
    
    a,b = map(str,input().split())
    
    if a == b:
        point[0] += 1
        point[1] += 1
        continue
    
    n2 = min(len(a),len(b))
    
    for i2 in range(n2):
        ac = ord(a[i2])
        bc = ord(b[i2])
        
        if ac > bc:
            point[0] += 3
            break
        elif bc > ac:
            point[1] += 3
            break
        
        if i2 == len(a)-1:
            point[1] += 3
        
        elif i2 == len(b)-1:
            point[0] += 3
            

print(' '.join(map(str,point)))


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n;
	bool flag=false;
	cin>>n;
	if(n/100==7||n%100/10==7||n%10==7)
		flag=true;	
	if(flag==true)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}


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

using namespace std;


int main()
{
  int P, Q;
  cin >> P >> Q;
  Q /= __gcd(P, Q);
  long long ret = 1;
  for(int i = 2; i * i <= Q; i++) {
    if(Q % i == 0) {
      ret *= i;
      while(Q % i == 0) Q /= i;
    }
  }
  cout << ret * Q << endl;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, k;
  cin >> n >> k;
  
  vector<ll> h(n);  
  rep(i, 0, n) cin >> h[i];
  sort(all(h));
  
  ll ans = 1e9+1;
  rep(i, 0, n-k+1)
    ans = min(ans, h[i+k-1]-h[i]);
    
  cout << ans << "\n";

}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;


int main(void){
 int D;
 cin>>D;
 
 if(D==25)std::cout<<"Christmas"<<std::endl;
 else if(D==24)std::cout<<"Christmas Eve"<<std::endl;
 else if(D==23)std::cout<<"Christmas Eve Eve"<<std::endl;
 else std::cout<<"Christmas Eve Eve Eve"<<std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<ll> T(N);
	vector<ll> A(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> T[i];
	}
	for (auto i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	auto ans = 1ll;
	auto mod = (ll)1e9 + 7;
	for (auto i = 0; i < N; ++i)
	{
		if (i == 0 || T[i - 1] < T[i])
		{
			if (T[i] > A[i])
			{
				ans = 0;
				break;
			}
		}
		else if (i == N - 1 || A[i] > A[i + 1])
		{
			if (T[i] < A[i])
			{
				ans = 0;
				break;
			}
		}
		else
		{
			ans = ans * min(T[i], A[i]) % mod;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1920
/*                    ___          |\    /|           ____   ____   ____  ____
   |     |    /\    /    \ |     | | \  / |    /\    |    \ |    \ |     |    \
   |_____|   /__\   \____  |_____| |  \/  |   /__\   |____/ |____/ |__   |____/
   |     |  /    \       \ |     | |      |  /    \  |      |      |     |   \
   |     | /      \ \____/ |     | |      | /      \ |      |      |____ |    \
*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define pf push_front
#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define pld pair<long double,long double>
#define endl '\n'
#define loop(i,n) for(ll i=0;i<n;i++)
#define mod ((ll)(1e9+7))
#define in(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define in3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define inv(v) for(auto&i:v) in(i)
#define vl vector<ll>
#define ml unordered_map<ll,ll> 
#define vpl vector<pair<ll,ll>>
#define INF 0x3f3f3f3f

int main() {
    ll n;   in(n);
    float f = 1.08;
    // cout<<n/f<<endl;
    ll beg = n/f;
    // cout<<beg<<endl;;
    ll end = ((n+1)/f);
    // cout<<beg<<" "<<end<<endl;
    while (beg<=end)
    {
        ll mid = (beg+end)/2;
        // cout<<mid<<endl;
        ll val = mid*(1.08);
        if(val==n) {
            cout<<mid<<endl;
            return 0;
        }
        else if(val<n) beg = mid+1;
        else end = mid-1;
    }
    cout<<":("<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 456789;
int c[300][300];
int main(){
  	string s, t;
	cin >> s >> t;
	int len = s.size();
	for(int i = 0; i < len; i++) c[s[i]][t[i]]++;
	for(int i = 'a'; i <= 'z'; i++) {
		int tot = 0;
		for(int j = 'a'; j <= 'z'; j++) tot += c[i][j];
		for(int j = 'a'; j <= 'z'; j++) if(c[i][j] && c[i][j] != tot){
			cout << "No" << endl;
			return 0;
		}
		tot = 0;
		for(int j = 'a'; j <= 'z'; j++) tot += c[j][i];
		for(int j = 'a'; j <= 'z'; j++) if(c[j][i] && c[j][i] != tot){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 776
#include <cstdio>
int a[100001];
int n;
long long int sum = 0,t = 0;
int main(int argc, const char * argv[]) {
    scanf("%d",&n);
    for (int i = 0; i < n; i++){
        scanf("%d",&a[i]);
        sum += a[i];
        t += i + 1;
    }

    if (sum % t){
        printf("NO\n");
        return 0;
    }
    int tmp = a[0];
    int d = sum / t;
    for (int i = 0; i < n - 1; i ++)
        a[i] = a[i + 1] - a[i] - d;
    a[n - 1] = tmp - a[n - 1] - d;
    
    for (int i = 0; i < n; i ++)
        if (a[i] > 0 || a[i] % n ){
            printf("NO\n");
            return 0;
        }
    printf("YES\n");

    return 0;
}

Measured memory_bytes: 512
import java.io.*;

public class Main
{
	public static void main(String[] args)
	{
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String[] str = br.readLine().split(" ");
			int[] ar = new int[n];
			for(int i= 0 ; i< n ; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			}
			gyalaxySort(ar,n);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void gyalaxySort(int[] a, int len)
	{
		StringBuilder sb = new StringBuilder();
		sb.append(giganticBunshou(a,len));
		for(int i = 1 ; i < len ; i++)
		{
			int tar = a[i];
			int j = i - 1;
			while(j >= 0 && a[j] > tar )
			{
				a[j+1] =a[j]; 
				a[j] = tar;
				j--;
				
			}
			sb.append(giganticBunshou(a,len));
		}
		System.out.print(sb);
	}
	public static String giganticBunshou(int[] b, int l)
	{
		StringBuilder sb = new StringBuilder();
		for(int i=0 ; i<l-1 ; i++)
		{
			sb.append(b[i]).append(" ");
		}
		sb.append(b[l-1]).append("\n");
		return sb.toString();
	}
	
}

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

typedef long long int ll;
typedef long double ld;
const ll MAX=3e3+5;
const ll MAX1=1e2+5;
const ll INF=1e15+2;
const ll MOD=1e9+7;

#define pb push_back
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi pair<ll,ll>
#define map1 unordered_map

ll n;
string s;
ll dp[MAX][MAX];

ll rec(ll pos,ll bel,ll abv)
{
    if(bel<0 || abv<0)
        return 0;
    if(pos==n-1)
        return 1;
        
    ll &ans=dp[pos][bel];
    if(ans != -1)
        return ans;
    ans=0;
    
    char op=s[pos];
    
    if(op=='<')
    {
        ans+=rec(pos+1,bel,abv-1);
        ans+=rec(pos,bel+1,abv-1);
        ans%=MOD;
    }
    if(op=='>')
    {
        ans+=rec(pos+1,bel-1,abv);
        ans+=rec(pos,bel-1,abv+1);
        ans%=MOD;
    }
    return ans;
}

int main()
{
    faster;
    cin>>n>>s;
    
    memset(dp,-1,sizeof(dp));
    
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        ll bel=i-1;
        ll abv=n-i;
        
        ans+=rec(0,bel,abv);
        ans%=MOD;
        
    }
    cout<<ans;
}

Measured memory_bytes: 71168
n = int(input())
import sys

def input():
    return sys.stdin.readline().rstrip()
ans = []
def calc(s1,s2):
    lens1 = len(s1)
    lens2 = len(s2)
    # print(len(s1),s1[-1])
    dp = [0]*(lens2+1)
    for i in range(lens1):
        dp2 = dp[:]
        e = s1[i]
        for j in range(lens2):
            if e == s2[j]:
                dp[j+1] = dp2[j] + 1
            elif dp[j]>dp[j+1]:
                dp[j+1] = dp[j]
    # print(dp)
    ans.append(dp[-1])


for i in range(n):
    s1 = input()
    s2 = input()
    calc(s1,s2)
for i in ans:
    print(i)

# def lcs(x, y):
#     a = len(x)
#     b = len(y)
#     c1 = [0] * (b + 1)
#     for i in range(a):
#         e1 = x[i]
#         c2 = c1[:]
#         for j in range(b):
#             if e1 == y[j]:
#                 c1[j+1] = c2[j] + 1
#             elif c1[j+1] < c1[j]:
#                 c1[j+1] = c1[j]
#     return c1[-1]
    
# n = int(input().rstrip())
# ret = []
# for i in range(n):
#     s1 = input().rstrip()
#     s2 = input().rstrip()
#     ret.append(lcs(s1, s2))
# print(*ret, sep="\n")


Measured memory_bytes: 5632
/*input
11 10 9
*/
#include<bits/stdc++.h>
#define int        long long
#define MOD        1000000007
#define MAX        100005
#define pb         push_back
#define mp         make_pair
#define pii        pair<int,int>
#define mii        map<int,int>
#define vi         vector<int>
#define ff         first
#define ss         second
#define T          int t;cin>>t;while(t--)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define umi        unordered_map<int,int>
#define maxheap    priority_queue<int>
#define minheap    priority_queue<int,vector<int>,greater<int> >
#define inp(n)     for(int i=0;i<n;i++)
#define N          200005
#define mxN           2000005
#define all(v)        v.begin(),v.end()
#define lb(v,val)  (int)(lower_bound(v.begin(),v.end(),val)-v.begin())
#define ub(v,val)  (int)(upper_bound(v.begin(),v.end(),val)-v.begin())
using namespace std;
using namespace std::chrono;

void solve(){
    int a,b,n;
    cin>>a>>b>>n;
    int ans = (a*n)/b-a*(n/b);
    if(n >= b-1){
        ans = (a*b-a)/b;
    }
    cout << ans << '\n';
}

signed main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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




Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans=0,n;
int main(){
	cin>>n;
	ll a[n]={},b[n]={};
	ll k;
	for(int i=0;i<n;i++){
		cin>>k;
		a[i]=k;
		b[i]=k;
	}
	sort(a,a+n);//aはソート
	for(int i=0;i<n;i++){
		if(a[i]==b[i]){
			ans++;
		}
	}
	if(ans==n){
		cout<<"0"<<endl;
		return 0;
	}
	ll q,x,y;
	cin>>q;
	for(int i=0;i<q;i++){
		//cout<<ans<<endl;
		cin>>x>>y;
		x--;
		y--;
		//cout<<a[x]<<" "<<a[y]<<endl;
		//cout<<b[x]<<" "<<b[y]<<endl;
		if(a[x]==b[x]){
			ans--;
		}
		if(a[y]==b[y]){
			ans--;
		}
		ll r;
		r=b[x];
		b[x]=b[y];
		b[y]=r;
		if(a[x]==b[x]){
			ans++;
		}
		if(a[y]==b[y]){
			ans++;
		}
		if(ans==n){
			cout<<++i<<endl;
			return 0;
		}
	}
	cout<<"-1"<<endl;
}
		
		
		


Measured memory_bytes: 7852
#include <iostream>

using namespace std;

int main() {
    int n, r, mn = 2e9, mx = 1-1e9;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> r;
        mx = max(mx, r - mn);
        mn = min(mn, r);
    }
    cout << mx << endl;
    return 0;
}



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

int main() {
    vector<int> time(5);
    rep(i,5) cin >> time[i];
    vector<int> nexttime(5);
    rep(i,5) {
      nexttime[i] = 10*((time[i]+9)/10);
    }
    int ans = 1001001001;
    rep(i,5) {
      int sum = 0;
      rep(j,5) {
        if (i == j) sum += time[j];
        else sum += nexttime[j];
      }
      ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        //Dummy input (for Debug)
        int n_d = 7;
        int[] h_d = {2,9,4,5,1,6,10};
        
        //Get Input
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String n_in = br.readLine();
        String h_in = br.readLine();

        int n = Integer.parseInt(n_in);

        String[] s = h_in.split(" ");
        int[] h = new int[s.length];
        for (int i = 0; i < s.length; i++) {
            h[i] = Integer.parseInt(s[i]);
        }
        
        //Set and Run
        DPRunner dpr = new DPRunner();
        dpr.setInput(n,h);
        int result = dpr.runDP();
        // dpr.print();    //deb

        //Output
        System.out.println(result);
    }
    
    static class DPRunner {
        private int n;
        private int[] h;
        int[] minCosts;
        
        
        void setInput(int n, int[] h){
            this.n = n;
            this.h = h;
            this.minCosts =  new int[h.length];
        }
        
        //ノードごとの最小コストを探索。最後のノードへの最小コストを返却
        int runDP(){
            //Member Initialization Check
            if(n == 0 || n != h.length)
                throw new RuntimeException();
            
            
            for(int i = 0; i < n; i++){
                minCosts[i] = calcNode(i);
            }
            return minCosts[n-1];
        }
        
        private int calcNode(int node){
            //まずノード1。コストは無い
            // minCosts[0] = 0;
            if(node == 0) {
                return 0;
            }
            
            
            //minCosts[1] = Math.abs(h[0] - h[1]);
            if(node == 1) {
                int cost1 = Math.abs(h[0] - h[1]);
                return cost1;
            }
            
            //1マスjump
            int cost1 = minCosts[node - 1] + Math.abs(h[node - 1] - h[node]);
            //ノード2は1マスjumpのみ許容
            if(node == 1) {
                return cost1;
            }
            //2マスjump
            int cost2 = minCosts[node - 2] + Math.abs(h[node - 2] - h[node]);
            return (cost1 < cost2) ? cost1 : cost2;
        }
        
        void print(){
            System.out.println("n:" + n + ", h:" + Arrays.toString(h));
            System.out.println("minCosts:" + Arrays.toString(minCosts));
        }
    }
}

Measured memory_bytes: 33492
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000001
using namespace std;
typedef long long ll;

int main(){
  int n, m; cin >> n >> m;
  vector<pair<int, int>> scity;
  vector<pair<int, int>> bcity;
  map<int, int> idmp;
  rep(i, 0, m){
    int p, y; cin >> p >> y;
    scity.push_back(make_pair(p, y));
    bcity.push_back(make_pair(p, y));
  }
  sort(all(scity));
  int rank = 1;
  rep(i, 0, m){
    idmp[scity[i].second]=rank;
    rank++;
    if(i<m-1 and scity[i].first!=scity[i+1].first)  rank=1;
  }
  rep(i, 0, m){
    cout << fill0(6) << bcity[i].first << fill0(6) << idmp[bcity[i].second] << endl;
  }
  return 0;
}

Measured memory_bytes: 7788
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

using namespace std;

int n;
int A[100005];

double dabs(int x){
	if(x<0) return -x;
	return x;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	sort(A,A+n);
	double md=A[n-1]/2.0;
	int pos=lower_bound(A,A+n-1,md)-A;
//	printf("%lf %lf %lf %lf\n",A[n/2],A[n/2-1],dabs(md-(double)A[n/2]),dabs(md-(double)A[n/2-1]));
	if(dabs(md-(double)A[pos])<dabs(md-(double)A[pos-1])) printf("%d %d\n",A[n-1],A[pos]);
	else printf("%d %d\n",A[n-1],A[pos-1]);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

map<ll,ll> mapp;

ll func(ll n)
{
    if(n==0){return 0;}

    if(mapp.find(n)==mapp.end())
    {
        mapp[n]=1+2*func(n/2);
    }
    return mapp[n];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin>>n;
    ll ans=func(n);
    cout<<ans;

    return (0);
}


Measured memory_bytes: 256
// OURL: https://atcoder.jp/contests/abc140/tasks/abc140_a
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));  }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v);  }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", ";  } first = false; res += to_string(x);  } res += "}"; return res;  }

string to_string(string s) { return '"' + s + '"';  }
string to_string(const char* s) { return to_string((string) s);  }
string to_string(bool b) { return (b ? "true" : "false");  }
string to_string(vector<bool>::reference b) { return to_string(bool(b));  }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";  }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res; }

void debug_out() { cerr << endl;  }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...);  }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

  int n;
  cin >> n;

  cout << pow(n, 3) << endl;

  return 0;
}


Measured memory_bytes: 384
/*input

*/
#include<bits/stdc++.h>
//priority_queue<ll, vector<ll>, std::greater<ll> > q;
//gcc 1.cpp -lstdc++ -o main.o
#define ull                 unsigned long long
#define ll                         long long
#define M                         1000000007
#define pb                         emplace_back
#define p_q                 priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define all(a)      (a).begin(),(a).end()
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b))/gcd((a),(b))
#define ios                    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp                         make_pair
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define F first
#define S second
#define N 200005
using namespace std;


int main(void)
{
        ios
        ll n , k;
        cin>>n>>k;
        vi v(n);
        rep(i,0,n)
                cin>>v[i];
        sort(all(v));
        ll ans = 0;
        rep(i,0,k)
                ans = ans + v[i];
        cout<<ans;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pib = pair<int,bool>;
using ll = long long;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#ifdef fread_unlocked
#define fread fread_unlocked
#define fwrite fwrite_unlocked
#endif
#define mp make_pair
#define lc ind<<1
#define rc ind<<1|1
const int MN = 1e4+5, MOD = 1e9+7, BASE = 31, MASK = (1 << 10) - 1;
int main () {
	int n;
	scanf ("%d",&n);
	vector<int> a(n); int sum = 0;
	for (int i = 0; i < n; i++) {
		scanf ("%d",&a[i]); sum ^= a[i];
	}
	for (int i = 0; i < n; i++) printf ("%d ",sum^a[i]);
	printf ("\n");
	return 0;
}


Measured memory_bytes: 4056
package main

import "fmt"

func main() {
	var K, A, B int
	fmt.Scan(&K,&A,&B)
	if A%K==0||B%K==0{
		fmt.Println("OK")
      return
	}
	for i:=0; i<B-A;i++ {
		if (A+i)%K==0 {
			fmt.Println("OK")
			return
		}
	}
 fmt.Println("NG")

}

Measured memory_bytes: 1820
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long Mod = (long)1e9 + 7;
        static long[] primes = new long[1001];
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NH = Sarray();
            var N = NH[0];
            var H = NH[1];
            var AB = new List<Tuple<int, long, long>>();
            for (var i = 0; i < N; ++i)
            {
                var ab = Sarray();
                AB.Add(Tuple.Create(i, ab[0], ab[1]));
            }
            var maxA = AB.Max(m => m.Item2);
            // 投げたら最大A以上のものを全部投げる
            AB = AB.Where(ab => ab.Item3 >= maxA).ToList();
            AB = AB.OrderByDescending(ab => ab.Item3).ToList();
            var dmg = 0L;
            var ans = 0L;
            for (var i = 0; i < AB.Count; ++i)
            {
                dmg += AB[i].Item3;
                ++ans;
                if (H <= dmg)
                {
                    WriteLine(ans);
                    return;
                }
            }
            // 残る分は殴っておいたことにする
            if (dmg < H)
                ans += (H - dmg + maxA - 1) / maxA;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}


Measured memory_bytes: 30908
a = int(input())
b = int(input())
c = int(input())
x = int(input())
counter = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k == x:
                counter += 1
print(counter)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N = 66666, MOD = 1e9 + 7; // N > 2 * sqrt(n) 就可
void add(int &x, int y) {
  x += y;
  if(x >= MOD) x -= MOD;
}
vector<int> v;
int dp[2][N], len[N]; // len[] 记录每一个一起计算的部分的长度
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n, k; cin >> n >> k;
  for(int i = 1, j; i <= n; i = j + 1) {
    j = n / (n / i); // 边界值
    v.push_back(i);
  }
  v.push_back(n + 1);
  const int m = v.size();
  for(int i = 0; i + 1 < m; i++) {
    len[i] = v[i + 1] - v[i];
  }
  for(int i = 1; i < m; i++) dp[0][i] = 1;
  for(int q = 1; q <= k; q++) {
    int cur = 1, whe = m - 1;
    for(int i = 1, j; i <= n; i = j + 1, cur++, whe--) {
      j = n / (n / i); // 边界值
      dp[q & 1][cur] = 1ll * dp[~q & 1][whe] * len[cur - 1] % MOD; // dp转移
    }
    for(int i = 1; i < m; i++) add(dp[q & 1][i], dp[q & 1][i - 1]); // 求前缀和
  }
  cout << dp[k & 1][m - 1] << "\n";
}

Measured memory_bytes: 1404
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

int main() {
	ll n, x; cin >> n >> x;
	ll L[100] = {};
	rep(i, 0, n)cin >> L[i];

	ll cnt = 1;
	ll D = 0;
	rep(i, 0, n) {
		D += L[i];

		if (x >= D) {
			cnt++;
		}
		else {
			break;
		}
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

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

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

template <typename T>
inline T gcd(T a, T b) {
    for (; b; a %= b, swap(a, b));
    return a; 
}

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    string S, T; cin >> S >> T;
    int rst = T.size();
    for (int i = 0; i < S.size(); i++) {
        int sub = T.size();
        for (int j = 0; j < T.size(); j++) {
            if (i+j >= S.size()) {
                sub = rst;
                break;
            }
            
            if (S[i+j] == T[j]) sub--;
        }

        rst = min(rst, sub);
    }

    cout << rst;
}

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

int main()
{
  int H,W; std::cin >> H >> W;
  using Vector = std::vector<char>;
  std::vector<Vector> A(H, Vector(W));
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      std::cin >> A[i][j];
    }
  }
  int ans = true;
  for(int row = 0; row < H; ++row){
    for(int column = 0; column < W; ++column){
      if(A[row][column] == '#'){
        int res{};
        if(row - 1 >= 0){
          if(A[row - 1][column] == '#'){
            res = true;
          }
        }
        if(row + 1 < H){
          if(A[row + 1][column] == '#'){
            res = true;
          }
        }
        if(column - 1 >= 0){
          if(A[row][column - 1] == '#'){
            res = true;
          }
        }
        if(column + 1 < W){
          if(A[row][column + 1] == '#'){
            res = true;
          }
        }
        ans &= res;
      }
    }
  }
  std::cout << (ans ? "Yes" : "No") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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 n; ll k;
int cycleRoot;
int cycleLen = 0;
int a[200010];
ll dist[200010];

void dfs(int now) {
    int next = a[now];
    if (dist[next] == INF) {
        dist[next] = dist[now] + 1;
        dfs(next);
    } else {
        cycleRoot = next;
        cycleLen = dist[now] - dist[next] + 1;
        return;
    }
}

int main() {
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;

    rep(i, n) dist[i] = INF;
    dist[0] = 0;
    dfs(0);

    if (k < dist[cycleRoot]) {
        rep(i, n) {
            if (dist[i] == k) {
                cout << i + 1 << endl;
                return 0;
            }
        }
    } else {
        ll rem = k - dist[cycleRoot];
        rem %= cycleLen;
        rep(i, n) {
            if (dist[i] - dist[cycleRoot] == rem) {
                cout << i + 1 << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 5944
def main():
    import itertools

    n = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))

    nums = list(range(1,n+1))
    perm = list(itertools.permutations(nums, n))
    a = perm.index(p) + 1
    b = perm.index(q) + 1

    print(abs(a-b))

if __name__ == "__main__":
    main()

Measured memory_bytes: 70380
/**
 * 最小全域木
 * https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_2_A
 * プリム法
 * */

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

#define INF 1LL<<60 //使いやすい無限(ll)
#define debug2(x,y) cout<<"("<<#x<<","<<#y<<") = ("<<(x)<<","<<(y)<<")\n"

using Node = long long; //頂点
using Weight = long long; //重み
using Edge = pair<Weight, Node>; //辺={重み, 行き先}
using Graph = vector<vector<Edge>>; //隣接リスト

ll V,E;

Graph G;
vector<Edge> Tree;
vector<bool> isTree;

void prim(Node start){
  //Weightの小さいものから取り出す
  priority_queue<Edge, vector<Edge>,greater<Edge> >que;
  isTree.assign(V, false);
  isTree[start] = true;

  for(Edge n: G[start]){
    que.push(n);
  }

  while(Tree.size() != V-1){//木にV-1本の辺が入れば木が完成
    auto now = que.top(); que.pop();
    Node Nnow = now.second;
    Weight Wnow = now.first;
    if(isTree[Nnow])continue;

    Tree.push_back(now); //木に辺を入れる
    isTree[Nnow] = true; //行き先の頂点を木に含める
    //debug2(Wnow, Nnow);

    for(auto n: G[Nnow]){
      if(isTree[n.second])continue;
      que.push(n); //新しい頂点からの辺をキューに入れる
    }

    //continue: 木へ向かう辺の処理を避けている
  }
}

int main(){
  cin>>V>>E;
  G.resize(V);

  for(int i=0; i<E; i++){
    ll s,t,d;
    cin>>s>>t>>d;
    G[s].push_back({d,t});
    G[t].push_back({d,s});//無効グラフで入力
  }

  prim(0);

  ll ans = 0;
  for(auto x: Tree){
    ans += x.first;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 10560
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y !=NIL && x == y->right){
    x = y; 
    y = y->parent;
  }
  return y;
}
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
    if(u != NIL){
      inorder(u->left);
      printf(" %d",u->key);
      inorder(u->right);
    }
  }
  
  void preorder(Node u){
    if(u != NIL){
      printf(" %d",u->key);
      preorder(u->left);
      preorder(u->right);
    }
  }
 
  int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
      scanf("%s", com);
      if ( com[0] == 'f' ){
	scanf("%d", &x);
	Node t = treeSearch(root, x);
	if ( t != NIL ) printf("yes\n");
	else printf("no\n");
      } else if ( com[0] == 'i' ){
	scanf("%d", &x);
	insert(x);
      } else if ( com[0] == 'p' ){
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
      } else if ( com[0] == 'd' ){
	scanf("%d", &x);
	treeDelete(treeSearch(root, x));
      }
    }

    return 0;
  }

Measured memory_bytes: 19364