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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == 0) {
        v.clear();
        return 0;
    }
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    return i;
}
int solve(vi& a) {
    int ans=INT_MAX;
    amin(ans, a[0]+a[1]);
    amin(ans, a[1]+a[2]);
    amin(ans, a[2]+a[0]);
    return ans;
}

int main() {
    vi a(3);
    loadvec(a,3);
    cout << solve(a) << endl;
    return 0;
}


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


class AlphabetCards{
	String cards;
	AlphabetCards(String cards){
		this.cards = cards;
	}
	void shuffleSomeCardsFromBottom(int numCards){
		cards = cards.substring(numCards) + cards.substring(0, numCards);
	}
	@Override
	public String toString(){
		return cards;
	}
}
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String line = "";
		while(true){
			line = scan.nextLine();
			if(line.charAt(0) == '-')
				return;
			AlphabetCards cards = new AlphabetCards(line);
			
			int shuffleTime = scan.nextInt();
			for(int i=0; i < shuffleTime; i++)
				cards.shuffleSomeCardsFromBottom(scan.nextInt());
			System.out.println(cards);
			scan.nextLine();
		}
	}
}

Measured memory_bytes: 18440
#include <iostream>
#include <list>
#include <vector>
using namespace std;
int main(){
    long long n,m;
    int ans = 1;
    cin >> n >> m;
    vector<int> a;
    for(int i=1;i*i<=m;i++){
        if((m%i == 0) && (m/i >= n)){
             a.push_back(i);
        }
    }
    for(int i=0;i<a.size();i++){
        if(a[i]>=ans){
            ans = a[i];
        }
        if((a[i] >= n) && (ans < m/a[i])){
            ans = m/a[i];
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, ans = 0;
	vector<vector<int>> C;
	
	cin>>N;
	
	C.resize(N,vector<int>(N));
	
	for(int i = 0 ; i < N; i++){
		for(int j = 0; j < N ;j++){
			cin>>C[i][j];
		}
	}
	
	for(int i = 0 ; i < N; i++){
		for(int j = i + 1; j < N ;j++){
			ans += min(C[i][j], C[j][i]);
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 3264
dicS={'a':0,'b':0,'c':0,'d':0,'e':0,
     'f':0,'g':0,'h':0,'i':0,'j':0,
     'k':0,'l':0,'m':0,'n':0,'o':0,
     'p':0,'q':0,'r':0,'s':0,'t':0,
     'u':0,'v':0,'w':0,'x':0,'y':0,'z':0}
dicT={'a':0,'b':0,'c':0,'d':0,'e':0,
     'f':0,'g':0,'h':0,'i':0,'j':0,
     'k':0,'l':0,'m':0,'n':0,'o':0,
     'p':0,'q':0,'r':0,'s':0,'t':0,
     'u':0,'v':0,'w':0,'x':0,'y':0,'z':0}
S=input()
for i in range(len(S)):
  dicS[S[i]]+=1
T=input()
for i in range(len(T)):
  dicT[T[i]]+=1
lsS=list(dicS.values())
lsT=list(dicT.values())
lsS.sort()
lsT.sort()
if lsS==lsT:
  print("Yes")
else:
  print("No")



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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

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

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    vl H(n);
    rep(i,n)cin>>H[i];
    ll res=0;
    ll now=0;
    rep(i,n-1){
        if(H[i+1]<=H[i])now++;
        else now=0;
        chmax(res,now);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;

// 2i -> n
// 4i ->
//2 2 2 2 1 4
//4 1 4 1 4 1
//2 2 4 1
//1 1 2 4 1
//1 4 1 2 1
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  int cnt2 = 0;
  int cnt4 = 0;
  rep(i,n) {
    if(a[i]%4 == 0) cnt4++;
    else if(a[i]%2 == 0) cnt2++;
   }
  int cnt1 = n- (cnt4+cnt2);

  if(cnt2 == 0 && cnt4+1 >= cnt1) cout << "Yes" << endl;
  else if(cnt2 != 0 && cnt4 >= cnt1) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3700
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    cout << N * 800 - (N / 15) * 200 << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def inpl():
    return list(map(int, input().split()))


def f(n):
    if n < 2:
        return 1
    ret = [0] * (n + 1)
    ret[0] = 1
    ret[1] = 1
    for i in range(2, n + 1):
        ret[i] = ret[i - 2] + ret[i - 1]
    return ret[n]


print(f(int(input())))



Measured memory_bytes: 5604
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N, X;
	cin >> N >> X;
	vector<int> L(N);
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}
	int rec = 0;
	int ans = 1;
	while (1) {
		rec += L[ans - 1];
		if (X < rec || ans == N + 1) break;
		else ans++;

	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int n,m,xs,ys,xt,yt,ans[10005][10005];
int yi[10]={0,0,0,1,-1};
int xi[10]={0,1,-1,0,0};
int ym[30]={-2,-2,-2,-2,-2,-1,0,1,2,2,2,2,2,1,0,-1,1,-1,-1,1};
int xm[30]={-2,-1,0,1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2,1,1,-1,-1};
char a[1005][1005];
struct node{int x,y,w;node(){}node(int X,int Y,int W){x=X;y=Y;w=W;}
bool operator<(const node o)const{return w>o.w;}};
inline bool chcek(int xx,int yy,int ww)
{
	if(a[xx][yy]=='#'||xx<1||xx>n||yy<1||yy>m||ans[xx][yy]<=ww)
		return 0;
	return 1;
}
inline void bfs()
{
	priority_queue<node> q;
	node now;
	q.push(node(xs,ys,0));
	while(q.size())
	{
		now=q.top();
		q.pop();
		if(ans[now.x][now.y]<now.w)
			continue;
		ans[now.x][now.y]=now.w;
		for(int i=1;i<=4;i++)
			if(chcek(now.x+xi[i],now.y+yi[i],now.w))
				q.push(node(now.x+xi[i],now.y+yi[i],now.w));
		for(int i=1;i<=20;i++)
			if(chcek(now.x+xm[i],now.y+ym[i],now.w+1))
				q.push(node(now.x+xm[i],now.y+ym[i],now.w+1));
	}
}
inline int read() 
{
    int x=0;char ch=getchar();
    while(ch<'0'||ch>'9')
		ch=getchar();
    while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
    return x;
}
inline char read1() 
{
    char x=getchar();
    while(x!='.'&&x!='#')
		x=getchar();
    return x;
}
int main()
{
	n=read();m=read();
	xs=read();ys=read();
	xt=read();yt=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			a[i][j]=read1();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			ans[i][j]=0x3f3f3f3f;
	ans[xs][ys]=0;
	bfs();
	if(ans[xt][yt]==0x3f3f3f3f)
		printf("-1");
	else
		printf("%d",ans[xt][yt]);
}


Measured memory_bytes: 13192
#include<bits/stdc++.h>
using namespace std;
long long arr1[1000][1000];
char arr[1000][1000];
int main()
{
	long long h,w,k,i,j,l,x;
	x=1;
	cin>>h>>w>>k;
	for (i=0;i<h;i++)
	{
		for (j=0;j<w;j++)
		{
			cin>>arr[i][j];
			if (arr[i][j]=='#')
			{
				arr1[i][j]=x;
				x++;
			}
		}
	}
	for (i=0;i<h;i++)
	{
		for (j=1;j<w;j++)
		{
			if (arr1[i][j]==0)
			{
				arr1[i][j]=arr1[i][j-1];
			}
		}
		for (j=w-1;j>=0;j--)
		{
			if (arr1[i][j]==0)
			{
				arr1[i][j]=arr1[i][j+1];
			}
		}		
	}
	for (i=0;i<w;i++)
	{
		for (j=1;j<h;j++)
		{
			if (arr1[j][i]==0)
			{
				arr1[j][i]=arr1[j-1][i];
			}
		}
		for (j=h-1;j>=0;j--)
		{
			if (arr1[j][i]==0)
			{
				arr1[j][i]=arr1[j+1][i];
			}
		}		
	}
	for (i=0;i<h;i++)
	{
		for (j=0;j<w;j++)
		{
			cout<<arr1[i][j]<<" ";
		}
		cout<<endl;
	}		
}

Measured memory_bytes: 3968
#include <iostream>


int main()
{
	long long int n;
	long long int a;
	std::cin >> n;

	for (int i = 1;; i++) {
		if (n*i % 2 == 0) {
			a = n * i;
			break;
		}
	}
	std::cout << a << std::endl;

	std::cin>>a;
	return 0;
}

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

int n;
int x[100][100], y[100][100];
int used[100][100];

int dfs(int i, int j){
	if(used[i][j] == 1){
		used[i][j] = 2;
		return 1;
	}
	if(used[i][j] == 2) return 0;
	used[i][j] = 1;
	int res = dfs(y[i][j], x[i][j]);
	used[i][j] = 2;
	return res;
}

int solve(){
	int res = 0;
	memset(used, 0, sizeof(used));
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(used[i][j]) continue;
			res += dfs(i, j);
		}
	}
	return res;
}

int main(){
	while(1){
		cin >> n;
		if(n==0) break;
		
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				cin >> x[i][j] >> y[i][j];
			}
		}
		cout << solve() << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
#include<stdio.h>

int main(){
	long long a,b;
	scanf("%lld%lld",&a,&b);
	long long z;
	z=b/2;
	if(z<=a){
		printf("%lld",z);
	}
	else{
		z-=a;
		z*=2;
		z/=4;
		a+=z;
		printf("%lld",a);
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(i=0; i<n; ++i)
using namespace std;
int main(void){
  int i,n; cin>>n;
  vector<int> p(n/2),q(n-n/2);
  rep(i,n) if(i&1) cin>>q[i/2]; else cin>>p[i/2];
  sort(p.begin(),p.end()); sort(q.begin(),q.end());
  int cnt=1,res=0,res2=0,r=0,s=0;
  rep(i,n/2) {if(p[i]==p[i+1]) ++cnt; else cnt=1; if(res<cnt){ res=cnt; r=p[i];}}
  cnt=1;
  rep(i,n-n/2) {if(q[i]==q[i+1]) ++cnt; else cnt=1; if(res2<cnt){ res2=cnt; s=q[i];}}
  if(s!=r) cout<<n-res-res2<<endl;
  else{
    int res3=0,res4=0;
    cnt=1;
    rep(i,n/2) {
      if(p[i]==p[i+1]) ++cnt; else cnt=1;
      if(res3<cnt&&p[i]!=r) res3=cnt;
    }
    cnt=1;
    rep(i,n-n/2) {
      if(q[i]==q[i+1]) ++cnt; else cnt=1;
      if(res4<cnt&&q[i]!=s) res4=cnt;
    }
    cout<<n-res-max(res3,res4)<<endl;
  }
  return 0;
}


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

int main() {
  long long N, A, B, C, D, E;
  scanf("%lld%lld%lld%lld%lld%lld", &N, &A, &B, &C, &D, &E);
  long long X = min({A, B, C, D, E});
  long long ans = (N + (X - 1)) / X + 4;
  printf("%lld", ans);
  return 0;
}

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

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

  string s;
  cin >> s;
  rep(i, s.size()) {
    cout << "x";
  }
  cout << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)
	m := a
	if m < b {
		m = b
	}
	if m < c {
		m = c
	}
	sum := a + b + c - m
	for i := 0; i < k; i++ {
		m *= 2
	}
	fmt.Println(sum + m)
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#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 print(x) cout << x << "\n"
#define SORT(a, n) sort(a, a+n);
#define REVERSE(a,n) reverse(a,a+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VREVERSE(v) reverse(v.begin(), v.end());
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
const ll mod = 1000000007;
const int inf = 1e9+7;
const ll infl = 1e18+7;

int main() {
    fastcin;
    int n, ans = 0;
    cin >> n;
    int a;
    rep(i, 0, n) {
        cin >> a;
        ans += a-1;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int MAXN=11;
char a[MAXN],b[MAXN],cnt;
int main(){
	for(int i=1;i<=3;i++) cin>>a[i];
	for(int i=1;i<=3;i++) cin>>b[i];
	if(a[3]==b[1]&&a[1]==b[3]) cnt++;
	if(a[2]==b[2]) cnt++;
	if(cnt==2) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
from itertools import permutations
ans = []
for i,r in enumerate(permutations(range(1,n+1))):
    if all(p[j]==r[j] for j in range(n)):
        ans.append(i)
    if all(q[j]==r[j] for j in range(n)):
        ans.append(i)
ans = abs(ans[0]-ans[1])
print(ans)

Measured memory_bytes: 45020
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 998244353



n, m = LI()
graph = [[] for _ in range(n)]
for a, b in LIR(m):
    graph[a - 1] += [b - 1]
    graph[b - 1] += [a - 1]


visited = [0] * n
que = deque([0])
visited[0] = 1
ans = deque([0])
while que:
    cur = que.pop()
    for nxt in graph[cur]:
        if visited[nxt]:
            continue
        else:
            que += [nxt]
            ans += [nxt]
            visited[nxt] = 1
            break


que = deque([0])
while que:
    cur = que.pop()
    for nxt in graph[cur]:
        if visited[nxt]:
            continue
        else:
            que += [nxt]
            ans.appendleft(nxt)
            visited[nxt] = 1
            break


print(len(ans))
print(*[i + 1 for i in ans])




Measured memory_bytes: 85552
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int T;
  cin >> T;
  while(T--){
    ll n,m,a,b;
    cin >> n >> m >> a >> b;
    cout << atcoder::floor_sum(n,m,a,b) << "\n";
  }

  


  return 0;
}

Measured memory_bytes: 3640
n = int(input())
h = list(map(int, input().split()))

dp = [-1 for _ in range(n)]
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2, n):
    dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]))
print(dp[n-1])


Measured memory_bytes: 20572
#include <bits/stdc++.h>
using namespace std;
inline bool chmin (int& a, int b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
class low_link_tree {
	int n;
	int tmr = 0;
	int rt = 0;
	vector<int> ord;
	vector<int> low;
	set<int> atc;
	set<pair<int, int>> bdg;
	vector<vector<int>> grh;
public:
	low_link_tree (
		vector<vector<int>> const& grh
	)
	: n(grh.size())
	, ord(n, -1)
	, low(n, -1)
	, grh(grh)
	{
		dfs(0, 0);
	}
	void dfs (
		int crr
	,	int prt
	) {
		int cnt = 0;
		ord[crr] = low[crr] = tmr++;
		for (int nxt : grh[crr]) {
			if (ord[nxt] == -1) {
				cnt++;
				dfs(nxt, crr);
				chmin(low[crr], low[nxt]);
				if (crr != rt && ord[crr] <= low[nxt]) atc.insert(crr);
				if (ord[crr] < low[nxt]) bdg.emplace(min(crr, nxt), max(crr, nxt));
			}
			if (nxt != prt) chmin(low[crr], ord[nxt]);
		}
		if (crr == rt && cnt > 1) atc.insert(crr);
	}
	auto const &order() {return ord;}
	auto const &low_link() {return low;}
	auto const &articulation_points() {return atc;}
	auto const &bridges() {return bdg;}
};
int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> grh(n);
	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		grh[s].push_back(t);
		grh[t].push_back(s);
	}
	auto bdg = low_link_tree(grh).bridges();
	for (auto it = bdg.begin(); it != bdg.end(); it++) {
		cout << it->first << ' ' << it->second << '\n';
	}
	cout << flush;
	return 0;
}


Measured memory_bytes: 4884
#include<iostream>
using namespace std;
string str;
int cnt=0;
bool check(){
  for(int i=0;i<(int)str.size()/2;i++){
    if(str[i]!=str[str.size()-i-1])return false;
  }
  return true;
}
int main(){
  while(cin>>str){
    if(check())cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define vecin1(n) vector<int> vec1(n); rep(i,n) cin >> vec1.at(i)
#define vecin2(n) vector<int> vec2(n); rep(i,n) cin >> vec2.at(i)
typedef long long ll;


int main() {

int ans,a,b; //a:0101...., b:1010....に必要な手数
a = b = 0;
string S;
cin >> S;
rep(i,S.length())
{
  if(i % 2 == 0)
  {
    if(S.at(i)=='0')
      b++;
    else
      a++;
  }
  else
  {
    if(S.at(i)=='1')
      b++;
    else
      a++;
  }
}
ans = min (a,b);
  cout << ans << endl;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var N, K int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &N, &K)

	ans := 0
	for b := 1; b <= N; b++ {
		//fmt.Println("-- b=", b)
		var v1, v2, v3 int
		if K == 0 {
			v1 = max(b-1, 0)
		} else {
			v1 = max(b-K, 0)
		}
		num := (N - b + 1) / b
		rem := (N - b + 1) % b
		v2 = max((b-K)*num, 0)
		v3 = max(rem-K, 0)
		v := v1 + v2 + v3
		//fmt.Println("\tv1=", v1)
		//fmt.Println("\tv2=", v2)
		//fmt.Println("\tv3=", v3)
		//fmt.Println("\tv =", v)
		ans = ans + v
	}
	fmt.Println(ans)
}

func max(ns ...int) int {
	ret := math.MinInt64
	for _, n := range ns {
		if n > ret {
			ret = n
		}
	}
	return ret
}


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

int main(){
	string s,t;
	cin >> s >> t;

	rep(i, s.size()){
		if(s.at(i) != t.at(i)){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 3552
n = int(input())
arr = []
fst = 0
scd = 0
for i in range(n):
  t = int(input())
  fst, scd = sorted([fst, scd, t], reverse=True)[:2]
  arr.append(t)

for i in range(n):
  print(fst if arr[i]!=fst else scd)


Measured memory_bytes: 12520
#include <bits/stdc++.h>
 
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define hello777 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <string>
#define pie 3.14159265358979323846
constexpr int MOD = 1e9+7;
const int MAX= 1e5+5;
using namespace std;


//ll gcd(int a, int b)
//{ 
//    if (a == 0) 
//        return b;  
//    return gcd(b % a, a);  
// } 
// 
//ll lcm(int a, int b)  
// {  
//    return a/gcd(a, b) *b;  
// }
//  
//int prime(int n)
//{
//	rep(i,2,n+1)
//	{
//		if(n%i==0)return i;
//	}
//	
//vector<unordered_set<int> > prime_factors(MAX,unordered_set<int>());
//int primes[MAX];
//int prefix[MAX][6];
//void sieve(){
//    //primes i stores the largest prime factor of a number....
//    for(int i=2;i<MAX;++i){
//        if(primes[i]!=0){
//            continue;
//        }
//        primes[i] = i;
//        for(int j=2*i;j<MAX;j+=i){
//            primes[j] = i;
//        }
//    }
//    
//    for(int i=2;i<MAX;++i){
//        int current = i;
//        
//        while(current!=1){
//            prime_factors[i].insert(primes[current]);
//            current = current/primes[current];
//        }
//    }
//    
//    for(int i=1;i<MAX;++i){
//        for(int k=1;k<=5;++k){
//            prefix[i][k] = prefix[i-1][k] + (prime_factors[i].size()==k);
//        }
//    }
//    
//}
const int N = 2e5;
int n, m;
long long k, a[N + 1], b[N + 1];
void solve() 
{	

	cin>>n>>m>>k;

 	for (int i = 0; i < n; ++i) {
        cin >> a[i + 1];
        a[i + 1] += a[i];
    }
    for (int j = 0; j < m; ++j) {
        cin >> b[j + 1];
        b[j + 1] += b[j];
    }
    int res = 0;
    for (int i = 0, j = m; i <= n; ++i) {
        if (a[i] > k)
            break;
        while (a[i] + b[j] > k)
              --j;
        res = max(i + j, res);
 
    }
    cout << res << endl;
}

int main()
{
	hello777;
	int q=1;
	
//    cin>>q;
    while(q--)
    {   
      solve();

    }
}




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

int X[15][15];

int main(void){
    int N, D; cin >> N >> D;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }
    
    int ans = 0;
    
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            long long sum = 0;
            for (int k = 0; k < D; k++) {
                sum += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
            }
            int sqr = sqrt(sum);
            if (sum == sqr*sqr) ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
//2018年  3月 21日 水曜日 18:11:26 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 62;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;
int S[60][60];
int X[60], Y[60];
vl vx, vy;

int fd(const vl& vec, int a) {
	return lower_bound(all(vec), a) - vec.begin();
}

void solve() {
	cin >> N >> K;
	rep(i, 0, N) {
		cin >> X[i] >> Y[i];
		vx.pb(X[i]); vy.pb(Y[i]);
	}
	sort(all(vx));
	vx.erase(unique(all(vx)), vx.end());
	sort(all(vy));
	vy.erase(unique(all(vy)), vy.end());
	rep(i, 0, N) {
		int xat = fd(vx, X[i]), yat = fd(vy, Y[i]);
		S[xat + 1][yat + 1]++;
	}
	rep(i, 1, N + 1) {
		rep(j, 1, N + 1) {
			S[i][j] += S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1];
		}
	}
	ll ans = linf;
	// debug(ans);
	// debug(vx, vy);
	rep(i1, 0, sz(vx)) {
		rep(j1, 0, sz(vy)) {
			rep(i2, i1 + 1, sz(vx)) {
				rep(j2, j1 + 1, sz(vy)) {
					int t = S[i2 + 1][j2 + 1] - S[i2 + 1][j1] - S[i1][j2 + 1] + S[i1][j1];
					if(t >= K) {
						MIN(ans, (vx[i2] - vx[i1]) * (vy[j2] - vy[j1]));
					}
				}
			}
		}
	}
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
# https://atcoder.jp/contests/abc051/submissions/1055446

def main():
    import sys
    input = sys.stdin.readline

    inf = 1000 * 100 + 10

    N, M = map(int, input().split())

    dist = [[inf for _ in range(N)] for _ in range(N)]
    for j in range(N):
        dist[j][j] = 0

    es = []
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        es.append((a, b, c))
        dist[a][b] = dist[b][a] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                d = dist[i][k] + dist[k][j]
                if dist[i][j] > d:
                    dist[i][j] = d

    ans = 0
    for a, b, c in es:
        if dist[a][b] == c: continue
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

#define X first
#define Y second
#define eps  1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const int INF  = 1<<30;
const int mod  = 1e9+7;

int f[maxn];

void solve(){
    int n,m,a,b,v,k;
    scanf("%d%d",&n,&m);
    for(int i=0;i<(1<<n);i++){
        f[i] = INF;
    }
    f[0] = 0;
    while(m--){
        scanf("%d%d",&a,&b);
        for(v=0;b--;){
            scanf("%d",&k);
            v |= 1<<(k-1);
        }
        for(int i=(1<<n)-1;i>=0;i--){
            f[i | v] = min(f[i|v],f[i] + a);
        }
    }
    printf("%d\n",f[(1<<n)-1] == INF ? -1 : f[(1<<n)-1]);
    
    return;
}

int main()
{
#ifndef ONLINE_JUDGE
  //  freopen("in.txt","r",stdin);
#endif
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
#ifndef ONLINE_JUDGE
   // printf("%.10f\n",1.0*clock()/CLOCKS_PER_SEC);
#endif
    return 0;
}

Measured memory_bytes: 256
# AOJ 0547: Commute routes
# Python3 2018.7.1 bal4u

import sys
from sys import stdin
input = stdin.readline

S, W = 0, 1
while True:
	w, h = map(int, input().split())
	if w == 0: break
	p = [[[[0 for a in range(2)] for b in range(2)] for c in range(h+1)] for d in range(w+1)]
	for x in range(1, w+1): p[x][1][W][S] = p[x][1][W][W] = 1
	for y in range(1, h+1): p[1][y][S][W] = p[1][y][S][S] = 1
	p[w][1][W][W] = p[1][h][S][S] = 0
	for y in range(2, h+1):
		for x in range(2, w+1):
			p[x][y][S][S] += p[x][y-1][S][S] + p[x][y-1][W][S]
			p[x][y][W][W] += p[x-1][y][W][W] + p[x-1][y][S][W]
			p[x][y][S][W] += p[x][y-1][S][S]
			p[x][y][W][S] += p[x-1][y][W][W]
			p[x][y][S][S] %= 100000
			p[x][y][W][W] %= 100000
			p[x][y][S][W] %= 100000
			p[x][y][W][S] %= 100000
	print((p[w][h][S][S]+p[w][h][W][W]) % 100000)


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

int digit_length(int a)
{
    int lengh = 0;
    while (a > 0)
    {
        a = a / 10;
        lengh++;
    }
    return lengh;
}

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

    for (int i = 1; i <= N; i++)
    {
        if ((digit_length(i) % 2) != 0)
        {
            counts++;
        }
    }

    cout << counts << endl;
    return 0;
}

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

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

#define INFTY 999999

int gd(int n,int m){
    int a;
    int b;

    if(n<m){
        a=m;
        b=n;
    }
    else{
        a=n;
        b=m;
    }

    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }

    return b;
}

int main(void){
    int A,B,K;
    scanf("%d %d %d",&A,&B,&K);

    int* G;
    NEW(G,101);

    int d=gd(A,B);
    int i=d;
    int count=0;
    while(i>0){
        if(d%i==0){
            count++;
            G[count]=i;
        }
        i--;
    }



    printf("%d\n",G[K]);

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> v(n + 10);
  cout << n + n * n + n * n * n << endl;
}

Measured memory_bytes: 3620
//https://atcoder.jp/contests/abc127/tasks/abc127_a

import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        sc.close();
        if (A>12){
            System.out.println(B);
        } else if (A<6){
            System.out.println(0);
        } else {
            System.out.println(B/2);
        }
    }
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  int a, b;
  int c[n];

  for (int i = 0; i < n; i++) c[i] = 0;

  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    c[a - 1]++;
    c[b - 1]++;
  }

  for (int i = 0; i < n; i++) cout << c[i] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define P pair<int,int>
#define SET set<int>
#define mp map<int,int>
#define mk make_tuple
#define got(container,num) get<num-1>(container)
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
using namespace std;
const int INF=LLONG_MAX-1e10;
const int maxn=1e6+1e5;
//const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;
map<int,int>h;
int mo_num;
main()
{
    IOS
    cin>>n>>mo_num;
    string k;
    cin>>k;
    int num=0;
    if(10%mo_num==0)
    {
        fa(i,k)
        {
            num++;
            int val=i-'0';
            if(val%mo_num==0)
            {
                ans+=num;
            }
        }
    }else{
        reverse(all(k));
        int base=1,have=0;
        h[0]++;
        fa(i,k)
        {
            int v=i-'0';
            have=mod(have+v*base);
            ans+=h[have];
            h[have]++;
            base=mod(base*10);
        }
    }
    out(ans)
    return 0;
}

Measured memory_bytes: 1044
n = int(input())

n10=int(n/10)*10
n1=n-n10

if (n1 == 3):
  print ("bon")
elif (n1 == 0 or n1 == 1 or n1== 6 or n1 == 8): 
  print ("pon")
else:
  print ("hon")

Measured memory_bytes: 9172
object Main {
	def main(args: Array[String]) {
		val input = io.Source.stdin.getLines().mkString("\n")
		println(solve(input).trim)
	}

	def solve(input: String): String = {
		cont(input.split("\n")(1).split(" ").map(_.toInt).toList,0).toString()
	}

	def cont(list: List[Int], count: Int): Int = {
		if(list.forall(_%2==0)) {
			cont(list.map(_/2), count+1)
		}else{
			count
		}
	}
}

Measured memory_bytes: 27212
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define MAX_C 1000000001
#define MOD 1000000007

int main() {
  int s, w;
  cin >> s >> w;

  cout << ((s <= w) ? "unsafe" : "safe") << endl;
}


Measured memory_bytes: 3632
from fractions import gcd
N, M = map(int, input().split())
S = input()
T = input()
flg = True

ans = N*M//gcd(N, M)
n = ans // N
m = ans // M
a = n*m//gcd(n, m)
nn = a // n
mm = a // m
for i in range(1, ans//a):
    if S[nn*i] != T[mm*i]:
        flg = False
if S[0] != T[0]:
    flg = False
if flg:
    print(ans)
else:
    print(-1)

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

long double factorial(int x){
  long double r;

  r = 1;
  while (0 < x) {
    r = r * x;
    x = x - 1;
  }
  return (r);
}

int main(void){
  int n;
  int m;
  int result;
  long double answer;
  int out;

  result = scanf("%d", &n);
  result = scanf("%d", &m);
  answer = 0;
  if (n < 2 && m < 2)
    answer = 0;
  
  else if ((n < 2 && m == 2) || (n == 2 && m < 2))
    answer = 1;
  else if (n < 2 && m > 2)
    answer = factorial(m) / (factorial(m - 2) * factorial(2));
  else if (n > 2 && m < 2)
    answer = factorial(n) / (factorial(n - 2) * factorial(2));
  else
    answer = factorial(n) / (factorial(n - 2) * factorial(2)) + factorial(m) / (factorial(m - 2) * factorial(2));

  out = (int)round(answer);
  printf("%d", out);
  return (0);
}


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

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	ll a, b, c, k; cin >> a >> b >> c >> k;
	ll ans = min(a, k); k -= min(a, k);
	k -= min(b, k);
	ans -= min(c, k);
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 3612
n, W = map(int, input().split())
wv = [ list(map(int, input().split())) for _ in range(n) ]
dp = [ [float("inf")]*(10**5+1) for _ in range(n+1) ]
dp[0][0] = 0
for i in range(n):
  w, v = wv[i]
  for j in range(10**5+1):
    if j < v:
      dp[i+1][j] = dp[i][j]
    else:
      dp[i+1][j] = min(dp[i][j], dp[i][j-v]+w)
ans = 0
for j in range(10**5+1):
  if dp[n][j] <= W:
    ans = j
print(ans)

Measured memory_bytes: 310808
#include <iostream>
using namespace std;
long long d[10][1001];

int main(void){
  int n,s;
  d[0][0]=1;
  for(int i=0;i<101;i++){
    for(int j=1000;j>-1;j--){
      for(int k=9;k>0;k--){
	if(j+i<1001)d[k][i+j]+=d[k-1][j];
      }
    }
  }
  while(cin>>n>>s,!(n==0&&s==0)){
    cout<<d[n][s]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
#define endl  "\n"
#define ll long long
#define PI acos(-1.0)
#define test cout<<"\n****\n"
#define precise fixed(cout);cout<<setprecision(12)
#define fast  ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using  namespace  std;

set<ll> vec;
int main(){

    fast;
    ll n;
    cin>>n;

    for(int i=0;i<n;i++){
        ll temp;
        cin>>temp;
        vec.insert(temp);
    }
    
    if(vec.size()==n){
        cout<<"YES";
    } else{
        cout<<"NO";
    }
    
    return 0;
}


Measured memory_bytes: 12968
C = []
C.append(list(map(int, input().split())))
C.append(list(map(int, input().split())))
C.append(list(map(int, input().split())))

if C[0][0] + C[1][1] + C[2][2] \
== C[1][0] + C[2][1] + C[0][2] \
== C[2][0] + C[0][1] + C[1][2] \
== C[0][0] + C[2][1] + C[1][2] \
== C[1][0] + C[0][1] + C[2][2] \
== C[2][0] + C[1][1] + C[0][2]:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
from heapq import heappush, heappop, heapify
def main():
    k, t = map(int, input().split())
    A = list(map(lambda x: -int(x), input().split()))
    heapify(A)
    tmp = heappop(A)
    while A:
        now = heappop(A)
        if tmp != -1:
            heappush(A, tmp + 1)
        tmp = now
    print(-(tmp + 1))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9064
n,y = map(int, raw_input().split())
a = -1
b = -1
c = -1
for i in range(n+1):
  for j in range(n-i+1):
    k = n - i - j
    if i * 10000 + j * 5000 + k * 1000 == y:
      a = i
      b = j
      c = k
      break
  if a + b + c > -3:
    break
print a,b,c


Measured memory_bytes: 2692
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  n,k = readline() |> split |> parseArray
  s = readline() |> strip |> collect

  ans=0
  n>1&&s[1]=='R'&&s[2]=='R' && (ans+=1)
  for i in 2:n-1
    s[i]=='R'&&s[i+1]=='R' && (ans+=1)
    s[i]=='L'&&s[i-1]=='L' && (ans+=1)
  end
  n>1&&s[end-1]=='L'&&s[end]=='L' && (ans+=1)

  ans=min(ans+2k, n-1)

  println(ans)
end

main()


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(24);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x;
string s;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	string s,t;
	cin>>s>>t;
	for(ll i=0;i<s.length();i++) {
		if(s[i]!=t[i]) {
			cout<<"No";
			return;
		}
	}
	cout<<"Yes";
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3656
N = gets.to_i

(1 .. 3500).each do |a|
  (1 .. 3500).each do |b|
    
    next if (4 * a * b  - N * b  - N  * a) < 1
    
    c,m = (N * a * b).divmod(4 * a * b  - N * b  - N  * a ) 

    next if m > 0

    puts [a,b,c].join(' ')
    exit
  end
end


Measured memory_bytes: 14396
/**
*    created: 20.06.2020 13:33:22
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

    int a;
    cin >> a;
    if (a == 3 || a == 5 || a == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main()
{
  constexpr int N = 1000000;

  bool is_not_prime[N] = { true, true };
  bool is_prime[N] = {};
  for( int i=2; i<N; ++i ) {
    if ( is_not_prime[i] )
      continue;

    is_prime[i] = true;

    for( int j=i; j<N; j+=i ) {
      is_not_prime[j] = true;
    }
  }


  int  n;
  while( cin >> n ) {
    if ( n == 0 )
      break;

    int num = 0;
    for( int i=n+1; i<=2*n; ++i ) {
      if ( is_prime[i] )
        ++num;
    }

    cout << num << endl;
  }
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
void debug(vector<T> &vec) {
    for (auto x : vec) {
        cout << x << " ";
    }
    cout << endl;
    return;
}

template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

long long dp[1010][1010];

int main() {
    int N, sumTime = 0;
    cin >> N;
    vector<pair<int, int>> vec;
    vector<int> A(N), B(N);
    REP(i, N) {
        int x, y;
        cin >> x >> y;
        vec.push_back(make_pair(y, x));
    }

    sort(ALL(vec));
    REP(i, N) { A[i] = vec[i].second; B[i] = vec[i].first; }

    FILL(dp, llINF);
    dp[0][0] = 0;


    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (dp[i][j] == llINF) continue;
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            if (dp[i][j] + A[i] > B[i]) continue;
            dp[i + 1][j + 1] = min(dp[i + 1][i + 1], dp[i][j] + A[i]);
        }
    }

    int ans = 0;
    for (int cnt = 0; cnt < N + 1; cnt++) {
        if (dp[N][cnt] == llINF) continue;
        ans = cnt;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long int lli;

const int LOG = 60;
const int MOD = 1000000007;

int n;

int qtdBits[LOG][2];

lli ans;

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

	for(int i = 1 ; i <= n ; i++)
	{
		lli v;
		scanf("%lld",&v);

		for(int j = 0 ; j < LOG ; j++)
		{
			lli pot = (1LL << j);

			int ind = ( v & pot ) ? 1 : 0;

			pot %= MOD;

			ans += pot*qtdBits[j][1 - ind];
			ans %= MOD;

			qtdBits[j][ind]++;
		}
	}

	printf("%lld\n",ans);
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int H, W;
    cin >> H >> W;

    int N = 10;
    vector<vector<int>> G(N, vector<int>(N, INF));
    for (int i = 0; i < N; i++) {
        G[i][i] = 0;
    }
    rep(i, 10) rep(j, 10) { cin >> G[i][j]; }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
    lint ans = 0;
    rep(i, H) rep(j, W) {
        int a;
        cin >> a;
        if (a == -1) continue;
        ans += G[a][1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//vector<vector<int>> a(n, vector<int> ())
int main(){
    long long int money = 100;
    long long int x;
    cin >> x;
    long long int year = 1;
    for(int i = 0; i < x; i++){
        money *= 1.01;
        
        if(money >= x){
            break;
        }
        year++;
    }

    cout << year << endl;
}

Measured memory_bytes: 3632