akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  int A[N], B[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 1; i < N; i += 2) swap(A[i], B[i]);
  const int INF = INT_MAX / 10;
  int ans = INF;
  int r = (N + 1) / 2;
  vector<bool> v(N, false);
  fill(v.end() - r, v.end(), true);
  do {
    pair<int, int> even[r], odd[N - r];
    int ei = 0, oi = 0;
    for (int i = 0; i < N; i++) {
      if (v[i]) {
        even[ei++] = {A[i], i};
      } else {
        odd[oi++] = {B[i], i};
      }
    }
    sort(even, even + r);
    sort(odd, odd + N - r);
    bool isok = true;
    for (int i = 0; i + 1 < N; i++) {
      if (i & 1) {
        isok &= odd[i / 2].first <= even[i / 2 + 1].first;
      } else {
        isok &= even[i / 2].first <= odd[i / 2].first;
      }
    }
    if (isok) {
      int tmp = 0;
      int ord[N];
      for (int i = 0; i < N; i++) {
        if (i & 1) {
          ord[odd[i / 2].second] = i;
        } else {
          ord[even[i / 2].second] = i;
        }
      }
      for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++)
          if (ord[i] > ord[j]) tmp++;
      }
      ans = min(ans, tmp);
    }
  } while (next_permutation(v.begin(), v.end()));
  if (ans == INF) ans = -1;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
	int N,a,b,c;
	cin>>N;
	while(N--)
	{
		cin>>a>>b>>c;
		if(a+b>c&&a+c>b&&b+c>a&&a-b<c&&b-c<a&&c-b<a&&a*b*c!=0)
		{
			if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a)
			cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		else cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long LL;

const int maxn=2e5+5;

int n,a[maxn],Q;
bool takai[maxn];

int tr[2][4*maxn];
int tr_cx(int ty,int k,int l,int r,int x)
{
	if (x>n) return 0;
	int re=0;
	while (l<r)
	{
		int t=k<<1, mid=(l+r)>>1;
		if (x<=mid) re=max(re,tr[ty][t+1]), k=t, r=mid;
			else k=t+1, l=mid+1;
	}
	return max(re,tr[ty][k]);
}
void tr_xg(int ty,int k,int l,int r,int x,int z)
{
	if (l==r)
	{
		tr[ty][k]=z;
		return;
	}
	int t=k<<1, mid=(l+r)>>1;
	if (x<=mid) tr_xg(ty,t,l,mid,x,z); else tr_xg(ty,t+1,mid+1,r,x,z);
	tr[ty][k]=max(tr[ty][t],tr[ty][t+1]);
}

bool check(int hx,int hy,int cx,int cy,int ai)
{
	if (ai>hx) hx=ai, cx++;
	int ned=cx-cy+Q;
	if (ned>=0 && (tr_cx(1,1,1,n,hy+1)>=ned || !(ned&1) && tr_cx(0,1,1,n,hy+1)>=ned)) return 1;
	ned=cy-cx+Q;
	if (ned>=0 && (tr_cx(1,1,1,n,hx+1)>=ned || !(ned&1) && tr_cx(0,1,1,n,hx+1)>=ned)) return 1;
	return 0;
}

char ans[maxn];
int main()
{
	// freopen("e.in","r",stdin);
	// freopen("e.out","w",stdout);
	
	scanf("%d",&n);
	int maxa=0;
	fo(i,1,n)
	{
		scanf("%d",&a[i]);
		if (a[i]>maxa)
		{
			takai[i]=1;
			maxa=a[i];
			Q++;
		}
	}
	
	fd(i,n,1)
	{
		int tr0=tr_cx(0,1,1,n,a[i]+1), tr1=tr_cx(1,1,1,n,a[i]+1), f0, f1;
		if (takai[i]) f0=tr0+2, f1=(tr1) ?tr1+2 :0 ;
			else f0=0, f1=max(tr0,tr1)+1;
		tr_xg(0,1,1,n,a[i],f0);
		tr_xg(1,1,1,n,a[i],f1);
	}
	
	int hx=0, hy=0, cx=0, cy=0;
	fo(i,1,n)
	{
		Q-=takai[i];
		tr_xg(0,1,1,n,a[i],0);
		tr_xg(1,1,1,n,a[i],0);
		if (check(hx,hy,cx,cy,a[i]))
		{
			ans[i]='0';
			if (a[i]>hx) hx=a[i], cx++;
		} else if (check(hy,hx,cy,cx,a[i]))
		{
			ans[i]='1';
			if (a[i]>hy) hy=a[i], cy++;
		} else
		{
			puts("-1");
			return 0;
		}
	}
	
	hx=hy=cx=cy=0;
	fo(i,1,n) if (ans[i]=='0')
	{
		if (a[i]>hx) hx=a[i], cx++;
	} else
	{
		if (a[i]>hy) hy=a[i], cy++;
	}
	assert(cx==cy);
	
	printf("%s\n",ans+1);
}

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

int main(){

  double x1,y1,x2,y2,x3,y3;
  double px,py;
  int n;

  cin >> n;

  for(int i=0; i<n; i++){
    cin >> x1>>y1>>x2>>y2>>x3>>y3;
    px = ( (y1-y3)*(y1*y1-y2*y2 + x1*x1-x2*x2)-(y1-y2)*(y1*y1-y3*y3+x1*x1-x3*x3))/(2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));
    py = ( (x1-x3)*(x1*x1-x2*x2 + y1*y1-y2*y2)-(x1-x2)*(x1*x1-x3*x3+y1*y1-y3*y3))/(2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3));
    printf("%.3f %.3f %.3f\n", px,py,sqrt((px-x1)*(px-x1)+(py-y1)*(py-y1)));

  }


  return 0;
}

