akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int N = sc.nextInt();
      int AC=0,WA=0,TLE=0,RE=0;
      for(int i=1;i<N+2;i++){
      	String S = sc.nextLine();
        if(S.equals("AC")){
        	AC++;
          	continue;
        }else if(S.equals("WA")){
        	WA++;
          continue;
        }else if(S.equals("TLE")){
        	TLE++;
          continue;
        }else if(S.equals("RE")){
        	RE++;
          continue;
        }
      }
      System.out.println("AC x "+AC);
      System.out.println("WA x "+WA);
      System.out.println("TLE x "+TLE);
      System.out.println("RE x "+RE);
    }
}

Measured memory_bytes: 50980
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n; cin >> n;
    vector<int> l(2*n);
    rep(i, 2*n) cin >> l[i];
    sort(all(l));

    int sum = 0;
    rep(i, n) {
        sum += min(l[2*i], l[2*i+1]);
    }
    cout << sum << endl;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

    string S;
    cin >> S;

    int Q;
    cin >> Q;

    int T, F;
    string C;

    bool rev = false;

    string front, back;

    REP(i,Q){
        cin >> T;
        if(T == 1){
            rev = !rev;
        }
        else{
            cin >> F >> C;
            if(!rev){
                if(F == 1){
                    front += C;
                }
                else{
                    back += C;
                }
            }
            else{
                if(F == 1){
                    back += C;
                }
                else{
                    front += C;
                }
            }
        }
    }

    string ans;
    if(rev){
        reverse(S.begin(),S.end());
        reverse(back.begin(), back.end());
        ans += back;
        ans += S;
        ans += front;
    }
    else{
        reverse(front.begin(),front.end());
        ans += front;
        ans += S;
        ans += back;
    }
    cout << ans << "\n";

return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

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

  int N, R;
  cin >> N >> R;

  if (N >= 10) {
    cout << R << endl;
  } else {
    cout << R + 1000 - 100 * N << endl;
  }

  return 0;
};


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



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    ll x;
//    x=1ll << 59;
//    ll y=(1ll << 59) - 1ll;
//    cout<<((double)(x)==(double)(x-1))<<endl;
    ll n;
    cin>>n;
    ll t[n+1],x[n+1],y[n+1];t[0]=0,x[0]=0,y[0]=0;ll d=0;
    for(int i=1;i<=n;i++){
        cin>>t[i]>>x[i]>>y[i];
        ll a=t[i]-t[i-1],b=abs(x[i]-x[i-1]),c=abs(y[i]-y[i-1]);
        if(b+c==a);
        else if(a>(b+c)&& (a-b-c)%2==0);
        else{
            d=2;break;
        }
    }
    if(d==2)cout<<"No";
    else cout<<"Yes";
}


Measured memory_bytes: 5952
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, a[100010];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	ll s = 0;
	for (int i = 0; i < n; i++)
		s += (i & 1 ? -a[i] : a[i]);
	for (int i = 0; i < n; i++) {
		printf("%lld\n", s);
		s = -s + a[i] * 2;
	}
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef map<string, int> msi;
typedef pair<int, int> PII;

int main() {
    double a, b, h , m; cin >> a >> b >> h >> m;
    h = h * 60;
    double angle_h = (h + m) * 0.5;
    double angle = angle_h-m*6;
    if(angle > 180) angle = 180 - (angle-180);
    printf("%.10lf", pow(a*a + b*b - 2*a*b*cos(angle * 3.1415926535897932384/180),0.5));
    return 0;
}

Measured memory_bytes: 4352
let () =
  let n, k = Scanf.scanf "%d %d\n" (fun n k -> n, k) in
  let s = Scanf.scanf "%s\n" (fun s -> s) in
  let tmp = ref "" in
  for i = 0 to n - 1 do
    if i = k - 1 then tmp := !tmp ^ (String.sub s i 1 |> String.lowercase)
    else tmp := !tmp ^ (String.sub s i 1)
  done;
  !tmp |> print_string

Measured memory_bytes: 384
n = int(input())
h = list(map(int, input().split()))
dp = [10 ** 18 for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]),
                dp[i-2] + abs(h[i] - h[i-2]))
print(dp[-1])


