akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


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;
}
ll modinv(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while(b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0) u += m;
    cout << u << endl;
    return u;
}

 
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    ll cash = 1000;
    ll stock = 0;
    vector<ll> dp(n, 0);
    FOR(i,0,n-1){
        if(a[i]>a[i+1]){
            //cout << stock << "株 売却" << endl;
            cash += stock * a[i];
            stock = 0;
        }else if(a[i]<a[i+1]){
            ll stock_f = (ll)(cash / a[i]);
            stock += stock_f;
            //cout << stock_f << "株 購入" << endl;
            cash -= stock_f * a[i];
            //cout << cash << "残金" << endl;
        }else{
            continue;
        }
    }
    if(stock > 0){
        cash += a[n-1] * stock;
    }
    cout << fixed << cash << endl;
}



Measured memory_bytes: 3588
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,k=INTM()
    print(((k-1)**(n-1))*k)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
def gcd(a, b):
  if a < b:
    a, b = b, a
  while a % b:
    a, b = b, a % b
  return b
A, B, C = map(int, input().split())
if C % gcd(A, B) == 0:
  print('YES')
else:
  print('NO')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n;
string s;
main(){
  while(cin>>n,n){
    int a[26][26]={},b[26]={},c[26][26],f1=0,f2=0,p1=0,p2=0;
    r(i,n)cin>>s,a[s[0]-'a'][s[s.size()-1]-'a']++,b[s[0]-'a']++,b[s[s.size()-1]-'a']++;
    r(i,26){r(j,26)p1+=a[i][j],p2+=a[j][i];if(p1!=p2)f1++;p1=p2=0;}
    if(!f1)r(i,26)r(j,26)c[i][j]=(a[i][j]?1:1e9);
    if(!f1)r(k,26)r(i,26)r(j,26)c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
    if(!f1)r(i,26)r(j,26)if(b[i]&&b[j]&&i!=j&&c[i][j]==1e9)f2++;
    cout<<((f1||f2)?"NG":"OK")<<endl;
  }
}

Measured memory_bytes: 3092
N=int(input())
act=[]
for i in range(N):
    act.append(list(map(int,input().split())))
dp=[[0]*3 for i in range(N+1)]

for i in range(1,N+1):
    for j in range(3):
        for k in range(3):
            if(j!=k):
                dp[i][j]=max(dp[i][j],dp[i-1][k]+act[i-1][j])
                