Measured memory_bytes: 1244
#include "bits/stdc++.h"
using namespace std;

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const long long N = 301 , inf = 100000000000;
long long g[N][N] ,ans[N][N];
bool done[N];

int main()
{
	 #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	int n , m , l ; cin >> n >> m >> l;
    int x , y , z ;
    for(int i = 1 ; i <= n ; ++i)
        for(int j = 1 ; j <= n ; ++j)
            g[i][j] = ans[i][j] = inf ;
    for(int i = 1 ; i <= m ; ++i)
    {
        cin >> x >> y >> z ;
        g[x][y] = g[y][x] = z;
    }
    for(int k = 1 ; k <= n ; ++k)
    	for(int i = 1 ; i <= n ; ++i)
    		for(int j = 1 ; j <= n ; ++j)
    			g[i][j] = min(g[i][j] , g[i][k] + g[k][j]);

    for(int i = 1 ; i <= n ; ++i)
    	for(int j = 1 ; j <= n ; ++j)
    		if(g[i][j] <= l) ans[i][j] = 1;

    for(int k = 1 ; k <= n ; ++k)
    	for(int i = 1 ; i <= n ; ++i)
    		for(int j = 1 ; j <= n ; ++j)
    			ans[i][j] = min(ans[i][j] , ans[i][k] + ans[k][j]);
    int q ; cin >> q ; 
    for(int i = 1 ; i <= q ; ++i)
    {
    	cin >> x >> y ;
    	cout <<(ans[x][y] != inf ? ans[x][y] - 1 : -1) << endl;
    }

	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 998244353
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

vector<ll> suma,sumb;
void pre_process(vector<ll> &a,vector<ll> &s){//累積和のvector
    ll n=(ll)a.size();
    s.assign(n+1,0);
    for(ll i=0;i<n;i++){
        s[i+1]=s[i]+a[i];
    }
}
ll query(ll i,ll j,vector<ll> &s){//区間[i,j]の和
    return (s[j]-s[i]);
}

int main(){
    ll n,m,k;cin>>n>>m>>k;
    vector<ll> a(n),b(m);
    rep(i,n) cin>>a[i];
    rep(i,m) cin>>b[i];

    pre_process(a,suma);
    pre_process(b,sumb);

    ll ans=0,notcho=true;
    rep(i,n+1){
        if(k<suma[i]) break;
        notcho=false;
        vector<long long int>::iterator position;
        position=upper_bound(sumb.begin(),sumb.end(),k-suma[i]);
        ll key=distance(sumb.begin(),position);

        ans=max(i+key,ans);
    }

    rep(i,m+1){
        if(k<sumb[i]) break;
        notcho=false;
        vector<long long int>::iterator position;
        position=upper_bound(suma.begin(),suma.end(),k-sumb[i]);
        ll key=distance(suma.begin(),position);

        ans=max(i+key,ans);
    }

    if(!notcho) cout<<ans-1<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 9536
import java.util.Scanner;
import java.io.*;

// public class Main {
//     public static void main(){
//         System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
//         Scanner sc = new Scanner(System.in);
//     }
// }

/**
 * Main
 */
public class Main {
    /*A Password*/
    public static void main(String[] args){
        //System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        System.out.print(n*n*n);
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String j = scanner.nextLine();
        String[] tmpcards = j.split(" ");
        int[] cards = new int[3];
        for (int i = 0; i < 2; i++){
            cards[i] = Integer.parseInt(tmpcards[i]);
            if (cards[i] == 1)
                cards[i] += 13;
        }
        if (cards[0] == cards[1]){
            System.out.println("Draw");
        } else {
            System.out.println(cards[0] > cards[1]?"Alice":"Bob");
        }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <cstdlib>
#include <algorithm>

#define MAX_DIGIT 80
#define ERROR ("overflow")

int main(void){
	using namespace std;

	int N;
	cin >> N;

	list< pair<string,string> > input;

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

		string slhs, srhs;
		cin >> slhs >> srhs;

		reverse(slhs.begin(), slhs.end());
		reverse(srhs.begin(), srhs.end());

		input.push_back(make_pair(slhs,srhs));

	}

	for(auto p=input.begin(); p!=input.end(); p++){

		auto slhs = p->first, srhs = p->second;
		if(slhs.size()>MAX_DIGIT || srhs.size()>MAX_DIGIT){
			cout << ERROR << endl;
			continue;
		}

		int headDigit = std::max(slhs.size(),srhs.size());
		vector<int> lhs(headDigit), rhs(headDigit);
		list<int> res;

		auto atoi_digit = [] (char x) -> int {
			return atoi(&x);
		};
		transform(slhs.begin(), slhs.end(), lhs.begin(), atoi_digit);
		transform(srhs.begin(), srhs.end(), rhs.begin(), atoi_digit);

		int carry = 0;
		for (auto itr=lhs.begin(); itr!=lhs.end(); itr++){
			int index = itr - lhs.begin();
			auto d = div(lhs[index]+rhs[index]+carry,10);
			carry = d.quot;
			res.push_back(d.rem);
		}

		if(headDigit==MAX_DIGIT && carry !=0){
			cout << ERROR << endl;
		}
		else{
			if (carry!=0){
				res.push_back(carry);
			}
			for(auto itr=res.rbegin(); itr!=res.rend();itr++){
				cout << *itr;
			}
			cout << endl;
		}

	}
}

Measured memory_bytes: 1224
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = (int) 1e6;

int n, a[N], d[N], v[N];
char s[N];
vector <int> q;
vector <int> g[N];

int main() {

	scanf("%s", s);

	int n = strlen(s);
	
	for (int i = 0; i <= n; i++) {
		d[i] = 0;
		v[i] = 0;
	}

	for (int i = 0; i < n; i++) {
		if (s[i] == '<') {
			d[i + 1]++;
			g[i].push_back(i + 1);
		} else if (s[i] == '>') {
			d[i]++;
			g[i + 1].push_back(i);
		}
	}

	n++;

	for (int i = 0; i < n; i++) {
		if (d[i] == 0) {
			v[i] = 0;
			q.push_back(i);
		}
	}

	for (int i = 0; i < q.size(); i++) {
		int now = q[i];
		for (int j = 0; j < g[now].size(); j++) {
			int cur = g[now][j];
			v[cur] = max(v[cur], v[now] + 1);
			if (--d[cur] == 0) q.push_back(cur);
		}
	}

	long long res = 0;

	for (int i = 0; i < n; i++) {
		res += v[i];
	}

	printf("%lld\n", res);

	return 0;

}

Measured memory_bytes: 48888
#include <stdio.h>
#include <math.h>
int main(void){
    int n,i;
    double xa,ya,ra,xb,yb,rb,sum;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
        sum=sqrt((yb-ya)*(yb-ya)+(xb-xa)*(xb-xa));
        if(rb+sum <ra)
            puts("2");
        else if(ra+sum < rb)
            puts("-2");
        else if(sum > ra+rb)
            puts("0");
        else
            puts("1");
    }
    return 0;
}

Measured memory_bytes: 620
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
#define MOD1 1000000007
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){
    return *(ll *)a>*(ll *)b?1:*(ll *)a<*(ll *)b?-1:0;}

int main(void){
    ll n,c,k,i,ans=1;
    scanf("%lld%lld%lld",&n,&c,&k);
    ll t[n];
    for(i=0;i<n;i++){
        scanf("%lld",&t[i]);
    }
    qsort(t,n,sizeof(ll),compare);
    ll p,t1;
    for(i=0;i<n;i++){
        if(i==0){
            p=1;
            t1=t[i];
        }else{
            if(p==c){
                ans++;
                p=1;
                t1=t[i];
            }else if(t[i]-t1>k){
                ans++;
                p=1;
                t1=t[i];
            }else{
                p++;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int s[MAX_N];
int a[MAX_N]; //0は羊,1は狼

int main()
{
	int n;
	cin >> n;
	rep(i,n){
		char c;
		cin >> c;
		if(c=='o'){
			s[i] = 0;
		}else{
			s[i] = 1;
		}
	}
	rep(i,8){
		rep(j,3){
			if(i&(1<<j)){
				a[(n+1-j)%n] = 1;
			}else{
				a[(n+1-j)%n] = 0;
			}
		}
		if(a[1] != (a[n-1]+s[0]+a[0])%2){
			continue;
		}
		for(int j=2;j<n-1;j++){
			a[j] = (a[j-2]+s[j-1]+a[j-1])%2;
		}
		if(a[n-1] == (a[n-3]+s[n-2]+a[n-2])%2){
			if(a[0] == (a[n-2]+s[n-1]+a[n-1])%2){
				rep(k,n){
					if(a[k] == 0){
						cout << "S";
					}else{
						cout << "W";
					}
				}
				cout << "\n";
				return 0;
			}	
		}
	}
	cout << "-1\n";
	return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
 
using namespace std;
 
int A, B, C;
 
int main() {
  scanf("%d %d", &A, &B);
  
  if (B%A){
    C = B - A;
  } else {
    C = B + A;
  }
  printf("%d\n", C);
}

Measured memory_bytes: 128
# include <iostream>
# include <string>

using namespace std;

bool is_complex(string s) {
    for (int i=0; i<s.size()-1; i++) {
        if (s[i] == s[i+1]) return true;
    }
    return false;
}


int main() {
    string s; cin >> s;
    if (is_complex(s)) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;

#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define RFOR(i,a,b) for(int (i)=(a)-1;(i)>=(b);--(i))
#define MP make_pair
#define MOD 1000000007
#define INF 1000000001
#define PB push_back
#define eps 1e-5
#define X first
#define Y second

int n;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if (a==b && b==c) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}
ll solve(ll n){
    switch(n%4){
        case 0:
            return n;
        case 1:
            return 1;
        case 2:
            return n^1;
        case 3:
            return 0;
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    a--;
    cout << (solve(a)^solve(b)) <<endl;
    return 0;

}






Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String line = in.readLine();
      long k = Long.parseLong(in.readLine());

      for (int i = 0; i < k; i++) {
        if(line.charAt(i) != '1') {
          System.out.println(line.charAt(i));
          return;
        }
      }

      System.out.println("1");
    }
    catch(IOException e){
      System.err.println(e);
    }
  }
}

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

int a[2000000];

int main(){
	int n,c[10001]={};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		c[a[i]]++;
	}
	int j=0;
	for(int i=0;i<10001;i++){
		for(int k=0;k<c[i];k++)
			a[j++]=i;
	}
	for(int i=0;i<n;i++)
		cout<<a[i]<<((i!=n-1)?' ':'\n');
	return 0;
}

Measured memory_bytes: 10892
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n,k;
    cin >> n >> k;
    ll res = pow(n/k,3);
    if(k%2==0){
        ll tmp=k/2;
        int cnt=0;
        while(tmp<=n){
           cnt++;
           tmp+=k;
        } 
        res += pow(cnt,3); 
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 512
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes" : "No") << endl;  

  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
   cin>>x>>y;
    while(x!=0||y!=0){
        
    
        if(x<y){
            cout<<x<<" "<<y<<endl;
        }
        else{
            cout<<y<<" "<<x<<endl;
        }
        cin>>x>>y;
    }
}


Measured memory_bytes: 3052
n,Y = map(int,input().split())
Y = int(Y / 1000)
ans = [-1,-1,-1]
for x in range(n+1):
    for y in range(n+1):
        if 10*x + 5*y + (n-x-y) == Y and n-x-y >= 0:
            ans = [x,y,n-x-y]
print(*ans)

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

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
    boost();
    ll a;
    cin >> a;
    cout << a+pow(a,2)+pow(a,3) << endl;
}

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

int main(){
    int N,D; cin >> N >> D;
    int kai = 0;
    for(int i=1;i<=N;i++){
        if((2*D+1)*i >= N){
            kai = i;
            break;
    }
    }
    cout << kai << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){

	int a, b;
	cin >> a;

	//scanf("%d", &a);

	cin >> b;
	//scanf("%d", &b);

	//printf("面積＝%d", a*b);

	cout << a*b << " " <<  a*2+b*2  <<  endl;

	return 0;
}



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

int n,m,a,b;
vector<int>e[100009],A,B;
bool visited[100009];

int main(){
    cin>>n>>m;
    rep(i,m){
        cin>>a>>b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    visited[a]=visited[b]=true;
    A.push_back(a);
    B.push_back(b);
    while(true){
        int i=0;
        while(i<e[A[A.size()-1]].size()&&visited[e[A[A.size()-1]][i]])i++;
        if(i==e[A[A.size()-1]].size())break;
        A.push_back(e[A[A.size()-1]][i]);
        visited[A[A.size()-1]]=1;
    }
    while(true){
        int i=0;
        while(i<e[B[B.size()-1]].size()&&visited[e[B[B.size()-1]][i]])i++;
        if(i==e[B[B.size()-1]].size())break;
        B.push_back(e[B[B.size()-1]][i]);
        visited[B[B.size()-1]]=1;
    }
    cout<<A.size()+B.size()<<endl;
    for(int i=A.size()-1;i>=0;i--)cout<<A[i]<<" ";
    rep(i,B.size()){
        if(i)cout<<" ";
        cout<<B[i];
    }
    cout<<endl;
}

Measured memory_bytes: 6904
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N = int(input())
D, X = inpl()
A = [int(input()) for i in range(N)]

chocos = [0]*D

for a in A:
    for i in range(0, D, a):
        chocos[i] += 1

print(sum(chocos) + X)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
#include <stdlib.h>

using namespace std;



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

  int sub = 0;
  bool flag = false;

  while(!flag){
    sub += 2;
    int i;
    for(i=0 ; i<(s.length() - sub)/2 ; i++){
      if(s[i] != s[i + (s.length() - sub)/2])
        break;
    }

    if(i == (s.length() - sub)/2)
      flag = true;

  }

  cout << s.length() - sub << endl;

  return 0;

}

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

using namespace std;

int main()
{
    int r, D, x;
    long tmp;
    cin >> r >> D >> x;
    tmp = x;
    for (int i = 0; i < 10; i++) {
        tmp = tmp * r - D;
        cout << tmp << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int N,M,Q;cin>>N>>M>>Q;
    vvin train(N+1,vin(N+1));
    int L,R;
    rep(i,M){
        cin>>L>>R;
        train[L][R]++;
    }
    rep2(i,1,N+1)rep2(j,i,N+1)train[i][j]+=train[i][j-1];
    queue<int> que;
    int p,q,sum;
    rep(i,Q){
        cin>>p>>q;
        sum=0;
        rep2(j,p,q+1)sum+=train[j][q];
        que.push(sum);
    }
    while(que.size()){
        cout<<que.front()<<endl;
        que.pop();
    }
}

Measured memory_bytes: 2304
N=int(input())
A=list(map(int,input().split()))

modular=10**9+7
sum=0

AllSum=0
for i in range(N):
  AllSum+=A[i]
  AllSum=AllSum%modular

  
RuisekiWa=[]
NextSum=AllSum

for i in range(N):
  RuisekiWa.append((NextSum-A[i])%modular)
  NextSum=RuisekiWa[i]

#print(RuisekiWa)
for i in range(N):
  sum+=(A[i]*RuisekiWa[i])%modular
  sum=(sum%modular)
    
print(sum%modular)


Measured memory_bytes: 101568
a,v=(int(x) for x in input().split())
b,w=(int(x) for x in input().split())
t = int(input())

flag = 0
if v > w and a<b:
    if a+v*t >= b+w*t:
        flag = 1
elif v > w and a>b:
    if a-v*t <= b-w*t:
        flag = 1
    

if flag ==1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9204
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

typedef long long ll;

int main()
{
	int n;
	ll x;
	cin >> n >> x;
	int i;
	ll input[100003];
	memset(input,0,sizeof(input));
	for(i=1;i<=n;i++)
		cin >> input[i];
	
	ll ans=0;	
	for(i=1;i<=n;i++)
	{
		if(input[i-1]+input[i]>x)
		{
			int tmp=input[i-1]+input[i]-x;
			input[i]-=tmp;
			ans+=tmp;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <complex>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef complex<double> P;
#define EPS (1e-9)

inline double dot(const P& a, const P& b) { return real(conj(a)*b); }
inline double cross(const P& a, const P& b) { return imag(conj(a)*b); }
P crosspoint(const P& l0, const P& l1, const P& m0, const P& m1) {
    const double A = cross(l1-l0, m1-m0);
    const double B = cross(l1-l0, l1-m0);
    if (abs(A) < EPS && abs(B) < EPS) return m0;
    return m0 + B/A*(m1-m0);
}

bool ok(const vector<P>& ps) {
    const int m = ps.size();
    if (m%2) return false;
    rep (i, m/2) {
        if (fabs(cross(ps[i+1]-ps[i], ps[(m/2+i+1)%m]-ps[m/2+i])) > EPS) {
            return false;
        }
    }
    const P cp = crosspoint(ps[0], ps[m/2], ps[1], ps[m/2+1]);
    rep (i, m/2) if (i) {
        const P p = crosspoint(ps[0], ps[m/2], ps[i], ps[m/2+i]);
        if (abs(p-cp) > EPS) return false;
    }
    return true;
}

int main() {
    int n;
    scanf("%d", &n);
    vector<P> ps;
    rep (i, n) {
        double x, y;
        scanf("%lf%lf", &x, &y);
        ps.push_back(P(x, y));
    }
    if (ok(ps)) {
        const int m = ps.size();
        const P cp = crosspoint(ps[0], ps[m/2], ps[1], ps[m/2+1]);
        printf("%.12f %.12f\n", cp.real(), cp.imag());
    }
    else {
        puts("NA");
    }
    return 0;
}

Measured memory_bytes: 1112
n = gets.to_i
Work = Struct.new(:time, :limit)
works = n.times.map {
  a, b = gets.split.map &:to_i
  Work[a, b]
  }.sort { |w1, w2| (w1.limit <=> w2.limit) * 2 + (w1.time <=> w2.time) }
time = 0
works.each do |w|
  time += w.time
  if time > w.limit
    puts "No"
    exit
  end
end
puts "Yes"

Measured memory_bytes: 31684
use std::io;
use std::collections::HashSet;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let mut set = HashSet::new();
	set.insert(v[0]);
	set.insert(v[1]);
	set.insert(v[2]);
	println!("{}", set.len());
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  vector<string> ans;
  while (cin >> s) {
    size_t pos;
    pos = s.find("apple");
    if (pos != string::npos) {
      s.replace(pos, 5, "peach");
      ans.emplace_back(s);
      continue;
    }
    pos = s.find("peach");
    if (pos != string::npos) {
      s.replace(pos, 5, "apple");
      ans.emplace_back(s);
      continue;
    }
    ans.emplace_back(s);
  }
  for (int i = 0; i < (int)ans.size(); i++) {
    cout << ans[i] << " \n"[i + 1 == (int)ans.size()];
  }

  return 0;
}


Measured memory_bytes: 3108
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.charAt(0)!='A') {
			System.out.println("WA");
			return;
		}
		int count =0;
		for (int i=2;i<s.length()-1;i++) {
			if (s.charAt(i)=='C') {
				count ++;
			}
		}
		if (count!=1) {
			System.out.println("WA");
			return ;
		}
		for (int i=1;i<s.length();i++) {
			if (s.charAt(i)!='C'&&(s.charAt(i)<'a'||s.charAt(i)>'z')) {
				System.out.println("WA");
				return ;
			}
			if (s.charAt(i)=='C') {
				if (i==1||i==s.length()-1) {
					System.out.println("WA");
					return ;
				}
			}
		}
		System.out.println("AC");
		return ;
	}
}

Measured memory_bytes: 35764
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
inline void nl(int num){for(int i = 0; i < num; i++)std::cout<<std::endl;}
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ui = uint64_t;

//----------------library in this time--------------------------------
template <class T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <class T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <class T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}

long long squareTwo(const long long a,const long long b) {
    return (b == 1) ? a : squareTwo(a * 2, b - 1);
}

template<class T> inline bool UpdateMin(T& a, T b) {
    if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
    if (a < b) { a = b; return 1; } return 0;
}

//------------------------main function-------------------------------
void Main(){
    int n; cin >> n;
    vector<int> length(n);
    rep(i, n) cin >> length[i];
    sort(length.begin(), length.end());
    //rep(i, n) cout << length[i] << " ";
    //nl(2);
    int ans = 0;
    
    for(int a = 0; a < n - 1; a++){
        for(int b = a + 1; b < n - 1; b++){
            int ab = length[a] + length[b];
            int left = b + 1, right;
            for(int i = b + 1; i < n; i++){
                if(length[i] >= ab){
                    right = i;
                    break;
                }else if(i == n -1){
                    right = n;
                    break;
                }
            }
            /*
            cout << "a = " << a << "  b = " << b << "  sum = " << ab << endl;
            cout << "right = " << right << "  left = " << left << endl;
            rep(i, n) {
                if(i == a)cout << "A:";
                if(i == b)cout << "B:";
                if(i == left)cout << "C{ ";
                if(i == right)cout << "} ";
                cout << length[i] << " ";
                
            }
            if(right == n)cout << "} ";
            nl(2);
            */
            ans += max(0,right - left);
        }
    }
    cout << ans << endl;
}

//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    
    Main();
    return 0;
}

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