Measured memory_bytes: 13976
#include<bits/stdc++.h>
#define ll long long
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl;
#define mod 1000000007
using namespace std;
int n;
int vis[100005];
ll memo[100005][2];
vector<int>e[100005];
ll dp(int src,int col)
{
    //watch(src)
    //watch(col)
    int Size=e[src].size();
    //watch(Size)
    if(memo[src][col]!=-1)
    {
        //printf("memo\n");
        return memo[src][col];
    }
    if(Size==1&&src!=1)
    {
        //printf("return 1\n");
        return 1;
    }
    ll way_node=1;
    for(int i=0;i<Size;++i)
    {
        int v=e[src][i];
        //watch(v)
        ll w,b=0;
        if(!vis[v])
        {
            vis[v]=1;
            w=dp(v,0);
            //watch(w)
            if(!col)
            {
                b=dp(v,1);
                //watch(b)
            }
            vis[v]=0;
            ll way_1_child=(w+b)%mod;
            //watch(way_1_child)
            way_node=(way_node*way_1_child)%mod;
            //watch(way_node)
        }
    }
    return memo[src][col]=way_node;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n-1;++i)
    {
        int n1,n2;
        scanf("%d%d",&n1,&n2);
        e[n1].push_back(n2);
        e[n2].push_back(n1);
    }
    memset(memo,-1,sizeof memo);
    vis[1]=1;
    ll ans=dp(1,0);
    memset(memo,-1,sizeof memo);
    memset(vis,0,sizeof vis);
    vis[1]=1;
    ans=(ans+dp(1,1))%mod;
    printf("%lld",ans);
    return 0;
}




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

void solve(std::vector<long long> x)
{
    for (int i = 0; i < 5; i++)
    {
        if (x[i] == 0)
        {
            cout << i + 1 << endl;
        }
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    std::vector<long long> x(5);
    for (int i = 0; i < 5; i++)
    {
        scanf("%lld", &x[i]);
    }
    solve(std::move(x));
    return 0;
}


Measured memory_bytes: 3692
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=305;
const int mod=998244353;
int n,m;
int a[maxn][maxn],pw[maxn*2];

int gauss(){
	int r=1,res=0;
	REP(i,m){
		int j=r;
		while(j<=n&&!a[j][i])j++;
		if(j>n){
			res++;
			continue;
		}
		if(j!=r){
			REP(k,m)swap(a[j][k],a[r][k]);
		}
		for(int j=r+1;j<=n;j++)if(a[j][i]){
			for(int k=i;k<=m;k++)a[j][k]^=a[r][k];
		}
		r++;
	}
	return res;
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	pw[0]=1;
	REP(i,n+m)pw[i]=2LL*pw[i-1]%mod;
	REP(i,n)REP(j,m)scanf("%d",&a[i][j]);
	int ans=(pw[n+m-1]-pw[n+gauss()-1]+mod)%mod;
	printf("%d\n",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


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

using namespace std;

typedef long long ll;

int solve(){
    ll n, i, minn = 1010000000000000, sum;
    cin >> n;
    vector <ll> vec(n);
    for(auto &i : vec){
        cin >> i;
    }
    sort(vec.begin(), vec.end());
    for(i = vec[0]; i <= vec[n - 1]; i++){
        sum = 0;
        for(auto j : vec){
            sum += ((i - j) * (i - j));
        }
        minn = min(sum, minn);
    }
    cout << minn << "\n";
    return 0;
 }

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];
	static int ans = 0;
	static long n = 0;




	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] even = new int[n/2];
		int[] odd = new int[n/2];
		for(int i = 0;i < n/2;i++){
			even[i] = sc.nextInt();
			odd[i] = sc.nextInt();
		}
		int[] edata = new int[100001];
		int[] odata = new int[100001];
		for(int i = 0;i < n/2;i++){				//頻度チェック
			edata[even[i]]++;
			odata[odd[i]]++;
		}
		
		int feven = 0;			//偶数番目の中での最頻数
		int seven = 0;			//偶数番目の中での2番目の頻数
		int max = 0;
		for(int i = 0;i <= 100000;i++){
			if(max <= edata[i]){
				seven = feven;
				feven = i;
				max = edata[i];
			}
//			if(edata[seven] <= edata[i]){
//				seven = i;
//			}
		}
		max = 0;
		for(int i = 0;i <= 100000;i++){
			if(max <= edata[i] && i != feven){
				seven = i;
				max = edata[i];
			}
		}
		
		int fodd = 0;			//偶数番目の中での最頻数
		int sodd = 0;			//偶数番目の中での2番目の頻数
		max = 0;
		for(int i = 1;i <= 100000;i++){
			if(max <= odata[i]){
				sodd = fodd;
				fodd = i;
				max = odata[i];
			}
//			if(odata[sodd] <= odata[i]){
//				sodd = i;
//			}
		}
		max = 0;
		for(int i = 0;i <= 100000;i++){
			if(max <= odata[i] && i != fodd){
				sodd = i;
				max = odata[i];
			}
		}
		
		if(feven != fodd){
			int count = 0;
			for(int i = 0;i < n/2;i++){
				if(even[i] != feven){
					count++;
				}
			}
			for(int i = 0;i < n/2;i++){
				if(odd[i] != fodd){
					count++;
				}
			}
			System.out.println(count);
			return;
			
			
		}else{
			int count1 = 0;
			int count2 = 0;
			for(int i = 0;i < n/2;i++){
				if(even[i] != feven){
					count1++;
				}
				if(odd[i] != sodd){
					count1++;
				}
			}
			for(int i = 0;i < n/2;i++){
				if(even[i] != seven){
					count2++;
				}
				if(odd[i] != fodd){
					count2++;
				}
			}
			int ans = Math.min(count1, count2);
			System.out.println(ans);
			
			
		}
		
		
		
	}
}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



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

 using namespace std;
 
 #define inf (INT_MAX)
 #define ninf (INT_MIN)
 #define inf64 ((1<<63)-1)
 #define ll long long
 #define mpr make_pair
 #define mtp make_tuple
 #define pb emplace_back
 #define rep(i,n) for(int i=0;i<(int)(n);i++)

 #define _tab '\t'
 #define $ <<_tab<<

 #define cinarr(A,len) for(int i=0;i<len;i++){cin>>A[i];}
 #define coutarr(A,len) for(int i=0;i<len;i++){cout<<A[i]<<' ';}cout<<endl
 #define coutin(V) for(auto& i : V){cout << i << ' ';}cout<<endl // for vect and set
 #define coutmap(U) for(auto& i : U){cout << i.first << "->" << i.second << ", ";}cout<<endl // for map

 // DEBUG
 #define deb(x) cout << #x << '\t' << x << endl

 // ==== fast function ====
 /*
 #define sortsec(T1,T2) [](const pair<T1,T2> &a,const pair<T1,T2> &b){ return a.second<b.second;}
 #define sortsecgreater(T1,T2) [](const pair<T1,T2> &a,const pair<T1,T2> &b){ return a.second>b.second;}
 */
 //ll middle3(ll a,ll b,ll c){if(a>b){if(b>c){return b;}else if(a>c){return c;}else{return a;}}else{if(a>c){return a;}else if(b>c){return c;}else{return b;}}}