print(max([dp[N][0],dp[N][1],dp[N][2]]))

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u') {
      cout << "vowel" << endl;
  } else {
      cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
/// hi_im_manh :D
#include <bits/stdc++.h>
#define reset(a,n) memset(a,0,(n+1)*sizeof(int))
#define endl "\n"
#define llmin LLONG_MIN
#define llmax LLONG_MAX
#define intmax INT_MAX
#define intmin INT_MIN
#define ll long long
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define duckman "TASK"

#define input freopen(duckman".inp", "r", stdin);
#define output freopen(duckman".out", "w", stdout);

#define nmax 22000
const ll INF = 1e18L + 5;
using namespace std;

void max_self(ll &a, ll b) {
    a = max(a, b);
}

void min_self(ll &a, ll b) {
    a = min(a, b);
}
int main()
{
    fast;
//    input;
//    output;

//    ll n, weight;
//    cin >> n >> weight;
//    vector<ll> dp(weight+1);
//    for (int i = 0; i < n; ++i) {
//        ll v, w;
//        cin >> w >> v;
//        for (ll weight_now = weight; weight_now - w >= 0; --weight_now) {
//            max_self(dp[weight_now], dp[weight_now - w] + v);
//        }
//    }
//    cout << dp[weight];

//    ll n, weight;
//    cin >> n >> weight;
//    vector<ll> w(n), v(n);
//    ll sum_v = 0;
//    for (ll i = 0; i < n; i++) {
//        cin >> w[i] >> v[i];
//        sum_v += v[i];
//    }
//    vector<ll> dp (sum_v + 1, INF);
//    dp[0] = 0;
//    for (ll i = 0; i < n; ++i) {
//        for (ll value_now = sum_v; value_now >= v[i]; --value_now) {
//            min_self(dp[value_now], dp[value_now - v[i]] + w[i]);
//        }
//    }
//    for (ll i = sum_v; i >= 0; --i) {
//        if (dp[i] <= weight) {
//            cout << i;
//            return 0;
//        }
//    }

    string x, y;
    getline(cin, x);
    getline(cin, y);
    ll n = x.size(), m = y.size();
    vector<vector<ll>> dp (n+2, vector<ll>(m+2));
    for (ll i = 0; i <= n; i++) {
        for (ll j = 0; j <= m; j++) {
            if (i == 0 || j == 0) {
                dp[i][j] = 0;
            }
            else {
                if (x[i-1] == y[j-1]) {
                    dp[i][j] = dp[i-1][j-1] + 1;
                }
                else {
                    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
                }
            }
        }
    }
    string ans = "";
    ll i = n, j = m;
    while (i && j) {
        if (x[i-1] == y[j-1]) {
            ans = x[i-1] + ans;
            --i;
            --j;
        }
        else {
            if (dp[i][j] == dp[i-1][j]) {
                --i;
            }
            else {
                --j;
            }
        }
    }
    cout << ans;
}

/*

*/


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

using namespace std;
const int mxN=50,M=1e9+7;
int N ;
typedef  long long ll ;
ll K;

struct Matrix{
  vector<vector<int >> a = vector<vector<int >>( N ,vector<int>(N));
  Matrix operator *(const Matrix &o){
    Matrix pro;
    vector<vector<long long>> tem( N , vector<long long>(N));
    for(int i=0 ; i<N ; i++){
        for(int j=0 ; j<N ; j++){
            for(int k=0 ; k<N ; k++){
                //ll &tem = pro.a[i][j];
                tem[i][j]+=(long long)a[i][k]*o.a[k][j];
                if(tem[i][j]>8LL*M*M){
                    tem[i][j]-=8LL*M*M;
                }
                
            }
        }
    }
    for(int i=0 ; i< N ; i++){
        for(int j=0 ; j<N ;++j){
            pro.a[i][j] = tem[i][j]%M;
        }

    }
    return pro;
  }
};

Matrix expo(Matrix x , ll k){
    Matrix res;
    for(int i=0 ; i<N ;++i)res.a[i][i] =1;
     
    while(k>0){
        if(k%2)
        res = res * x;

        x = x*x;
        k/=2;
    } 
    return res;
}

int main(){
    cin >> N >> K;

    Matrix v;
    for(int i=0 ; i<N ; i++){
        for(int j=0 ; j<N ; j++){
            cin>> v.a[i][j];
        }
    }

    Matrix f = expo(v,K);

    ll ans = 0;
    for(int i=0 ; i< N ; i++){
        for(int j=0 ; j<N ; j++){
            ans+=f.a[i][j];
            if(ans>=M)ans-=M;
        }

    }
    cout <<  ans;




}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define int long long

using namespace std;


int const N = 55;
int a[N];

int Max(int n){
    int M = 0;
    for(int i=1; i<=n; i++)
        M = max(M, a[i]);
    return M;
}

int Get(int n, int mid){
    memset(a, 0, sizeof(a));
    a[1] = mid;
    int cnt = 0;
    int M = 0;
    while( (M = Max(n)) >= n){
        int num = 0;
        for(int i=1; i<=n; i++){
            if(a[i] == M){
                num++;
            }
        }
        for(int i=1; i<=n; i++)
            if(a[i] != M){
                a[i] += M / n * num;
            }
            else{
                a[i] = a[i] % n;
                a[i] += M / n * (num - 1);
            }
        cnt += M / n * (num);
    }
    return cnt;
}

void Print(int n, int val){
    cout << n << endl;
    int x = val / n;
    for(int i=1; i<n; i++)
        cout << x / n * n << "  ";
    cout << ((x / n) + x % n) * n + val % n;
}

bool Check(int n, int k){
    int L = -1;
    int R = k + 50 * 50;
    while(R - L > 1){
        int mid = (L + R) / 2;
        if(Get(n, mid) >= k)    R = mid;
        else
            L = mid;
    }
    Get(n, R-1);
    if(Get(n, R) == k){
        Print(n, R);
        return true;
    }
    return false;
}

main()
{
  //  freopen("inp.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//    int k;
//    cin >> k;
//    for(int i=50; i>=1; i--){
//        if(Check(i, k)){
//            return 0;
//        };
//    }
    int n, M;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }

    int cnt = 0;

    while( (M = Max(n)) >= n){
        int num = 0;
        for(int i=1; i<=n; i++){
            if(a[i] == M){
                num++;
            }
        }
        for(int i=1; i<=n; i++)
            if(a[i] != M){
                a[i] += M / n * num;
            }
            else{
                a[i] = a[i] % n;
                a[i] += M / n * (num - 1);
            }
        cnt += M / n * (num);
    }
    cout << cnt;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

bool ok(int l,int r,int x,int i,int j,int k){
    int cnt=0;
    if(l<=i and i<=r) ++cnt;
    if(l<=j and j<=r) ++cnt;
    if(l<=k and k<=r) ++cnt;
    return cnt==x;
}

void solve(){
    int N,M;
    cin >> N >> M;

    vector<vector<int>> l(N+1),x(N+1);
    rep(i,0,M){
        int l_,r_,x_;
        cin >> l_ >> r_ >> x_;
        l[r_].push_back(l_);
        x[r_].push_back(x_);
    }

    auto ok2=[&](int r,int i,int j,int k){
        bool res=true;
        rep(i_,0,l[r].size()) if(!ok(l[r][i_],r,x[r][i_],i,j,k)) return false;
        return true; 
    };

    i64 mod=1000000007;
    static i64 memo[301][301][301];
    static bool done[301][301][301];
    fill_n((i64*)memo,301*301*301,0);
    fill_n((bool*)memo,301*301*301,false);
    function<i64(int,int,int)> rec=[&](int i,int j,int k){
        auto &res=memo[i][j][k];
        if(done[i][j][k]) return res;
        done[i][j][k]=true;
        if(i==N) return res=1;
        
        int ma=max({i,j,k})+1;
        {
            int mi=min(j,k),md=j+k-mi;
            if(ok2(ma,ma,md,mi)) res=(res+rec(ma,md,mi))%mod;
        }
        {
            int mi=min(i,k),md=i+k-mi;
            if(ok2(ma,ma,md,mi)) res=(res+rec(ma,md,mi))%mod;
        }
        {
            int mi=min(i,j),md=i+j-mi;
            if(ok2(ma,ma,md,mi)) res=(res+rec(ma,md,mi))%mod;
        }
        return res;
    };

    if(!ok2(1,1,0,0)) cout << 0 << endl;
    else cout << rec(1,0,0)*3%mod << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 238208
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

Q=I()

#nまでの素数を列挙(n loglogn)
n = 10**5

#is_prime[i]にはi-1が素数か否かを示すboolが入る，[0]に1の素数判定がある．
is_prime = [True]*(n+1)
is_prime[0] = False

for i in range(2, n+1):
    if is_prime[i-1]:
        j = 2 * i
        while j <= n:
            is_prime[j-1] = False
            j += i

table = [ i for i in range(1, n+1) if is_prime[i-1]]

L=[]

for p in table:
    p2=(p+1)//2
    if p2 in table:
        L.append(p)
        
S=[0]*(n+1)

for a in L:
    S[a]+=1
    
for i in range(n):
    S[i+1]+=S[i]
    
    
for i in range(Q):
    l,r=MI()
    print(S[r]-S[l-1])
    





Measured memory_bytes: 54232
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

signed main(void) {
  int A, B, C;
  cin >> A >> B >> C;

  int ans;
  if (B/A > C) {
    ans = C;
  } else {
    ans = B/A;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int MOD = 1000000007;
using namespace std;
//g++ -std=c++14
//setprecision(10)
int main(){
	int n, k;
	cin >> n >> k;
	int x, sum = 0;
	for(int i = 0; i < n; i++){
		cin >> x;
		int va = min(x, k - x);
		sum += 2 * va;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>


int main(){
	int x, a;
	std::cin >> x >> a;
	if(x < a){
		std::cout << 0 << std::endl;
	}else{
		std::cout << 10 << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define all(a) a.begin(),a.end()
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){x=x>y?y:x;}
template<class T> inline void gmax(T &x,const T &y){x=x<y?y:x;}
template<class T> inline bool Gmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T> inline bool Gmax(T &x,const T &y){return x<y?x=y,1:0;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){rev|=c=='-';c=Getchar();if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=0x3f3f3f3f;
const int N=200005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,k;

int main(){
#ifdef rqgao2014
	assert(freopen("input.txt","r",stdin));
#endif
	scanf("%d%d",&n,&k);
	if(!k){printf("%lld\n",(ll)n*n);return 0;}
	k--;
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j+=i){
			if(j+i-1<=n) ans+=min(i,k+1);
			else ans+=min(k,n-j+1);
		}
	}
	printf("%lld\n",(ll)n*n-ans);
	return 0;
}

Measured memory_bytes: 256
while True:
    n,m = [int(i) for i in input().split()]
    if n == 0 and m == 0:
        break

    table = []
    for i in range(n):
        table.append(i+1)

    p = m - 1
    for i in range(n-1):
        table.pop(p)
        p = (p+m-1) % len(table)
        #print(table)
    print(table[0])


Measured memory_bytes: 5600
h,w = map(int, input().split())
ans = []
for i in range(h):
    a = list(input())
    if a[0]=="." and len(set(a)) == 1:
        continue
    ans.append(a)

ans1 = []
for j in list(zip(*ans)):
    if j[0]=="." and len(set(j)) == 1:
        continue
    ans1.append(j)

for k in list(zip(*ans1)):
    print( ''.join(k))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
ll A,B;
ll nums[45];
ll undernums[45];
vector<pair<ll,ll> > shops;
int main(void)
{
  ll ans=0;
  memset(nums,0,sizeof(nums));
  cin >> A >> B;
  ll under=0;
  if(A>0)
    {
      under=A;
    }
  A++,B++;
  ll tmp=2;
  int index=0;
  while((tmp/2)<=B)
    {
      if (B%tmp==0)
	{
	  nums[index]+=(B/tmp)*(tmp/2);
	  //cout << index << ' ' << nums[index] << endl;
	}
      else
	{
	  nums[index]+=(B/tmp)*(tmp/2);
	  nums[index]+=max((B%tmp)-(tmp/2),0LL);
	  //cout << index << ' ' << nums[index] << endl;
	}
      tmp*=2;
      index++;
    }
  tmp=2;
  index=0;
  while((tmp/2)<=under)
    {
      if (under%tmp==0)
	{
	  undernums[index]+=(under/tmp)*(under/2);
	  // cout << index << ' ' << undernums[index] << endl;
	}
      else
	{
	  undernums[index]+=(under/tmp)*(tmp/2);
	  undernums[index]+=max((under%tmp)-(tmp/2),0LL);
	  //cout << index << ' ' << nums[index] << endl;
	}
      tmp*=2;
      index++;
    }
  for(ll i=0;i<=40;i++)
    {
      //cout << (1<<(i+1)) << ':' << nums[i] << endl;
      if((nums[i]-undernums[i])%2!=0)
	{
	  ans+=ll(1LL<<i);
	}
    }
  cout << ans << endl;
  return 0;
}


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

int main()
{
	int N, W;
	scanf("%d%d", &N, &W);
	using vi = std::vector<int>;
	vi w(N), v(N);
	for (int i{}; i < N; i++)
		scanf("%d%d", &v[i], &w[i]);
	vi dp(W + 1);
	dp[0] = 0;
	for (int i{}; i < N; i++)
		for (int j{}; j + w[i] <= W; j++)
			dp[j + w[i]] = std::max(dp[j + w[i]], dp[j] + v[i]);
	printf("%d\n", *std::max_element(dp.begin(), dp.end()));
	return 0;
}


Measured memory_bytes: 3244
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<assert.h>
#define INF 0x3f3f3f3f//3f3f3f3f
#define ll long long
#define ull unsigned long long
#define lowbit(a) ((a)&(-(a)))
using namespace std;
int cal(char a,char b,char c){
    if(a==b && b == c)return 0;
    if(a == b || b == c || a == c) return 1;
    return 2;
}
int main() {
    int n;
    string a,b,c;
    while(cin>>n>>a>>b>>c){
        int ans = 0;
        for(int i = 0;i<n;i++){
            ans += cal(a[i],b[i],c[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        long a= sc.nextLong();
        double k = Math.sqrt(a);
        long r = (long)k;
        if(k-r==0)
        {
            System.out.println(a);
        }
        else
        {
            long p =a-1;
            while(true)
            {
                k=Math.sqrt(p--);
                r=(long)k;
                if(k-r==0)
                {
                    System.out.println(p+1);
                    return;
                }
            }
        }


    }
}


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

#ifdef LOCAL_PC
	#define debug(args...) cout.flush(); fflush(stdout); fprintf(stderr, args)
#else
	#define debug(args...) ; /*  */
#endif
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class num> inline void rd(num &x) {
	char c; while(isspace(c = getchar()));
	bool neg = false;
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar()))
	x = (x << 3) + (x << 1) + c - '0';
	if (neg) x = -x;
}

const int MAXN = 2e3 + 5, INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
inline int add(int x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
	return x;
}

inline int sub(int x, int y) {
	x -= y;
	if (x < 0) x += MOD;
	return x;
}

inline int mul(int x, int y) {
	return ll(x) * y % MOD;
}

inline int inv(int x) {
	int y = MOD - 2;
	int ret = 1;
	while(y) {
		if (y&1) ret = mul(ret, x);
		x = mul(x, x);
		y >>= 1;
	}
	return ret;
}

inline int divi(int x, int y) {
	return mul(x, inv(y));
}

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

int memo[MAXN][MAXN];
int main() {
	int n, m; rd(n); rd(m);

	for (int i = 1; i <= n; i++) rd(a[i]);
	for (int i = 1; i <= m; i++) rd(b[i]);

	int ans = 1;
	for (int i = 0; i <= n; i++) memo[i][0] = 1;
	for (int j = 0; j <= m; j++) memo[0][j] = 1;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			memo[i][j] = add(memo[i][j-1], memo[i-1][j]);
			memo[i][j] = sub(memo[i][j], memo[i-1][j-1]);
			if (a[i] == b[j]) {
				ans = add(ans, memo[i-1][j-1]);
				memo[i][j] = add(memo[i][j], memo[i-1][j-1]);
			}

		}
	}

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

Measured memory_bytes: 16000
import java.util.*;
import java.io.*;
 
public class Main {
    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
 
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        public long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
    }
 
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
      PrintWriter out = new PrintWriter(System.out);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String s1 = Integer.toString(a);
        String s2 = Integer.toString(b);
//        String sc1 = "";
//        String sc2 = "";
        for (int i = 0; i < b - 1; ++i) {
            s1 += s1.charAt(i);
        }
        for (int i = 0; i < a - 1; ++i) {
            s2 += s2.charAt(i);
        }
//        boolean ok = false;
//        for (int i = 0; i < a ; ++i) {
//            for(int j = 0; j <)
//            if (s1.charAt(i) >= s2.charAt(i)) {
//                ok = true;
//            }
//
//
//        }
//        if (ok == true) {
//            System.out.println(s2);
//        } else {
//            System.out.println(s1);
//        }
         if(a >= b){
             out.println(s2);
         }
         else{
             out.println(s1);
         }
      out.close();
    }
}

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

using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> d(10, vector<int>(10));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) cin >> d[i][j];
  }
  for (int k = 0; k < 10; k++) {      // 経由する頂点
    for (int i = 0; i < 10; i++) {    // 始点
      for (int j = 0; j < 10; j++) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  vector<vector<int>> a(h, vector<int>(w));
  int total = 0;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int k;
      cin >> k;
      if (k == -1) continue;
      total += d[k][1];
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var input string
	if sc.Scan() {
		input = sc.Text()
	}
	item := strings.Split(input, " ")
	a, _ := strconv.ParseInt(item[0], 10, 64)
	b, _ := strconv.ParseInt(item[1], 10, 64)
	if (a*b)%2 == 1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

parity = [[i % 2 for i in row] for row in A]

odd_list = []
for i in range(H):
    for j in range(W):
        if parity[i][j] == 1:
            odd_list.append([i, j])

used = [[0 for _ in range(W)] for _ in range(H)]

ll = []
for h in range(H):
    for w in range(W):
        if h % 2 == 1:
            w = W - w - 1
        ll.append([h, w])

output = []
for i, c in enumerate(ll[:-1]):
    h = c[0]
    w = c[1]
    if parity[h][w] == 1:
        output.append([h+1, w+1, ll[i+1][0]+1, ll[i+1][1]+1])
        parity[ll[i+1][0]][ll[i+1][1]] = (parity[ll[i+1][0]][ll[i+1][1]] + 1) % 2

print(len(output))
for r in output:
    r = [str(i) for i in r]
    print(" ".join(r))


Measured memory_bytes: 92932
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct tree{
    size_t n,r,md;
    vector<vector<int>> e;
    vector<int> pa,d,sz;
    explicit tree(int n):n(n),e(n){}
    void built(bool f=true){
        static int a,b;
        fr(i,n-1){
            cin>>a>>b;
            if(f) --a,--b;
            add(a,b);
        }
    }
    void pbuilt(bool f=true){
        static int a;
        Fr(i,n-1){
            cin>>a;
            if(f) --a;
            add(a,i,false);
        }
    }
    void add(int a,int b,bool f=true){
        e[a].emplace_back(b);
        if(f) e[b].emplace_back(a);
    }
    void r_dfs(int i,int p=-1,int D=0){
        pa[i]=p;d[i]=D;md=max(md,(size_t)D);++D;
        for(auto j:e[i]) if(j!=p) r_dfs(j,i,D),sz[i]+=sz[j];
    }
    void r_i(int r_){
        pa.resize(n);d.resize(n);sz.resize(n,1),r=r_;md=0;
        r_dfs(r);
    }
};

void cent_dfs(tree&t,vector<int>&path,pair<int,int>&ans,int&D,int i,int pa=-1){
    path.push_back(i);
    if(path.size()>D){
        D=path.size();
        ans=make_pair(path[(D-1)/2],path[D/2]);
    }
    for(auto&j:t.e[i]) if(j!=pa) cent_dfs(t,path,ans,D,j,i);
    path.pop_back();
}
int DD{};
pair<int,int> cent(tree&t){
    int n=t.n;
    int D=-1,DL=-1;
    stack<pair<int,int>> q;
    t.r_i(0);
    fr(i,n) if(D<t.d[i]) D=t.d[i],DL=i;
    t.pa.assign(n,0);
    t.sz.clear();
    t.d.assign(n,0);
    pair<int,int> ans(-1,-1);
    vector<int> path;
    D=0;
    cent_dfs(t,path,ans,D,DL);
    DD=D;
    return ans;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    tree t(n);
    t.built();
    auto cen=cent(t);
    vector<int> bra(DD/2+1,1);
    bool f=cen.first==cen.second;
    struct dfs{
        int i,pa,d;
    };
    stack<dfs> st;
    if(f) st.push(dfs{cen.first,-1,0});
    else{
        st.push(dfs{cen.first,cen.second,1});
        st.push(dfs{cen.second,cen.first,1});
        bra[0]=2;
    }
    while(!st.empty()){
        auto D=st.top();st.pop();
        chmax(bra[D.d],t.e[D.i].size()-(D.pa!=-1));
        for(auto&j:t.e[D.i]) if(j!=D.pa) st.push(dfs{j,D.i,D.d+1});
    }
    ll ans{1};
    for(auto&i:bra) ans*=i;
    if(f){
        for(auto&i:t.e[cen.first]){
            bra.assign((DD+1)/2+1,1);
            st.push(dfs{cen.first,i,1});
            st.push(dfs{i,cen.first,1});
            bra[0]=2;
            while(!st.empty()){
                auto D=st.top();st.pop();
                chmax(bra[D.d],t.e[D.i].size()-(D.pa!=-1));
                for(auto&j:t.e[D.i]) if(j!=D.pa) st.push(dfs{j,D.i,D.d+1});
            }
            ll tmp{1};
            for(auto&I:bra) tmp*=I;
            chmin(ans,tmp);
        }
    }
    cout<<(DD+1)/2<<" "<<ans<<endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
std = []
for i in range(n):
  std.append(list(map(int,input().split())))
chk = []
for j in range(m):
  chk.append(list(map(int,input().split())))
for i in range(n):
  can = []
  for j in range(m):
    can.append([abs(std[i][0]-chk[j][0])+abs(std[i][1]-chk[j][1]),j+1])
  print(min(can)[1])

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

int main(){
  int a, b, c, x, count;
  cin >> a >> b >> c >> x;
  vector<int> A(a+1), B(b+1), C(c+1);
  A.at(0) = 0;
  B.at(0) = 0;
  C.at(0) = 0;
  for (int i=1; i<a+1; i++) {
    A.at(i) = 500*i;
  }
  for (int i=1; i<b+1; i++) {
    B.at(i) = 100*i;
  }
  for (int i=1; i<c+1; i++) {
    C.at(i) = 50*i;
  }
  count = 0;
  for (int i=0; i<a+1; i++) {
    for (int j=0; j<b+1; j++) {
      for (int k=0; k<c+1; k++) {
        if (A.at(i) + B.at(j) + C.at(k) == x)
          count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


//変数
int N;
vector<pair<LL,LL>> num;





//サブ関数
//入力
void input()
{
	cin >> N;
	LL l, r;
	REP(i, N) {
		cin >> l >> r;
		num.push_back(make_pair(l, r));
	}
}


//計算
void calc()
{
	//exception
	bool same = true;
	for (auto p : num) {
		if (p.first != p.second)same = false;
	}
	if (same) {
		cout << 0 << endl;
		return;
	}
	//sum
	LL sum = 0;
	for (auto p : num)sum += p.first;

	//dist min
	LL best = (LL)INF*INF;
	LL bestId = 0;
	REP(i,N){
		auto p = num[i];
		if (p.first > p.second) {
			if (p.second < best) {
				best = p.second;
				bestId = i;
			}
		}
	}
	cout << sum - num[bestId].second << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 1020
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    int n;
    cin>>n;
	ll a[n];
	ll ans=1;
	bool zero=false,chk=false;
	rep(i,0,n)cin>>a[i];
	rep(i,0,n){
		if(a[i]==0){ans=0;zero=true;break;}
		if((double)log10(a[i])+(double)log10(ans)>(double)18){
			chk=true;
			ans=-1;
		}
		else{
			if(ans!=-1||ans!=0)ans=ans*a[i];
		}
	}
	if(chk==false&&ans<=(ll)1e+18)cout<<ans<<endl;
	else if(zero)cout<<ans<<endl;
	else cout<<"-1"<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int a,b;
    cin >> a >> b;
    if(a<= b) cout << a << endl;
    else cout << a-1 << endl;
}

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

int main() {
	int N, K, R, S, P;
	string T;
	long int score=0;
	cin >> N >> K;
	cin >> R >> S >> P;
	cin >> T;

	vector<vector<string>> data(K,vector<string>((int)2 + N/K));
	for (int i = 0; i < N; i++) {
		data.at(i % K).at((int)i/K)=T[i];
	}
	bool counter=true;
	for (int i = 0; i < K; i++) {
		for (int j = 0; j < (int) (N + K - i%K) / K; j++) {
			if (data.at(i).at(j) == "r" && counter == true) {
				score += P;
			}
			else if (data.at(i).at(j) == "s" && counter == true) {
				score += R;
			}
			else if(data.at(i).at(j) == "p" && counter == true){
				score += S;
			}

			if ( data.at(i).at(j) == data.at(i).at(j + 1) && counter == true) {
				counter = false;
			}
			else {
				counter = true;
			}
		}
		counter = true;
	}
	cout << score << endl;
	return 0;
}

Measured memory_bytes: 14968
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    int n;
    cin >> n;
    vector<int> a(n), p(n), q(n);
    for(int i = 0; i < n; i++) {
        a[i] = i + 1;
    }
    for(int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> q[i];
    }
    int c, d;
    ll fact = 1;
    for(int i = 0; i < n; i++) {
        fact *= (i + 1);
    }
    for(int i = 0; i < fact; i++) {
        if(a == p) {
            c = i;
        }
        if(a == q) {
            d = i;
        }
        next_permutation(all(a));
    }
    cout << abs(c - d) << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().strip().split())

hh = list(map(int, input().strip().split()))

rr = [1] * n

for i in range(m):
  a, b = map(int, input().strip().split())
  if hh[a-1] <= hh[b-1]: 
    rr[a-1] = 0
  if hh[b-1] <= hh[a-1]:
    rr[b-1] = 0
    
print(sum(rr))

Measured memory_bytes: 20080
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
 
int main() {
    
    vector<int> A(5);
    for(int i=0;i<5;i++)
    {
      cin>>A[i];
      if(A[i]==0)
      {
        cout<<i+1<<endl;
        break;
      }
    }
   
    return 0;
}

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

#define ll long long
#define ld long double
#define pi 3.14159265359

int main() {
    string S, T; cin >> S >> T;
    T.erase(T.size() - 1);
    if (S == T) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

struct edge{
    int from, to; lint cost;
    edge(int f, int t, lint c) : from(f), to(t), cost(c) {}
    edge(int t, lint c) : from(-1), to(t), cost(c) {}
};

struct dijkstra{
    vector<vector<edge> > G;
    vector<lint> d;
    int V, s;
    dijkstra(vector<vector<edge> > _G, int _s) : G(_G), s(_s){
        init();
    }
    void init(){
        V = G.size();
        d = vector<lint>(V, INF);
        priority_queue<P, vector<P>, greater<P> > que; que.push(P(0, s));
        d[s] = 0;
        while(!que.empty()){
            P p = que.top(); que.pop();
            int v = p.second;
            if(d[v] < p.first) continue;
            for(int i = 0; i < G[v].size(); i++){
                edge e = G[v][i];
                if(d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
    }
    int dist(int t){
        return d[t];
    }
};

int main(){
    int n; cin>>n;
    vector<vector<edge>> G(n);
    rep(i,n){
        int u,k; cin>>u>>k;
        rep(j,k){
            lint v,c; cin>>v>>c;
            G[u].push_back(edge(u,v,c));
        }
    }

    dijkstra dij(G, 0);
    rep(v, n){
        outs(v); out(dij.dist(v));
    }
}



Measured memory_bytes: 27560
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main implements Runnable{
	int N;
	int[] c = new int[111];
	int[] a = new int[26];
	public void solve() {
		while((N=nextInt())!=0){

			for(int i = 0;i < N;i++)c[i] = next().charAt(0)-'A';
			Arrays.fill(a, 0);
			boolean flag = true;
			for(int i = 0;i < N;i++){
				a[c[i]]++;
				int max = -1;
				boolean f = false;
				for(int j = 0;j < 26;j++)if(max == -1 || a[max] < a[j])max = j;
				for(int j = 0;j < 26;j++){
					if(max != j){
						f |= a[max] <= a[j]+N-i-1;
					}
				}

				if(!f){
					out.println((char)(max+'A') + " " + (i+1));
					flag = false;
					break;
				}
			}
			if(flag)out.println("TIE");
		}
	}

	public static void main(String[] args) {
		new Thread(null,new Main(),"",32 * 1024 * 1024).start();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	@Override
	public void run() {
		out.flush();
		new Main().solve();
		out.close();

	}
}

Measured memory_bytes: 33560
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			inCnt++;
			if (inCnt % 2 == 1)
				continue;
			String[] se = s.split(" ");
			doMain(inCnt, se);
		}
		System.exit(0);
	}

	private static void doMain(int inCnt, String[] se) {
		int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
		long total = 0;
		for (int i = 0; i < se.length; i++) {
			int e = Integer.valueOf(se[i]);
			if (max < e)
				max = e;
			if (min > e)
				min = e;
			total += e;
		}
		System.out.printf("%d %d %d\n", min, max, total);

	}
}

Measured memory_bytes: 29364
#include<stdio.h>
int main()
{

    int x,y,r,W,H;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

    if(x+r<=W && x-r>=0 && y+r<=H && y-r>=0){

        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define pi 3.1415926536
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define INF 2147483647
#define _INF -2147483647
#define MM multimap
#define PB push_back
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    vi a(5);
    rep(i, 0, 5) cin >> a[i];
    int k;
    cin >> k;
    if (a[4] - a[0] <= k)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	int n,m;
	cin>>n>>m;
	
	priority_queue<int> q;
	REP(i,n){
		int a;
		cin>>a;
		q.push(a);
	}
	
	REP(i,m){
		int tmp=q.top();
		q.pop();
		tmp/=2;
		q.push(tmp);
	}
	
	llong ans=0;
	while(!q.empty()){
		//cout<<'!'<<endl;
		ans+=q.top();
		q.pop();
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 892
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;
 use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;

procedure main is
   A: Integer;
   B: Integer;
begin
   get(A);
   get(B);
   if (B * 2 >= A) then put(0, 0);
   else put(A - B * 2, 0);
   end if;
end main;

Measured memory_bytes: 3660
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;

int main() {
	long long N, K;
	long long a, b;
	cin >> N >> K;
	if (N > K) {
		a = N % K;
		b = K - a;
		if (a <= b) cout << a << endl;
		else cout << b << endl;
	}
	else if (N == K) {
		cout << 0 << endl;
	}
	else {
		a = N;
		b = K - N;
		if (a <= b) cout << a << endl;
		else cout << b << 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 All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main() 
{
  string a, s, b; cin >> a >> s >> b;
  cout << "A" << s[0] << "C" << endl;
  system("pause");
}

Measured memory_bytes: 504
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);



int main(){
  FAST_IO  
  
  int a, b; cin >> a >> b;
  cout << (a + b + 1) / 2 << "\n";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
//再帰関数
string f(ll n){
  if(n == 0)return "";
  n--;
  return f(n/26) + string(1,'a'+n%26);//1文字でaからn%26だけはなれたアルファベットを持ってくる
}

int main(){
  ll n;
  cin >> n;
  cout << f(n) << endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<ctime>

#define ll long long
#define R register
#define IL inline
#define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))
#define Tf(a,b,c) for(R int (a)=(b);(a)>=(c);--(a))
#define MP make_pair
#define PA pair<int,int>
#define MES(a,b) memset((a),(b),sizeof((a)))
#define MEC(a,b) memcpy((a),(b),sizeof((b)))
#define D double

using namespace std;

const int N=100;

int n,m,q,ans,a[N],b[N],c[N],d[N],A[N],t;

IL int read() {
    int x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x*=10;x+=(ch-'0');ch=getchar();}
    return x*f;
}
IL void write(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
//A3-A1=3  A2-A1=2  A3-A2=2;

void calc() {
	R int sum=0;
	Rf(i,1,q) 
		if(A[b[i]]-A[a[i]]==c[i]) sum+=d[i];
	ans=max(ans,sum);
}

void dfs(int x,int pre) {
	if(x>=n) {
		calc();
		return ;
	}
	Rf(i,pre,m) {
		A[++t]=i;
		dfs(x+1,i);
		t--;
	}
}

signed main()
{
	n=read();m=read();q=read();
	Rf(i,1,q) {
		a[i]=read();b[i]=read();
		c[i]=read();d[i]=read();
	}
	dfs(0,1);
	write(ans);
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int segsize = 19;

ll SegTree[1<<segsize],Lazy[1<<segsize];
bool Flag[1<<segsize];
void denpa(int k,int l,int r)
{
	if(Flag[k])
	{
		SegTree[k]+=Lazy[k];
		//if(Lazy[k]!=INT_MAX)
		if(r-l>1)
		{
			Lazy[2*k] += Lazy[k]/2;
			Lazy[2*k+1] += Lazy[k]/2;
			Flag[k*2] = Flag[k*2+1]=true;
		}
		Lazy[k]=0;
		Flag[k] = false;

	}
}

void update(int a,int b,ll x,int k=1,int l=0,int r =-1)
{
	if(r<0)r=(1<<(segsize-1));
	//cout<<a<<' '<<b<<' '<<x<<' '<<k<<' '<<l<<' '<<r<<endl;
	denpa(k,l,r);
	if(b<=l||r<=a)return;
	if(a<=l&&r<=b)
	{
		Lazy[k] = (1LL)*(r-l)*x;
		Flag[k] = true;
		denpa(k,l,r);
	}
	else
	{
		update(a,b,x,k*2,l,(l+r)/2);
		update(a,b,x,k*2+1,(l+r)/2,r);
		SegTree[k] =SegTree[k*2]+SegTree[k*2+1];
	}
}

ll getsum(int a,int b,int k=1,int l=0,int r=-1)
{
	if(r<0)r = 1<<(segsize-1);
	denpa(k,l,r);
	if(b<=l||r<=a)return 0;
	if(a<=l&&r<=b)return SegTree[k];
	ll vl = getsum(a,b,k*2,l,(l+r)/2);
	ll vr = getsum(a,b,2*k+1,(l+r)/2,r);
	return vl+vr;
}

int main()
{
	for(int i = 0;i<(1<<segsize);i++)
	{
		SegTree[i]=0;
		Lazy[i] = 0;
	}
	int n,q;
	cin >> n >> q;
	for(int i = 0;i<q;i++)
	{
		int op;
		cin >> op;
		if(op)
		{
			int a,b;
			cin >> a >> b;
			
			cout<<getsum(a-1,b)<<endl;
		}
		else
		{
			int a,b,x;
			cin >> a >> b >> x;
			
			update(a-1,b,x);
		}
		//for (int i = 0; i < (1<<segsize); i++){cout<<SegTree[i]<<' '<<Lazy[i]<<endl;}cout<<endl;
		
		
	}
}


Measured memory_bytes: 11504