#define ll long long
#define endl "\n"

ll a[1000005][4], n, dp[1000005][4], k;

ll solve(ll i,ll j){
	if(i==n)	
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	ll maxi=INT_MIN;
	if(j==0){
		maxi=max(maxi,a[i][1]+solve(i+1,1));
		maxi=max(maxi,a[i][2]+solve(i+1,2));
		maxi=max(maxi,a[i][3]+solve(i+1,3));
	}
	else if(j==1){
		maxi=max(maxi,a[i][2]+solve(i+1,2));
		maxi=max(maxi,a[i][3]+solve(i+1,3));
	}
	else if(j==2){
		maxi=max(maxi,a[i][1]+solve(i+1,1));
		maxi=max(maxi,a[i][3]+solve(i+1,3));
	}
	else{
		maxi=max(maxi,a[i][1]+solve(i+1,1));
		maxi=max(maxi,a[i][2]+solve(i+1,2));
	}
	return dp[i][j]=maxi;
}

int main(){
	memset(dp,-1,sizeof dp);
	cin >> n;
	for(ll i=0;i<n;i++)
		for(ll j=1;j<4;j++)
			cin >> a[i][j];
	cout << solve(0,0) << endl;		
	return 0;
}

Measured memory_bytes: 45740
fn main() {
    let s : String = read();
    let b_main = is_palindrome(&s);

    let half = (s.len()-1) / 2;
    let s_half  = &s[..half].to_string();
    let b_half = is_palindrome(s_half);
    
    let tmp = (s.len()+3) / 2;
    let s_tmp  = &s[tmp-1..].to_string();
    let b_tmp = is_palindrome(s_tmp);

	if b_main && b_half && b_tmp {
		println!("{}", "Yes");
	} else {
		println!("{}", "No");
	}
}

