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

using namespace std;

int main() {
    int M, D;
    cin >> M >> D;

    int ans = 0;
    for (int i = 21; i <= D; ++i) {
        if (i % 10 < 2) continue;
        if ((i % 10) * (i / 10) <= M) ans++;
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
l=-1
r=-1
i=0
ans=0
while sum(h)!=0:
	if l==-1 and h[i]!=0:
		l=i
	if l!=-1 and h[i]==0:
		r=i-1
	elif r==-1 and i==n-1:
		r=i
	if l!=-1 and r!=-1:
		tmp=min(h[l:r+1])
		ans+=tmp
		for j in range(l,r+1):
			h[j]-=tmp
		l=-1
		r=-1
		i=-1
	i+=1
print(ans)

Measured memory_bytes: 3064
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N = input().rstrip('\n')
    c = int(N[0])
    ans = c + 9*(len(N)-1)
    if N[1:]!='9'*(len(N)-1):
        ans -= 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include<bitset>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;

int32_t last[256];
std::multiset<int32_t> count[256];
std::string s;
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> s;
	for (char w = 'a'; w <= 'z'; ++w)
	{
		last[w] = -1;
		for (int32_t i = 0; i < s.size(); ++i)
		{
			if (s[i] == w) {
				count[w].insert(i - last[w]-1);
				last[w] = i;
			}
		}
		last[w] = (s.size() - last[w] - 1);
	}
	int32_t min = 150;
	for (char w = 'a'; w <= 'z'; ++w)
	{
		if (count[w].empty()) { continue; }
		int32_t tmp = 0;
		int32_t diss = 0;
		int32_t last_a_a_ = last[w];
		while (last_a_a_>0 || std::any_of(count[w].begin(), count[w].end(), [&diss](int c) {return c > diss; }))
		{
			++tmp; ++diss;
			if (last_a_a_ == 0) {
				//auto v = *--count[w].end();
				//count[w].erase(--count[w].end());
				//count[w].insert(v - 1);
			}
			else {
				--last_a_a_;
			}
		}
		min = std::min(min, tmp);
	}
	out << min << endl;

	return 0;
}
#endif




Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
cnt = 0

for _ in range(N):
    x, y = map(int, input().split())
    if x == y:
        cnt += 1
    else:
        cnt = 0
    if cnt >= 3:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 9048
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;


int main() {

	
	string p;
	cin >> p;
	for (int i = 0; i < p.size(); i += 2) {
		cout << p[i];
	}
	cout<<endl;
	return 0;
	
}


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

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
    
    long long n, sum = 0; cin >> n;
    for(long long i = 1; i <= n; ++i){
        if(!(i % 3 == 0 || i % 5 == 0)) sum += i;
    }
    cout << sum;
}


Measured memory_bytes: 3640
#include <stdio.h>

int main(){
	int ans = 0, i, n, l, r;

	scanf("%d", &n);

	for(i=0; i<n; i++){
		scanf("%d %d", &l, &r);
		ans += r-l+1;
	}

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

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, M; ll K;
    cin >> N >> M >> K;
    ll A[N], B[M];
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    ll sum = 0;
    rep(i, N) sum += A[i];
    int now = 0;
    ll tmp = 0;
    int ans = 0;
    rep3(i, N-1, 0){
        while(now < M && sum+tmp+B[now] <= K) tmp += B[now++];
        if(sum + tmp <= K) chmax(ans, i+1+now);
        //cout << now << endl;
        sum -= A[i];
    }
    while(now < M && sum+tmp+B[now] <= K) tmp += B[now++];
    chmax(ans, now);
    cout << ans << endl;
}

Measured memory_bytes: 6752
package main
import "fmt"

func main() {
  var n int
  fmt.Scan(&n)
  a := aArray(n)
  max := maxNum(a)
  ind := index(max, a)
  a[ind] = 0
  big := maxNum(a)
  if max == big {
    for i := 0; i < n; i++{
      fmt.Println(max)
    }
    }else{
    for i, _ := range a{
        if i == ind {
          fmt.Println(big)
        }else{
          fmt.Println(max)
        }
      }
    }
}

func aArray(n int) []int{
  var d int
  a := make([]int, 0)
  for i := 0; i < n; i++ {
    fmt.Scan(&d)
   	a = append(a, d)
  	}
  return a
}

func maxNum(a []int) int {
	var ans int
	for _, v := range a {
		if ans < v {
			ans = v
		}
	}
	return ans
}

func index(m int, a []int) int {
  var ind int
  for i, v := range a {
    if ind == 0 {
      switch {
    	case v == m :
      		ind = i
      }
    }
  }
  return ind
}

