akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define MIN(a,b) ((a) < (b)? (a) : (b))

template <class T>
class Queue
{
private:
    static const int LEN = 100005;
    T a[100005];
    int head, tail;

public:
    Queue(): head(0), tail(0) {};

    const bool empty() const {
        return( head == tail );
    }

    void enque(const T &x){
        a[ tail ] = x;
        tail = (tail+1) % LEN;
    }

    const T& front() const {
        return( a[head] );
    }

    const T& deque() {
        const T &ret = a[head];
        return( head = (head+1) % LEN, ret );
    }
};

struct Ps
{
    char name[16];
    int t;

    Ps() {}
    Ps(char s[], int n):  t(n) {
        strcpy(name, s);
    }
};

int main()
{
    static Queue <Ps> que;
    int N, Q;
    int elapse = 0;
    scanf("%d%d", &N, &Q);

    rep(i, N){
        int t;
        char s[16];
        scanf("%s %d", s, &t);
        que.enque( Ps(s,t) );
    }

    while(!que.empty()){
        Ps p = que.deque();
        elapse += MIN(Q, p.t);
        p.t -= Q;
        if(p.t <= 0){
            printf("%s %d\n", p.name, elapse);
        }
        else {
            que.enque(p);
        }
    }
}

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


#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
#define nrep(i,a,b) for(int i=int(a);i>=int(a);--i)
#define trv(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define watch(x) cout<<"\n"<<#x<<" is "<<x<<"\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ZERO(box) memset(box, 0, sizeof(box));
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define chkbit(s, b) (s & (1<<b))
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
const int mod=1e9+7;
const int mxN = 1e5+5;

string s,t;
vvi dp;

