akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>

#define MAX_N 100

using namespace std;

int A[MAX_N][MAX_N];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> A[i][j];
    }
  }
  int res = 0;
  for (int i = 0; i < N; ++i) {
    int t = 0;
    for (int j = 0; j <= i; ++j) {
      t += A[0][j];
    }
    for (int j = i; j < N; ++j) {
      t += A[1][j];
    }
    res = max(res, t);
  }
  printf("%d\n", res);
}

Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <climits>
#include <bitset>

using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 5;

ll mod_pow(ll k, ll p)
{
    if (k == 0)
    {
        return 1 % p;
    }
    if (k == 1)
    {
        return 2 % p;
    }

    if (k % 2 == 0)
    {
        ll tmp = mod_pow(k / 2, p);
        return tmp * tmp % p;
    }
    else
    {
        ll tmp = mod_pow((k - 1) / 2, p);
        tmp *= tmp;
        tmp %= p;
        tmp *= 2;
        tmp %= p;
        return tmp;
    }
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2) % MOD;
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, (k - 1) / 2);
        return tmp * tmp * 2;
    }
}

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

    map<ll, ll> mp;
    for (ll x = 1; x <= 1e2; x++)
    {
        for (ll y = 1; y <= 1e2; y++)
        {
            for (ll z = 1; z <= 1e2; z++)
            {
                mp[x * x + y * y + z * z + x * y + y * z + z * x] += 1;
            }
        }
    }
    for (ll i = 1; i <= N; i++)
    {
        cout << mp[i] << endl;
    }
        
}

Measured memory_bytes: 5912
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

struct Edge{
    int to,cost;
    Edge(int to,int cost) :to(to),cost(cost){}
    Edge(){}
};
struct Lost{
    int s,t;
    Lost(int s,int t) :s(s),t(t){}
    Lost(){}
};
struct State{
    int v;
    int cost;
    int bit1,bit2;
    State(int v,int cost,int bit1,int bit2):
        v(v),cost(cost),bit1(bit1),bit2(bit2){}
    State(){}

    bool operator>(const State rth) const {
        return this->cost>rth.cost;
    }

};
int n,m,k,p;
vector<Edge> G[1003];
Lost lost[10];
int dp[1003][1<<6][1<<6];

int dijk() {
    rep(i,1003) rep(j,1<<6) rep(c,1<<6) dp[i][j][c]=INF;
    dp[p][0][0]=0;
    priority_queue<State,vector<State> ,greater<State> > que;
    que.push(State(p,0,0,0));

    while(que.size()) {
        State s=que.top(); que.pop();

        rep(i,G[s.v].size()) {
            Edge e=G[s.v][i];
            rep(a,k) {
                if(lost[a].s==e.to) {
                    if(dp[e.to][s.bit1|1<<a][s.bit2]>dp[s.v][s.bit1][s.bit2]+e.cost) {
                        dp[e.to][s.bit1|1<<a][s.bit2]=dp[s.v][s.bit1][s.bit2]+e.cost;
                        que.push(State(e.to,dp[e.to][s.bit1|1<<a][s.bit2],s.bit1|1<<a,s.bit2));
                    }
                }
                if(lost[a].t==e.to&&(s.bit1>>a)&1) {
                    if(dp[e.to][s.bit1][s.bit2|1<<a]>dp[s.v][s.bit1][s.bit2]+e.cost) {
                        dp[e.to][s.bit1][s.bit2|1<<a]=dp[s.v][s.bit1][s.bit2]+e.cost;
                        que.push(State(e.to,dp[e.to][s.bit1][s.bit2|1<<a],s.bit1,s.bit2|1<<a));
                    }
                }
            }
            if(dp[e.to][s.bit1][s.bit2]>dp[s.v][s.bit1][s.bit2]+e.cost) {
                dp[e.to][s.bit1][s.bit2]=dp[s.v][s.bit1][s.bit2]+e.cost;
                que.push(State(e.to,dp[e.to][s.bit1][s.bit2],s.bit1,s.bit2));
            }
        }
    }

    int ans=INF;
    rep(i,n) ans=min(ans,dp[i][(1<<k)-1][(1<<k)-1]);

    return ans;
}