fn is_palindrome(s : &String) -> bool {
    let l = s.len() / 2;

	let f_half = s.chars().take(l);
	let l_half = s.chars().rev().take(l);

	return f_half.eq(l_half);
}


fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int X, Y, Z;

int main(){
	while(scanf("%d %d %d", &X, &Y, &Z) != EOF)
	{
		printf("%d\n", (X - Z) / (Z + Y));
	}
	return 0;
}

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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;

int N;
double ans, d;

int main(){
	cin>>N;
	for(int i=0; i<N; i++){
		scanf("%lf", &d);
		ans+=(1.0/d);
	}
	ans = (1.0/ans);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
(defvar N (read))
(defvar M (read))

(defvar S (loop repeat M 
                collect (loop repeat (read) collect (read))))

(defvar P (loop repeat M collect (read)))



(defun solve ()
  (loop for i below (expt 2 N) with arr 
        do (setf arr (map 'vector #'digit-char-p 
                          (format nil "~v,'0B" N i)))
        sum (loop for s_i in S
                  for p_i in P
                  if (/= p_i (mod (loop for s_ij in s_i
                                       sum (aref arr (1- s_ij)))  2)) 
                  return 0
                  finally (return 1))))

(princ (solve))

Measured memory_bytes: 10600
import numpy as np
n,m,k = map(int,input().split())
a_ls = list(map(int, input().split()))
b_ls = list(map(int, input().split()))
a_csum = np.cumsum(a_ls)
b_csum = np.cumsum(b_ls)
def isOK(index, key, l):
    if l[index] > key:
        return True
    else:
        return False
def binary_search(l, key):
    '''
    keyより大きい値を持つ最小のインデックスを返す
    '''
    left = -1
    right = len(l)

    while (right - left) > 1:
        mid = left + (right - left) // 2
        # 直感的に記憶　
            # 「含まれている」んだったら「含むを許容（等号付き）する右側」はmidまで動かして問題ない
                # 新しいrightの位置がkeyの位置だとしても、「含む」は許容されてる
            # 「含まれていない」んだったら「含まない(<)左の壁」をそこまで動かしてもkeyを通り過ぎることはない
        if isOK(mid, key, l):
            right = mid
        else:
            left = mid
    
    # whileを抜ける時、rightとleftは一個差で、かつkeyがrightの位置にある
    return right
ans = 0
for i in range(n):
    rest = k - a_csum[i]
    if rest < 0:
        break
    ind = binary_search(b_csum, rest)
    canread_b = max(0,ind)
    canread = i+1 + canread_b
    ans = max(canread, ans)
rest = k
ind = binary_search(b_csum, rest)
canread_b = max(0,ind)
ans = max(canread_b, ans)

print(ans)





Measured memory_bytes: 58328
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

const INI: i64 = -1;
use std::cmp::*;

fn main() {
    input! {
        n: usize,
        abc: [(i64,i64,i64);n],
    }

    let mut a = vec![];
    let mut b = vec![];
    let mut c = vec![];

    for (e1, e2, e3) in abc {
        a.push(e1);
        b.push(e2);
        c.push(e3);
    }

    let mut dp = vec![vec![INI; 3]; n];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for i in 0..n - 1 {
        dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a[i + 1];
        dp[i + 1][1] = max(dp[i][0], dp[i][2]) + b[i + 1];
        dp[i + 1][2] = max(dp[i][1], dp[i][0]) + c[i + 1];
    }

    println!("{}", max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]));
}