/*========================================================================*/
/* strategi/note:



/================================*/



bool solved=0;
void solve(){solved=1;
    int n,x,t;
    cin >> n >> x >> t;
    // ceil(n/x)*t
    cout << ( ((n+x-1)/x)*t ) << endl;
}

int main(){
     ios_base::sync_with_stdio(0);
     cin.tie(0);
     //cout<<fixed<<setprecision( ); // iomanip **

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

     if(!solved)cout<<"solve() function blm dipanggil!"<<endl;
	 //cout.flush(); cin.get();
     return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
const int MAX=1e6+10;
const int modn=1e9+7;
typedef long long ll ;
#define int ll
#define endl '\n'
#define cwk     freopen("D:\\workplace\\CLion\\in.in","r",stdin),freopen("D:\\workplace\\CLion\\out.out","w",stdout)
using namespace std;
int n,m,d,t,s;
string p,q;
int a[MAX],b[MAX];
void solve(){
    cin>>d>>t>>s;
    if(t*s>=d) cout<<"Yes\n";
    else cout<<"No\n";
}
signed main() {
    //ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    //cwk;
    int _=1;
    //cin>>_;
    while(_--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3676
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        char[][] s = new char[h][w];
        for (int i = 0; i < h; i++) {
            s[i] = sc.next().toCharArray();
        }
        sc.close();

        // 主処理
        int[] pointX = new int[] { 0, 0, -1, 1 }; // 上下左右
        int[] pointY = new int[] { 1, -1, 0, 0 };

        boolean judge = true;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int x = j;
                int y = i;
                if (s[y][x] == '#') {
                    boolean isLink = false;
                    for (int k = 0; k < 4; k++) {
                        int targetX = x + pointX[k];
                        int targetY = y + pointY[k];
                        if (0 <= targetX && 0 <= targetY && targetX < w && targetY < h) {
                            if (s[targetY][targetX] == '#') {
                                isLink = true;
                                break;
                            }
                        }
                    }
                    if (!isLink) {
                        judge = false;
                        break;
                    }
                }
            }
        }
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int N = 1e6 + 7, inf = 1e9;
ll ar[123456];
int main()
{
    ll n, m, ac = 0, penalty = 0;
    cin>>n>>m;
    map<ll, ll>mp;
    for(int i = 0; i < m; i++)
    {
        ll x; string ver;
        cin>>x>>ver;
        if(ver == "WA" && mp[x] != -1) mp[ x ]++;
        else if(mp[x] != -1)
        {
            ac++;
            penalty += mp[x];
            mp[x] = -1;
        }
    }
    cout<<ac<<" "<<penalty<<"\n";
    return 0;
}


Measured memory_bytes: 6528
#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
char s[1000005];
int w;
int main()
{
	scanf("%s",s);
	scanf("%d",&w);
	int len=strlen(s);
	for(int i=0;i<len;i+=w)
		printf("%c",s[i]);
}

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


int main() {
    ios::sync_with_stdio(false);

    long long x,y;
    cin >> x >> y;

    int cnt = 0;
    for(long long i=x; i<=y;){
        cnt++;
        i*=2;
    }


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



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

using namespace std;

int main() {
    int x, a, b;
    int expired_days;

    cin >> x >> a >> b;
    expired_days = -a + b;
    if (expired_days <= 0) {
        cout << "delicious" << endl;
    } else if (expired_days <= x) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
b = [int(input()) for _ in range(N)]
 
res = a[1]

for i in range(N):
    for ii in range(0,a[0]):
        if 1 + (b[i] * ii) <= a[0]:
            res += 1
        else:
            break
print(res)


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

using namespace std;
int n,m,mx=INT_MIN,mn=INT_MAX;
int main()
{
    cin>>n>>m;
    for(int i=0,a,b;i<m;i++){
        cin>>a>>b;
        mx=max(mx,a);
        mn=min(mn,b);
    }
    mn=min(mn,n);
    cout<<max(0,mn-mx+1);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double PI = acos(-1);

int main(){
    double a,b;
    cin >> a >> b;
    cout << fixed << setprecision(7);
    cout << PI*b*b*b*4/3 << endl;
    return 0;
}



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

int main(){
  int m,j,b;
  cin >> m>> j>> b;
  if(m >= b){
      cout << 0<<endl;
  }else if(m+j>=b){
      cout << b-m  <<endl;
  }else{
      cout <<"NA" <<endl;
  }
  return 0;
}


Measured memory_bytes: 3080
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        LDeque solver = new LDeque();
        solver.solve(1, in, out);
        out.close();
    }

    static class LDeque {
        long[][] dp;
        boolean[][] used;
        long[] a;

        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            a = new long[n];
            dp = new long[n][n];
            used = new boolean[n][n];

            for (int i = 0; i < n; i++) {
                Arrays.fill(used[i], false);
                a[i] = in.nextLong();
            }

        /*
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                out.println(f(i, j));
            }
        }
        
         */

            out.println(f(0, n - 1));
        }

        long f(int l, int r) {
            if (used[l][r]) {
                return dp[l][r];
            }
            used[l][r] = true;
            if (l == r) return dp[l][r] = a[l];
            return dp[l][r] = Math.max(a[l] - f(l + 1, r),
                    a[r] - f(l, r - 1));
        }

    }
}



Measured memory_bytes: 130984
/*
    _____
  .'|||||'.
 /  >   <  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
    |||||
*/

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
#define REP(i,r,n) for(int i=r;i<=n;i++)
#define RREP(i,n,r) for(int i=n;i>=r;i--)
int n,a[200010];
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    multiset<int,greater<int>> s;
    for (int i=1;i<=n;i++)
    {
        multiset<int>::iterator it=s.upper_bound(a[i]);
        if (it!=s.end()) s.erase(it);
        s.insert(a[i]);
    }
    printf("%d\n",s.size());
    return(0);
}


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