Measured memory_bytes: 10368
#include<stdio.h>
 int max(int a, int b, int c)
 {
int max=-10000;
if (a>max)
max=a;
 if (c>max)
max=c;
if (b>max)
max=b;
return max;
 }
 main()
 {
 	int t, i, s=0,b, c,a, k, max1;
 	scanf("%d%d%d%d", &a, &b, &c, &k);
    max1=max(a, b, c);
    t=max1;
	for(i=0;i<k;i++)
{
	max1=max1*2;
}
if (t==a)
s=b+c+max1;
else if (t==b)
s=max1+a+c;
else if (t==c)
s=a+b+max1;
printf("%d", s);
 	return 0;
 }

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
 
 int main (){
     int x,i = 0;
     while(i++<10000){
         cin >> x;
         if (x == 0){
             return 0;
         }else{
            cout <<"Case "<< i <<": " <<  x << endl;;
         }

     }
 }


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

using ll=long long;
const ll INF=1e18;
int main(){
    int n;
    cin>>n;
    ll t,e;
    cin>>e>>t;
    vector<ll> x(n+1);
    for(int i=1;i<=n;i++) cin>>x[i];

    vector<ll> dp(n+1);    
    multiset<ll> As;
    multiset<ll> Bs;
    vector<ll> A(n);
    vector<ll> B(n);
    auto calcA=[&](int i){
        return dp[i]-2*x[i+1]-x[i];
    };
    auto calcB=[&](int i){
        return dp[i]-x[i];
    };
    A[0]=calcA(0),B[0]=calcB(0);
    Bs.insert(B[0]);
    int iter=0;
    for(int i=1;i<=n;i++){
        while(iter<i && 2*(x[i]-x[iter+1])>=t){
            As.insert(A[iter]);
            Bs.erase(Bs.find(B[iter]));
            iter++;
        }
        ll vX=(As.empty() ? INF : *As.begin()+3*x[i]);
        ll vY=(Bs.empty() ? INF : *Bs.begin()+x[i]+t);
        dp[i]=min(vX,vY);
        if(i==n) break;
        A[i]=calcA(i),B[i]=calcB(i);
        Bs.insert(B[i]);
    }
    cout<<e-x[n]+dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    cs
    vector<vector<int>> v(10,vector<int>(10));
    int n,t=0;cin>>n;
    repp(i,1,n) {
        int j=i,k=j%10;
        while(j>9) {
            j/=10;
        }
        v[j][k]++;
    }
    repp(i,1,9) repp(j,1,9)
    t+=v[i][j]*v[j][i];
    cout<<t;   
}

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

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    
    int x[N+1];
    //int y[M+1];
    
    //都市の座標入力
    for(int i = 0; i< N; ++i){
        cin >> x[i];
    }
    x[N] = X;
    
    int y;
    
    string flag = "No War";
    for(int i = 0; i< M; ++i){
        cin >> y;
        for(int j = 0; j< N+1; ++j){
            if(y <= x[j]){
                flag = "War";
            }
        }
        
        y = Y;
        for(int j = 0; j< N+1; ++j){
            if(y <= x[j]){
                flag = "War";
            }
        }
        

    }
    cout << flag << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[3001][3001][2];
vector<vector<int>> known(3001, vector<int>(3001, 0));
int a[3000];
int n;
int INF = -1e12+7;
void recur(int i, int k, int m){
    if(k==0){
        dp[i][k][0]=0;
        dp[i][k][1]=0;
        return;
    } 
    if(i==n){
        dp[i][k][0]=-INF;
        dp[i][k][1]=-INF;
    }
    if(!known[i+1][k-1])recur(i+1,k-1,1-m);
    if(!known[i][k-1])recur(i,k-1,1-m);
    known[i+1][k-1]=1;
    known[i][k-1]=1;
    if(m){//jiro's move
        int o1 = a[i] + dp[i+1][k-1][1];
        int o2 = a[i+k-1] + dp[i][k-1][1];
        if(o1 >= o2){
            dp[i][k][1] = o1;
            dp[i][k][0] = dp[i+1][k-1][0];
        } else {
            dp[i][k][1] = o2;
            dp[i][k][0] = dp[i][k-1][0];
        }
    } else {
        int o1 =a[i] + dp[i+1][k-1][0];
        int o2 =a[i+k-1] + dp[i][k-1][0];
        if(o1 >= o2){
            dp[i][k][0] = o1;
            dp[i][k][1] = dp[i+1][k-1][1];
        } else {
            dp[i][k][0] = o2;
            dp[i][k][1] = dp[i][k-1][1];
        }
    }
}
int32_t main() {
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    recur(0,n,0);
    cout<<dp[0][n][0] - dp[0][n][1]<<"\n";
    /*for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            cout<<"{"<<dp[i][j][0]<<","<<dp[i][j][1]<<"} ";
        }
        cout<<"\n";
    }*/
    return 0;
}