Measured memory_bytes: 14588
package main

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

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInt() int {
  var x int
  x,_ = strconv.Atoi(NextLine())
  return x
}
func NextInts() (int,int) {
  var x,y int
  var s []string = strings.Split(NextLine()," ")
  x,_ = strconv.Atoi(s[0])
  y,_ = strconv.Atoi(s[1])
  return x,y
}

var tree [][]int

func main() {
  var n int = NextInt()
  tree = make([][]int,n)
  for i:=0;i<n-1;i++ {
    var a,b int = NextInts()
    a,b = a-1,b-1
    tree[a] = append(tree[a],b)
    tree[b] = append(tree[b],a)
  }
  var df []int = make([]int,n)
  var ds []int = make([]int,n)
  dfs(0,-1,df)
  dfs(n-1,-1,ds)
  var m int
  for i:=0;i<n;i++ {
    if df[i] <= ds[i] { m++ }
  }
  if m > n-m {
    fmt.Println("Fennec")
  } else {
    fmt.Println("Snuke")
  }
}

func dfs(v,p int,d []int) {
  if p != -1 { d[v] = d[p]+1 }
  for _,e := range tree[v] {
    if e == p { continue }
    dfs(e,v,d)
  }
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 500

int N;
int a[MAX], hoge[MAX][MAX], dp[MAX][MAX];

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	
	
	cin>>N;
	
	for(int i = 0; i < N; i++){
		cin>>hoge[i][i];
	}
	
	for(int i = 2; i <= N; i++){
		for(int j = 0; j <= N-i; j++){
			int k = j+i-1;
			dp[j][k] = INF;
			for(int l = j; l < k; l++){
				hoge[j][k] = min(hoge[j][k], hoge[j][l]+hoge[l+1][k]);
				if(dp[j][l]+dp[l+1][k]+ hoge[j][l]+hoge[l+1][k] < dp[j][k]){
					hoge[j][k] = hoge[j][l]+hoge[l+1][k];
					dp[j][k] = dp[j][l]+dp[l+1][k]+ hoge[j][l]+hoge[l+1][k];
				}
				// cout<<i<<" "<<j<<" "<<l<<" "<<k<<" "<<hoge[j][k]<<" "<<hoge[j][l]<<" "<<hoge[l+1][k]<<endl;
			}
			
		}
	}
	
	cout<<dp[0][N-1]<<endl;
	
	return 0;
}