int main() {
    cin>>n>>m>>k>>p;
    p--;
    rep(i,m) {
        int x,y,w;
        cin>>x>>y>>w;
        x--,y--;
        G[x].pb(Edge(y,w));
        G[y].pb(Edge(x,w));
    }
    rep(i,k) {
        int s,t;
        cin>>s>>t;
        s--,t--;
        lost[i].s=s;
        lost[i].t=t;
    }
    int ans=dijk();
    if(ans==INF) cout<<"Cannot deliver"<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 19236
def f(s):
  m,y = int(s[:2]), int(s[2:])
  return (0 < m <= 12,0 < y <= 12)

print {(0,0):'NA', (0,1): 'YYMM', (1,0): 'MMYY', (1,1):'AMBIGUOUS'}[tuple(map(int,list(f(raw_input()))))]


Measured memory_bytes: 28012
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint dp(N+1,N);

    dp[0]=0;
    for(int i=0;i<N;i++){
        for(int j=1;i+j<=N;j*=6){
            dp[i+j]=min(dp[i+j],dp[i]+1);
        }
        for(int j=1;i+j<=N;j*=9){
            dp[i+j]=min(dp[i+j],dp[i]+1);
        }
    }
    cout<<dp[N]<<endl;
 
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
int main()
{
 int N,i,v,j,i2;
 cin>>N;
 int A[N];

 
 for(i=0;i<N;i=i+1)
 { 
  cin>>A[i];
  //cout<<A[i]<<endl;
 }

for(i2=0;i2<N;i2=i2+1)
  {
   if(i2==N-1)
   {
    cout<<A[i2]<<endl;
    }else{
    cout<<A[i2]<<" ";}
  }



for(i=1;i<N;i++)
 {
  v=A[i];
  j=i-1;
  
  while(j>=0 and A[j]>v)
  {
   A[j+1]=A[j];
   j--;
   A[j+1]=v;
  } 
   
   for(i2=0;i2<N;i2=i2+1)
   {
    if(i2==N-1)
    {
    cout<<A[i2]<<endl;
    }else{
    cout<<A[i2]<<" ";}
   }
 }
 



 return 0;
}


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

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

    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<ll> questions(N);
    for(ll i = 0; i < N; i++)
    {
        ll A;
        cin >> A;
        questions.at(i) = A;
    }
    sort(questions.begin(), questions.end(), greater<ll>());
    vector<ll> ruisekiPoint(N + 1);
    for(ll i = 0; i < N; i++){
        ruisekiPoint.at(i + 1) += ruisekiPoint.at(i) + questions.at(i);
    }
    ll answer = P;
    for(ll i = P; i < N; i++){
        ll remainV = max((V - (P - 1) - (N - i)), (ll)0);
        ll remainScore = remainV * M;
        ll borderPoint = questions.at(P - 1);
        //先にボーダーの右側の追い越し対象にPと同じ値まで均等に振る
        remainScore -= borderPoint * (i - P) - (ruisekiPoint.at(i) - ruisekiPoint.at(P));
        //余りが残ったらボーダーを含めてなるべく均等に振る
        if(remainScore > 0){
            borderPoint += remainScore / (i - P + 1);
            if (remainScore % (i - P + 1)){
                borderPoint++;
            }
        }
        ll currentMaxPoint = questions.at(i) + M;
        if(borderPoint <= currentMaxPoint){
            answer++;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1792
eval"H,W,*A="+`dd`.split*?,
A.pop(H*W).zip(A){|a,b|a=(a-b).abs
$.%W<1&&N=0
N|=$*[-W]||0**$.<<T=1e4
$*<<N=N<<a|N>>a
$.+=1}
p (0..T).find{|i|N[T+i]+N[T-i]>0}

Measured memory_bytes: 37248
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<cstdio>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<long int, long int>


int main(){
    long int n, m;
    cin >> n >> m;
    long int a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    priority_queue<P> que;
    rep(i, m) {
        long int b, c;
        cin >> b >> c;
        que.push(P(c, b));
    }
    P p = que.top();
    que.pop();
    for (long int i = 0; i < n; i++){
        if (a[i] < p.first){
            a[i] = p.first;
            p.second--;
        }
        
        if (p.second == 0 && !que.empty()){
            p = que.top();
            que.pop();
        }else if (p.second == 0 && que.empty()) break;
        
    }
    long int ans = 0;
    rep(i, n) ans += a[i];
    cout << ans << endl;
    
    
}


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;//list用
using System.Text.RegularExpressions;//正規表現用
using System.Text;//StringBuilder用
class Program
{
    static List<int> s = new List<int>();
    static string result;
    static void Main()
    {
        //string tmp1 = Console.ReadLine();
        //int x = int.Parse(tmp1);
        string[] tmp2 = Console.ReadLine().Split(' ');
        for (int i = 0; i <2; i++) { s.Add(int.Parse(tmp2[i])); }
        for (int i = 1; i < 2 * s[0] ; i++) { result+=(s[1]-s[0]+i).ToString();if(i<=2*s[0]-2){result+=" ";} }
      //result.Append("test");
          Console.WriteLine(result);
    }
}

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

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int k;
    string s;
    cin>>k>>s;
    if(s.size()>k)cout<<s.substr(0,k)+"..."<<endl;
    else cout<<s<<endl;

    return 0;
}

Measured memory_bytes: 3644
H,W = map(int, input().split())
m = [input() for _ in range(H)]
ans_m=[[0]*W for _ in range(H)]
dhw = [(1,0),(-1,0),(0,1),(0,-1),(1,1),(-1,-1),(-1,1),(1,-1)]
def main():
  global ans_m
  for h in range(H):
    for w in range(W):
      if m[h][w]=="#":
        ans_m[h][w]="#"
      else:
        n_mines=0
        for dh, dw in dhw:
          nh, nw = h+dh, w+dw
          if 0<=nh<H and 0<=nw<W:
            if m[nh][nw]=="#":
              n_mines+=1
          ans_m[h][w]=str(n_mines)
  for _ in range(H):
    print("".join(ans_m[_]))
  return

if __name__ == "__main__":
  main()

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

using namespace std;

vector<long> A;

long func(long X){
    long ans=0;
    for(int i=0; i<A.size(); ++i){
        ans += X^A[i];
    }
    return ans;
}

long max_X(long X, int bits){
    for(int i=bits; i>=0; --i){
        int count_1=0;
        for(int j=0; j<A.size(); ++j){
            if(((A[j]>>i) & long(1)) == long(1)){
                count_1++;
            }
        }
        if(count_1>=A.size()/2.0){
            if(((X>>i) & long(1)) == long(1)){
                X = X - long(pow(2, i));
            }
        }else{
            if(((X>>i) & long(1)) != long(1)){
                X = X + long(pow(2, i));
            }
        }
    }
    return X;
}

int main(){
    long N, K;
    
    cin>>N>>K;
    A.resize(N);
    for(int i=0; i<N; ++i){
        cin>>A[i];
    }
    long ans=0;
    long max_ans = func(K);
    for(int i=40; i>=0; --i){
        if(((K>>i) & long(1)) == long(1)){
            long X = K - long(pow(2, i));
            ans = func(max_X(X, i-1));
            if(max_ans < ans){
                max_ans = ans;
            }
        }
    }
    cout<<max_ans<<endl;


    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
const lli MAX=1e9+7;
 
int main()
{
    fast;
    int n;
    cin>>n;
    string s;
    cin>>s;
    int r=0;
    for(int i=0; i<n;  i++){
        if(s[i]=='R') r++;
    }
    int cnt=r;
    for(int i=0;i<r; i++){
        if(s[i]=='R') cnt--;
    }
    cout<<cnt<<"\n";
    return 0;
}

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


using namespace std;
const int maxn = 55;
int head[maxn];

struct edge{
    int to;
    int next;
}E[maxn*maxn];

int cnt;

int buc1[maxn*maxn];
int buc2[maxn*maxn];
void addedge(int u , int v , int i)
{
    buc1[i] = cnt;
    E[cnt].to = v;E[cnt].next = head[u];head[u] = cnt++;
    buc2[i] = cnt;
    E[cnt].to = u;E[cnt].next = head[v];head[v] = cnt++;

}

int vis[maxn];

void dfs(int rt , int p)
{
   // cout<<"rt "<<rt<<endl;
    vis[rt] = 1;
    for(int i = head[rt] ; i != -1 ; i = E[i].next){
        if(i == buc1[p] || i == buc2[p]) continue;
        int v = E[i].to;
        if(vis[v] == 1) continue;
        dfs(v , p);
    }
}

int main()
{
    int N,M;
    cin>>N>>M;
    memset(head , -1 , sizeof(head));
    for(int i = 0 ; i< M ; i++){
        int u,v;
        scanf("%d%d" , &u,&v);
        addedge(u,v,i);
    }
    int ans = 0;
    for(int i = 0 ; i < M ; i++){
        memset(vis , 0 , sizeof(vis));
        dfs(1 , i);
        int t = 0;
        for(int i = 1 ; i <= N ; i++){
            t += vis[i];
        }
       // cout<<"fsdfas"<<endl;
        if(t != N){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			int k = stdIn.nextInt();
			if(n == 0 && k == 0)
			{
				break;
			}
			List<Integer> list = new ArrayList<Integer>();
			for(int i = 0; i < n; ++i)
			{
				int a = stdIn.nextInt();
				list.add(a);
			}
			int max = 0;
			int sum = 0;
			for(int i = 0; i < k; ++i)
			{
				sum += list.get(i);
			}
			if(max < sum)
			{
				max = sum;
			}
			for(int i = 1; i + k - 1 < n; ++i)
			{
				sum -= list.get(i - 1);
				sum += list.get(i + k - 1);
				if(max < sum)
				{
					max = sum;
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 15000
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int a,b;
    cin>>a>>b;
    rep(i,10000){
        if((int)(i*0.08)==a&&(int)(i*0.1)==b){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		long n = scan.nextLong();
		long k = scan.nextLong();
		
		long a = n%k;
		long b = k-a;
		
		System.out.println(Math.min(a,b));
	}
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int n,k,p,ke;
int in(){
cin>>n;
}
int out(){
for(int a=0;a<n;a++){
cin>>k>>p;
ke=k%p;
if(ke==0)
ke=p;
cout<<ke<<endl;
}
}
int main(){
in();
out();
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;


signed main() {
	int n, p; cin >> n >> p;
	int ans = 1;
	map<int, int>M;
	
	for (int i = 2; i*i <= p; i++) {
		while (p%i == 0) {
			p /= i;
			M[i]++;
		}
	}
	if (p != 1)M[p]++;
	for (auto itr = M.begin(); itr != M.end(); itr++) {
		int e = itr->second;
		e /= n;
		rep(i, e)ans *= itr->first;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 101

int main()
{
  int i,j,n,count=0,v,c,c1,v1;
  int G[N][N],col[N],d[N],pi[N],mincost,i2;

  for(i = 0; i < N; i++){

    for(j = 0; j < N; j++)
      G[i][j] = -1;

  }

  scanf("%d",&n);

  for(i = 0; i < n; i++){

    scanf("%d%d",&v,&c);

    for(j = 0; j < c; j++){
      scanf("%d%d",&v1,&c1);
      G[v][v1] = c1;
    }

  }
 
  for(i = 0; i < n; i++){

    col[i] = 0;
    pi[i] = -1;
    d[i] = 10000001;

  }

  d[0] = 0;
 
  while(1){

    mincost = 10000001;

    for(i = 0; i < n; i++){

      if(col[i] != 2 && d[i] < mincost){
        mincost = d[i];
        i2 = i;
      }

    }

    if(mincost == 10000001)break;

    col[i2] = 2;

    for(i = 0; i < n; i++){

      if(G[i2][i] != -1 && col[i] != 2 && (G[i2][i]+d[i2]) < d[i]){
	pi[i] = i2;
	d[i] = G[i2][i] + d[i2];
	col[i] = 1;
      }

    }

  }

  for(i = 0; i < n; i++)printf("%d %d\n",i,d[i]);

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int MOD = 1e9 + 7;
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}

ii a[211111];
int dp[211111],L[211111],R[211111];
int pref[211111];

bool cmp(const ii &a, const ii &b)
{
	if(a.fi!=b.fi) return a.fi<b.fi;
	else return a.se>b.se;
}

int sum(int l, int r)
{
	if(l==0) return pref[r];
	else return add(pref[r],MOD-pref[l-1]);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vector<ii> vec;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].fi>>a[i].se;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		vec.pb(mp(a[i].se,i));
	}
	sort(vec.begin(),vec.end());
	int mx=0; int mn=n;
	for(int i=0;i<n;i++)
	{
		mx=max(mx,vec[i].se);
		R[vec[i].se]=mx;
	}
	for(int i=n-1;i>=0;i--)
	{
		mn=min(mn,vec[i].se);
		L[vec[i].se]=mn;
	}
	vector<ii> tmp;
	for(int i=0;i<n;i++) 
	{
		L[i]++,R[i]++;
		tmp.pb(mp(L[i],R[i]));
	}
	sort(tmp.begin(),tmp.end(),cmp);
	vec.clear();
	for(int i=0;i<tmp.size();i++)
	{
		while(!vec.empty()&&vec.back().fi<=tmp[i].fi&&tmp[i].se<=vec.back().se)
		{
			vec.pop_back();
		}
		vec.pb(tmp[i]);
	}
	vi ele2;
	for(int i=0;i<vec.size();i++) 
	{
		ele2.pb(vec[i].se);
	}
	dp[0]=1; pref[0]=1;
	for(int i=1;i<=n;i++)
	{
		int z=lower_bound(ele2.begin(),ele2.end(),i)-ele2.begin();
		z--;
		int lastgood = 0;
		if(z>=0) lastgood = vec[z].fi;
		dp[i] = add(dp[i],sum(lastgood,i-1));
		pref[i]=add(pref[i-1],dp[i]);
	}
	cout<<add(pref[n],MOD-pref[vec.back().fi-1])<<'\n';
}


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

ll f(ll a, ll b, ll x){
    return (a*x)/b - (x/b) * a;
}

int main(void) 
{
    ll a, b, n;
    cin >> a >> b >> n;
    ll ans =0;
    ll N = min(b-1,n);
    ans = f(a,b,N);
    cout << ans << endl;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int MOD = 100000;

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int M = sc.nextInt();
			int P = sc.nextInt() - 1;
			int Q = sc.nextInt() - 1;
			int R = sc.nextInt();
			Node EDGE = new Node(0, 0);
			Node top = new Node(1, N);
			top.prev = top.next = EDGE;
			EDGE.next = EDGE.prev = top;
			for (int i = 0; i < M; ++i) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				Node sy = walk(EDGE.next, x);
				Node sz = walk(sy, y - x);
				exchange(EDGE.next, sy.prev, sz, EDGE.prev);
			}
			int count = 0;
			for (Node cur = EDGE.next; cur != EDGE; count += cur.len, cur = cur.next) {
				if (count > Q) break;
				if (count + cur.len <= P) continue;
				if (count < P) {
					cur.divide(P - count);
					continue;
				}
				if (count + cur.len > Q + 1) {
					cur.divide(Q - count + 1);
					break;
				}
			}
			count = 0;
			int ans = 0;
			for (Node cur = EDGE.next; cur != EDGE; count += cur.len, cur = cur.next) {
				if (count > Q) break;
				if (count + cur.len <= P) continue;
				if (cur.start > R) continue;
				if (cur.start + cur.len - 1 <= R) {
					ans += cur.len;
				} else {
					ans += R - cur.start + 1;
				}

			}
			System.out.println(ans);
		}
	}

	static Node walk(Node cur, int count) {
		int sum = 0;
		while (true) {
			sum += cur.len;
			if (sum == count) {
				return cur.next;
			}
			if (sum > count) {
				return cur.divide(cur.len - (sum - count));
			}
			cur = cur.next;
		}
	}

	static void exchange(Node xs, Node xe, Node zs, Node ze) {
		Node xp = xs.prev;
		Node xn = xe.next;
		Node zp = zs.prev;
		Node zn = ze.next;
		xp.next = zs;
		zs.prev = xp;
		xn.prev = ze;
		ze.next = xn;
		zp.next = xs;
		xs.prev = zp;
		zn.prev = xe;
		xe.next = zn;
	}

	static class Node {
		Node prev, next;
		int start, len;

		Node(int start, int len) {
			this.start = start;
			this.len = len;
		}

		Node divide(int ns) {
			Node nn = new Node(start + ns, len - ns);
			this.len = ns;
			this.next.prev = nn;
			nn.next = this.next;
			nn.prev = this;
			this.next = nn;
			return nn;
		}
	}
}

Measured memory_bytes: 13000
#include <iostream>


using namespace std;

int main() {
    int A, B, result = -1;
    cin >> A >> B;

    for (int i = 1; i < 10000; i++) {
        if ((int)(i*0.08)==A && (int)(i*0.1)==B) {
            result = i;
            break;
        }
    }

    cout << result << endl;
    return 0;

}

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

int main() {
    string S;
    cin >> S;

    if(S == "AAA" or S== "BBB"){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

public class Main {

    static int N;
    static String S;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        S = sc.next();

        solve();
    }

    static void solve() {

        int max = 0;
        for (int i = 1; i < N; i++) {

            String lhs = S.substring(0, i);
            String rhs = S.substring(i, N);

            max = Math.max(max, intersection(lhs, rhs));
        }

        System.out.println(max);
    }

    static int intersection(String s1, String s2) {

        Set<String> set1 = s1.chars().mapToObj(c -> String.valueOf((char)c)).distinct().collect(Collectors.toSet());
        Set<String> set2 = s2.chars().mapToObj(c -> String.valueOf((char)c)).distinct().collect(Collectors.toSet());

        set1.retainAll(set2);

        return set1.size();
    }

}


Measured memory_bytes: 27092
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, M;
  cin>>N>>M;
  ll ans;
  if(N>=2 && M>=2){
    ans = (N-2)*(M-2);
  }
  else if(N==1 && M>=2){
    ans = M-2;
  }
  else if(N>=2 && M==1){
    ans = N-2;
  }
  else{
    ans = 1;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3600
#include <cstdio>
#include <vector>
#include <map>
using namespace std;

int main()
{
  int N, M;
  while (~scanf("%d %d", &N, &M)) {
    if ((N|M) == 0)
      break;

    vector<int> h(N), w(M);
    for (int i = 0; i < N; ++i)
      scanf("%d", &h[i]);
    for (int i = 0; i < M; ++i)
      scanf("%d", &w[i]);

    map<int, int> h_cnt, w_cnt;
    for (int i = 0; i < N; ++i) {
      int sum = 0;
      for (int j = i; j < N; ++j) {
	sum += h[j];
	++h_cnt[sum];
      }
    }
    for (int i = 0; i < M; ++i) {
      int sum = 0;
      for (int j = i; j < M; ++j) {
	sum += w[j];
	++w_cnt[sum];
      }
    }

    int ans = 0;
    for (map<int, int>::iterator it = h_cnt.begin(); it != h_cnt.end(); ++it) {
      map<int, int>::iterator jt = w_cnt.find(it->first);
      if (jt == w_cnt.end())
	continue;
      ans += it->second * jt->second;
    }

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

Measured memory_bytes: 18000
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int x, y;
	cin >> x >> y;
	int a, b;
	bool judge = false;
	for(a = 0; a<=x;a++){
		int asi = a*2 + 4*(x-a);
		if(asi == y) judge = true;
	}
	if(judge) cout << "Yes" << endl;
	if(!judge) cout << "No" << endl;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<int> ans(n+1);
    for(int x = 1; x * x <= n; x++){
        for(int y = 1; y *y <= n; y++){
            for(int z = 1; z * z <= n; z++){
                ll sum = x*x + y*y + z*z + x*y + y*z + z*x;
                if (sum <= n) ans[sum]++;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main() {
	string s; cin >> s;
	queue<char> que;
	que.push(s[0]);
	int res = 0;
	for (int i = 1; i < s.size(); i++)
	{
		if(que.empty()) que.push(s[i]);
		else if(s[i] == que.back()) que.push(s[i]);
		else {
			res += 2;
			que.pop();
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<Edge>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,K,ans=0;
  cin>>N>>K;
  
  RREP(i,N){
    ans+=N/i*max(0ll,i-K);
    ans+=max(0ll,N%i-K+1);
  }
  
  if(K==0) ans-=N;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    int N;LL M;
    GI(N);GLL(M);
    vector<LL> S(N);
    REP(i,N){
        LL a;
        GLL(a);
        if(i==0)
            S[i]=a;
        else
            S[i]=S[i-1]+a;
        S[i]%=M;
    }
    LL ans=0;
    map<LL,LL> ma;
    for(int i=N-1;0<=i;i--){
        ans+=ma[S[i]];
        ma[S[i]]++;
        // printf("i=%d S[i]=%lld ma[S[i]]=%lld\n",i,S[i],ma[S[i]]);
    }
    ans+=ma[0];
    printf("%lld\n",ans);
    return 0;
}

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

int main(){
  string j;
  int n,a;
  cin >> n >> a;
  
  n = n % 500;
  if (n <= a){
    j = "Yes";
  }
  else{
    j = "No";
  }
  cout << j << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import re

if __name__ == '__main__':

    s = input()

    s = re.sub(r'[^ACGT]+', '_', s)


    maxlen = 0

    for ss in s.split('_'):
        if len(ss) > maxlen:
            maxlen = len(ss)

    print(maxlen)


Measured memory_bytes: 3316
fun main(args: Array<String>) {
	val (w, h, n) = readLine()!!.split(' ').map { it.toInt() }
	val arr = Array(h) { Array(w) { 1 } }

	for (i in 0 until n) {
		val (xi, yi, a) = readLine()!!.split(' ').map { it.toInt() }

		for (y in 0 until h) {
			for (x in 0 until w) {
				when (a) {
					1 -> {
						if (x < xi) {
							arr[y][x] = 0
						}
					}
					2 -> {
						if (x >= xi) {
							arr[y][x] = 0
						}
					}
					3 -> {
						if (y < yi) {
							arr[y][x] = 0
						}
					}
					4 -> {
						if (y >= yi) {
							arr[y][x] = 0
						}
					}
				}

			}
		}
	}
	var ans = 0

	for (y in 0 until h) {
		ans += arr[y].sum()
	}
	println(ans)
}


Measured memory_bytes: 39264
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	ll s = 0;
	rep(i, n) {
		cin >> a[i];
		s ^= a[i];
	}
	rep(i, n) {
		ll y = s ^ a[i];
		cout<< y<< " ";
	}
}

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

int main(void)
{
	int h, a;
  	cin >> h >> a;
  	
  	int cnt = 0;
  	while(h > 0)
    {
    	h -= a;
      	cnt++;
    }
  
  	cout << cnt << endl;
  	
  	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n, m;
    int ac[100010] = {};
    int wa[100010] = {};
    int a = 0, w = 0;
    int p;
    char s[3];
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++)
    {
        scanf("%d %s", &p, s);
        if (s[0] == 'A')
        {
            ac[p] = 1;
        }
        else if (s[0] == 'W' && ac[p] == 0)
        {
            wa[p]++;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (ac[i] == 1)
        {
            a++;
            w += wa[i];
        }
    }
    printf("%d %d", a, w);
    return 0;
}

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

int main(){
  int n,m,In,ai,now=1,ans=0;
  cin >> n >> m;
  int dp[n+100];
  vector<int> dis;
  for(int i=0;i<n-1;i++){
    cin >> In;
    dis.push_back(In);
  }
  int next;
  dp[0] = 0;
  for(int i=1;i<n;i++){
    dp[i] = dp[i-1] + dis[i-1];
    //cout << i << "-th is " << dp[i] << endl;
  }
  for(int i=0;i<m;i++){
    cin >> ai;
    next = now+ai;
    ans += abs(dp[next-1]-dp[now-1]);
    ans%=100000;
    //cout << "next = " << dp[next-1] << ",now = " << dp[now-1] << endl;
    now = next;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2072
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  string s;
  cin>>s;
  int cnt(0);
  if (s[0] == '1') cnt++;
  if (s[1] == '1') cnt++;
  if (s[2] == '1') cnt++;
  cout << cnt << endl;
  return 0;
}



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

using namespace std;

vector<int> damage,mana;
int h,n,d,m;
int dp[1001][20001];

int attacks(int i,int sum)
{
    if(sum<=0)
        return 0;
    if(i==n && sum>0)
        return 999999999;
    if(dp[i][sum]!=-1)
        return dp[i][sum];
    return dp[i][sum]=min(attacks(i+1,sum),attacks(i,sum-damage[i])+mana[i]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp,-1,sizeof dp);
    cin>>h>>n;
    for(int i=0; i<n; i++)
    {
        cin>>d>>m;
        damage.push_back(d);
        mana.push_back(m);
    }
    cout<<attacks(0,h)<<endl;

}


Measured memory_bytes: 78976
# -*- coding: utf-8 -*-


def solve(s_pp, p_pp):
    p_nums = []
    for x, y in s_pp:
        distance = []
        for xx, yy in p_pp:
            n = abs(x - xx) + abs(y - yy)
            distance.append(n)
        min_distance_idx = distance.index(min(distance))
        p_nums.append(min_distance_idx + 1)
    return p_nums


def main():
    students, points = [int(e) for e in input().split()]
    students_ps = []
    points_ps = []

    for _ in range(students):
        x, y = [int(e) for e in input().split()]
        students_ps.append([x, y])
    for _ in range(points):
        x, y = [int(e) for e in input().split()]
        points_ps.append([x, y])
    
    for answer in solve(students_ps, points_ps):
        print(answer)


main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <queue>
#include <utility>
#include <functional>
#include <sstream>
using namespace std;
#define ll long long
 
int main(void){
    ll x, y;
    cin >> x >> y;
    if(abs(y)>=abs(x)){
        if(x>=0 && y >= 0) cout << y-x << endl;
        else if(x>=0 && y<0) cout << (-1*y)-x+1 << endl;
        else if(x<0 && y>=0) cout << abs(y-(-1)*x)+1 << endl;
        else cout << abs(y-x)+2 << endl;  
    }
    else if(abs(y)<abs(x)){
        if(x>=0 && y > 0) cout << x-y+2 << endl;
        else if(x>0 && y<=0) cout << y-(-1)*x+1 << endl;
        else if(x<0 && y>0) cout << abs(y-(-1)*x)+1 << endl;
        else cout << abs(y-x) << endl;  
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back

char str[12][6] ={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
int mod[12] = {0,5,3,3,3,3,3,4,3,4};

int main(void){
  int n;
  cin >> n;
  rep(test,n){
    string s;
    cin >> s;
    int num = -1;
    int cnt = -1;
    rep(i,s.sz){
      if(s[i] == '0'){
        if(num != -1){
          printf("%c", str[num][cnt%mod[num]]);
          num = -1;
          cnt = -1;
        }
      }else{
        num = s[i] - '0';
        cnt++;
      }
    }
    puts("");
  }
  return 0;
}

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

typedef int ll;

#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define endl '\n'

typedef pair<int,int>pii;
typedef pair<int,pair<int,int> > piii;

const int mod=1e9+7;

int POWER[65];
int power(int a, int b) {int ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
int inv(int x) {return power(x,mod-2);}

void precompute() {
	POWER[0]=1;
	for(int i=1;i<63;i++) POWER[i]=POWER[i-1]<<1LL;
}

vector<pii>v;
ll main() {
	// freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);

	std:ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int q,h,s,d;
	cin>>q>>h>>s>>d;
	v.pb(mp(q*8,1));
	v.pb(mp(h*4,2));
	v.pb(mp(s*2,3));
	v.pb(mp(d,4));
	sort(all(v));

	int m,ret=0;
	cin>>m;

	for (int i=0 ; i<sz(v) ; i++) {
		// cout<<v[i].ss<<" "<<m<<" "<<ret<<endl;
		if(v[i].ss==1) {
			int b=v[i].ff/8;
			ret+=((m*4)*b);
			m=0;
		}
		else if(v[i].ss==2) {
			int b=v[i].ff/4;
			ret+=((m*2)*b);
			m=0;
		}
		else if(v[i].ss==3) {
			ret+=((v[i].ff/2)*m);
			m=0;
		}
		else {
			ret+=((m/2)*v[i].ff);
			m%=2;
		}
	}
	cout<<ret<<endl;
}

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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int N, W;
    ist >> N >> W;

    vector<int> w;
    vector<int> v;

    for (int i = 0; i < N; i++)
    {
        int input_w, input_v;
        ist >> input_w >> input_v;
        w.emplace_back(input_w);
        v.emplace_back(input_v);
    }

    /* ------- 計算 ------- */

    int max_V = 110110;
    int max_N = 110;

    vector<vector<long long>> dp_table;

    dp_table.emplace_back(0);
    for (int j = 0; j <= max_V; j++)
    {
        dp_table.at(0).emplace_back(INT_MAX);
    }

    dp_table.at(0).at(0) = 0;

    for (int i = 0; i < N; i++)
    {
        dp_table.emplace_back(0);

        for (int j = 0; j <= max_V; j++)
        {
            // i番目の品物を追加できない場合の価値
            long long insert_value = dp_table.at(i).at(j);

            // i番目の品物を追加できる（する）場合の価値
            if (v.at(i) <= j)
            {
                insert_value = min(dp_table.at(i).at(j - v.at(i)) + w.at(i), insert_value);
            }

            dp_table.at(i + 1).emplace_back(insert_value);
        }
    }

    // for (int i = 0; i < N; i++)
    // {
    //     for (int j = 0; j < 30; j++)
    //     {
    //         if (dp_table.at(i).at(j) == INT_MAX)
    //         {
    //             cout << "INF"
    //                  << " ";
    //         }
    //         else
    //         {
    //             cout << dp_table.at(i).at(j) << " ";
    //         }
    //     }
    //     cout << endl;
    // }

    // 最適値の出力
    long long res = 0;
    for (int j = 0; j < max_V; j++)
    {
        if (dp_table[N][j] <= W)
        {
            res = j;
        }
    }
    ost << res << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 91092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    vector<int> a;
    rep(i,n){
        a.push_back(i+1);
    }
    vector<int> p(n),q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    int A,B;
    int cnt=1;
    do {
        if(a==p) A = cnt;
        if(a==q) B = cnt;
        cnt++;
    }while(next_permutation(a.begin(),a.end()));

    cout << abs(A-B) << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from functools import cmp_to_key
import itertools

N, T = map(int, readline().split())
m = map(int, read().split())
AB0 = []
AB1 = []
for a,b in zip(m,m):
    if a == 0:
        AB0.append(b)
    else:
        AB1.append((a,b))

def sort_func(ab0, ab1):
    a0, b0 = ab0
    a1, b1 = ab1
    return a1*(1+b0) - a0*(1+b1)

AB0.sort()
AB1.sort(key=lambda x: x[0] / (x[1] + 1), reverse=True)
AB0, AB1

def compute_0():
    INF = T + 1
    dp = [INF] * 40
    dp[0] = 0
    for a,b in AB1:
        for n in range(39, -1, -1):
            if dp[n] > T:
                continue
            x = (dp[n] + 1) * (a + 1) + b
            if x < dp[n+1]:
                dp[n+1] = x
    return dp

def compute_1():
    return [0] + list(itertools.accumulate(x + 1 for x in AB0))

dp0 = compute_0()
dp1 = compute_1()

R = len(dp1) - 1
answer = 0
for i,x in enumerate(dp0):
    if x > T:
        break
    while x + dp1[R] > T:
        R -= 1
    value = i + R
    if answer < value:
        answer = value

print(answer)


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

int main() {
  string s;
  cin >> s;
  
  int i, r = 0, b = 0;
  for(i = 0; i < s.size(); i++){
    if(s.at(i) == '0') r++;
    else b++;
  }
  
  cout << 2 * min(r, b) << endl;
}

Measured memory_bytes: 512
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include<bits/stdc++.h>

using namespace std;

char a[5005];
char b[5005];
set<string>s;
string p;
int main()
{
    int k;
    scanf("%s",a);
    scanf("%d",&k);
    int len=strlen(a),j;
    for(int i=0;i<len;i++)
    {
        j=0;
        b[j++]=a[i];
        b[j]='\0';
        p=b;
        s.insert(p);
    }
    for(int i=0;i<len-1;i++)
    {
        j=0;
        b[j++]=a[i],b[j++]=a[i+1];
        b[j]='\0';
        p=b;
        s.insert(p);
    }
    for(int i=0;i<len-2;i++)
    {
        j=0;
        b[j++]=a[i],b[j++]=a[i+1],b[j++]=a[i+2];
        b[j]='\0';
        p=b;
        s.insert(p);
    }
    for(int i=0;i<len-3;i++)
    {
        j=0;
        b[j++]=a[i],b[j++]=a[i+1],b[j++]=a[i+2],b[j++]=a[i+3];
        b[j]='\0';
        p=b;
        s.insert(p);
    }
    for(int i=0;i<len-4;i++)
    {
        j=0;
        b[j++]=a[i],b[j++]=a[i+1],b[j++]=a[i+2],b[j++]=a[i+3],b[j++]=a[i+4];
        b[j]='\0';
        p=b;
        s.insert(p);
    }
    int m=0;
    for(set<string>::iterator it=s.begin();it!=s.end();it++)
    {
        m++;
        if(m==k)
        {
            cout<<*it<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007

using namespace std;
int main()
{
 	speed_up
    ll l,r;cin>>l>>r;
    ll out=MAX;
    if(l<2019&&r>2019)
    {
    	cout<<0;return 0;
	}
    for(ll i=l;i<r&&out;i++)
    {
    	for(ll j=i+1;j<=r&&out;j++)
    	out=min(out,(i%2019*j%2019)%2019);
	}
	cout<<out;
   
	
	
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>

#define MAX 10001
#define YES 1
#define NO  0

using namespace std;

bool CheckDownShelves(int sub, int N, int yn[][MAX]){
	for(int i = sub + 1; i <= N+1; ++i){
		if( yn[1][i] == YES )
			return true;
	}
	return false;
}

int main(void){
	int T;
	cin >> T;

	for(int P = 0; P < T; ++P){
		int cost = 0;
		int main_passage = 0;
		int yn[2][MAX] = {{NO,},};
		
		string in;
		int N;

		cin >> N;
		cin >> in;

		for(unsigned int i = 1; i <= in.length(); ++i){
			if( in[i-1] == 'Y' ){
				if( i <= 2*N ){
					yn[0][(int)floor(double(i)/2)+1] = YES;
				}else{
					int t = i-2*N;
					yn[1][(int)floor(double(t)/2)+1] = YES;
				}
			}
		}

		for(int i = 1; i <= N; ++i){
			if( yn[0][i] == YES && yn[1][i] == NO ){
				if( !CheckDownShelves( i, N, yn ) )
					main_passage = 0;
				else
					main_passage = 1;
				cost += 1;
			}
			if( yn[0][i] == NO && yn[1][i] == YES ){
				if( main_passage == 0 ){
					main_passage = 1;
					cost += 2;
				}else{
					cost += 1;
				}
			}
			if( yn[0][i] == YES && yn[1][i] == YES ){
				if( main_passage == 0 ){
					if( !CheckDownShelves( i, N, yn ) )
						cost += 3;
					else{
						cost += 2;
						main_passage = 1;
					}
				}else{
					cost += 2;
					if( !CheckDownShelves( i, N, yn ) )
						main_passage = 0;
				}
			}
			cost += 1;
		}
		if( main_passage == 0 ){
			if( yn[0][N+1] == YES )
				cost += 1;
			if( yn[1][N+1] == YES )
				cost += 3;
		}
		if( main_passage == 1 ){
			if( yn[1][N+1] == YES )
				cost += 2;
			else
				cost += 1;
		}

		cout << cost << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
int a[3],ans;
int main(){
	int t;
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	for(int i=0;i<=2;i++)
		for(int j=i;j<=2;j++)
			if(a[i]<a[j]){
				t=a[i];
				a[i]=a[j];
				a[j]=t;
			}
	ans=a[0]*10+a[1]+a[2];
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long ull;
typedef long long ll;

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

using namespace std;

typedef pair<int ,int > P;

int a1,a2,a3,a4;
int b1,b2,b3,b4;
vector<int> a,b;

int main()
{
	while(cin>>a1>>a2>>a3>>a4>>b1>>b2>>b3>>b4)
	{
		int hit=0,blow=0;
		if(a1==b1)
			hit++;
		if(a2==b2)
			hit++;
		if(a3==b3)
			hit++;
		if(a4==b4)
			hit++;
		
		if(a1==b2||a1==b3||a1==b4)
			blow++;
		if(a2==b1||a2==b3||a2==b4)
			blow++;
		if(a3==b2||a3==b1||a3==b4)
			blow++;
		if(a4==b2||a4==b3||a4==b1)
			blow++;

		cout<<hit<<" "<<blow<<endl;
	}
	


	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<map>
using namespace std;
typedef pair<int, pair<int, int> >PP;
typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec;
int inf=-1;
ll mod = pow(10, 9) + 7;
 
int main(){
    int n;cin>>n;
    int d[55];
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    int sum=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            sum+=d[i]*d[j];
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <functional>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main(){
    int n;
    cin >> n;

    vector<int> fiv;
    for(int i = 2;i <= 55555;i++){
        bool flag = true;
        for(int j = 2;j * j <= i;j++){
            if(i % j == 0)flag = false;
        }
        if(flag){
            if(i % 5 == 4)fiv.push_back(i);
        }
    }

    for(int i = 0;i < n;i++){
        cout << fiv[i];
        if(i != n-1)cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 256
object Main {
  def main(args:Array[String]):Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val list = List.fill(n)(sc.nextLong)
    println(list.foldLeft(list.min)(gcd))
  }

  def gcd(a:Long,b:Long):Long = {
    if(b > a) gcd(b,a) else if(b == 0) a else gcd(b, a%b)
  }
}

Measured memory_bytes: 60320