int main(){
  int64_t n;
  cin >> n;
  int64_t ans = 0,m = 1;
  while(n!=0){
    n/=2;
    ans+=m;
    m*=2;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	long long a, b, c, k; cin >> a >> b >> c >> k;
	if(k % 2 == 0) cout << a - b << endl;
	else cout << b - a << endl;
	 
	
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    cout << a[n - 1] - a[0] << endl;
}

Measured memory_bytes: 256
S = list(str(input()))
atgc = ["A","T","G","C"]
cout = 0
a = [0]
for i in range(len(S)):
    if S[i] in atgc:
        cout+=1
    else: 
        if cout>0:
            a.append(cout)
            cout = 0
a.append(cout)
ans = max(a)
print(ans)

        

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

int main(void){
    
   int N,M,X,Y,l,r;
   cin >> N >> M >> X >> Y;
   int data_X[N];
   int data_Y[M];
   
   for(int i=0;i<N;i++) cin >> data_X[i];
   for(int i=0;i<M;i++) cin >> data_Y[i];
   
   sort(data_X,data_X+N,greater<int>());
   sort(data_Y,data_Y+M);
   
   l = data_X[0];
   r = data_Y[0];
   
   for(int i=l+1;i<=r;i++){
       if(X < i && i <= Y){
           cout << "No War" << endl;
           return 0;
       }
   }
   
   cout << "War" << endl;
}

Measured memory_bytes: 3628
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (a, b) = listOfInt()
    val ss = next()

    ss.forEachIndexed { index, c ->
        if (index == a && c != '-') {
            println("No")
            return
        }

        if (index != a && !('0'..'9').contains(c)) {
            println("No")
            return
        }
    }

    println("Yes")
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37864
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

string a, b, c;

int main() {
	cin >> a >> b >> c;
	cout << ((a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[2020][2020];
const ll mod=1e9+7;
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
	printf("%d\n",a/(2*b+1)+(a%(2*b+1)!=0));
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i, n) cin >> vec.at(i);
    bool clear = true;
    int p = 1;
    int count = 0;
    while (p != 2)
    {
        p = vec.at(p-1);
        count++;
        if (count > n*2) {
            clear = false;
            break;
        }
    }
    if (clear == false) cout << -1 << endl;
    else cout << count << endl;
    return 0;
}

Measured memory_bytes: 3788
/*{{{*/
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define mset(x,c) memset(x, c, sizeof(x))
#define mem0(x) mset(x,0)
#define mem1(x) mset(x,-1)
#define memc(x,y) memcpy(x, y, sizeof(x));
#define P(a,n) FOR(_,0,n) _W(a),printf("%c", " \n"[_==n-1])
#define print(a,n) cout << #a << " = ";FOR(_,0,n) _W(a),printf("%c", " \n"[_==n-1])
using namespace std;

template<class T> void _R(T &x) { cin >> x; }
void _R(signed &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const signed &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.fi); putchar(' '); _W(x.se);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef LOCAL
 #define debug(...) {printf(" [" #__VA_ARGS__ "]: ");W(__VA_ARGS__);}
#else
 #define debug(...)
#endif

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
/*}}}*/
//#define int long long

signed main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	string s, t;
	R(s, t);
	int ans = t.size();
	FOR(i,0,s.size()-t.size()+1) {
		int cnt = 0;
		FOR(j,0,t.size()) {
			if (t[j] != s[i+j]) cnt++;
		}
		ans = min(ans, cnt);
	}
	W(ans);
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
   int n;
   cin >> n;
   int num;
      if(n>=100000){
        num= 90909;
        cout << num << endl;}
      else if (n>=10000 && n<=99999)
      { num = n -9090;
      cout << num << endl; }
      else if (n>=1000 && n<=9999)
      {num =909;
       cout << num << endl;}
      else if (n>=100 && n<=999){
      num = n-90;
      cout << num << endl;}
      else if (n>=10 && n<=99)
      {num = 9;
       cout << num << endl;}
      else if (n<=9){
         num = n;
      cout <<num << endl;}
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int D,T,S;
  cin>>D>>T>>S;
  cout<<(S*T>=D?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 3632
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

res = [0]*N
hands = ["r", "s", "p"]

for i in range(N):
    res[i] = hands[hands.index(T[i])-1]

for i in range(N):
    if i >= K and res[i-K] == res[i]:
        res[i] = 0

score = R*res.count("r") + S*res.count("s") + P*res.count("p")
print(score)

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

//INSERT ABOVE HERE
Int n,ans=0;
void dfs(Int x,Int a,Int b,Int c){
  if(x>n) return; 
  if(a&&b&&c) ans++;
  dfs(x*10+3,1,b,c);
  dfs(x*10+5,a,1,c);
  dfs(x*10+7,a,b,1);
}
signed main(){
  cin>>n;
  dfs(0,0,0,0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<string>

using namespace std;
int main()
{
	int n;

	cin >> n;

	vector<int>a(n);
	vector<int>b(n-1);


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

	for (int i = 0; i < n-1; i++) {
		if (a[i] < a[i + 1]) {
			b[i] = 0;
		}
		else if (a[i] == a[i + 1]) {
			b[i] = 1;
		}
		else {
			b[i] = 2;
		}
	}
	bool state = 0;
	long long syoji = 1000;
	int kabu = 0;
	for (int i = 0; i < n-1; i++) {
		if (a[i]<a[i+1]) {
			
				syoji += (a[i + 1] - a[i]) * (syoji / a[i]);
			
		}


	}



	//for (int i = 0; i < n-1; i++) {
	//	cout << b[i] << endl;
	//}

	cout << syoji << endl;
	return 0;

}



Measured memory_bytes: 3548
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n, q, a, b, c;
    long long sum = 0;
    vector<int> A(100001, 0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a);
        A[a]++;
        sum += a;
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        scanf("%d%d", &b, &c);
        sum = sum + A[b]*(c-b);
        A[c] += A[b];
        A[b]  = 0;
        printf("%lld\n", sum);
    }
    
    return 0;
}

Measured memory_bytes: 3776
H,W=map(int,input().split())
G=[list(input()) for i in range(H)]
allwhite=['.']*W
tmp=[]
for i in range(H):
    if G[i]!=allwhite:
        tmp.append(G[i])
G=tmp
ans=["" for i in range(len(G))]
for j in range(W):
    p=False
    for i in range(len(G)):
        if G[i][j]=='#':
            p=True
            break
    if p:
        for i in range(len(G)):
            ans[i]+=G[i][j]
print(*ans,sep='\n')


Measured memory_bytes: 9164
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main()
{
    double r; 
    cin >> r;
    printf("%.5f %.5f\n", M_PI*r*r, 2*M_PI*r);
    //cout << M_PI * r * r << " " << 2 * M_PI * r << endl;
    return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

vector<int> toporogical_sort(const vector<vector<int> > g){
	const int n = g.size();
	vector<int> in_deg(n,0);

	for(int i = 0; i < n; i++){
		for(int j = 0; j < g[i].size(); j++){
			in_deg[g[i][j]]++;
		}
	}
	
	stack<int> S;
	for(int i = 0; i < n; i++){
		if(in_deg[i]==0) S.push(i);
	}

	vector<int> res;
	while(!S.empty()){
		int x = S.top();S.pop();
		res.push_back(x);
		for(int i = 0; i < g[x].size(); i++){
			in_deg[g[x][i]]--;
			if(in_deg[g[x][i]] == 0) S.push(g[x][i]);
		}
	}

	return res;
}


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

	vector<int> t_sorted = toporogical_sort(g);
	vector<int> dp(n,0);

	for(int i = 0; i < n; i++){
		for(int j = 0; j < g[t_sorted[i]].size(); j++){
			int x = g[t_sorted[i]][j];
			dp[x] = max(dp[x],dp[t_sorted[i]]+1);
		}
	}

	int ans = 0;
	for(int i = 0; i < n; i++){
		ans = max(ans,dp[i]);
	}
	cout << ans << endl;



	return 0;
}

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

string dfs(int n){
	if( n == 0 ) return "";
	if ( n % 3 == 2 ){
		return dfs((n+2)/3) + "-";
	}else if( n % 3 == 1 ){
		return dfs(n/3) + "+";
	}else if( n % 3 == 0 ){
		return dfs(n/3) + "0";
	}
	
}
int main(){
	int n;
	cin >> n;
	cout << dfs(n) << endl;

}

Measured memory_bytes: 3160
#include <iostream>
#include <vector>
 
using namespace std;
using ll = long long;
 
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for(int i = 0; i < N; i++) cin >> A[i];
 
  ll prod = 1e18;
  ll ans = 1;
  for(int i = 0; i < N; i++) {
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    prod /= A[i];
    ans *= A[i];
  }
  
  if (prod == 0) {
    cout << -1 << endl;
    return 0;
  }
  
  cout << ans << endl;
  
  
  
  return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 55;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

ll a[55];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    ll k;
    cin >> k;
    ll g = k / 50;
    ll y = g + 49;

    int h = k - (y - 49) * 50;
    FOR(i,1,50) a[i] = y;
    FOR(i,1,h) {
        a[i] += 50;
        FOR(j,1,50)
            if (j != i) a[j]--;
    }
    cout << 50 << endl;
    FOR(i,1,50) cout << a[i] << ' ';
    return 0;
}

Measured memory_bytes: 256
// g++ -std=gnu++1y -O2 main.cpp

#include <cassert>
#include <cstdio>
#include <vector>
#include <set>

#include <map>
#include <unordered_map>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

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; }

const int INF = 1e9;
const long long LINF = 1e18;

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

	int p1 = N % 10;
	N /= 10;
	int p2 = N % 10;
	N /= 10;
	int p3 = N % 10;
	
	if (p1 == 7 || p2 == 7 || p3 == 7) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

using int64 = long long;

void calc_sum(string S, vector<int64> &store, vector<int64> &right_num_store,
              int64 current_keta, int64 keta) {
  if (current_keta == keta - 1) {
    return;
  }
  char next_num_char = S[current_keta + 1];
  int64 next_num = next_num_char - '0';
  vector<int64> store_copy = store;
  vector<int64> right_num_store_copy = right_num_store;
  // + を入れない場合
  transform(store_copy.begin(), store_copy.end(), right_num_store_copy.begin(),
            store_copy.begin(), minus<int64>());
  for (int64 &x : right_num_store_copy) {
    x = x * 10 + next_num;
  }
  transform(store_copy.begin(), store_copy.end(), right_num_store_copy.begin(),
            store_copy.begin(), plus<int64>());
  // + を入れる場合
  for (int64 &x : store) {
    x += next_num;
  }
  for (int64 &x : right_num_store) {
    x = next_num;
  }
  store.insert(store.end(), store_copy.begin(), store_copy.end());
  right_num_store.insert(right_num_store.end(), right_num_store_copy.begin(),
                         right_num_store_copy.end());
  current_keta++;
  calc_sum(S, store, right_num_store, current_keta, keta);
}

int main() {
  string S;
  cin >> S;
  int64 keta = S.size();
  int64 first_keta = S[0] - '0';
  vector<int64> store = {first_keta};
  vector<int64> right_num_store = {first_keta};
  calc_sum(S, store, right_num_store, 0, keta);
  cout << accumulate(store.begin(), store.end(), 0LL) << endl;
  return 0;
}

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

int main(){
  double a, b, c, s, l, h, rad, pi;
  pi = acos(-1.0);
  scanf("%lf %lf %lf", &a, &b, &c);
  rad = c * (pi / 180.0);
  s = 0.5 * a * b * sin(rad);
  l = a + b + sqrt(a * a + b * b - 2 * a * b* cos(rad));
  h = b * sin(rad);

  printf("%.10lf\n%.10lf\n%.10lf\n", s, l, h);

  return 0;
}


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

int main(void){
    int n, ans=0;
    scanf("%d", &n);
    int a[n];
    for(int i=0; i<n; i++){
        scanf("%d", &a[i]);
        ans += a[i];
    }
    printf("%d", ans-n);
}


Measured memory_bytes: 256
($D,$G)=glob<>;
($p[@p],$c[@c])=glob for<>;
$m=1e3;
for$b(0..2**$D-1){
	$x=0;
	$n=0;
	for(0..$D-1){
		if($b>>$_&1){
			$x+=($_+1)*100*$p[$_]+$c[$_];
			$n+=$p[$_]
		}
	}
	for$i(reverse 0..$D-1){
		if($b>>$i&1^1){
			for(1..$p[$i]){
				if($x<$G){
					$x+=($i+1)*100;
					++$n
				}
			}
		}
	}
	$m-=$-=$m-$n
}
print$m


Measured memory_bytes: 768
N,C =map(int,input().split())
chan=[[] for i in range(C)]
for i in range(N):
    a,b,c=map(int,input().split())
    chan[c-1].append([a,b])
for i in range(C):
    chan[i].sort()
imos=[0]*(10**5+2)
for i in range(C):
    if len(chan[i])==0:
        continue
    imos[chan[i][0][0]]+=1
    imos[chan[i][0][1]+1]-=1
    for k in range(1,len(chan[i])):
        if chan[i][k][0]==chan[i][k-1][1]:
            imos[chan[i][k][0]+1]+=1
            imos[chan[i][k][1]+1]-=1
        else:
            imos[chan[i][k][0]]+=1
            imos[chan[i][k][1]+1]-=1

for i in range(1,10**5+2):
     imos[i] +=imos[i-1]  
print(max(imos))

Measured memory_bytes: 20724
N = int(input())
dp = [10**20]*(N+10)
dp[0] = 0
for i in range(N+10):
    k = 0
    j = 1
    while i-6**k >= 0:
        dp[i] = min(dp[i-6**k]+1,dp[i])
        k += 1
    while i-9**j >= 0:
        dp[i] = min(dp[i-9**j]+1,dp[i])
        j += 1
print(dp[N])

Measured memory_bytes: 3828
#include<stdio.h>

int Q[1000000],head=0,tail=0;

void enqueue(int x){
  Q[tail]=x;
  tail++;
}

int dequeue(){
  int x;
  x= Q[head];
  head++;
  
  return x;
}


  
  

int main() {


  int x,i,j,n,q,sum_time=0;

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

  char c[n][10];
  int time[n];

  

  for(i=0;i<n;i++){
    scanf("%s%d",c[i],&time[i]);
    enqueue(i);
  }

  while(head!=tail){
    x=dequeue();
    if(q<time[x]){
      sum_time+=q;
      time[x] = time[x]-q;
      enqueue(x);
    }
    else{
      sum_time+=time[x];
      printf("%s %d\n",c[x],sum_time);
    }
  }

  return 0;
}
    
    
  
  
  



Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 998244353
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

const int MAX=510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        //???
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    COMinit();
    
    ll n,a,b,k;cin>>n>>a>>b>>k;
    ll ans=0;
    for(ll i=0;i<=n;i++){
        ll rem=k-a*i;
        if(rem<0) break;
        if(rem%b) continue;
        ll j=rem/b;
        if(j>n) continue;
        // ans+=(nCi)*(nCj)
        ans=(ans+COM(n,i)*COM(n,j)%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;

int main() {
    int N, cop;
    cin >> N;
    set<int> T;
    bool S = true;

    for (int i = 0; i < N; i++){
        int a;
        cin >> a;
        if (i == 0){
            cop = a;
        }
        else {
            cop = __gcd(a, cop);
        }
        if (S){
            for (int j = 2; j * j <= a; j++){
                if (a % j == 0){
                    if (T.count(j)){
                        S = false;
                    }
                    else{
                        T.insert(j);
                    }
                }
                while(a % j == 0){
                    a /= j;
                }
            }
            if (a != 1){
                if (T.count(a)){
                    S = false;
                }
                else{
                    T.insert(a);
                }
            }
        }
    }
    if (S){
        cout << "pairwise coprime" << endl;
    }
    else if (cop == 1){
        cout << "setwise coprime" << endl;
    }
    else {
        cout << "not coprime" << endl;
    }
}

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

int main(){
  int N;
  while(cin >> N, N){
    string str;
    cin >> str;

    int ba = 0;
    vector< int > people( N, 0);
    int player = 0;

    for(int i = 0; i < str.size(); i++, player = (player + 1) % N){
      ++people[player];
      char& c = str.at(i);
      switch(c){
      case 'S':
        ba += people[player];
        people[player] = 0;
        break;
      case 'L':
        people[player] += ba;
        ba = 0;
        break;
      }
    }
    sort(people.begin(), people.end());
    for(__typeof people.begin() it = people.begin(); it != people.end(); it++){
      cout << *it << " ";
    }
    cout << ba << endl;
  }
}

Measured memory_bytes: 1228
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
// #include 
using namespace std;

void solve()
{
    string sa, sb, sc; cin >> sa >> sb >> sc;
    int ca, cb, cc;
    ca = sa.size();
    cb = sb.size();
    cc = sc.size();
    int turn = 0;
    while(1){
        switch(turn){
            case 0:
                if(!ca) {
                    cout << "A" << endl;return;
                }
                turn = sa[0]-'a';
                sa.erase(0, 1);
                break;
            case 1:
                if(!cb) {
                    cout << "B" << endl;return;
                }
                turn = sb[0]-'a';
                sb.erase(0,1);
                break;
            case 2:
                if(!cc) {
                    cout << "C" << endl;return;
                }
                turn = sc[0]-'a';
                sc.erase(0,1);
                break;
            default: 
                cout  << "Error" <<endl;
        }
        ca = sa.size();
        cb = sb.size();
        cc = sc.size();
    }
}

int main()
{
    solve();
    return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

ll a,b,c;
int main(){
    cin >> a >> b >> c;
    ll d = c - a - b;
    if(d > 0 and 4 * a * b < d * d){
        cout << "Yes" << endl;
    }else cout << "No" << endl;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
vec_a = []
vec_b = []

n.times do
  vec_a << gets.split.map(&:to_i)
end

m.times do
  vec_b << gets.to_i
end

vec_c = Array.new(n, 0)

n.times do |i|
  m.times do |j|
    vec_c[i] += vec_a[i][j] * vec_b[j]
  end
end

vec_c.each do |c|
  p c
end



Measured memory_bytes: 6980
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int R;
    cin >> R;
    if (R < 1200) cout << "ABC" << endl;
    else if (R < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    
    return 0;
}

Measured memory_bytes: 256
///------------------  CODE FOR FUN -------------------
#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i = j; i <= k; i ++)
#define FORD(i,j,k) for(int i = j; i >= k; i --)
#define mp make_pair
#define f first
#define s second
//#define int long long
using namespace std;

const int MOD=1e9+7;
const int N = 200005;
int n;
int a[N], res = 0;
bool d[N * 10];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    #define task""
//    freopen(task".inp","r",stdin);
//    freopen(task".out","w",stdout);
    cin >> n;
    FOR(i, 1 ,n)
    {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    a[n + 1] = 0;
    FOR(i, 1, n)
    {
        if(d[a[i]] == 0)
        {
           if(a[i] != a[i + 1]) res ++;
           for(int x = a[i]; x <= a[n]; x += a[i]) d[x] = 1;
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 5316