Measured memory_bytes: 3328
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);

		while (true) {
			p = scanner.nextInt();
			if (p == 0)
				break;
			n = new int[6];
			for (int i = 0; i < 6; i++)
				n[i] = scanner.nextInt();
			u = new int[6];
			System.out.println(slove(p, 5));
		}
	}

	private int slove(int r, int c) {
		if (c >= 0) {
			int ans = 1 << 30;
			for (int i = 0; i < 2; i++) {
				u[c] = Math.min(n[c], r / coin[c] + i);
				ans = Math.min(ans,
						slove(Math.max(0, r - u[c] * coin[c]), c - 1) + u[c]);
			}
			return ans;
		} else {
			int ch = -p;
			for (int i = 0; i < 6; i++)
				ch += coin[i] * u[i];
			int ans = 0;
			for (int i = 5; i >= 0; i--) {
				ans += ch / coin[i];
				ch %= coin[i];
			}
			return ans;
		}
	}

	int p;
	int[] n, u;
	int[] coin = { 1, 5, 10, 50, 100, 500 };
}

Measured memory_bytes: 23052
n=int(input())
res=0
xy = [map(int, input().split()) for i in range(n)]
x, y = [list(i) for i in zip(*xy)]
for i in range(n-2):
    if x[i]==y[i] and x[i+1]==y[i+1] and x[i+2]==y[i+2]:
        res+=1