Measured memory_bytes: 155560
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 301;
ll DP[N][N], DP2[N][N];
int n, m;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  DP[1][0] = 1;
  FOR(i, 0, m){
    memset(DP2, 0, sizeof DP2);
    FOR(j, 1, n+1)FOR(k, 0, n-j+1){
      DP[j][k]%=MOD;
      DP2[j+k][0] += DP[j][k]*j;
      DP2[j][k] += DP[j][k]*k;
      DP2[j][k+1] += DP[j][k]*(n-j-k);
    }
    swap(DP, DP2);
  }
  cout << DP[n][0]%MOD << endl;
}

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

int main(){
  vector<int> data{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << data[K-1] <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll sum[200009];
ll a[200009];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];
    }
    ll minn=1e15;
    for(int i=1;i<=n-1;i++)
    {
        minn=min(minn,abs(sum[i]-(sum[n]-sum[i])));
    }
    cout<<minn<<endl;
}

Measured memory_bytes: 3328
#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(){
  lint N;
  cin>>N;
  lint A[N];
  REP(i,N)cin>>A[i];
  map<lint,lint> m;
  REP(i,N)m[A[i]]++;
  lint ans=0;
  for(auto e:m){
    lint n=e.second;
    ans+=n*(n-1)/2;
  }
  REP(i,N){
    lint n=m[A[i]];
    cout<<ans-n*(n-1)/2+(n-1)*(n-2)/2<<endl;
  }
  return 0;
}


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

string n;
bool temp;

int main() {
  cin >> n;
  temp = false;
  rep (i, 3) {
  temp = temp || n.at(i) == '7';
  }
  if (temp) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

int main(){
    //wtf atcoder mf
    int n;
    cin>>n;
    char a[n];
    int f=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]=='Y')f=1;
    }
    if(f==1)cout<<"Four";
    else cout<<"Three";
    
}    

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int cnt[300];
int main(){
    rep(i,200)rep(j,200){
        if(i*j<300)cnt[i*j]++;
    }
    int n;cin>>n;
    int ans=0;
    rep(i,n+1)if(i%2==1&&cnt[i]==8)ans++;
    cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
        public static void main(String args[]){
        	Scanner scn = new Scanner(System.in);
        	int n=scn.nextInt();
        	 long [] arr =new long[n];
        	 long xor = 0;
        	 for(int i=0;i<n;i++){
        		 arr[i]=scn.nextLong();
        		 xor^=arr[i];
        	 }
        	StringBuilder sb =new StringBuilder();
        	for(int i=0;i<n;i++){
        		long val = xor^arr[i];
        		sb.append(val+" ");
        	}
        	System.out.println(sb);
        }
}

Measured memory_bytes: 62904
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

inline void up(int &x,const int &y){if(x<y)x=y;}
const int maxn = 210000;

int n,m;
vector<int>V[maxn];
int pre[maxn];

struct segment{int c,flag;}seg[maxn<<2];
void pushdown(const int x)
{
	if(seg[x].flag)
	{
		int lc=x<<1,rc=lc|1,fl=seg[x].flag; seg[x].flag=0;
		seg[lc].c+=fl,seg[lc].flag+=fl;
		seg[rc].c+=fl,seg[rc].flag+=fl;
	}
}
void pushup(const int x){ seg[x].c=max(seg[x<<1].c,seg[x<<1|1].c); }
void build(const int x,const int l,const int r)
{
	if(l==r) {seg[x].c=pre[l]-l; return;}
	int mid=l+r>>1,lc=x<<1,rc=lc|1;
	build(lc,l,mid); build(rc,mid+1,r);
	pushup(x);
}
int lx,rx,c;
void upd(const int x,const int l,const int r)
{
	if(rx<l||r<lx) return;
	if(lx<=l&&r<=rx) { seg[x].flag+=c,seg[x].c+=c; return; }
	pushdown(x);
	int mid=l+r>>1,lc=x<<1,rc=lc|1;
	upd(lc,l,mid); upd(rc,mid+1,r);
	pushup(x);
}
int query(const int x,const int l,const int r)
{
	if(rx<l||r<lx) return 0;
	if(seg[x].c<0) return 0;
	if(lx<=l&&r<=rx) return seg[x].c;
	pushdown(x);
	int mid=l+r>>1,lc=x<<1,rc=lc|1;
	return max(query(lc,l,mid),query(rc,mid+1,r));
}

int ans;