int main(){
	cin>>s>>t;
	int n = s.length();
	int m = t.length();
	dp = vvi(n+1,vi(m+1));
	string f;
	rep(i,1,n){
		rep(j,1,m){
			if(s[i-1]==t[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else {
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	int i=n,j=m;
	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			f = s[i-1]+f;
			i--;j--;
		} else if(dp[i-1][j]>=dp[i][j-1]) i--;
		else j--; 
	}
	cout<<f;
}

Measured memory_bytes: 70784
//yashverma

#include<bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define Pi 3.141592653589793
#define MOD 1000000007
// For i/o
#define sd1(a) scanf("%d",&a)
#define sd2(a,b) scanf("%d %d",&a,&b)
#define sd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf scanf
#define pf printf
// For debugging
#define deb(a) printf("deb%d\n",a)

typedef pair<int,int> ii;
typedef long long ll;

vector<int> vec[200005];
int ans = 0;

int n;

void dfs(int num, int len)
{
	if(num == n && len == 2){ans = 1;}
	if(len == 2)return ;
	for(int i=0; i < vec[num].size(); i++)
		dfs(vec[num][i], len + 1);
}

int main()
{
	ios::sync_with_stdio(false);
	int m;
	cin >> n >> m;
	rep(i,0,m)
	{
		int a,b;
		cin >> a >> b;
		vec[a].pb(b);
		vec[b].pb(a);
	}
	dfs(1,0);
	if(ans == 1)cout << "POSSIBLE\n";
	else cout << "IMPOSSIBLE\n";
	return 0;
}

Measured memory_bytes: 12016
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int compute(int x) {return x*x;}
int main() {
  int num=0;
  cin>>num;
  for(int i=0;i<num;i++) {
    vector<int> triangle;
    int a,b,c;
    cin>>a>>b>>c;
    triangle.push_back(a);
    triangle.push_back(b);
    triangle.push_back(c);
    sort(triangle.begin(),triangle.end());
    if(compute(triangle[2])==(compute(triangle[0])+compute(triangle[1]))) 
      cout<<"YES";
    else
      cout<<"NO";
    cout<<endl;
  }
  return 0;
}

  



Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool ab[15000],ac[15000],bc[15000];
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	int lena=a.length(),lenb=b.length(),lenc=c.length(),ans=lena+lenb+lenc;
	for(int i=0;i<lena;i++){
		for(int j=0;j<lenb;j++){
			if(a[i]!='?'&&b[j]!='?'&&a[i]!=b[j]) ab[i-j+10000]=true;
		}
	}
	for(int i=0;i<lena;i++){
		for(int j=0;j<lenc;j++){
			if(a[i]!='?'&&c[j]!='?'&&a[i]!=c[j]) ac[i-j+10000]=true;
		}
	}
	for(int i=0;i<lenb;i++){
		for(int j=0;j<lenc;j++){
			if(b[i]!='?'&&c[j]!='?'&&b[i]!=c[j]) bc[i-j+10000]=true;
		}
	}
	for(int i=-4000;i<=4000;i++){
		for(int j=-4000;j<=4000;j++){
			if(!ab[i+10000]&&!ac[j+10000]&&!bc[j-i+10000]){
				int l=min(0,min(i,j));
				int r=max(lena,max(lenb+i,lenc+j));
				ans=min(ans,r-l);
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
//#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007
//#define N 12
#define sz 1000*1000

 int main(){

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

 sort(a,a+n);

  ll sum =0,ans=n;

  for(int j=n-1;j>=0;j--){
      if(sum + a[j] < k)
            sum += a[j];
      else{
            ans = j;
            }
  }

  cout<<ans<<endl;

return 0;
 }

Measured memory_bytes: 3624
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        BigInteger MOD = new BigInteger("1000000007");
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());

        BigInteger ans = new BigInteger(String.valueOf(n - k + 1));
        System.out.println(ans.toString(10));
        for(int i = 1; i < k; i++) {
            // ans = ans * (n - k - i + 1) * (k - i) / (i + 1) / i;
            ans = ans.multiply(new BigInteger(String.valueOf(n - k - i + 1)))
                    .multiply(new BigInteger(String.valueOf(k - i)))
                    .divide(new BigInteger(String.valueOf(i + 1)))
                    .divide(new BigInteger(String.valueOf(i)));
            System.out.println(ans.remainder(MOD).toString(10));
        }
    }
}

Measured memory_bytes: 24148
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
bool operator<(S a, S b) { return a.cost < b.cost; }
bool operator>(S a, S b) { return a.cost > b.cost; }
struct H {
	int x, y;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
 //---------------------------------------------------
 //+++++++++++++++++++++++++++++++++++++++++++++++++++
int a[300][300], b[300][300];
int pa[300];
int root(int x) {
	if (pa[x] == x) return x;
	return pa[x] = root(pa[x]);
}
void unite(int x, int y) {
	x = root(x), y = root(y);
	pa[x] = y;
}
signed main() {
	int n, sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
			b[i][j] = a[i][j];
			sum += a[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				if (b[i][k] + b[k][j] < b[i][j]) {
					b[i][j] = b[i][k] + b[k][j];
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (a[i][j] != b[i][j]) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			bool l = 0;
			for (int x = 0; x < n; x++) {
				if (i == x || j == x) continue;
				if (b[i][j] == b[i][x] + b[x][j]) {
					l = 1;
				}
			}
			if (l)
				sum -= b[i][j];
		}
	}
	cout << sum/2 << endl;
	getchar(); getchar();
}

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

int main(){

  int N;cin>>N;
    string A,B,C;
    cin>>A>>B>>C;
    int ans=0;
    for(int i=0;i<N;i++){
        if(A[i]!=B[i]&&B[i]!=C[i]&&C[i]!=A[i]) ans+=2;
        else if(!(A[i]==B[i]&&B[i]==C[i])) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int i = 1;
		try {
			while ((line = reader.readLine()) != null) {
				if (line.equals("0"))
					break;
				System.out.println("Case " + i + ": " + line);
				i++;
			}
		} catch (IOException e) {
		}
	}
}

Measured memory_bytes: 27924
N, K = map(int, input().split())
A = list(map(lambda a: int(a) - 1, input().split()))

now = 0
for d in range(64):
    if ((1 << d) & K) > 0:
        now = A[now]
    A = [A[a] for a in A]
print(now + 1)


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

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n, w;
  cin >> n >> w;
  vector<pair<ll, ll>> nw(n);
  // F:weight, S:value
  rep(i, n) cin >> nw[i].F >> nw[i].S;
  // d[i][v]=重さの最小値
  vector<vector<ll>> dp(n, vector<ll>((ll)1e+5 + 1, INF));
  dp[0][0] = 0;
  dp[0][nw[0].S] = nw[0].F;
  repz(kind, 1, n) {
    rep(value, (ll)1e+5 + 1) {
      // not choose
      chmin(dp[kind][value], dp[kind - 1][value]);
      // choose
      int newvalue = value + nw[kind].S;
      if (newvalue < (ll)1e+5 + 1) {
        chmin(dp[kind][newvalue], dp[kind - 1][value] + nw[kind].F);
      }
    }
  }
  for(ll value=(ll)1e+5;value>=0;value--){
    if(dp[n-1][value]<=w){
      cout << value << endl;
      ret;
    }
  }
  ret;
}


Measured memory_bytes: 82404
main(){double a,b,c,d,e,f;for(scanf("%*d");~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f);puts(d>c+f?"0":c>d+f?"2":f>c+d?"-2":"1"))d=hypot(a-d,b-e);}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<cstdlib> 
#include<string>
#include<math.h>
#include<bitset>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<queue>
using namespace std;

int main(){

	string s;
	cin >> s;

	for(int i=0;i<12;i++){
		cout << s[i];
		if(i==3)cout << " ";
	}
	cout << endl;

	//while(1);

	return 0;
}

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

using namespace std;

typedef long long ll;

template<typename T> ostream& operator << (ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " "; return os; 
}
template<typename T> istream& operator >> (istream& is, vector<T>& v) {
  for (auto& i : v) is >> i; return is;
}
template<typename K, typename V> ostream& operator << (ostream& os, unordered_map<K, V> m) {
  for (auto& i : m) os << i.first << ":" << i.second << endl; return os;
}
template<typename T> inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template<typename T> inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  cin >> a;

  vector<vector<ll>> dp(n+1, vector<ll>(k+1, 0));
  dp[0][0] = 1;
  for (int i=0; i<n; i++) {
    // cumulative sum
    vector<ll> sum(k+1);
    sum[0] = dp[i][0];
    for (int j=1; j<=k; j++) {
      sum[j] = sum[j-1] + dp[i][j];
    }
    for (int j=0; j<=k; j++) {
      if (j-a[i]-1 >= 0) {
        dp[i+1][j] = sum[j] - sum[j-a[i]-1];
      } else {
        dp[i+1][j] = sum[j];
      }
      dp[i+1][j] %= (int) 1e9+7;
    }
  }
  cout << dp[n][k] << endl;
  return 0;
}


Measured memory_bytes: 80256
n=int(input())

ansli=[]
for i in range(1, n):
    mn=n-i
    s1=str(i)
    s2=str(mn)
    dli=[]
    for j in s1:
        dli.append(int(j))
    for k in s2:
        dli.append(int(k))
    ans=0
    for l in dli:
        ans+=l
    #print(ans)
    ansli.append(ans)
print(min(ansli))


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

int main(){
    string a, b, c, ans = "NO";
    cin >> a >> b >> c;
    
    if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) {
        ans = "YES";
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

bool exist(int n, int a[],int N){
  bool r = false;
  REP(i,N){ if(n==a[i]){r = true;break;} }
  return r;
}

int main(){
  int N,K; cin>>N>>K;
  int d[K]; CINA(d,K);
  for(int i=N;i<N*100;i++){
    int temp = i;
    bool ok = true;
    while(temp>0){
      if( exist(temp%10,d,K) ){ ok = false; break;}
      temp /= 10;
    }
    if(ok){cout<<i<<"\n"; break;}
  }
}

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		String str1 = s.next();
		String str2 = s.next();
		int sum=0;
		for(int i=0;i<3;i++) {
			if(str1.charAt(i)==str2.charAt(i)) {
				sum++;
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allg(v) v.begin(), v.end(), greater<int>()



signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;  
  cin >> s;
  
  bool ans = true;
  
  if(s[0] != 'A') ans = false;  
  if(s[1] == 'C' or s[s.size()-1] == 'C') ans = false;
  
  int f = 0;
  rep(i, 0, s.size()) {
    if(s[i] == 'C') f++;
  }
  if(f != 1) ans = false;
  
  if(ans) {
    rep(i, 1, s.size()) {
      if( i != s.find('C') and (s[i]-'a' < 0 or s[i]-'a' >= 26) ) ans = false;
    }
  }
  
  cout << ( ans ?"AC" :"WA") << "\n";

}


Measured memory_bytes: 256
a,b,c,x,y = map(int,input().split())
ans = 0
if 2*c < a + b:
    ans += 2*c*min(x,y)
    if x > y:
        ans += (x-y)*a if a <= 2*c else (x-y)*(2*c)
    else:
        ans += (y-x)*b if b <= 2*c else (y-x)*(2*c)
else:
    ans += a*x + b*y
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
int H, ha, ma, sa;

int gcd(int a, int b) {
    if(a == 0) return b;
    if(b == 0) return a;
    if(a < b) swap(a, b);
    if(a % b == 0) return b;
    return gcd(b, a % b);
}

struct Clock {
    int h, m, n, d;
    Clock(int _h, int _m, int _n, int _d) {
        h = _h;
        m = _m;
        n = _n;
        d = _d;
        int g = gcd(n, d);
        n /= g;
        d /= g;
    }
};

bool operator <(Clock a, Clock b) {
    if(a.h != b.h) return a.h < b.h;
    if(a.m != b.m) return a.m < b.m;
    return a.n * b.d < b.n * a.d;
}

bool operator <=(Clock a, Clock b) {
    if(a.h != b.h) return a.h < b.h;
    if(a.m != b.m) return a.m < b.m;
    return a.n * b.d <= b.n * a.d;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> H >> ha >> ma >> sa;
        if(H == 0 && ha == 0 && ma == 0 && sa == 0) break;
        Clock a(ha, ma, sa, 1);
        Clock ans(-1, -1, 0, 1);
        for(int h = 0; h < H; h++) {
            for(int m = 0; m < 60; m++) {
                for(int delta = -1; delta <= 1; delta++) {
                    int Left = delta * 3600 * H + 60 * 60 * h + 60 * m * (H + 1);
                    if(Left < 0) continue;
                    if(Left >= 60 * (H * 120 - H - 1)) continue;
                    Clock now(h, m, Left, H * 120 - H - 1);
                    if(60 * now.m * now.d == 59 * now.n) continue;
                    if(ans.h == -1) {
                        ans = now;
                    } else if(ans < a && a <= now) {
                        ans = now;
                    } else if(a <= now && now < ans) {
                        ans = now;
                    } else if(now <= ans && ans < a) {
                        ans = now;
                    }
                }
            }
        }
        cout << ans.h << " " << ans.m << " " << ans.n << " " << ans.d << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include<stdio.h>
int main(){
        int H,W,j,i;
        
        while(1){
        	scanf("%d %d",&H,&W);
        	//HとWの値が0の時抜ける
        	if(H == 0 && W == 0){
        	   break;
        	}
        	for(i = 1;i <= H;i++){
        		for(j = 1;j <= W;j++){
        			//全て#を出力する
        			printf("#");
        		}
        		printf("\n");
        	}
        	printf("\n"); 
        }
        return 0;
}


Measured memory_bytes: 2052
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func strSprit(str string) []string {
	cols := strings.Split(str, " ")
	return cols
}

func parseInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func intSprit(str string) []int {
	strs := strSprit(str)
	cols := make([]int, len(strs))
	for i, v := range strs {
		cols[i] = parseInt(v)
	}
	return cols
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
	line := nextLine()

	spl := intSprit(line)

	sort.Sort(sort.Reverse(sort.IntSlice(spl)))

	fmt.Println(spl[0]*10 + spl[1] + spl[2])
}


Measured memory_bytes: 640
n,m,x=map(int,input().split())
a=[int(i) for i in input().split()]
a=set(a)
ans=10**100
tmp=0
for i in range(x+1):
    if i in a:
        tmp+=1
ans=min(ans,tmp)
tmp=0
for i in range(x,n+1):
    if i in a:
        tmp+=1
ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
int minimum(int a, int b) { return a < b ? a : b; }
int maximum(int a, int b) { return a > b ? a : b; }
const long long mod = 1000000007;
//const long long mod = 998244353;
int main() {
	int N, K;
	scanf("%d %d", &N, &K);
	auto H = new int[N];
	for (int i = 0; i < N; i++)scanf("%d", H + i);
	std::sort(H, H + N);
	long long res = 0;
	for (int i = 0; i < N - K; i++) {
		res += H[i];
	}
	printf("%lld", res);
	return 0;
}

Measured memory_bytes: 1024
a = list(input())
b = list(input())
c = list(input())

turn = a.pop(0)
while True:
  if turn == 'a':
    if a :
      turn = a.pop(0)
    else:
      print("A")
      break
  elif turn == 'b':
    if b :
      turn = b.pop(0)
    else:
      print("B")
      break
  elif turn == 'c':
    if c :
      turn = c.pop(0)
    else:
      print("C")
      break


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n;

bool same(int n) {
	set<int> s;
	while (n) s.insert(n%10), n/= 10;
	return s.size()==1;
}

signed main() {
	cin >> n;
	while (1) {
		if (same(n)) return cout << n << endl, 0;
		n++;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 101

int main() {
  int i, j ,l, n, u, k, data[N][N];

  scanf("%d", &n);

  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      data[i][j] = 0;
    }
  }

  for (i = 0; i < n; i++) {
    scanf("%d%d", &u, &k);

    for (j = 0; j < k; j++) {
      scanf("%d", &l);
      data[u][l] = 1;
    }
  }

  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      printf("%d", data[i][j]);
      if (j != n) printf(" ");
    }
    printf("\n");
  }


  return 0;
}



Measured memory_bytes: 2132
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, bool isFront) {
	if (first_itr < 0 || first_itr > str.size()) {
		return str;
	}
	else {
		if (isFront) {
			std::string tmp;
			for (size_t i = 0; i < first_itr; i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
		else {
			std::string tmp;
			for (size_t i = first_itr; i < str.size(); i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
	}
}


bool dfs(int depth, str s) {
	/*if (depth == n) {
		ans.push_back(s);
		return false;
	}
	for (int i = 0; i < n; i++) {
		if (dfs(depth + 1, s + dic.at(i))) {
			return true;
		}
	}*/
	return false;
}


int main() {
	int n, k; cin >> n >> k;
	int x = 0;
	while (n>0)
	{
		n /= k;
		x++;
	}
	cout << x << endl;





	return 0;
}

Measured memory_bytes: 256
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll l,r,d;
    cin>>l>>r>>d;
    ll res=0;
    rep3(i,l,r+1){
        if(i%d==0)res++;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n;
  cin >> n;
  vector<long> a(n);
  vector<bool> select(n,false);
  rep(i,n) cin >> a.at(i);
  sort(a.begin(),a.end());
  vector<long> two(33);
  two.at(0) = 1;
  rep(i,32) two.at(i+1) = two.at(i)*2;
  long ans = 0;
  for(int i=n-1;i>=1;i--){
    
    if(select.at(i)){
      a.pop_back();
      continue;
    }
    //rep(i,n) cout << select.at(i) << " ";
    //cout << endl;
    //rep(i,a.size()) cout << a.at(i) << "  :::";
    //cout << endl;
    long x = a.at(i);
    long sum = *upper_bound(two.begin(),two.end(),x);
    long y = sum - x;
    //a.pop_back();
    /*if(a.at(i-1) < y){
      a.pop_back();
      continue;
    }*/
    long id = lower_bound(a.begin(),a.end(),y) - a.begin();
    //cout << i << " " << id << endl;
    if(id == i){
      a.pop_back();
      continue;
    }
    //cout << y << ":y" << "  ";
    //rep(j,7) cout << select.at(id) << " ";
    if(a.at(id) == y && !select.at(id)){
      long ch = upper_bound(a.begin(),a.end(),y) - a.begin();
      //cout << ch << ":ch" << endl;
      int j;
      if(i == ch-1) j = ch-2;
      else j = ch-1;
      for(;j>=id;j--){
        if(select.at(j)) continue;
        select.at(j) = true;
        ans++;
        break;
      }
    }
    //rep(j,7) cout << select.at(id) << " ";
    //cout << endl;
    a.pop_back();
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
import queue

q=queue.Queue()
for i in range(1,10):
    q.put(i)
    
k=int(input())

a=0

for i in range(k):
    a=q.get()
    if a%10!=0:
        q.put(10*a+a%10-1)
    q.put(10*a+a%10)
    if a%10!=9:
        q.put(10*a+a%10+1)

print(a)

Measured memory_bytes: 57428
#include<stdio.h>

int main(void) {
	int n;
	int a, b, c;
	scanf("%d", &n);
	while (scanf("%d %d %d", &a, &b, &c) != EOF) {
		if (a*a == b*b + c*c || b*b == a*a + c*c || c*c == a*a + b*b) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}

	}
	return 0;
}

Measured memory_bytes: 580
n, m = map(int, input().split())
k = list(map(int, input().split()))
d = [0]*(m-1)
k.sort()
for i in range(m-1):
    d[i] = abs(k[i]-k[i+1])
d = sorted(d, reverse=True)
print(sum(d)-sum(d[:n-1]))


Measured memory_bytes: 13968
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    double pos[1001];
    double total = 0, sum = 0, maxi = 0;
    for(int i = 1; i <= 1000; i++)
    {
        total += i;
        pos[i] = total / i;
    }
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        if(i < k)
        {
            sum += pos[a[i]];
        }
    }
    maxi = sum;
    for(int i = k - 1; i < n; i++)
    {
        if(i != k - 1)
        {
            sum += pos[a[i]];
        }
        if(sum >= maxi)
        {
            maxi = sum;
        }
        sum -= pos[a[i - k + 1]];
    }
    cout << fixed << setprecision(1) << maxi << endl;
    return 0;
}

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

int parse_int(string s){
	int reg = 1, res = 0;
	for(int i = 0;i < s.length();++i){
		if('2' <= s[i] && s[i] <= '9'){
			reg = s[i] - '0';
		}
		else{
			if(s[i] == 'm'){
				res += reg * 1000;
			}
			else if(s[i] == 'c'){
				res += reg * 100;
			}
			else if(s[i] == 'x'){
				res += reg * 10;
			}
			else {
				res += reg;
			}
			reg = 1;
		}
	}
	return res;
}

string parse_str(int a){
	string res = "";
	int divisor[] = {1000, 100, 10, 1};
	char symbol[] = {'m', 'c', 'x', 'i'};
	for(int i = 0;i < 4;++i){
		int c = a / divisor[i];
		if(c == 1){
			res += symbol[i];
		}
		else if(1 < c && c < 10){
			res += (c + '0');
			res += symbol[i];
		}
		a -= c * divisor[i];
	}
	return res;
}

int main(){
	int n;
	string a, b;
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> a >> b;
		cout << parse_str(parse_int(a) + parse_int(b)) << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>

int main()
{
	int a,b,c,cnt=3;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a==b) 
	  {
	  	cnt-- ;
	  	if(a==c) cnt--;
	  }
	else if(a==c)
	{
    	cnt--;
	}
	else if(b==c)
    {
    	cnt--;
	}
   
	printf("%d\n",cnt);

return 0;
}

Measured memory_bytes: 128
import math

n = int(input())
t_a = [tuple(map(int, input().split())) for _ in range(n)]

tmp_tuple = t_a[0]
ans = sum(tmp_tuple)
# ans = sum(tmp_tuple)
for i in range(1, n):
    if (tmp_tuple[0] / t_a[i][0]) == (tmp_tuple[1] / t_a[i][1]):
        continue
    else:
        # to prevent error
        factor = max(math.ceil((tmp_tuple[0] + t_a[i][0] - 1) // t_a[i][0]), math.ceil((tmp_tuple[1] + t_a[i][1] - 1) // t_a[i][1]))

    tmp_tuple = tuple(map(lambda x: x * factor, t_a[i]))
    # print(tmp_tuple)
    # print(sum(tmp_tuple) - ans)
    ans = sum(tmp_tuple)
    
print(sum(tmp_tuple))


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main() {
	int k, x;
	cin >> k >> x;
	for (int i = k - 1; i > 0; i--) {
		cout << x - i<<" ";
	}
	for (int j = 0; j <= k - 1; j++) {
		cout << x + j<<" ";
	}
	
	return 0;
}


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

struct cake
{
  int w, d;
  bool operator<(const cake &other) const
  {
    return w * d < other.w * other.d;
  }
  void print()
  {
    cout << w << "×" << d << endl;
  }
  int area()
  {
    return w * d;
  }
};

vector<cake> cakes;

void cut(int id, int s)
{
  cake ck = cakes.at(id);
  cakes.erase(cakes.begin() + id);
  bool flag = true;
  while (1)
  {
    if (flag)
    {
      if (s - ck.w <= 0)
      {
        break;
      }
      s -= ck.w;
      flag = !flag;
    }
    else
    {
      if (s - ck.d <= 0)
      {
        break;
      }
      s -= ck.d;
      flag = !flag;
    }
  }
  int w1, d1, w2, d2;
  if (flag)
  {
    w1 = s;
    w2 = ck.w - s;
    d1 = ck.d;
    d2 = ck.d;
  }
  else
  {
    d1 = s;
    d2 = ck.d - s;
    w1 = ck.w;
    w2 = ck.w;
  }
  cake ck1{w1, d1}, ck2{w2, d2};
  if (ck1 < ck2)
  {
    cakes.push_back(ck1);
    cakes.push_back(ck2);
  }
  else
  {
    cakes.push_back(ck2);
    cakes.push_back(ck1);
  }
}

int main()
{
  while (1)
  {
    cakes.clear();
    int n, w, d;
    cin >> n >> w >> d;
    if (!n && !w && !d)
    {
      break;
    }
    cakes.push_back(cake{w, d});
    rep(i, n)
    {
      int p, s;
      cin >> p >> s;
      p--;
      cut(p, s);
    }
    sort(cakes.begin(), cakes.end());
    rep(i, n + 1)
    {
      if (i)
        cout << " ";
      cout << cakes.at(i).area();
    }
    cout << endl;
  }
}


Measured memory_bytes: 3084
x = list(input())

y = 0
z = 0
for i in range(len(x)):
    if x[i] in ['A', 'C', 'G', 'T']:
        y += 1
    else:
        z = max(z,y)
        y = 0
else:
    z = max(z,y)

print(z)

Measured memory_bytes: 2940
# -*- coding: utf-8 -*-
# 整数の入力

n = int(input())
c = input()
# c = list(map(int, input().split()))


r_max = 0
w_min = n - 1

cnt = 0

while r_max < w_min:
    if c[r_max] == "R":
        r_max += 1
        continue
    elif c[w_min] == "W":
        w_min -= 1
        continue
    else:
        cnt += 1
        r_max += 1
        w_min -= 1


print("{}".format(cnt))


Measured memory_bytes: 67472
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
int a[2005];
LL dp[2005][2005];
pii p[2005];
int n;
LL dfs(int s, int e){
    if(dp[s][e] != -1) return dp[s][e];
    if(s > e) return 0;
    int idx = 1 + (s-1) + (n-e);
    dp[s][e] = max(dfs(s+1, e) + p[idx].first*1ll*abs(p[idx].second-s), dfs(s, e-1) + p[idx].first*1ll*abs(p[idx].second-e));
    return dp[s][e];
}
int main(){
    memset(dp, -1, sizeof(dp));
    scanf("%d", &n);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]), p[i] = pii(a[i], i);
    sort(p+1, p+1+n);
    reverse(p+1, p+1+n);
    printf("%lld\n", dfs(1, n));
}

Measured memory_bytes: 35348
#include<bits/stdc++.h>
using namespace std;
using li = long int;
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

li res = 0;
int N, i, j, val;
vector<int> L;


int main(){
    cin >> N;
    for(int i = 0; i < N; i++){ cin >> val; L.pb(val); }
    sort(L.begin(),L.end());

    for(i = 0; i < N-2; i++){
        for(j = i+1; j < N-1; j++){
          	auto Ite = lower_bound(ALL(L), L[i]+L[j]);
          	//cout << "L[" << i << "]+L[" << j << "] = " << L[i]+L[j] << " , Ite = " << (int)(Ite-L.begin()) << endl;
            int satis_n = (int)(Ite-L.begin());
            res += max(0, satis_n - (j+1));
        }
    }

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

Measured memory_bytes: 3532
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
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(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  ll n,W;cin >> n >> W;
  vector<ll> w(n), v(n);
  rep(i,n) {
    cin >> w[i] >> v[i];
  }

  ll w0 = w[0];
  rep(i,n) {
    w[i] -= w0;
  }
  
  vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(3*n+1, vector<ll>(n+1, 0)));

  rep(i,n) {
    rep(j, 3*n+1) {
      rep(k, n) {
	if(j - w[i] >= 0) {
	  chmax(dp[i+1][j][k], dp[i][j][k]);
	  chmax(dp[i+1][j][k+1], dp[i][j - w[i]][k] + v[i]);
	}
	else chmax(dp[i+1][j][k], dp[i][j][k]);
      }
    }
  }


  ll res = 0;
  rep(j,3*n+1) {
    rep(k,n+1) {
      if(j <= W - k*w0) chmax(res, dp[n][j][k]);
    }
  }
    
  cout << res << "\n";
  
  return 0;
}


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

int n, m;
int s[100005], t[100005];
vector<int> edge[10005], redge[10005];
bool used[10005];
vector<int> ord;
int comp[10005];
int noin[10005], noout[10005];

void dfs1(int a){
  if(used[a]) return;
  used[a]=true;
  for(int i=0; i<edge[a].size(); i++)
    dfs1(edge[a][i]);
  ord.push_back(a);
}

void dfs2(int a, int c){
  if(used[a]) return;
  used[a]=true;
  comp[a]=c;
  for(int i=0; i<redge[a].size(); i++)
    dfs2(redge[a][i], c);
}

int main(){
  cin >> n >> m;
  for(int i=0; i<m; i++){
    cin >> s[i] >> t[i];
    edge[s[i]].push_back(t[i]);
    redge[t[i]].push_back(s[i]);
  }
  fill(used, used+n, false);
  for(int i=0; i<n; i++) dfs1(i);
  int cnt=0;
  fill(used, used+n, false);
  for(int i=n-1; i>=0; i--) 
    if(!used[ord[i]]) dfs2(ord[i], cnt++);
  fill(noin, noin+n, 1);
  fill(noout, noout+n, 1);
  for(int i=0; i<m; i++){
    if(comp[s[i]]!=comp[t[i]]){
      noout[comp[s[i]]]=0;
      noin[comp[t[i]]]=0;
    }
  }
  int ans=0;
  if(cnt>1){
    int noincnt=0, nooutcnt=0;
    for(int i=0; i<cnt; i++) noincnt+=noin[i];
    for(int i=0; i<cnt; i++) nooutcnt+=noout[i]; 
    ans=max(noincnt, nooutcnt);
  }
  cout << ans << endl;
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  if(n % 1000 == 0){
    ANS(0);
  }else{
    ANS(1000-n%1000);
  }
  return 0;
}

Measured memory_bytes: 3648
using System;

namespace ITP1_9_C
{
	class Program
	{
		static void Main(string[] args)
		{
			int taro = 0, hanako = 0;

			int n = int.Parse(Console.ReadLine());
			for(int i = 0; i < n; i++) {
				string[] vs = Console.ReadLine().Split(' ');

				if(string.Compare(vs[0], vs[1]) < 0) {
					hanako += 3;
				}
				else if(string.Compare(vs[0], vs[1]) > 0) {
					taro += 3;
				}
				else {
					taro++;
					hanako++;
				}
			}

			Console.WriteLine($"{taro} {hanako}");
		}
	}
}



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

int main() {
  int N, sum = 0, a = 1;
  cin >> N;
  
  for (int i = 0; i < 8; i++){
    a *= 10;
    sum += (N % a) / (a / 10)  ;
  }
         
  if ((N % sum) == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

#define A first
#define B second

const ll p = 1e9+7;
const int MAXN = 2e5+5;

int n, s[MAXN], v[MAXN], pref[MAXN], suff[MAXN];
//how far left and right the ranges extend
ll dp[MAXN];
pii x[MAXN], r[MAXN];
map<int, int> m;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> x[i].A >> x[i].B;
		v[i] = x[i].B;
	}

	sort(x, x+n);
	sort(v, v+n);

	for (int i = 0; i < n; ++i)
		m[v[i]] = i;
	for (int i = 0; i < n; ++i)
		s[i] = m[x[i].B];

	pref[0] = s[0], suff[n-1] = s[n-1];
	for (int i = 1; i < n; ++i)
		pref[i] = max(pref[i-1], s[i]);
	for (int i = n-2; i >= 0; --i)
		suff[i] = min(suff[i+1], s[i]);

	for (int i = 0; i < n; ++i) {
		int lo = 0, hi = i;
		while (lo != hi) {
			int mid = (lo+hi)/2;
			if (pref[mid] >= s[i])
				hi = mid;
			else
				lo = mid+1;
		}
		r[i].A = lo;
		lo = i, hi = n-1;
		while (lo != hi) {
			int mid = (lo+hi+1)/2;
			if (suff[mid] <= s[i])
				lo = mid;
			else
				hi = mid-1;
		}
		r[i].B = lo;
	}

	sort(r, r+n);

	dp[0] = 1;
	int ctl = 0, ctr = 0;
	ll sum = 0;

	for (int i = 0; i < n; ++i) {
		while (ctl < n && r[ctl].B < i)
			sum = (sum+p-dp[ctl])%p, ++ctl;
		while (ctr < n && r[ctr].A <= i)
			sum = (sum+dp[ctr])%p, ++ctr;
		//so we are only consdering ranges [ctl, n-1]
		//find the last range that is killed by i

		dp[ctr] = (2*dp[ctr] + sum)%p;
	}

	cout << dp[n] << endl;
}

Measured memory_bytes: 17408
#include<stdio.h>
int main(){
	int H,N;
	int i;
	scanf("%d%d",&H,&N);
 	for( i=0;i<N;i++){
 	int A;
 	scanf("%d",&A);
	  	H-=A;
	}
 	if(H<=0)puts("Yes");
 	else puts("No");
    }


Measured memory_bytes: 128
#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 pb emplace_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
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
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 out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll l,r,d;cin>>l>>r>>d;
    ll ans=0;
    REP(i,l,r+1)if(i%d==0)ans++;
    out(ans);
}

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

	
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(NULL);
	
	int n, k, cnt = 0; cin >> n >> k;
	while(n--){
		int x; cin >> x;
		if(x >= k) ++cnt;
	}
	cout << cnt;
      
	
	
	return 0;
}

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

int info[51][51];
int main(){
    int N,M;cin>>N>>M;
    pair<int,int> node[M];
    rep(i,M){
        int p,q;cin>>p>>q;
        node[i]=make_pair(p,q);
        info[p][q]++;
        info[q][p]++;
    }
    int count=0;
    int check[N+1];
    rep(i,M){
        rep(j,N+1)check[j]=0;
        check[1]=1;
        queue<int> now;
        now.push(1);
        while(now.size()){
            int a=now.front();
            now.pop();
            rep(j,N+1){
                if((a==node[i].first and j==node[i].second)or(a==node[i].second and j==node[i].first))continue;
                else if(info[a][j]){
                    if(check[j])continue;
                    else{
                        check[j]=1;
                        now.push(j);
                    }
                }
            }
        }
        int sum=0;
        rep(j,N+1)sum+=check[j];
        if(sum!=N)count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256