if res>0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9192
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define LEN 100005
typedef struct pp{
	char name[100];
	int time;
}P;

P Q[LEN+1];
int main(void){

	int n, q;
	int j, top;
	P change;
	int i, cnt, t;
	cnt =0;
	scanf("%d %d", &n, &q);
	t =0;
	for(i =0;i<n;i++){
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].time);	
		
	}
	
	top=0;
	i=0;
	j=0;
	while(cnt !=n ){
		if(i ==n-cnt+top){
			i =0;
			top=0;
			j=0;
		}
		if(Q[i].time <=q && Q[i].time != 0 ){
			
			t =t + Q[i].time;
			Q[i].time = 0;
			cnt++;
			top++;
			printf("%s %d\n", Q[i].name, t);
			
		}
		else if(Q[i].time != 0 ){
			Q[i].time = Q[i].time - q;
			t = t+ q;
			
			
			Q[j] =Q[i];
			j++;
		}
		i++;
		
		
		
		/*
		change = Q[0];
		for(i = 0;i<n-1;i++){
			Q[i] = Q[i+1];
		}
		Q[n-1] = change;
		*/	
		
	}
	
	
	return 0;
}


Measured memory_bytes: 6776
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
using namespace std;
typedef long long ll;

int n,k;
char s[200005];