int main()
{
	scanf("%d%d",&n,&m); ans=n-m;
	for(int i=1;i<=n;i++)
	{
		int l,r; scanf("%d%d",&l,&r);
		pre[l]++;
		V[r].push_back(l);
	}
	for(int i=1;i<=m+1;i++) pre[i]+=pre[i-1];
	
	build(1,0,m);
	for(int i=1;i<=m+1;i++)
	{
		if(i-2>=0) lx=0,rx=i-2,up(ans,query(1,0,m)-(m-i+1));
		
		for(int j=0;j<V[i].size();j++)
		{
			lx=V[i][j],rx=m,c=-1; upd(1,0,m);
		}
	}up(ans,0);
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 16128
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int dp[40][401][401];
int a[40];
int b[40];
int c[40];
int main(){
  int N;
  int M_a;
  int M_b;
  cin >> N >> M_a >> M_b;
  for(int i = 0; i < N; i++){
    cin >> a[i] >> b[i] >> c[i];
  }

  for(int i = 0; i < N; i++){
    for(int j = 0; j <= 400; j++){
      for(int k = 0; k <= 400; k++){
        dp[i][j][k] = INT_MAX;
      }
    }
  }

  dp[0][0][0] = 0;
  dp[0][a[0]][b[0]] = c[0];
  
  for(int i = 1; i < N; i++){
    for(int j = 0; j <= 400; j++){
      for(int k = 0; k <= 400; k++){
        dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k]);
        if(j >= a[i] && k >= b[i] && dp[i - 1][j - a[i]][k - b[i]] != INT_MAX){
          dp[i][j][k] = min(dp[i][j][k], c[i] + dp[i - 1][j - a[i]][k - b[i]]);
        }
      }
    }
  }

  int ans = INT_MAX;
  for(int i = 1; i <= 400; i++){
    for(int j = 1; j <= 400; j++){
      if(i % M_a == 0 && j % M_b == 0 && i / M_a == j / M_b){
        ans = min(ans, dp[N - 1][i][j]);
      }
    }
  }
  if(ans == INT_MAX){
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  int long long fibo[100];
  fibo[0] = 2;
  fibo[1] = 1;
  int long long t, s = 0;
  
  for(int i = 2; i < N +1; i++){
    t = fibo[i-2];
    s = fibo[i-1]; //t,sに値を保存しておく
    
    fibo[i] = t + s;
  }
  
  cout << fibo[N] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll e=a*c,f=b*d,g=a*d,h=b*c;
    ll ans=max(max(e,f),max(g,h));
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using ull = unsigned long long;
using namespace std;
int main() {
	int n; cin >> n;
	ull ans = 1;
	bool zero = false;
	bool exceed = false;
	for (int i = 0; i < n; i++) {
		ull x; cin >> x;
		ull t = ans * x;
		if (x == 0) zero = true;
		else if (t / x != ans or t > ull(1e18)) exceed = true;
		else ans = t;
	}
	if (zero) cout << 0 << "\n";
	else if (exceed) cout << -1 << "\n";
	else cout << ans << "\n";
}


Measured memory_bytes: 3636
<?php

function input() {
    return trim(fgets(STDIN));
}
function input_array() {
    return explode(' ', input());
}

list($N, $T) = input_array();
list($N, $T) = [(int)$N, (int)$T];

$min_cost = 1001;

for ($i = 0; $i < $N; $i++) {
    list($c, $t) = input_array();
    list($c, $t) = [(int)$c, (int)$t];
    if ($t <= $T) {
        $min_cost = min($min_cost, $c);
    }
}

if ($min_cost === 1001) {
    echo "TLE\n";
} else {
    echo "{$min_cost}\n";
}

Measured memory_bytes: 4604
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
#define MAX_A 1000000007

ll f(ll n,ll x){

    if(n == -1){
        return 0;
    }else{
        return (n/x+1);
    }
}


int main(){

    ll a,b,x;
    cin >> a >> b >> x;

    ll f_a = f(a-1,x);
    ll f_b = f(b,x);
    //cout << f_a << " " << f_b << endl;

    cout << f_b-f_a << endl;


    return 0;
}

Measured memory_bytes: 256
import sys
def main():
    MOD = 10**9+7
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    count = [0] * 61
    ans = 0
    for a in A:
        for i, c in enumerate(format(a, 'b')[::-1]):
            if c == '1':
                count[i] += 1

    for i, c in enumerate(count):
        tmp = (c*(N-c) * pow(2, i, MOD))%MOD
        ans = (ans + tmp)%MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42156
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

using namespace std;

int main(){
	int a,b;
	char op;
	cin >> a >> op >> b;
	if(op=='+')cout << a+b << endl;
	else if(op=='-')cout << a-b << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
namespace IO
{
	template <typename T> inline void read(T &x)
	{
		int f = 1; x = 0; char c = getchar();
		for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
		for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
		x *= f;
	}

	template <typename T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }
	template <typename T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }

	template <typename T> inline void write(T x)
	{
		if (x < 0) putchar('-'), x = -x;
		if (x > 9) write(x / 10);
		putchar(x % 10 + '0');
	}
	template <typename T> inline void writesp(T x) { write(x); putchar(' '); }
	template <typename T> inline void writeln(T x) { write(x); putchar('\n'); }
}
using namespace IO;
int main(){
	char c;
	cin>>c;
	if (isupper(c))cout<<"A\n";
	else cout<<"a\n";
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 40) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int c = 0;
    string s;
    cin >> s;
    int n = s.length();
    for(int i = 0; i < n; i++) {
        if(s[i] == 'o') {
            c++;
        }
    }
    if(c + (15 - n) >= 8) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long n, std::vector<long long> p){
  int ans=0;
  for (int i = 0; i < n-2; i++) {
    if((p[i] < p[i+1] && p[i+1] < p[i+2]) || (p[i] > p[i+1] && p[i+1] > p[i+2]))ans++;
  }
  cout << ans << endl;
}

