akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define ll long long
const long long INF = 1LL << 60;

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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd



int main() {
	int k;
	cin >> k;
	if (k % 2 == 0) {
		cout << k * k / 4;
	}
	else {
		cout << (k / 2)*((k + 1) / 2);
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int> As(N+2,0);
  for(int i=1;i<=N;i++){cin>>As.at(i);}
  int sum=0;
  for(int i=0;i<=N;i++){sum+=abs(As.at(i)-As.at(i+1));}
  for(int i=1;i<N+1;i++){
    int dif=abs(As.at(i)-As.at(i-1))+abs(As.at(i)-As.at(i+1))-abs(As.at(i-1)-As.at(i+1));
    cout<<sum-dif<<endl;
  }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n-1);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];
  int sum = 0;
  rep(i,n) sum += b[i];
  rep(i,n-1){
    if(a[i+1] - a[i] == 1 && a[i+1] > a[i]) sum += c[a[i]-1];
    //cout << c[i] << endl;
  }
  cout << sum << endl;
}


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

int main() {
  int N;
  string X;
  cin >> N >> X;
  int pcnt = 0;
  for (int i = 0; i < N; i++) {
    if (X[i] == '1') pcnt++;
  }
  ll X_minus = 0, X_plus = 0;
  vector<ll> p2_minus(N, 1), p2_plus(N, 1);
  for (int i = N-1; i >= 0; i--) {
    X_minus += (X[i] - '0') * p2_minus[i];
    X_plus += (X[i] - '0') * p2_plus[i];
    if (i > 0) {
      p2_minus[i-1] = p2_minus[i]*2;
      if (pcnt != 1) p2_minus[i-1] %= pcnt-1;
      p2_plus[i-1] = p2_plus[i]*2;
      p2_plus[i-1] %= pcnt+1;
    }
  }
  vector<int> ans(N, 0);
  for (int i = 0; i < N; i++) {
    if (X[i] - '0' == 1 && pcnt == 1) {
      cout << 0 << endl;
      continue;
    }
    int pcnt_re;
    ll X_tmp;
    if (X[i] == '0') {
      X[i] = '1';
      pcnt_re = pcnt+1;
      X_tmp = X_plus + p2_plus[i];
      X_tmp %= pcnt_re;
    }
    else {
      X[i] = '0';
      pcnt_re = pcnt-1;
      X_tmp = X_minus - p2_minus[i] + pcnt_re;
      if (pcnt_re != 0) X_tmp %= pcnt_re;
    }
    ans[i]++;
    while (X_tmp > 0) {
      X_tmp = X_tmp % __builtin_popcount(X_tmp);
      ans[i]++;
    }
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 7616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static int R;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        R = sc.nextInt();

        System.out.println(solve());
    }

    static String solve() {
        if( R < 1200 ) {
            return "ABC";
        } else if( R < 2800 ) {
            return "ARC";
        } else {
            return "AGC";
        }
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 22612
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
#define rrep(i,N) for(int i=N-1;i>=0;--i)
typedef long long int LL;

const LL mod = 1000000007;
std::string S;
LL cnt, ans;

// (num ^ x) % mod
LL pow_mod(LL num, LL x, LL mod)
{
	LL res = 1;
	while (x > 0)
	{
		if (x & 1)
		{
			res = (res*num) % mod;
		}
		num = (num*num) % mod;
		x >>= 1;
	}
	return res;
}

int main()
{
	in >> S;
	std::vector<LL>sumA(S.length(), 0), sumC(S.length(), 0);
	rep(i, S.length())
	{
		if (S[i] == '?')
		{
			if (i > 0) sumA[i] = sumA[i - 1] * 3 + pow_mod(3, cnt, mod);
			else sumA[i] = 1;
			++cnt;
		}
		else if (S[i] == 'A')
		{
			if (i > 0) sumA[i] = sumA[i - 1] + pow_mod(3, cnt, mod);
			else sumA[i] = 1;
		}
		else
		{
			if (i > 0) sumA[i] = sumA[i - 1];
			else sumA[i] = 0;
		}
		sumA[i] %= mod;
	}
	cnt = 0;
	rrep(i, S.length())
	{
		if (S[i] == '?')
		{
			if (i < S.length() - 1) sumC[i] = sumC[i + 1] * 3 + pow_mod(3, cnt, mod);
			else sumC[i] = 1;
			++cnt;
		}
		else if (S[i] == 'C')
		{
			if (i < S.length() - 1) sumC[i] = sumC[i + 1] + pow_mod(3, cnt, mod);
			else sumC[i] = 1;
		}
		else
		{
			if (i < S.length() - 1) sumC[i] = sumC[i + 1];
			else sumC[i] = 0;
		}
		sumC[i] %= mod;
	}
	rep(i, S.length())
	{
		if ((0 < i&&i < S.length() - 1) && (S[i] == 'B' || S[i] == '?'))
		{
			ans += (sumA[i - 1] * sumC[i + 1]) % mod;
			ans %= mod;
		}
	}
	out << ans << std::endl;
	return 0;
}


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

using namespace std;

inline int read(){
    int w=1,s=0;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if (ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

int main(){
    int n=read();
    if (n<1200) cout<<"ABC";
    else if(n<2800) cout<<"ARC";
    else cout<<"AGC";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int N;
    string S,T;
    cin >> N >> S >> T;
    for(int i=0;i<N;i++){
        cout << S[i] << T[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		String S = sc.next();

		char[] c = S.toCharArray();

		if (c[0] == c[1] && c[2] == c[3] && c[1] != c[2]) {
			System.out.println("Yes");
		} else if (c[0] == c[2] && c[1] == c[3] && c[2] != c[3]) {
			System.out.println("Yes");
		} else if (c[0] == c[3] && c[1] == c[2] && c[2] != c[3]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

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

    int pre = 0;
    for (int i = 0; i < N; i++) {
        if (pre <= H[i] - 1) {
            pre = H[i] - 1;
        } else if (pre <= H[i]) {
            pre = H[i];
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

  using namespace std;
  using namespace std::chrono; 

  typedef long long int ll;

  #define MOD (ll)(1e9+7)
  #define endl "\n"
  #define pb push_back
  #define TEST_CASES  ll t;cin>>t;while(t--)
  #define forn(i,a,n) for (int i = a; i < n; ++i)
  #define f first
  #define s second
  #define all(x) x.begin(), x.end()

  void __print(int x) {cerr << x;}
  void __print(long x) {cerr << x;}
  void __print(long long x) {cerr << x;}
  void __print(unsigned x) {cerr << x;}
  void __print(unsigned long x) {cerr << x;}
  void __print(unsigned long long x) {cerr << x;}
  void __print(float x) {cerr << x;}
  void __print(double x) {cerr << x;}
  void __print(long double x) {cerr << x;}
  void __print(char x) {cerr << '\'' << x << '\'';}
  void __print(const char *x) {cerr << '\"' << x << '\"';}
  void __print(const string &x) {cerr << '\"' << x << '\"';}
  void __print(bool x) {cerr << (x ? "true" : "false");}

  template<typename T, typename V>
  void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  template<typename T>
  void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  void _print() {cerr << "]\n";}
  template <typename T, typename... V>
  void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  #ifndef ONLINE_JUDGE
  #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
  #else
  #define debug(x...)
  #endif

  ll powD(ll x,ll y){
    ll res = 1;
    while(y > 0){
      if(y & 1)
        res = (res*x)%MOD;
      x = (x*x)%MOD;
      y = y>>1;
    }
    return res;
  }

  /*CHECK FOR CORNER CASES FOR GOD'S SAKE*/
  int main()
  {
    //freopen("dislodging_logs_validation_input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
      ll x,k,d;
      cin>>x>>k>>d;
      ll q = abs(x)/d;
      if(q >= k){
        ll ans = abs(x) - k*d;
        cout<<ans<<endl;
      } 
      else{
        if((k+q)%2 == 0){
          cout<<abs(x)-q*d<<endl;
        }
        else{
          ll ans = abs(abs(x)-(q+1)*d);
          cout<<ans<<endl;
        }
      }
     
}



   
  


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    bool varied = true, a[26];
    for (int i = 0; i < 26; i++) a[i] = false;
    for (int i = 0; i < s.size(); i++)
    {
        if (a[s[i] - 97] == true)
        {
            cout << "no";
            varied = false;
            break;
        }
        else a[s[i] - 97] = true;
    }
    if (varied == true) cout << "yes";
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;

using namespace std;

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   ll arr[n];
   for(ll i=0;i<n;i++)
        cin>>arr[i];
   
   ll sum = 0;
   for(ll i=0;i<64;i++)
   {
       ll temp = (1LL<<i);
       ll cnt = 0;
       for(ll j=0;j<n;j++)
       {
           if((temp&arr[j]))
                cnt++;        
       }
       
       if(cnt%2 == 1)
       {
           sum+=temp;
           for(ll j=0;j<n;j++)
           {
               if((temp&arr[j]))
                    arr[j]-=temp;
           }
       }
   }
   
   ll id = 0;
   for(ll i=63;i>-1;i--)
   {
       ll mid = id;
       ll mel = LLONG_MIN;
       ll temp = (1LL<<i);
       for(ll j=id;j<n;j++)
       {
           if((temp&arr[j]) && mel<arr[j])
           {
               mel = arr[j];
               mid = j;
           }
       }
       
       if(mel == LLONG_MIN)
            continue;
       swap(arr[id],arr[mid]);
       mid = id;
       for(ll j=0;j<n;j++)
       {
           if(j!=mid&&(temp&arr[j]))
                arr[j] = arr[j]^arr[mid];
       }
       id++;
   }
   
   ll ans = 0;
   
   for(ll i=0;i<n;i++)
        ans^=arr[i];
   
   ans<<=1;
   sum+=ans;
   cout<<sum;
   
   return 0;
}

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

int main() {
    int a,b;
    string s,t,u;
    cin >> s >> t >> a >> b >> u;
    if(u==s) a--;
    if(u==t) b--;
    cout << a << " " << b << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	string s;
  cin>>s;
  ll r;
  ll ans = 0;
  for(int i = 0 ; i<s.length();i++){
  	r = (s.length()-i-1);
    if(i>=r)break;
    if(s[i] != s[r])ans++;
  }
  cout<<ans<<"\n";
  

}



Measured memory_bytes: 256
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
a=[]
ans=0
if m>n:
        for i in range(len(x)-1):
                a.append(abs(x[i+1]-x[i]))
        a.sort()
        for j in range(len(a)-n+1):
                ans += a[j]
print(ans)




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

const int mod=1e9+7;
const int INF=1001001001;

int main() {
  int N;
  cin>>N;
  vector<int>dp(1000005,INF);
  dp[1]=1;
  dp[0]=0;
  for(int j=0;j<N;j++){
    int64_t a=1,b=1;
    for(int i=0;i<10;i++){
      if(j+a*6<=N){a*=6;}
      if(j+b*9<=N){b*=9;}
      chmin(dp[j+a],dp[j]+1);
      chmin(dp[j+b],dp[j]+1);
      chmin(dp[j+1],dp[j]+1);
    }
  }
  //for(int i=1;i<100;i++){
  //  cout<<i<<" "<<dp[i]<<endl;
  //}
  cout<<dp[N]<<endl;
  return 0;  
}

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

using namespace std;

int main()
{
    double n,k;
    cin>>n>>k;
    int o=0;
    while(n--)
    {
        double l,p;
        cin>>l>>p;
        if(sqrt(l*l+p*p)<=k)
        o++;
    }
    cout<<o;
}


Measured memory_bytes: 3804
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll N;
    if (!(cin >> N)) { return; }
    ll b, c;
    cin >> b >> c;
    cout << N * b / 2 << endl;
}

int main(int argc, char *argv[]) {
    string FileName("D"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    // /home/USER/.../MEPH_X -> MEPH_X
    if (sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size() - ExecutionName.size(), ExecutionName.size());

    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(0);
        ios::sync_with_stdio(false);
        while (cin) { solve(cin); }
    } else {
        cerr << sub << " test" << endl;
        string inFile = FileName + ".txt";
        auto fs = fstream(inFile, fstream::in);
        while (fs) { solve(fs); }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef tuple<int,int,bool> Tb;


int abc118_b(){
    //入力
    int n,m;
    cin >> n >> m;
    int check[40]={};
    REP(i,n){
        int k;
        cin >> k;
        REP(j,k){
            int tmp;
            cin >> tmp;
            check[tmp-1]++;
        }
    }
    
    //処理
    int ans = 0;
    REP(i,m){
        if(check[i]==n) ans++;
    }
    
    
    
    
    //出力
    cout << ans << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    string N;
    cin >> N;
    int l = N.length();
    int k[l];
    for (int i = 0; i < l; i++) {
        k[i] = N[i] - '0';
    }
    int d[l][2]{};
    d[0][0] = k[0];
    d[0][1] = 11 - k[0];
    
    for (int i = 1; i < l; i++) {
        d[i][0] = min(d[i - 1][0] + k[i], d[i - 1][1] + k[i]);
        d[i][1] = min(d[i - 1][0] + 11 - k[i], d[i - 1][1] + 9 - k[i]);
    }
    cout << min(d[l - 1][0], d[l - 1][1]) << "\n";
    return 0;
}

Measured memory_bytes: 13060
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int N,X,Y;
  cin>>N>>X>>Y; 
  X--;
  Y--;
  vector<int>ans(N);
  vector<vector<int>> data(N, vector<int>(N));
  for(int i=0;i<N;++i){
    for(int j=0;j<N;++j){
      data.at(i).at(j)=min(abs(j-i),abs(X-i)+1+abs(Y-j));
      data.at(i).at(j)=min(data.at(i).at(j),abs(Y-i)+1+abs(X-j));
      ans.at(data.at(i).at(j))++;
    }
  }
  for(int i=1;i<N;++i){
    cout<<ans.at(i)/2<<endl;
  }
  

}


Measured memory_bytes: 16000
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &s)

	level, left := 0, 0
	for _, c := range s {
		if c == '(' {
			level++
		} else if c == ')' {
			level--
			if level < 0 {
				level++
				left++
			}
		}
	}

	ans := strings.Repeat("(", left) + s + strings.Repeat(")", level)
	fmt.Printf("%s\n", ans)
}

func scanIntSlice(size int) []int {
	input := []int{}
	for i := 0; i < size; i++ {
		var in int
		fmt.Scanf("%d", &in)
		input = append(input, in)
	}
	return input
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(){
  int N; cin >> N;
  vector<vector<int> > G(N);
  vector<P> vec;
  for( int i = 1; i < N; i++ ){
    int a, b; scanf("%d%d", &a, &b); --a; --b;
    G[a].push_back(b); G[b].push_back(a);
    vec.push_back(P(a, b));
  }
  vector<int> used(N, -1), color(N, 0);
  map<P, int> MAP;
  queue<int> que;
  int MAX_COLOR = 0;
  used[0] = 1; que.push(0);
  while( que.size() ){
    int v = que.front(); que.pop();
    int num = 1;
    for( int i = 0; i < G[v].size(); i++ ){
      int u = G[v][i];
      if( used[u] != -1 ) continue;
      if( color[v] == num ) num++;
      color[u] = num;
      used[u] = 1;
      MAP[P(u, v)] = MAP[P(v, u)] = num;
      que.push(u);
      num++;
    }
    MAX_COLOR = max( MAX_COLOR, int(G[v].size()) );
  }
  cout << MAX_COLOR << '\n';
  for( auto p : vec ) cout << MAP[p] << '\n';
}

Measured memory_bytes: 20084
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
vector<ll> v;
set<int> s;
vector<int> to;
int solve(int n){
    if(s.find(n) != s.end()) return n;
    else{
        s.insert(n);
        to.push_back(n);
        solve(v[n]);
    }
}
int main(){
    cout << fixed << setprecision(10);
    ll n,k;
    cin >> n >> k;
    rep(i,n){
        int x;
        cin >> x;
        x--;
        v.push_back(x);
    }
    int num = solve(0);
    int len = 0;
    int beg = 0;
    rep(i,to.size()){
        if(to[i] == num){
            len = to.size() - i;
            beg = i;
        }
    }
    if(k < to.size()){
        //cout << "short" << endl;
        cout << to[k] + 1 << endl;
        return 0;
    }
    vector<int> loop;
    for(int i = beg; i < int(to.size()); i++){
        loop.push_back(to[i]);
    }
    /*
    cout << "loop size " << int(loop.size()) << endl;
    cout << "len " << len << endl;
    cout << "k" << " " << k <<"to.size() " << to.size() << endl;
    */
    ll div = k - to.size();
    //cout << "div " << div << endl;
    cout << loop[div%(loop.size())] + 1 << endl;
    return 0;
}

Measured memory_bytes: 21000
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

ll subcalc(ll x) { return x * (x + 1) / 2; }

int n;
int c[200009];
V<int> G[200009];
ll ans[200009];

int sz[200009];

vector<int> lst[200009];

void dfs1(int v, int p) {
    sz[v] = 1;
    for(int u : G[v]) {
        if(u != p) {
            dfs1(u, v);
            sz[v] += sz[u];
        }
    }
}

void dfs2(int v, int p) {
    lst[c[p]].push_back(sz[v]);
    lst[c[v]].back() -= sz[v];
    for(int u : G[v]) {
        if(u != p) {
            dfs2(u, v);
        }
    }
    ans[c[p]] += subcalc(lst[c[p]].back());
    lst[c[p]].pop_back();
}

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

    cin >> n;

    rep(i, n) {
        cin >> c[i + 1];
        lst[i + 1].push_back(n);
    }

    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs1(1, 0);
    dfs2(1, 0);

    FOR(i, 1, n + 1) { ans[i] += subcalc(lst[i].back()); }

    FOR(i, 1, n + 1) cout << subcalc(n) - ans[i] << endl;

    return 0;
}

Measured memory_bytes: 44756
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
string s[N];

int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=0; i<n; i++){
		string tmp; cin >> tmp;
		sort(tmp.begin(), tmp.end());
		s[i] = tmp;
	}
	ll ans = 0;
	sort(s, s+n);
	for(int i=0; i<n; i++) cerr << s[i] << endl;
	int cnt = 1;
	s[n] = "CC";
	for(int i=1; i<=n; i++){
		if (s[i] != s[i-1]) {
			ans += 1LL*cnt*(cnt-1)/2;
			cnt = 1;
		} else cnt++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
inline int newline() { putchar('\n'); return 0; }

bool isOK(vector<ll> mx, ll threshold) {
    for (auto i: mx) {
        if (i < threshold) return false;
    }

    return true;
}

int main() {
    ll n, m, x;
    cin(n);
    cin(m);
    cin(x);

    vector<ll> c(n);
    vector<vector<ll>> a(n, vector<ll>(m));
    rep2(i, n) {
        cin(c[i]);
        rep2(j, m) cin(a[i][j]);
    }

    ll prices = LLONG_MAX;

    rep2(i, 1 << n) {
        ll sum = 0;
        vector<ll> mx(m, 0);

        rep2(j, n) {
            if (i >> j & 1) {
                sum += c[j];

                rep2(k, m) mx[k] += a[j][k];

                if (isOK(mx, x) && sum < prices) prices = sum;
            }
        }
    }

    print((prices == LLONG_MAX ? -1 : prices));
    return 0;
}

Measured memory_bytes: 3636
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,A,B = map(int,input().split())

    tot = A + B
    set = N // tot
    res = N % tot

    ans = set * A

    if res >= A:
        ans += A
    else:
        ans += res

    print(ans)



main()


Measured memory_bytes: 2940
from operator import itemgetter
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(0, 1))
ans = 0
for ab in AB:
  if ab[1] >= M:
    ans += ab[0] * M
    break
  else:
    ans += ab[0] * ab[1]
    M -= ab[1]

print(ans)

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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 5e1 + 10;

int N, M;
int Nr[MAX_N][2], Mr[MAX_N][2];
int main() {
	cin >> N >> M;
	for(int i=0; i<N; i++) scanf("%d%d", &Nr[i][0], &Nr[i][1]);
	for(int i=0; i<M; i++) scanf("%d%d", &Mr[i][0], &Mr[i][1]);
	for(int i=0; i<N; i++) {
		int ix = -1, dis = INF; 
		for(int k=0; k<M; k++) {
			int now = abs(Nr[i][0] - Mr[k][0]) + abs(Nr[i][1] - Mr[k][1]);
			if(dis > now) dis = now, ix = k;
		}
		printf("%d\n", ix+1);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	int n;
	std::cin >> n;
	std::map<std::string, int> map;
	rep(i,n) {
		std::string s;
		std::cin >> s;
		map[s]++;
	}
	std::cout << "AC x " << map["AC"] << EL;
	std::cout << "WA x " << map["WA"] << EL;
	std::cout << "TLE x " << map["TLE"] << EL;
	std::cout << "RE x " << map["RE"] << EL;
}


Measured memory_bytes: 3656
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int X = sc.nextInt();
        sc.close();

        OneClue(K, X);
    }
    public static void OneClue(int K, int X) {
        if (K == 1) {
            System.out.println(X);
            return;
        }
        for (int i = (X - (K - 1)); i <= X + (K - 1); i++) {
            if (i != (X - (K - 1))) {
                System.out.print(" ");
            }
            System.out.print(i);
        }
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <functional>

using namespace std;

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

    vector<pair<long long,pair<int,int>>> YP(M);
    for(int i=0;i<M;i++){
        YP[i].second.second=i;
        cin>>YP[i].second.first;
        cin>>YP[i].first;
    }
    vector<int> P(M);
    for(int i=0;i<M;i++){
        P[i]=YP[i].second.first;
    }

    sort(YP.begin(),YP.end());

    vector<int> count(N);
    for(int i=0;i<N;i++){
        count[i]=0;
    }

    vector<int> x(M);
    for(int i=0;i<M;i++){
        x[YP[i].second.second]=count[YP[i].second.first-1]+1;
        count[YP[i].second.first-1]++;
    }

    vector<string> ans(M);
    for(int i=0;i<M;i++){
        ans[i]="";
        string temp="";
        int len=to_string(P[i]).length();
        for(int k=0;k<6-len;k++){
            temp+="0";
        }
        ans[i]=temp+to_string(P[i]);

        temp="";
        len=to_string(x[i]).length();
        for(int k=0;k<6-len;k++){
            temp+="0";
        }
        ans[i]+=temp+to_string(x[i]);
    }
    for(int i=0;i<M;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<vector<int>> p(N,vector<int>(3));
  for(int i=0;i<N;i++){
    cin>>p.at(i).at(1)>>p.at(i).at(2)>>p.at(i).at(0);
  }
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  int A=0;
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      A=0;
      int H=p.at(0).at(0)+abs(i-p.at(0).at(1))+abs(j-p.at(0).at(2));
      for(int k=1;k<N;k++){
        if(p.at(k).at(0)!=max(0,H-abs(i-p.at(k).at(1))-abs(j-p.at(k).at(2)))){
          A=1;
          break;
        }
      }
      if(A==0){
        A=2;
        cout<<i<<" "<<j<<" "<<H<<endl;
        break;
      }
    }
    if(A==2){
      break;
    }
  }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

ll cnt(ll n) {
	ll res = 0;
	for (int i = 1; ; i++) {
		n -= i;
		if (n == 0) return i;
		if (n < 0) return i-1;
	}
}

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


	vector<pair<ll, ll>> fac = prime_factorize(n);

	ll ans = 0;
	rep (i, fac.size()) {
		ans += cnt(fac[i].se);
	}

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


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

struct edge {
    int to, cost;
};

int V;
vector<int> G[1000000];
ll d[1000000];

void DFS(int n) {
    fill(d, d + V, llmax);
    queue<int> que;
    d[n] = 0;
    que.push(n);
    while (que.size() > 0) {
        int base = que.front();
        que.pop();
        int s = G[base].size();
        for (int i = 0; i < s; i++) {
            int to = G[base][i];
            if (d[to] == llmax) {
                d[to] = d[base] + 1;
                que.push(to);
            }
        }
    }
}

int main() {
    int N;
    cin >> N;
    V = N;
    for (int i = 0; i < N; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int n;
            cin >> n;
            G[i].push_back(n - 1);
        }
    }
    DFS(0);
    for (int i = 0; i < N; i++) {
        if (d[i] == llmax) {
            d[i] = -1;
        }
        cout << i + 1 << " " << d[i] << endl;
    }
}



Measured memory_bytes: 26568
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class APoisonousCookies {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            long a = in.ints(), b = in.ints(), c = in.ints();
            if (a + b >= c) {
                out.println(b + c);
            } else {
                out.println(b + Math.min(a + b + 1, c));
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }
}



Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin>>n;
    while(n)
    {
        if(n%10==7)
        {
            cout<<"Yes";
            break;
        }
        n/=10;
    }
    if(n==0)
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3652
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
x = [int(x) for x in input().split()]

ans = 10**15
for i in range(N-K+1) :
    if x[i]*x[i+K-1] >= 0 :
        temp = max(abs(x[i]), abs(x[i+K-1]))
    elif abs(x[i]) > x[i+K-1] :
        temp = abs(x[i]) + 2*x[i+K-1]
    else :
        temp = x[i+K-1] + 2*abs(x[i])
    ans = min(ans, temp)

print(ans)


Measured memory_bytes: 14544
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double EPS = 1e-9;
int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0 ,1, 1, 1, 0, -1, -1, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int sumMod(int a, int b){return 0LL + a + b > mod ? a + b - mod : a + b;}
int n;
double mul;
double v[3010];
double dp[3010][3010];
double f(int i, int tail){
    if(i == n){
        return 1;
    }
    double &ans = dp[i][tail];
    if(ans < 0){
        ans = 0;
        int head = n - tail;
        if(head > tail + 1)
            ans += f(i + 1, tail + 1) * (1.0 - v[i]);
    
        ans += f(i + 1, tail) * v[i];
    }
    return ans;
}
int main(){
    //FL;
    FIN;
    cin >> n;
    mul = 1;
    for(int i = 0; i < n; i++){
        double x;
        cin >> v[i];
        mul *= v[i];
    }
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            dp[i][j] = -1.0;
    cout << fixed << setprecision(9) << f(0, 0) << '\n';
    EjecuteTime;
    return 0;
}       

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

int main(){
    int n; 
    cin >> n;
	int a[11];
	int kotae = 1;
	int ans = 1;
	rep(i,n){
		cin >> a[i];
		ans = ans*3;
		if(a[i]%2==0){
			kotae=kotae*2;
		}
	}
	cout << ans-kotae << endl;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

string FMT_F = "%.10f";

T RD(T = long)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto W = RD;
	long[2][][4] wv;
	wv[0] ~= [RD, RD];
	long base_w = wv[0][0][0];
	foreach (i; 1..N)
	{
		auto w = RD;
		auto v = RD;
		wv[w-base_w] ~= [w, v];
	}
	foreach (ref e; wv)
		e.sort!"a[1] > b[1]"();

	long[2][][4] dp;
	foreach (i; 0..4)
	{
		dp[i] ~= [0, 0];
		foreach (j; 0..wv[i].length)
		{
			dp[i] ~= [dp[i][j][0] + wv[i][j][0], dp[i][j][1] + wv[i][j][1]];
		}
	}

	stderr.writeln(wv);
	stderr.writeln(dp);

	long ans;
	foreach (i; 0..dp[0].length)
	{
		foreach (j; 0..dp[1].length)
		{
			foreach (k; 0..dp[2].length)
			{
				foreach (l; 0..dp[3].length)
				{
					if (dp[0][i][0] + dp[1][j][0] + dp[2][k][0] + dp[3][l][0] > W) continue;
					ans = max(ans, dp[0][i][1] + dp[1][j][1] + dp[2][k][1] + dp[3][l][1]);
				}
			}
		}
	}

	writeln(ans);
	stdout.flush();
}

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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int n , k ;
vector < ll > a , b ;
map < pair < int , int > , int > dp ;

int solve( int i , int rem ){
if( i >= sz( a ) ) return 0 ;
int & ret = dp[ { i , rem } ] ;
if( ret ) return ret ;
if( rem - a[ i ] >= 0 ) ret = b[ i ] + solve( i + 1 , rem - a[ i ] ) ;
ret = max( ret , solve( i + 1 , rem ) ) ;
return ret ;
}

int main() {

   cin >> n >> k ;
   a.resize( n ) ;
   b.resize( n ) ;

   forn( int , i , 0 , n ){
      cin >> a[ i ] >> b[ i ] ;
   }

   cout << solve( 0 , k ) ;

   cerr << "\n\n" << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
   return 0 ;
}


Measured memory_bytes: 6272
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int main() {
    int n, m;
    cin >> n >> m;
    int a[n][2];
    for (int i = 0; i < n; i++) {
        fill(a[i], a[i] + 2, 0);
    }
    int sum = 0;
    for (int i = 0; i < m; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < n; j++) {
            if (s[j] == 'W') {
                a[j][0]++;
                sum++;
            } else {
                a[j][1]++;
            }
        }
    }
    int maxer = sum;
    int ans = -1;
    for (int i = 0; i < n; i++) {
        sum += a[i][1] - a[i][0];
        if (sum < maxer) {
            maxer = sum;
            ans = i;
        }
    }
    cout << ans + 1 << " " << ans + 2 << endl;
}



Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int takahashiHP = scanner.nextInt();
        int takahashiAttack = scanner.nextInt();

        int aokiHP = scanner.nextInt();
        int aokiAttack = scanner.nextInt();
        
        while(true) {
            aokiHP -= takahashiAttack;
            if(aokiHP <= 0) {
                System.out.println("Yes");
                break;
            }
            takahashiHP -= aokiAttack;
            if(takahashiHP <= 0) {
                System.out.println("No");
                break;
            }
        }
    }
}

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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repr(i, n) for (ll i = n - 1; i >= 0; --i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3620
#include<stdio.h>

int main(){
	
	
	int a;
	
	scanf("%d", &a);
	
	int visited[100005];
	
	for(int i = 0; i<100005; i++){
		visited[i] = 0;
	}
	int count = 0;
	int flag = 1;
	while(flag == 1){
		
		if(visited[a] == 1) break;
		
		if(visited[a] == 0){
			visited[a] = 1;
			count++;
		}
		
		if(a % 2 == 0){
			a = a/2;
		}
		else{
			a = 3*a + 1;
		}
	}
	
	printf("%d\n", count+1);
	
	return 0;
}


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

using namespace std;
typedef long long int ll;
#define MOD 2019

int main ()
{
  
  ll L, R;cin >> L >> R;

  ll ans = 2999999999;
  for (int i=L; i < R; i++) {
    for (int j=L+1; j <= R; j++) {
      ll tmp = ((i % MOD) * (j % MOD)) % MOD;
      ans = min(ans, tmp);
      if (ans == 0) break;
    }
    if (ans == 0) break;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000
#define nil -1
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

struct node{
    int p,l,r;
};
struct node t[MAX];
int n;

void preparse(int u){
    if(u==nil){
        return;
    }
    printf(" %d",u);
    preparse(t[u].l);
    preparse(t[u].r);
}

void inparse(int u){
    if(u==nil){
        return;
    }
    inparse(t[u].l);
    printf(" %d",u);
    inparse(t[u].r);
}

void postparse(int u){
    if(u==nil){
        return;
    }
    postparse(t[u].l);
    postparse(t[u].r);
    printf(" %d",u);
}

int main() {
    int v,l,r,root;
    scanf("%d",&n);
    rep(i,n){
        t[i].p=nil;
    }
    rep(i,n){
        scanf("%d %d %d",&v,&l,&r);
        t[v].l=l;
        t[v].r=r;
        if(l!=nil) t[l].p=v;
        if(r!=nil) t[r].p=v;
    }
    rep(i,n){
        if(t[i].p==nil){
            root=i;
        }
    }
    printf("Preorder\n");
    preparse(root);
     printf("\n");
    printf("Inorder\n");
    inparse(root);
     printf("\n");
    printf("Postorder\n");
    postparse(root);
    printf("\n");
    return 0;
}



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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int X;
  cin >> X;
  cout << ((X >= 30) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3640