int main(){
	scanf("%d%d%s",&n,&k,s);
	fore(i,0,n)s[i]-='A';
	int i=0;int w=0;
	int m=min(k,1<<20);
	if(m==(1<<20)&&k%2)m++;
	while(m--){
		if(s[i]^w)w^=1,i++,i%=n;
		else s[i]^=1;
	}
	fore(j,0,n)putchar('A'+(s[(i+j)%n]^w));puts("");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
// #define int long long int
using namespace std;
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int n;
	cin >> n;
	int a=0,b=0,c=0,d=0;
	string s;
	while(n--){
		cin >> s;
		if(s=="AC")	a++;
		else if(s=="WA")	b++;
		else if(s=="TLE")	c++;
		else	d++;
	}
	cout << "AC x " << a<< endl;
	cout << "WA x " << b<< endl;
	cout << "TLE x " <<c<< endl;
	cout << "RE x " << d<< endl;


	return 0;
}

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

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

int main() {

    int N;
    while(cin >> N, N) {
        int K;
        vector< vector< bool > > info(N);
        for(int i = 0; i < N; i++) {
            int M; cin >> M;
            info[i] = vector< bool >(N + 1, false);
            for(int j = 0; j < M; j++) {
                int p; cin >> p;
                info[i][p] = true;
            }
        }
        cin >> K;
        vector< int > pub(K), ans;
        for(int i = 0; i < K; i++)
            cin >> pub[i];
        for(int i = 0; i < N; i++) {
            int cnt = 0;
            for(int j = 0; j < K; j++) {
                cnt += info[i][pub[j]];
            }
            if(cnt == K) ans.push_back(i + 1);
        }
        if(ans.size() != 1) cout << -1 << endl;
        else cout << ans[0] << endl;
    }
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
int n,mo,k,c[500][500],f[500][500],w[500][500];
int main(){
    scanf("%d%d%d",&n,&k,&mo);
    for (int i=0;i<=n;++i){
		c[i][0]=1;
		for (int j=1;j<=i;++j)
	    	c[i][j]=(c[i-1][j-1]+c[i-1][j])%mo;
    }
    for(int i=k;i>=0;--i){
		f[i][0]=1;
		for(int j=1;j<=n;++j)
	    for (int t=0;t<j;++t)
		(f[i][j]+=1ll*w[i+1][j-t-1]*f[i][t]%mo*c[j-1][t]%mo)%=mo;
	for (int j=0;j<=n;++j)
	    w[i][j]=(w[i+1][j]+f[i][j])%mo;
    }
    cout<<f[0][n];
    return 0;
}

Measured memory_bytes: 2048
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  
  A = parseInt(input[0],10);
  B = parseInt(input[1],10);
  C = parseInt(input[2],10);
  X = parseInt(input[3],10);
  
  var count = 0;
  
  for(i=0; i<=A; i++){
    x = X-(500*(i));
    if(x == 0){
      count += 1;
    }
    if(x <= 0){
      break;
    }
    
    for(j=0; j<=B; j++){
      y = x-(100*(j));
      if(y == 0){
        count += 1;
      }
      if(y <= 0){
        break;
      }
      
      
      for(k=0; k<=C; k++){
        z = y-(50*(k));
        if(z == 0){
          count += 1;
        }
        if(z <= 0){
          break;
        }
      }
    }
 
  
  }
  
  console.log('%d', count);
 
}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
A, B, C, D, E, F = map(int, input().split())
items = []
water = list(set([100*(A*w+B*x) for w in range(16)
                  for x in range(16) if A*w+B*x <= 30]))
water.sort()

for w in water:
    for x in range(1501):
        c = C*x
        i = (F-w-c)//D
        for y in reversed(range(i+1)):
            d = D*y
            if 0 < w+c+d <= F and w*E >= 100*(c+d):
                items.append((100*(c+d)/(w+c+d), w+c+d, c+d))
                break

items.sort(reverse=True)
print(items[0][1], items[0][2])

Measured memory_bytes: 3316