// Generated by 1.1.6 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(){
    long long n;
    scanf("%lld",&n);
    std::vector<long long> p(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&p[i]);
    }
    solve(n, std::move(p));
}


Measured memory_bytes: 256
/*.....Bismillahir Rahmanir Rahim.....*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld long double
#define   pb push_back
#define  sz(x)  (int)x.size()
#define  ff first
#define  ss second
#define  pii  pair<int,int>
using namespace std;

int  gcd(int a,int b) {
	return  (b==0)? a: gcd(b,a%b);
}
int  sq(int i,int j){
	return ((i-j)*(i-j));
}
	
void solve(){ 
	int  n;  cin >> n ;
	int  a[n] ; 
	int mn=100,mx=-100;
	for (int i=0;i<n;i++){
		cin >> a[i]; 
		mn= min(a[i],mn);
		mx = max(a[i],mx);
	}
	int res=100000000,cur;
	for (int i=mn;i<=mx;i++){
		cur=0;
		for (int j=0;j<n;j++)
			cur += sq(a[j], i);
		res = min(res,cur);
	}
	cout << res << endl ; 
}

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


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

int A[100000],n;

 int Search(int key){
	 int l=0;
	 int r=n;
	 int m;
	 while( l<r ){
		 m = (l+r)/2;
		 if( A[m]<key ) l = m+1;
		 if( A[m]>key ) r = m;
		 else if( A[m]==key ) return 1;
	 }

	 return 0;
 }


int main(){
	int q,k,s=0;
	cin >> n;
	for(int i=0; i<n ; i++) cin >> A[i];
	cin >> q;
	for(int i=0; i<q; i++){
		cin >> k;

		if( Search(k) ) s++;
	}

	cout << s << "\n";
	return 0;
}

Measured memory_bytes: 3476
N,K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for i in range(K+1):
    left = []
    if i != 0:
        left = V[:i]
    for j in range(K-i+1):
        right = []
        if j == 0:
            right = []
        elif (N-i) == 0:
            right = []
        elif i+j > N:
            continue
        else:
            right = V[-j:]
        for k in range(K-i-j+1):
            if k > i+j:
                continue
            sort_merge = sorted(left+right)
            if sum(sort_merge[k:]) == 990000000:
                print(sort_merge)
            ans = max(ans, sum(sort_merge[k:]))

print(ans)

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

int main()
{
  int n;
  int w1, max = 0;

  cin >> n;
  for (int i = 0; i < n; i++){
    int a, v;
    cin >> a >> v;
    if (max < v){
      max = v;
      w1 = a;
    }
    else if (max == v){
      if (w1 > a){
        w1 = a;
      }
    }
  }
  cout << w1 << ' ' << max << endl;
  return (0);
}

Measured memory_bytes: 1160
from fractions import gcd
n=int(input())
a=list(map(int, input().split()))

leftgcd=[0]*n
leftgcd[0]=a[0]
for i in range(1,n):
	leftgcd[i]=gcd(leftgcd[i-1],a[i])

rightgcd=[0]*n
rightgcd[n-1]=a[n-1]
for i in reversed(range(0,n-1)):
	rightgcd[i]=gcd(rightgcd[i+1],a[i])

ans=rightgcd[1]
for i in range(1,n-1):
	ans=max(ans,gcd(leftgcd[i-1],rightgcd[i+1]))
print(max(ans,leftgcd[n-2]))

Measured memory_bytes: 16576
#include <cstdio>
#include <cstring>


int main(){
    char s[201], t[101], p[101];
    int list[26] = {};
    
    scanf("%s %s", s, p);
    strcpy(t, s);
    strcat(s, t);

    if (strstr(s, p) == NULL) printf("No\n");
    else printf("Yes\n");

}



Measured memory_bytes: 2760
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.cpp
 * Author: takaesumizuki
 *
 * Created on 2017/03/10, 10:07
 */

#include <cstdlib>
#include <iostream>
#define MOD 1000000007

typedef long long llint;

using namespace std;

/*
 * 
 */
