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

using namespace std;

using ll = long long int;
using ld = long double;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

	string s;
	cin >> s;

	int res = INF;
	for (int i = s.size() - 1; i > 0; i--) {
		int mid = i / 2;
		string midStr = s.substr(0, mid) + s.substr(0, mid);
		if (s.substr(0, i) == midStr) {
			res = min(res, (int)s.substr(0, i).size());
			break;
		}
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a){
    cout<<k;
  }else if(k<=a+b){
    cout<<a;
  }else{
    cout<<2*a+b-k;
  }
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+10;
const LL mod=1000000007;
typedef pair<LL,LL>pa;
LL gcd(LL a,LL b){
	if(a%b==0)return b;
	return gcd(b,a%b);
}
int R(LL x){
	if(x<0)return -1;
	if(x==0)return 0;
	return 1;
}
LL pow(LL x,LL p){
	LL ret=1ll;
	while(p){
		if(p&1)ret*=x,ret%=mod;
		p/=2;
		x*=x;x%=mod;
	}
	return ret;
}
map<pa,int>mp;
map<pa,bool>bk;
LL a[N],b[N],ax[N],bx[N],ans,n,tot;
LL st1[N],st2[N],cnt,cnt00,cnta0,cntb0;
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&a[i],&b[i]);
		int flag=R(a[i])*R(b[i]);
		if(flag==0){
			ax[i]=0;bx[i]=0;
			if(a[i]==0&&b[i]==0)cnt00++;
			else if(a[i]==0)cnta0++;
			else cntb0++;
			continue;
		}
		ax[i]=abs(a[i]);bx[i]=abs(b[i]);
		LL tmp=gcd(ax[i],bx[i]);ax[i]/=tmp;bx[i]/=tmp;
		pa now=make_pair(ax[i]*flag,bx[i]);
		mp[now]++;
	}
	for(int i=1;i<=n;i++){ 
		if(ax[i]==0)continue;
		if(!bk[make_pair(ax[i]*R(a[i])*R(b[i]),bx[i])]){
			bk[make_pair(ax[i]*R(a[i])*R(b[i]),bx[i])]=1;
			bk[make_pair(bx[i]*R(a[i])*R(b[i])*(-1),ax[i])]=1;
			LL tmp1=1ll*mp[make_pair(bx[i]*R(a[i])*R(b[i])*(-1),ax[i])];
			LL tmp2=1ll*mp[make_pair(ax[i]*R(a[i])*R(b[i]),bx[i])];
			if(tmp1==0)continue;
			st1[++tot]=tmp1;st2[tot]=tmp2;
			cnt+=tmp1+tmp2;
		}
	}	
	cnt+=cnta0+cntb0+cnt00;
	if(cnta0==0)cnt-=cntb0;
	else if(cntb0==0)cnt-=cnta0;
	else{
		st1[++tot]=cnta0,st2[tot]=cntb0;
	}
	ans=pow(2ll,n-cnt)%mod;
	for(int i=1;i<=tot;i++){
		//cout<<st1[i]<<" "<<st2[i]<<endl;
		LL tmp=(pow(2ll,st1[i])%mod+pow(2ll,st2[i])%mod-1)%mod;
		ans*=tmp;ans%=mod;
	}
	//if(cnt0)ans*=2;ans%=mod;
	ans=ans-1+cnt00;
	if(ans<0)ans+=mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 59916
import numpy as np

def dfs(i, cost, A):
    if i == n-1:
        global ans
        if cost < ans and all([ai>=x for ai in A]):
            ans = cost
        return
    
    i += 1
    dfs(i, cost, A[:])
    dfs(i, cost+c[i], A[:]+a[i])

    
        
        

if __name__ == "__main__":
    n, m, x = map(int, input().split())
    c, a = [None]*n, np.array([None]*n)
    for i in range(n):
        c[i], *a[i] = map(int, input().split())
    ans = 10**20
    dfs(-1, 0, np.array([0]*m))
    if ans == 10**20:
        print(-1)
    else:
        print(ans)


Measured memory_bytes: 27280
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    for (int i = 0; i < n; i++) {
      int a[8];
      for (int j = 0; j < 8; j++)
        cin >> a[j];
      cout << a[0]*a[4]-a[1]*a[5]-a[2]*a[6]-a[3]*a[7] << ' '
           << a[0]*a[5]+a[1]*a[4]+a[2]*a[7]-a[3]*a[6] << ' '
           << a[0]*a[6]-a[1]*a[7]+a[2]*a[4]+a[3]*a[5] << ' '
           << a[0]*a[7]+a[1]*a[6]-a[2]*a[5]+a[3]*a[4] << endl;
    }
  }
}

Measured memory_bytes: 1160
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define mod(x) ((x % MOD) + MOD) % MOD
#define int long long int
#define rep(i, a, n) for(int i = a; i < n; ++i)
#define rrep(i, a, n) for(int i = n-1; i >= a; --i)