int main() {
    llint n;
    llint result = 1;
    cin >> n;
    
    for(llint i = 1; i <= n; i++){
        result = (result * i) % MOD;
    }
        
    cout << result << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


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

    queue<ll> que;

    rep2(i,9){
        que.push(i);
    }
    rep(i,K-1){
        ll tmp = que.front();
        que.pop();

        if(tmp%10 != 0){
            que.push(10*tmp+ (tmp%10) -1);
        }
        que.push(10*tmp+ (tmp%10) );
        if(tmp%10 != 9){
            que.push(10*tmp+ (tmp%10) +1);
        }
    }


    cout<< que.front()<<endl;

    return 0;
    

}

Measured memory_bytes: 5124
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

int main(){
  //type
  int n;
  cin >> n;
  vt<int> d(n);
  rep(i,n)
    cin >> d[i];
    
  //solve
  sort(d.begin(),d.end());
  int s = n/2-1;
  int k = d[s]+1;
  int cnt = 0;
  while(k <= d[s+1]){
    cnt++;
    k++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define P pair<int,int>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	long long ans = 0;
	if (a + b > c * 2) { //cを2回引いたほうが安い
		while (x > 0 && y > 0) { //xもyもまだ残っている間c*2で引いていく
			x--, y--;
			ans += c * 2;
		}
		if (x > 0) { //xがまだ残ってる
			if (a < c * 2) { //c*2を引くよりaを引く方が安い
				while (x > 0) { // xが残っている間aで引く
					x--, ans += a;
				}
			} else { //c*2で引いた方が安い
				while (x > 0) { // xが残っている間c*2で引く
					x--, ans += c * 2;
				}
			}
		}
		if (y > 0) { //yがまだ残ってる
			if (b < c * 2) { //c*2を引くよりbを引く方が安い
				while (y > 0) { //yが残っている間bで引く
					y--, ans += b;
				}
			} else { //c*2で引いた方が安い
				while (y > 0) { //yが残っている間c*2で引く
					y--, ans += c * 2;
				}
			}
		}
	} else {
		while (x > 0) { //a+b<c*2なのでそれぞれをa,bで引いていく
			x--, ans += a;
		}
		while (y > 0) {
			y--, ans += b;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l_n = [input() for i in range(n)]
m = int(input())
l_m = [input() for i in range(m)]
max_c = 0
for i in range(n):
    max_c = max(max_c, l_n.count(l_n[i]) - l_m.count(l_n[i]))
print(max_c)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>
#include<cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i,n) FOR(i,0,n)

struct edge{int to,cost;};

void dump(int *b,int n){
	for(int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	cout << "\n";
}

ll mypow(ll x,ll n){
	if(n==0) return 1;
	ll res=mypow(x*x,n/2);
	if(n&1) res=res*x;
	return res;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	
	int n,m;
	cin >> n >> m;
	
	vector<P> py[n];
	int p,y;
	rep(i,m){
		cin >> p >> y;
		py[p-1].push_back(P(y,i));
	}
	rep(i,n) sort(py[i].begin(),py[i].end()); //py[県].(年,ind)
	
	int mae[m],usiro[m];
	int ind;

	rep(i,n){
		for(int j=0;j<py[i].size();j++){
			ind = py[i][j].second;
			mae[ind]=i+1,usiro[ind]=j+1;
		}
	}
	rep(i,m){
		printf("%06d%06d\n",mae[i],usiro[i]);
	}	

	return 0;
}

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

int N;
int A[20];
int x[20][20];
int y[20][20];

int Conquer(int x){
    if(x == 0)return 0;
    return Conquer (x>>1)+(x & 1);
}

void solve(){
    cin>>N;
    for(int i=1;i<=N;++i){
        cin>>A[i];
        for(int j=1;j<=A[i];++j){
            cin>>x[i][j] >>y[i][j];
        }
    }
    int ans=0;
    for(int bits =1;bits<(1<<N);++bits){
        bool ok =true;
        for(int i=1;i<=N;++i){
            if(!(bits & (1 <<(i-1))))continue;
            for(int j=1;j<=A[i];++j){
                if(((bits >>(x[i][j]-1)) & 1) ^ y[i][j])ok =false;
            }
        }
        if(ok)ans =max(ans,Conquer(bits));
    }
    cout <<ans << endl;
    return;
}

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

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

int main(){
	int N, M, res, sum = 0;
	int L[10000000];
	int i = 0;
	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		cin >> L[i];
		sum += L[i];
	}

	res = N - sum;
	if (res > 0) {
		cout << res << endl;
	}
	else if (res == 0) {
		cout << "0" << endl;
	}
	else if (res < 0) {
		cout << "-1" << endl;
	}
}


Measured memory_bytes: 3664
#!/usr/bin/env python3
import sys

def main():
    input = sys.stdin.readline
    a, b, c, d = map(int, input().split())

    if a * c >= 0 or b * d >= 0:
        print(max(a * c, b * d))
    else:
        print(max(a * d, b * c))

if __name__ == '__main__':
    main()


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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int INF = 0x3f3f3f3f;
const ll MOD = 1000000007LL;

//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){
    const int m = 13;
    int n;
    int dp[m] = {};
    string s;
    cin >> s;

    n = s.size();
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        int nextDP[m] = {};

        FOR(j, m){      // 0 - 12 toonuudaar hvsnegt vvsgeh 
            if(s[i] == '?'){
                FOR(k, 10){     // 0 - 9 tsifrvvd
                    nextDP[(j*10+k)%m] += dp[j];
                    nextDP[(j*10+k)%m] %= MOD;
                }
            } else {
                int k = s[i] - '0';        // string iig char aar guilgehed bvgd ascii bh uchir ('9' - '0') = (57 − 48) = 9
                nextDP[(j*10+k)%m] += dp[j];
                nextDP[(j*10+k)%m] %= MOD;
            }
        }

        // FOR(j, m){
        //     cout << dp[j] << " ";
        // }
        // cout << endl;

        swap(dp, nextDP);
        //copy(nextDP, nextDP + m, dp);
        //dp = nextDP;
    }

    cout << dp[5];

    return 0;
}




Measured memory_bytes: 512
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int sum = 0;
		int hapiness_500 = x/500;
		int hapiness_5 = (x-hapiness_500*500)/5;
		sum = hapiness_500*1000+hapiness_5*5;
		System.out.println(sum);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

//long longのシフト演算には気をつけよう

int main(){
    int N; cin >> N;
    vector<int> a(N+1, 0);
    for(int i=1; i<=N; i++) cin >> a[i];

    int cnt = 0, button = 1;

    while(button != 2 && cnt <= N){
        button = a[button];
        cnt++;
    }

    if(button == 2) cout << cnt << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 640
import sys
N,T =map(int,input().split())
c=[]
t=[]
t_count=0
for i in range(N):
    c_n,t_n=map(int,input().split())
    if t_n>T:
        t_count+=1
    if t_n<=T:
        c.append(c_n)
        t.append(t_n)
        #if i>len(t):
            #break
        
    

if t_count==N:
    print("TLE")
    sys.exit()

print(min(c))

Measured memory_bytes: 3064
x, y = map(int, input().split())
A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
C = [2]

if (x in A) and (y in A):
    print('Yes')
elif (x in B) and (y in B):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
N, M = [int(n) for n in input().split()]

s = [None] * M
c = [None] * M

for i in range(M):
    s[i], c[i] = [int(n) for n in input().split()]

ans = -1
if N == 1:
    lb = 0
elif N == 2:
    lb = 10
else:
    lb = 100
    
for k in range(lb, 10 ** N):
    check = True
    n = str(k)
    for i in range(M):
        if n[s[i] - 1] != str(c[i]):
            check = False
            break
    if check:
        ans = k
        break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
string rev(string x){
  reverse(all(x));
  return x;
}
  int main()	{
  string s;
  cin>>s;
  int count=0;
  int n=s.size();
  int a=(n-1)/2;
  int b=(n+1)/2;
  string srev=rev(s);
  if(s==srev){
    count++;
  }
  string s1=s.substr(0,a);
  string srev1=rev(s1);
  if(s1==srev1){
    count++;
  }
  string s2=s.substr(b);
  string srev2=rev(s2);
  if(s2==srev2){
    count++;
  }
  if(count==3)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ps push
#define pf push_front
#define mp make_pair
#define And &&
#define Or ||
#define inf INT_MAX
#define ppb pop_back
#define ppf pop_front
#define ignr cin.ignore()
#define Sort(name) sort(name.begin(),name.end())
#define For(name,start,finish) for(int name=start;name<finish;name++)
#define fast_in_out ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

//int row[]={-1,0,1,0};
//int col[]={0,1,0,-1};

const int N=1e3+10;
//vector<pair<int,int> > vec(N);
vector<int> vec;
ll Max(ll a,ll b){if(a>b)return a;return b;}


int main()
{
	fast_in_out;
	
    int n;
    cin>>n;
    
    int q=n%100;
    int p=n/100;
    
    
    if(p<=12 And q<=12 And p>0 And q>0)
    cout<<"AMBIGUOUS"<<endl;
    
    else if(p<=12 And p>0)
    cout<<"MMYY"<<endl;
    
    else if(q<=12 And q>0)
    cout<<"YYMM"<<endl;
    
    else
    cout<<"NA"<<endl;
    
	return 0;
	
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;
#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

char in[25][25];
int dis[25][25];
int main() {
	int N, M, i, j, k, l;
	scanf("%d %d", &N, &M);
	for (i = 0; i < N; i++) scanf("%s", in[i]);

	int ans = 0;
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (in[i][j] != '.') continue;
			memset(dis, 0x3f, sizeof(dis));
			dis[i][j] = 0;

			vector <pii> Vu;
			Vu.emplace_back(i, j);
			for (k = 0; k < Vu.size(); k++) {
				for (l = 0; l < 4; l++) {
					int x = Vu[k].first + "1102"[l] - '1';
					int y = Vu[k].second + "0211"[l] - '1';
					if (x < 0 || x >= N || y < 0 || y >= M || dis[x][y] != INF) continue;
					if (in[x][y] != '.') continue;

					dis[x][y] = dis[Vu[k].first][Vu[k].second] + 1;
					Vu.emplace_back(x, y);
				}
				ans = max(ans, dis[Vu[k].first][Vu[k].second]);
			}
		}
	}
	return !printf("%d\n", ans);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
	string s;
	cin>>s;
	int cnt=0;
	for(int i=0;i<(int)s.size()-1;i++){
	  if(s[i]==s[i+1]){
		   (s[i]=='0')?s[i+1]='1':s[i+1]='0'; 
		   cnt++;
		 }	
	}
	//cout<<s<<endl;
	cout<<cnt<<endl;
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}


Measured memory_bytes: 512
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

#define rep(i, n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    int ans=0;
    int v[n];
    int c[n];
    rep(i,n){
        cin>>v[i];
    }
    rep(i,n){
        cin>>c[i];
    }
    rep(i,n){
        if(v[i]>c[i])ans+=v[i]-c[i];
    }



    cout<<ans<<endl;





    return 0;
}


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

using namespace std;

typedef long long ll;

int sumv[1505][1505],rpos[1505][1505];
int minn[2][1505][1505],maxn[2][1505][1505];

char str[1505][1505];

int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%s",str[i]+1);
  int cur=0;
  ll ans=0;
  for(int i=n;i>0;i--) {
  	cur^=1;
  	for(int j=n;j>0;j--)
  	  if (str[i][j]!='#') {
  	  	  sumv[i][j]=sumv[i][j+1]+sumv[i+1][j]+str[i][j]-'0';
  	  	  rpos[i][j]=max(max(rpos[i][j+1],rpos[i+1][j]),i);
  	  	  minn[cur][j][i]=j;
  	  	  for(int k=i+1;k<=rpos[i+1][j];k++) minn[cur][j][k]=minn[cur^1][j][k];
  	  	  for(int k=max(rpos[i+1][j],i)+1;k<=rpos[i][j+1];k++) minn[cur][j][k]=minn[cur][j+1][k];
  	  	  maxn[cur][j][i]=j;
  	  	  for(int k=i;k<=rpos[i][j+1];k++) maxn[cur][j][k]=maxn[cur][j+1][k];
  	  	  for(int k=max(rpos[i][j+1],i)+1;k<=rpos[i+1][j];k++) maxn[cur][j][k]=maxn[cur^1][j][k];
  	  	  int d=i+1,r=min(rpos[i][j+1],rpos[i+1][j]);
  	  	  while (d<=r) {
  	  	  	    if (maxn[cur^1][j][d]>=minn[cur][j+1][d]) {
  	  	  	    	    sumv[i][j]-=sumv[d][minn[cur][j+1][d]];
  	  	  	    	    d=rpos[d][minn[cur][j+1][d]];
					  }
  	  	  	    d++;
			  }
		  ans+=(ll)(str[i][j]-'0')*(sumv[i][j]-(str[i][j]-'0'));
		}
  }
  printf("%lld\n",ans);
  return 0;
}

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

int main(){
  int n,k;
  string s;
  cin >> n >> k >> s;
  
  char c = s[k-1];
  if(c=='A') s[k-1] = 'a';
  if(c=='B') s[k-1] = 'b';
  if(c=='C') s[k-1] = 'c';
  
  cout << s;
  
  return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    s = input()
    if s == 'AC':
        ac += 1
    elif s == 'WA':
        wa += 1
    elif s == 'TLE':
        tle += 1
    else:
        re += 1
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)


Measured memory_bytes: 10488
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

vector<vector<int> > path;
vector<int> seen;
void dfs(int from) {
    if(seen[from] == false) {
        seen[from] = true;
        for(int i = 0; i < path[from].size(); i++) {
            dfs(path[from][i]);
        }
    }
}

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


    //vector<vector<int> > path(N, vector<int>());
    path.assign(N, vector<int>());

    for(int i = 0; i < M ; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;y--;
        path[x].push_back(y);
        path[y].push_back(x);
    }

    seen.assign(N, false);
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if(seen[i] == false) {
            dfs(i);
            cnt++;

        }
    }

    cout << cnt << endl;



}


Measured memory_bytes: 9216