using namespace std;

typedef pair<int,int> P;

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

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  return s;
}

struct edge {
  int to, diff;
};


bool dfs(vector<int>& x, vector< vector<edge> >& G, vector<bool>& used, int i) {
  stack<int> st;
  st.push(i);
  x[i] = 0;
  while (!st.empty()) {
    int i = st.top(); st.pop();
    rep(j, 0, G[i].size()) {
      edge e = G[i][j];
      if (used[e.to]) {
        if (x[i] + e.diff != x[e.to]) {
          return false;
        }
      } else {
        used[e.to] = true;
        x[e.to] = x[i] + e.diff;
        st.push(e.to);
      }
    }
  }
  return true;
}



signed main()
{
  int N, M;
  cin >> N >> M;
  vector< vector<edge> > G(N, vector<edge>());
  int l, r, d;
  rep(i, 0, M) {
    cin >> l >> r >> d;
    l--; r--;
    G[l].push_back(edge{ r, -d });
    G[r].push_back(edge{ l,  d });
  }

  vector<int> x(N);
  vector<bool> used(N, false);
  rep(i, 0, N) {
    if (!used[i]) {
      x[i] = 0;
      used[i] = true;
      if (!dfs(x, G, used, i)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}


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

int main(){
    string s; cin >> s;
    vector<string> v({"Sunny", "Cloudy", "Rainy"});
    for(int i=0; i<3; ++i){
        if(s == v[i]){
            cout << v[(i+1)%3] << "\n";
            return 0;
        }
    }
}

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

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;


int main(void) {

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

	ll a, b,k;
	cin >> a >> b >> k;
	
	ll aa = max(a - k, (ll)0);
	ll kk = max(k - a, (ll)0);
	ll bb = max(b - kk, (ll)0);
	
	cout << aa << " " << bb <<endl;


	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 
int calcA(int N,int k,int C){
  return N-1-k*C;
}
int calcB(int N,int k,int C){
  return N-1-(k+1)*C;
}

int main(void){
  int N;cin >> N;
  ll s[N];
  int i;
  REP(i,N)cin >> s[i];
  //A:(N+1)/2, 
  //C:1,2,...,(N+1)/2-1
  ll maximum = 0;
  for(int C=1;C<(N+1)/2;C++){
    set<int> st;
    ll calc = 0;
    for(int k=0;k*C<N-1;k++){
      if(calcB(N,k,C)<=0 || st.count(k*C) || k*C == N-1-k*C) break;
      calc += s[k*C] + s[N-1-k*C];
      maximum = max(maximum,calc);
      st.insert(N-1-k*C);
    }
  }
  cout << maximum << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#define pii pair<int, int>
#define fst first
#define snd second
#define pub push_back
#define vi vector<int>
#define ll long long

using namespace std;

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	long long a, c = 0; string b;
	cin >> a >> b;
	c = 100 * (int)(b[0] - '0') + 10 * (int)(b[2] - '0') + (int)(b[3] - '0');
	cout << a * c / 100 << "\n";
	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
using namespace std;

int main(){
  int q; cin>>q;
  multiset<int>s;
  while(q--){
    int x,y;
    cin>>x>>y;
    if(x==1)cout<<s.count(y)<<endl;
    else if(x==0){
      s.insert(y);
      cout<<s.size()<<endl;
    }
    else if(x==2)s.erase(y);
    else{
      int l=y,r;
      cin>>r;
      set<int>::iterator end,it;
      it=s.lower_bound(l);
      end=s.upper_bound(r);
      for(;it!=end;it++){
        cout<<(*it)<<endl;
      }
    }
  }
}


Measured memory_bytes: 12268
import java.util.*;
public class Main {
	static final Scanner stdin = new Scanner(System.in);
	public static void main(String[] args) {
		while(stdin.hasNext()){
			
			int a = stdin.nextInt();
			int b = stdin.nextInt();
      
			int comp_val = a - b;
			int num, aval,m,n,ans1;
			
			if(comp_val > 0){
				for(int i = 0;i <= a;i++){
					aval = a - i;
					if(a%aval==0 && b%aval==0){
						m = a/aval;
						n = b/aval;
						ans1 = m * n * aval;
						System.out.println(aval+" "+ans1);
						
						break;
					}
				}
			}else{
				for(int i = 0;i <= b;i++){
					aval = b - i;
					if(a%aval==0 && b%aval==0){
						m = a/aval;
						n = b/aval;
						ans1 = m * n * aval;
						System.out.println(aval+" "+ans1);
						
						break;
					}
				}
			}
		}
	}

}

Measured memory_bytes: 28056
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main(){
int x=0,y=0,z=0,w=0;
std::vector<int> v(4);

std::cin >>v[0]>>v[1]>>v[2]>>v[3];
sort(all(v));
if(v[0]==v[1]&&v[2]==v[3])std::cout << "yes" << '\n';
else std::cout << "no" << '\n';
}



Measured memory_bytes: 3136
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = sorted([a + b for a in A for b in B])[-1:-K-1:-1]
ABC = sorted([ab + c for ab in AB for c in C])[-1:-K-1:-1]
print('\n'.join(map(str, ABC)))


Measured memory_bytes: 139260
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#define MAX 1000000000000000000
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<unsigned long long int> v(n);
	bool zeroes=false;
	unsigned long long int mul = 1,x,prev=1;

	for (int i = 0; i < n; ++i)
	{
		cin >> v[i];
		if (v[i] == 0)
		{
			zeroes = true;
			break;
		}
		
	}
	if (zeroes)
	{
		cout << "0" << endl;
		return 0;
	}
	for (int i = 0; i < n; ++i)
	{
		mul *= v[i];
		if (mul/v[i]!=prev || mul>MAX)
		{
			cout << "-1" << endl;
			return 0;
		}
		prev = mul;
	}
	cout << mul << endl;
	return 0;
}

Measured memory_bytes: 3984
#include <stdio.h>
#include <string.h>

int c(char *p,int d){return ((26+*p-*(p+1))%26==d);}
int a(char *p){return((*p<'a')||(*p>'z'));}
char *decode (char *inbuf, int s) {
  int p = 0;
  while (inbuf[p] != 0) {
    if ((inbuf[p] >= 'a')&&(inbuf[p]<='z')) {
      int t = inbuf[p] + s;
      //inbuf[p] = inbuf[p] + (char)s;
      if (t > 'z')      inbuf[p] = (char)(t - 26);
      else if (t < 'a') inbuf[p] = (char)(t + 26);
      else              inbuf[p] = (char)t;
    }
    p++;
  }
  return (inbuf);
}

int main(){
  char inbuf[82];
  while(fgets(inbuf,80,stdin)){
    int s;
    char *p=inbuf;
    while(*p){
      s = 0;
      if(c(p,12)){
	//	if (((*p-*(p+2))==15)||((*p-*(p+2))==-11)) {
	if(c(p+1,3)){
	  if(a(p+3))
	    s = 't' - *p;
	}
	/* that */
	else if (((*p-*(p+2))==19)||((*p-*(p+2))==-7)) {
	  if (*p-*(p+3) == 0)
	  if(a(p+4))
	      s = 't' - *p;
	}
	/* this */
	else if (((*p-*(p+2))==11)||((*p-*(p+2))==-15)) {
	  if (((*p-*(p+3))==1)||((*p-*(p+3))==-25))
	  if(a(p+4))
	      s = 't' - *p;
	}
      }
      if (s) break;
      p++;
    }
    printf("%s",decode(inbuf, s));
  }
  return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

struct M{int e,a;};

int main(void){
	
	int x,y,z;
	double dp[51][5001];
	map<int,M>m;
	
	while(cin >> x >> y >> z,x|y|z){
		vector<int>v(x);
		m.clear();
		
		for(int i=0;i<x;i++)cin >> v[i];
		for(int i=0;i<z;i++){
			int n,e,a;
			M in;
			cin >> n >> in.e >> in.a;
			m[n]=in;
		}
		
		fill(dp[0],dp[51],0);
		dp[0][0]=1;
		
		for(int i=0;i<y;i++){
			for(int j=0;j<5001;j++){
				for(int k=0;k<x;k++){
					int nx=i+v[k];
					if(m.count(nx)){
						if(m[nx].e==1)dp[min(y,nx+m[nx].a)][j]+=dp[i][j]/x;
						else if(m[nx].e==2)dp[nx][j+m[nx].a]+=dp[i][j]/x;
						else if(m[nx].e==3)dp[nx][max(0,j-m[nx].a)]+=dp[i][j]/x;
					}
					else dp[min(y,nx)][j]+=dp[i][j]/x;
				}
			}
		}
		double ans=0;
		for(int j=0;j<5001;j++)ans+=dp[y][j]*j;
		
		cout << (int)ans << endl;
	}
	
return 0;
}

Measured memory_bytes: 3184
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

struct S{
  ll x, v;
  S(ll x, ll v): x(x), v(v) {}
};

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

  vector<S> Slist;
  for(ll i=0; i<N; ++i) {
    ll x, v;
    cin >> x >> v;
    Slist.emplace_back(x,v);
  }

  ll ans = 0;
  
  vector<ll> max_f(N), max_b(N);
  {
    ll sum_v = 0, m = 0;
    for(ll i=0; i<N; ++i) {
      S& s = Slist[i];
      sum_v += s.v;
      m = max_f[i] = max(m, sum_v - s.x);
    }
    ans = max(ans, m);
  }
  
  {
    ll sum_v = 0, m = 0;
    for(ll i=N-1; i>=0; --i) {
      S& s = Slist[i];
      sum_v += s.v;
      m = max_b[i] = max(m, sum_v - (C - s.x));
    }
    ans = max(ans, m);
  }
  
  for(ll i=0;   i<N-1; ++i) ans = max(ans, max_f[i]+max_b[i+1]-Slist[i].x);
  for(ll i=N-1; i>=1 ; --i) ans = max(ans, max_f[i-1]+max_b[i]-(C-Slist[i].x));

  cout << ans << endl;
  
  return 0;
}


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

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		long N=sc.nextLong();
		int ans=0;
		for(int a=1;a<N;++a) {
			long b=N-a;
			if(a<b)++ans;
		}
		pw.println(ans);
		pw.close();
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

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

using namespace std;

int main() {
    string s,t;
    cin>>s>>t;
    int x=s.length(),y=t.length(),mi=INT_MAX,cnt=0;
    for(int i=0;i<=(x-y);i++){
        for(int j=i;j<(i+y);j++){
            if(t[j-i]!=s[j])cnt++;
        }
        mi=min(cnt,mi);
        cnt=0;
    }
    cout<<mi;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder st = new StringBuilder();
         
        int i = 1;
         
        while(true){
            int line = Integer.parseInt(br.readLine());
            if(line == 0){
                break;
            }
             
            st.append("Case ").append(i).append(": ").append(line).append("\n");
            i++;
        }
         
        System.out.print(st);
    }
}

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

int main(){

  int N,A,B,C,D;
  int sum1=0,sum2=0,ans1,ans2;;

  cin>>N>>A>>B>>C>>D;

  while(1){
    sum1=sum1+A;
    sum2=sum2+B;
    // if(sum1==N){sum2=sum2-B; break; }
    if(sum1>=N){ break; }

  }

  ans1=sum2;


  sum1=0; sum2=0;



 while(1){
    sum1=sum1+C;
    sum2=sum2+D;

    // if(sum1==N){ sum2=sum2-D; break; }
if(sum1>=N){ break; }
  }




  ans2=sum2;
  if(ans1<ans2){
  cout<<ans1<<endl;
  }

  if(ans1>=ans2){
  cout<<ans2<<endl;
  }

  return 0;
}



Measured memory_bytes: 3116
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  if(n == 1){
    cout << "Hello World" << endl;
  }else{
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int main() {
	
	int n,m;
	cin >> n >> m;
	vector<int> c(m);
	for(auto &i:c) cin >> i;
	vector<int> dp(n+1);
	for(int i=1; i<=n; i++) dp.at(i) = i;
	for(int i=0; i<m; i++){
		for(int j=0; j<=n; j++){
			if(j-c.at(i)<0) continue;
			chmin ( dp.at(j) , dp.at(j-c.at(i)) + 1);
		}
	}
	
	cout << dp.at(n) << endl;
}


Measured memory_bytes: 3172
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    A.sort(reverse=True)
    dp = ["-"]*(N+10)
    dp[0] = ""
    match = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
    for i in range(N+1):
        if dp[i] == "-":
            continue
        for a in A:
            cur = dp[i+match[a]]
            ne = dp[i] + str(a)
            if len(cur) < len(ne) or cur < ne:
                dp[i+match[a]] = ne
    # print(dp)
    print(dp[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 134492
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1LL<<60
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main(){
  ll k[5] = { };
  int n;
  cin >> n;
  REP(i, n){
    string s;
    cin >> s;
    if(s[0] == 'M') k[0]++;
    if(s[0] == 'A') k[1]++;
    if(s[0] == 'R') k[2]++;
    if(s[0] == 'C') k[3]++;
    if(s[0] == 'H') k[4]++;
  }
  ll ans = 0;
  ans += k[0]*k[1]*k[2];
  ans += k[0]*k[1]*k[3];
  ans += k[0]*k[1]*k[4];
  ans += k[0]*k[2]*k[3];
  ans += k[0]*k[2]*k[4];
  ans += k[0]*k[3]*k[4];
  ans += k[1]*k[2]*k[3];
  ans += k[1]*k[2]*k[4];
  ans += k[1]*k[3]*k[4];
  ans += k[2]*k[3]*k[4];
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    map<string, int> mp;
    REP(i, N){
        string S;
        cin >> S;
        mp[S]++;
    }
    int mx = 0;
    for(auto x : mp)
        mx = max(mx, x.second);
    set<string> st;
    for(auto x : mp)
        if(x.second == mx)
            st.insert(x.first);
    for(auto x : st)
        cout << x << endl;
    return 0;
}


Measured memory_bytes: 34560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)


int main() {
  int n; cin >> n;
  vector<ll> A(n), B(n);
  loop(i,0,n) cin >> A[i] >> B[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (n&1) {
    ll x = A[n/2];
    ll y = B[n/2];
    cout << y-x+1 << endl;
    return 0;
  }

  ll x2 = A[(n/2)-1] + A[n/2];
  ll y2 = B[(n/2)-1] + B[n/2];
  ll ans = (y2/2 - (x2/2 + (x2%2!=0))) * 2 + 1;
  ans += x2&1;
  ans += y2&1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6428
import Control.Applicative

main :: IO ()
main = do
  ns <- (map read . words) <$> getLine :: IO [Int]
  putStrLn $ show $ solve ns

solve :: [Int] -> Int
solve (n:m:_)
  | n == 1 && m == 1 = 1
  | n == 1           = m - 2
  | m == 1           = n - 2
  | otherwise        = (n -2) * (m - 2)


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

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a*c %mod;}a=a*a %mod;b>>=1;}return c;}
vi calc(ll x){vi res; while(x>0){res.eb(x%10);x/=10;}reverse(all(res)); return res;}

void solve() {
  ll k,n;
  cin>>k>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  vi b;
  REP(i,1,n) b.eb(a[i]-a[i-1]);
  b.eb(k-a[n-1]+a[0]);
  sort(all(b));
  out(k-b[n-1]);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>

#define MAX 1000

using namespace std;


int m[MAX + 2][MAX + 2];
int lcs(string x, string y)
{
    for (int i = 0; i <= y.length(); i++)
        for (int j = 0; j <= x.length(); j++)
            m[i][j] = 0;

    for (int i = 1; i <= y.length(); i++) {
        for (int j = 1; j <= x.length(); j++) {
            if (x[j - 1] == y[i - 1]) {
                m[i][j] = m[i - 1][j - 1] + 1;
            } else {
                m[i][j] = max(m[i - 1][j], m[i][j - 1]);
            }
        }
    }

    return m[y.length()][x.length()];
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string x, y;
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }
}


Measured memory_bytes: 6984
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

char u[3] = {'R', 'G', 'B'};

void solve() {
	ll n;
	cin >> n;
	string s;
	cin >> s;
	if (n <= 2) {
		cout << 0 << endl;
		return;
	}
	ll ans = 0;
	for (ll i = 1; i < n - 1; i++) {
		char c = s[i];
		vector<char> use;
		rep(j,3) {
			if (c == u[j]) continue;
			use.push_back(u[j]);
		}
		map<char, ll> lmp;
		vector<char> v;
		for (ll j = 0; j < i; j++) {
			if (s[j] == c) continue;
			lmp[s[j]]++;
		}
		map<char, ll> rmp;
		for (ll j = i + 1; j < n; j++) {
			if (s[j] == c) continue;
			rmp[s[j]]++;
		}
		ll x = lmp[use[0]] * rmp[use[1]];
		ll y = lmp[use[1]] * rmp[use[0]];
		ans += x + y;
	}

	ll ng = 0;
	for (ll i = 1; i < n - 1; i++) {
		for (ll j = 0; j < i; j++) {
			char c1 = s[i];
			char c2 = s[j];
			ll k = i + (i - j);
			if (c1 == c2) continue;
			if (k >= n) continue;
			if (c1 != s[k] && c2 != s[k]) ng++;
		}
	}
	cout << ans - ng << endl;
}

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

Measured memory_bytes: 3636
#include "bits/stdc++.h"

using namespace std;

struct edge
{
	long to, cost;
};

struct UnionFind
{
	//number of parents(par[i] = i => root)
	vector<int> par;
	//rank of tree
	vector<int> rank;

	UnionFind(int n) : par(n), rank(n, 1)
	{
		//initialize
		for (int i = 0; i < n; i++)
			par[i] = i;
	}

	//find root (keiroasshuku at the same time)
	int root(int x)
	{
		if (par[x] == x)
			return x;
		else
			return par[x] = root(par[x]);
	}

	//unite
	void unite(int x, int y)
	{
		x = root(x);
		y = root(y);
		if (x == y)
			return;
		if (rank[x] > rank[y])
			swap(x, y);
		par[x] = y;
		rank[y] += rank[x];
	}

	//same tree?
	bool same(int x, int y)
	{
		return root(x) == root(y);
	}
};

struct Edge
{
	long from, to, cost;

	// コストの大小で順序定義
	bool operator<(const Edge &o) const
	{
		return cost < o.cost;
	}
};

struct Kruskal
{
	int V; // number of nodes
	vector<Edge> edges;

	Kruskal(int v)
	{
		V = v;
	}

	// グラフが非連結のときは最小全域森のコストの和となる
	long calc()
	{
		//init
		UnionFind uf(V);
		sort(edges.begin(), edges.end());
		long min_cost = 0L;

		for (Edge e : edges)
		{
			if (!uf.same(e.from, e.to))
			{
				min_cost += e.cost;
				uf.unite(e.from, e.to);
			}
		}
		return min_cost;
	}
};

void solve()
{
	long N;
	cin >> N;
	priority_queue<pair<long, long>, vector<pair<long, long>>, greater<pair<long, long>>> q;
	vector<edge> graph[2*N];
	for (int i = 0; i < N; i++)
	{
		long X;
		cin >> X;
		graph[i].push_back({i+N, X});
		graph[i+N].push_back({i, X});
		q.push({0, i});
	}
	for (int i = 0; i < N-1; i++)
	{
		long A, B, C;
		cin >> A >> B >> C;
		graph[A+N-1].push_back({B+N-1, C});
		graph[B+N-1].push_back({A+N-1, C});
	}

	Kruskal kruskal(N);

	vector<long> dist(2 * N, 1e18), par(2 * N, -1);
	for (int i = 0; i < N; i++)
	{
		par[i] = i;
		dist[i] = 0;
	}
	bitset<400040> vst;

	while (!q.empty())
	{
		auto p = q.top();
		q.pop();
		long v = p.second, d = p.first;
		vst[v] = 1;
		for (auto e : graph[v])
		{
			long nv = e.to;
			if (vst[nv])
			{
				if (par[v] == par[nv]) continue;
				kruskal.edges.push_back({par[v], par[nv], dist[v] + dist[nv] + e.cost});
				//cout << par[v] << ' ' << par[nv] << ' ' << dist[v] << ' ' << dist[nv] << ' ' << e.cost << endl;
			}
			else
			{
				if (dist[nv] > d + e.cost)
				{
					par[nv] = par[v];
					dist[nv] = d + e.cost;
					q.push({d + e.cost, nv});
				}
			}
		}
	}

	cout << kruskal.calc() << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 68200
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int n,d;
    cin >> n >> d;
    int x[n][d];
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin >> x[i][j];
        }
    }

    int c=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            int tmp=0;
            for(int k=0;k<d;k++){
                tmp += (int)pow((x[i][k]-x[j][k]),2);
            }
            if((int)pow(tmp,0.5)==pow(tmp,0.5)) c++;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 4064
#define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template <typename T>
struct SegmentTree
{
    using F  = function<T(T, T)>;
    int n;
    F f;
    T unit;
    vector<T> data;
    SegmentTree(){};
    SegmentTree(F f, T unit):f(f), unit(unit){}
    void init(int n_)
    {
        n = 1;
        while (n < n_) n <<= 1; 
        data.assign(n << 1, unit);
    }

    void build(const vector<T> &v)
    {
        init(v.size());
        for(int i=0; i<v.size(); ++i) data[n+i] = v[i];
        for(int i=n-1; i>0; --i) data[i] = f(data[2*i], data[2*i+1]);
    }

    void add(int k, T x)
    {
        data[k+=n] += x;
        while (k >>= 1)
            data[k] = f(data[2 * k], data[2 * k + 1]);
    }

    T query(int a, int b)
    {
        T vl, vr;
        vl = vr = unit;
        for (int l = a+n, r = b+n; l < r; l >>= 1, r >>= 1)
        {
            if (l&1) vl = f(vl, data[l++]);
            if (r&1) vr = f(vr, data[--r]);
        }
        return f(vl, vr);
    }
};


// example
// auto f=[&](int a,int b){return max(a,b);};
// SegmentTree<int> sgtree(f, 0);
// sgtree.build(values); 

const int INF = 100000000;
int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    rep(i, 0, N) cin >> P[i];

    auto f=[&](int a, int b){return min(a, b);};
    SegmentTree<int> sgtree(f, INF);
    sgtree.build(P);
    
    int cnt = 0;
    rep(i, 0, N)
    {
        int min_value = sgtree.query(0, i+1);
        debug(i, min_value);
        if (min_value == P[i]) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3072
n=int(input())
p=list(map(int,input().split()))

flg =[0]*n

cnt=0
tmp=0
for i in range(n):
    if i<n-1 and p[i]==i+1:
        p[i],p[i+1] =p[i+1],p[i]
        cnt+=1
    if i==n-1 and p[i]==i+1:
        cnt+=1




print(cnt)


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

int main(){
  int a,b;
  cin>>a>>b;
  int cnt=0;
  
  for(int i=a;i<=b;i++){
    string s=to_string(i);
    string Rs=s;
    reverse(Rs.begin(),Rs.end());
    if(s==Rs)cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pinin=pair<int ,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

string yes="Yes",no="No";

int main() {
  int x;
  cin>>x;
  if(x==0) cout<<1<<endl;
  else cout<<0<<endl;
    
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k; cin>>k;
    int o = k/2;
    int e = k/2;
    if(k%2==1) o++;
    cout<<o*e<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, k;
	cin >> n >> k;
	
	int ans = 1;
	for(int i=0; i<n; i++){
		int a = ans * 2;
		int b = ans + k;
		
		if(a<b){
			ans = a;
		}else{
			ans = b;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
//BY: YASH JAIN, CF: yashjain0333
#include <bits/stdc++.h>
using namespace std;
#define May_the_fork_be_with_you ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define INF 1e18
#define ll long long
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define int long long
#define N 1000005

void solve(){
    string s,t; cin>>s>>t;
    int res = INT_MAX, m = t.length(), n = s.length();
    for(int i=0;i<n-m+1;i++){
        string tmp = s.substr(i,m);
        int cur = 0;
        for(int j=0;j<m;j++){
            if(tmp[j]!=t[j]) cur++;
        }
        res = min(res,cur);
    }
    cout<<res;
}

int32_t main(){
    May_the_fork_be_with_you
    int t = 1; 
    // cin>>t;
    while (t--) {
        solve();
	}
}

Measured memory_bytes: 3660
import sys

a = ""
count = 0
for input in sys.stdin:
    a += (input)
a = a.split()
for i in range(0,len(a)):
    a[i] = int(a[i])
for i in range(a[0],a[1]+1):
    if(a[2] % i == 0):
        count += 1
print count


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

int main(){
    int k, i;
    string s, t;
    cin >> k;
    cin >> s;

    int len = s.length();
    if(len > k){
        for(i=0;i<k;i++){
            t += s[i];
        }
        t += "...";
    }else{
        t = s;
    }
    
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a < b && b < c){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}


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

int n;
int a[100010];
int dp[100010][3];

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

  for (int i = 1; i <= n; i++){
    if (a[i - 1] ^ a[i]){
      dp[i][0] = dp[i - 1][0] + 1;
      dp[i][1] = dp[i - 1][1] + 1;
      dp[i][2] = dp[i - 1][2] + 1;
    }
    else {
      dp[i][0] = 1;
      dp[i][1] = dp[i - 1][0] + 1;
      dp[i][2] = dp[i - 1][1] + 1;
    }
  }

  cout << *max_element(dp[0], dp[100010]) << endl;
}

Measured memory_bytes: 4656
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 100005;
const long long INF = 1E18 + 7;

int n, a[N][2], ind[N][2];
long long ans = INF, sum[2 * N], f[2];
vector<pair<int, int>> ve;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < 2; j++)
        {
            scanf("%d", &a[i][j]);
            f[j] += a[i][j];
            ve.push_back(make_pair(i, j));
        }
    sort(ve.begin(), ve.end(), [](const pair<int, int> &x, const pair<int, int> &y) { return a[x.first][x.second] < a[y.first][y.second]; });
    for (unsigned int i = 0; i < ve.size(); i++)
    {
        ind[ve[i].first][ve[i].second] = i + 1;
        sum[i + 1] = sum[i] + a[ve[i].first][ve[i].second];
    }
    for (int i = 1; i <= n; i++)
    {
        int cur = n - 2;
        while (cur - (ind[i][0] <= cur) - (ind[i][1] <= cur) < n - 2)
            ++cur;
        ans = min(ans, sum[cur] + (ind[i][0] <= cur ? 0 : a[i][0]) + (ind[i][1] <= cur ? 0 : a[i][1]));
    }
    printf("%lld", min(ans, min(f[0], f[1])));
}

Measured memory_bytes: 5104
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read(),d=read(),ans=0;
    while(n)n/=d,ans++;
    pr2(ans);
    return 0;
}

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

using namespace std;

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

    if(s == "RRR") return cout << "3" << endl, 0;
    if(s == "SRR") return cout << "2" << endl, 0;
    if(s == "RRS") return cout << "2" << endl, 0;
    
    bool flag = 0;
    for (int i = 0; i < 3; ++i)
        flag |= s[i] == 'R';

    cout << flag << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
int A[1000000];
int B[1000000];
using namespace std;
int is_pal(int start, int end, string &str)
{
    if (start >= end)
        return 1;
    if (str[start] != str[end])
        return 0;
    return is_pal(++start, --end, str);   
}
int main(){
    int c1=0,c2=0,c3=0;
  	string s;
  cin>>s;
  int N=s.length();
  c1=is_pal(0,N-1,s);
  c2=is_pal(0,(N-1/2)-1,s);
  c3=is_pal((N+3)/2-1,N-1,s);
  if(c1>0 && c2>0 && c3>0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
    
}




Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		int[][] a = new int[n][2];

		for(int i=0; i<n; i++){
			a[i][0] = sc.nextInt();
			a[i][1] = sc.nextInt(); 
		}

		int min=1001;

		for(int i=0; i<n; i++){
			if(a[i][1] <= t){
				if(a[i][0] < min){
					min = a[i][0];
				}
			}
		}

		if(min == 1001){
			System.out.println("TLE");
		}else{
			System.out.println(min);
		}
		

	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue

#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>


#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORd(i,a,b) for(int i=(a);i>=(b);i--)
#define FORl(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORN(i,n) for(int i=(0);i<(n);i++)
#define FORR(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)

ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................



int main()
{
    fast
    
    ll n,m;
    cin>>n>>m;
    ll a[n+1],mk[n+1];
    ll i,x,y;
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=0;i<=n;i++)
    mk[i]=1;
    while(m--)
    {
        cin>>x>>y;
        if(a[x]<=a[y])
        mk[x]=0;
        if(a[y]<=a[x])
        mk[y]=0;
    }
    ll ans=0;
    for(i=1;i<=n;i++)
    {   
       // cout<<mk[i]<<" ";
        if(mk[i]==1)
        ans++;
    }
   // cout<<"\n";
    cout<<ans<<"\n";
    
    return 0;
}

Measured memory_bytes: 5220
import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	var (h1, m1, h2, m2, m) = f.readLine().split(" ").map{it.toInt()}

	var answer = 0
	if(m2 > m1) answer = m2-m1
	if(m1 > m2){
		answer = 60-(m1-m2)
		h2--
	}

	answer += 60*(h2-h1)
	answer -= m
	println(answer)
}


Measured memory_bytes: 36372
while True:
    n=input()
    if n==0:
        break
    sale=[0]*4000
    raw=[]
    for unused in xrange(n):
        a,b,c=map(int,raw_input().split())
        sale[a]+=b*c
        if a not in raw:
            raw.append(a)
    ans=[i for i in raw if sale[i]>=1000000]
    if not ans:
        print "NA"
    else:
        print "\n".join(map(str,ans))

Measured memory_bytes: 4344
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i=0; i<n; i++) cin >> p[i];

    int ans = 0;
    for (int i=0; i<n-1; i++) {
        if (p[i] == i+1) {
            swap(p[i], p[i+1]);
            ans++;
        }
    }

    if (p[n-1] == n) ans += 1;

    cout << ans << endl;
}

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

int main(void){
  int n,m;
  int dx[4] = { 0 , 1 , 0 , -1 };
  int dy[4] = { 1 , 0 , -1 , 0 };
  int angle;
  string order;
  int x,y;
  int Go;

  while(1){

    angle = 0; x = y = 1;

    cin >> n >> m;

    if( n == 0 && m == 0 ) break;

    while(1){

      cin >> order;

      if( order == "RIGHT" ){
	angle++;
	if( angle == 4 ) angle = 0;
	continue;
      }

      else if( order == "LEFT" ){
	angle--;
	if( angle == -1 ) angle = 3;
	continue;
      }

      else if( order == "STOP" ){
	cout << x << " " << y << endl;
	break;
      }

      cin >> Go;

      if( order == "FORWARD" ){

	x += dx[angle]*Go;
	y += dy[angle]*Go;

	if( x < 0 ) x = 1;
	if( y < 0 ) y = 1;
	if( x > n ) x = n;
	if( y > m ) y = m;

      }

      else if( order == "BACKWARD" ){

	x -= dx[angle]*Go;
	y -= dy[angle]*Go;

	if( x < 0 ) x = 1;
	if( y < 0 ) y = 1;
	if( x > n ) x = n;
	if( y > m ) y = m;

      }
    }
  }

  return 0;

}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
 
typedef long long int ll;
typedef pair<int, int> P;
 
const long long INF = 3e18 + 12;
const int inf = 1e9;
 
int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i, n) { cin >> v[i]; }
  int kake = 1;
 
  rep(i, inf) {
    int all = 0;
    rep(j, n) {
      if (v[j] % kake == 0) {
        all++;
        continue;
      } else {
        break;
      }
    }
    if (all == n) {
      kake *= 2;
      continue;
    }
    break;
  }
  int ans = 0;
  while (kake % 2 == 0) {
    ans++;
    kake /= 2;
  }
 
  cout << ans - 1 << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n;
	scanf("%d", &n);
	int v[n];
	int i;
	for (i = 0; i < n;i++) {
		scanf("%d", &v[i]);
	}
	int c[n];
	for (i = 0; i < n;i++) {
		scanf("%d", &c[i]);
	}

	int ans = 0;
	for (i = 0; i < n; i++) {
		if (v[i] - c[i] > 0) {
			ans += (v[i] - c[i]);
		}
	}

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


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

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

  vector<set<int>> in(N);
  vector<set<int>> out(N);

  vector<vector<int>> outflow(N + 1);
  vector<int> inflow_num(N + 1, 0);
  vector<set<int>> inflow_set(N + 1);

  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    outflow[x].push_back(y);
    inflow_num[y]++;
    inflow_set[y].insert(x);
  }

  stack<int> g;
  for (int i = 1; i <= N; i++) {
    if (inflow_num[i] == 0) g.push(i);
  }

  vector<int> sorted;
  while (!g.empty()) {
    auto tmp = g.top();
    g.pop();
    sorted.push_back(tmp);
    for (auto i : outflow[tmp]) {
      if (--inflow_num[i] == 0) {
        g.push(i);
      }
    }
  }

  reverse(sorted.begin(), sorted.end());
  vector<int> dp(N + 1, 0);
  for (int i = 0; i < N; i++) {
    int node = sorted[i];
    for (auto inflow : inflow_set[node]) {
      dp[inflow] = max(dp[inflow], dp[node] + 1);
    }
  }

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


Measured memory_bytes: 28656