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

int N, M;

int comb(int n)
{
    return n * (n - 1) / 2;
}

int main()
{
    cin >> N >> M;
    vector<vector<bool>> connect(N, vector<bool>(N, false));

    for (int i = 0; i < M; i++)
    {
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        tmp1--;
        tmp2--;
        connect[tmp1][tmp2] = connect[tmp2][tmp1] = true;
    }

    vector<vector<int> > newedge(N);
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            if (!connect[i][j])
            {
                newedge[i].push_back(j);
                newedge[j].push_back(i);
                // cout << i << " " << j << endl;
            }
        }
    }
    vector<int> N_renketsu(N, -1);
    vector<int> color(N, -1);

    int num_ren = 0;

    for (int i = 0; i < N; i++)
    {
        if (N_renketsu[i] >= 0) continue;

        queue<pair<int, int>> q_tmp;
        q_tmp.push(make_pair(i, 0));

        while (!q_tmp.empty())
        {
            int q = q_tmp.front().first;
            int color_tmp = q_tmp.front().second;
            q_tmp.pop();
            N_renketsu[q] = num_ren;
            if (color[q] >= 0 && color[q] != color_tmp)
            {
                // cout << q << endl;
                cout << -1 << endl;
                return 0;
            }
            color[q] = color_tmp;
            for (auto nxt : newedge[q])
            {
                if ((N_renketsu[nxt] != -1 && N_renketsu[nxt] != num_ren) || (color[nxt] != -1 && color[nxt] != 1-color_tmp))
                {
                    // cout << q << " " << nxt << " " << N_renketsu[nxt] << " " << num_ren << " " << color_tmp << " " << color[nxt] << endl;
                    cout << -1 << endl;
                    return 0;
                }
                if (N_renketsu[nxt] == -1)
                {
                    q_tmp.push(make_pair(nxt, 1 - color_tmp));
                }
            }
        }
        num_ren++;
    }

    vector<pair<int, int> > shukei(num_ren);
    for (int i = 0; i < N; i++)
    {
        if (color[i] == 0) shukei[N_renketsu[i]].first++;
        if (color[i] == 1) shukei[N_renketsu[i]].second++;
    }

    vector<int> napz;
    int sameparam = 0;
    int napz_sum = 0;
    for (auto pa : shukei)
    {
        int tmp = min(pa.first, pa.second);
        sameparam += tmp;
        napz.push_back(pa.first + pa.second - 2 * tmp);
        napz_sum += napz.back();
    }

    bitset<701> st(1);
    for (auto val : napz) st |= (st << val);

    int min_dist = 700;
    for (int i = 0; i <= napz_sum; i++)
    {
        if (st[i]) min_dist = min(min_dist, abs(napz_sum - 2 * i));
    }

    cout << comb(sameparam + (napz_sum - min_dist)/2) + comb(sameparam + (napz_sum+min_dist)/2) << endl;
    return 0;
}


Measured memory_bytes: 3840
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <sstream>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}

int main() {
    int n;cin>>n;
    int x[3];cin>>x[0]>>x[1]>>x[2];
    vector<int>l(n);
    rep(i,n)cin>>l[i];
    
    int mp=1e9;
    for(int i=0;i<(1<<2*n);i++){
        //cout<<i<<endl;
        bool f[3];
        vector<vector<int>>v(3);
        f[0]=f[1]=f[2]=0;
        rep(j,n){
            int target=(i&(3<<(j*2)))>>(j*2);
            if(target==3)continue;
            v[target].push_back(l[j]);
            f[target]=1;
        }
        if(!(f[0]&&f[1]&&f[2]))continue;
        int mpp=0;
        rep(j,3){
            mpp+=v[j].size()*10-10;
            int sum=0;
            rep(k,v[j].size())sum+=v[j][k];
            mpp+=abs(x[j]-sum);
        }
        mp=min(mp,mpp);
    }
    cout<<mp<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using std::min;

int m_abs(int z)
{
    if (z<0)
        return -z;
    else
        return z;
}

int main(void)
{
    int *a,*dp,N,i,j,K;
    scanf("%d%d",&N,&K);
    a=new int [N];
    dp=new int [N];
    for (i=0;i<N;i++)
    {
        scanf("%d",a+i);
    }
    dp[N-1]=0;
    if(K>N)
        K=N;
    for(i=0;i<K;i++)
        dp[N-1-i]=abs(a[N-1]-a[N-1-i]);

    for(i=N-1-K;i>=0;i--)
    {
        dp[i]=dp[i+1]+abs(a[i]-a[i+1]);
        for(j=2;j<=K;j++)
        {
            dp[i]=min(dp[i+j]+abs(a[i]-a[i+j]),dp[i]);
        }
        //printf("dp[%d]= %d\n",i,dp[i]);

    }

    printf("%d\n",dp[0]);
    delete [] dp;
    delete [] a;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<int>vec(n);
  int sum =0;
  rep(i,n){
    cin >> vec[i];
    sum+=vec[i];
  }
  int ans =sum;
  int res = 0;
  rep(i,n){
    res+=vec[i];
    ans=min(ans,abs(sum-res-res));
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	unsigned N,W;
	cin>>N>>W;
	unsigned DP[101][10001];
	unsigned v[1000],w[1000];
	for(int i=0;i<N;i++)
		cin>>v[i]>>w[i];
	for(int j=0;j<=W;j++)
		DP[0][j]=0;
	
	for(int i=1;i<=N;i++)
		for(int j=0;j<=W;j++)
			if(j<w[i-1])
				DP[i][j]=DP[i-1][j];
			else{
				if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1])
					DP[i][j]=DP[i-1][j];
				else
					DP[i][j]=DP[i-1][j-w[i-1]]+v[i-1];
			}
	cout<<DP[N][W]<<endl;
	return 0;
}


Measured memory_bytes: 7024
#include<iostream>
using namespace std;
int main()
{
    int a=0,w=0,t=0,r=0;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string str;
        cin>>str;
        if(str[0] == 'R')
            r++;
        else if(str[0] == 'W')
            w++;
        else if(str[0] == 'T')
            t++;
        else if(str[0] == 'A')
            a++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;
}


Measured memory_bytes: 3624
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
#n,k = [int(i) for i in readline().split()]

n,m = [int(i) for i in readline().split()]
a = [-int(i) for i in readline().split()]


from heapq import *


heapify(a)
for i in range(m):
    c = heappop(a)
    c = -((-c)//2)
    heappush(a,c)

print(-sum(a))

Measured memory_bytes: 14168
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,cnt=0,ans=0,sum=0,o=0;
    string s[100];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        for(int k=0;k<i;k++){
            if(s[k]==s[i]){
                o++;
            }
        }
    }
    string a,b;
    for(int l=1;l<n;l++){
        a=s[l];
        b=s[l-1];
        if(a[0]!=b[b.size()-1]){
            o++;
        }
    }
    if(o==0){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>
#include <iomanip>
//#include <unordered_set>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;
const double eps = 0.005;
const int maxn = 100010;
const ll mod = 1e9+7;
const int INF = 1e9;
const double pi = acos(-1);
typedef double Matrix[maxn][maxn];
int n;
int a[maxn];
int main() {
    scanf("%d",&n);
    for (int i =0; i < n; i++) {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    if (a[0] == a[n-1]) {
        if (a[0] == n-1 || a[0] <= n/2) {
            printf("Yes");
        } else {
            printf("No");
        }
        return 0;
    }
    if (a[n-1] - a[0] > 1) {
        printf("No");
        return 0;
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == a[0]) cnt++;
    }
    if (cnt <= a[0] && a[0] <= (n+cnt)/2-1) {
        printf("Yes\n");
    } else {
        printf("No");
    }
    return 0;
}






Measured memory_bytes: 640
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back 
#define pb push_back
#define mp make_pair
#define int long long
#define y1 y_golabi
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
typedef pair<int , pair<int , int> > piii;
const int MAXN = 1e5 + 10;
int n , m , cnt , x , y , num[MAXN];
bool bo[MAXN];
int32_t main()
{
	cin >> n >> m , fill(num , num + n , 1) , bo[0] = true;
	for(int i = 0 ; i < m ; i ++)
	{
		cin >> x >> y , x -- , y -- , num[x] -- , num[y] ++;
		if(bo[x])
			bo[y] = true;
		if(!num[x])
			bo[x] = false;
	}
	for(int i = 0 ; i < n ; i ++)
		if(bo[i] and num[i])
			cnt ++;
	return cout << cnt << endl , 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
	string t1,t2;
	cin>>t1;
	cin>>t2;
	if(t1.length()==t2.length()-1)
	{
		bool p=false;
		for(int i=0;i<t1.length();i++)
		if(t1[i]!=t2[i])
		p=true;
		if(p)
		cout<<"No";
		else
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  while(cin>>s){
    for(int i = 0; i < s.size(); i++){
      s[i] -= 3;
      if(s[i]<'A' || s[i]>'Z')s[i] += 26;
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b || b == c)
    {
        if(a != c)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
  else if(a == c)
  {
    if(a != b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
  }
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import math
N,A,B = map(int,input().split())
h = list(int(input())for i in range(N))

def func(l,r):
    if l == r:
        return l
    c = (l+r)//2
    hoge = 0
    for i in h:
        hoge += max(math.ceil((i-(B*c))/(A-B)),0)
    if hoge > c:
        return func(c+1,r)
    elif hoge < c:
        return func(l,c)
    else:
        return c

print(func(0,10**9+7))

Measured memory_bytes: 7076
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int a,b,k;cin>>a>>b>>k;
  int len=b-a+1;
  if(len<2*k){
    ireps(i,a,b)cout(i);
  }else{
    irep(i,a,a+k)cout(i);
    ireps(i,b-k+1,b)cout(i);
  }
  return 0;
}

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

#define MAX 301

int main(){

  while(true){
    int N,M;
    int w[MAX];
    int v[MAX];
    int d[MAX];
    int l[MAX];
    int v_dp[MAX][MAX];
    int d_dp[MAX][MAX];
    int l_dp[MAX][MAX];

    cin >> N >> M;
    if(cin.eof())break;

    //cout << N << ' ' <<  M << endl;
    for(int i = 0; i < N; ++i){
      string tmp;
      getline(cin,tmp);
      string name;
      getline(cin,name);
      cin >> w[i];
      cin >> v[i];
      cin >> d[i];
      cin >> l[i];
    }

    for(int i = 0; i < N; ++i){
      for(int j = 0; j <= M; ++j){
	if( j < w[i] ){
	  v_dp[i+1][j] = v_dp[i][j];
	  d_dp[i+1][j] = d_dp[i][j];
	  l_dp[i+1][j] = l_dp[i][j];
	}else{
	  v_dp[i+1][j] = max( v_dp[i][j], v_dp[i+1][j-w[i]]+v[i] );
	  d_dp[i+1][j] = max( d_dp[i][j], d_dp[i+1][j-w[i]]+d[i] );
	  l_dp[i+1][j] = max( l_dp[i][j], l_dp[i+1][j-w[i]]+l[i] );
	}
      }
    }
    cout << max( v_dp[N][M],
		 max( d_dp[N][M], l_dp[N][M] ) ) << endl;
    
  }
  return 0;  
}

Measured memory_bytes: 1996
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    map<int, int> mp;
    for(int i = 0; i < n; i++)
    {
        mp[a[i]]++;
    }
    int ans = 0;
    for(auto p : mp){
        int x = p.first;
        int co = p.second;
        if (x > co) {
            ans += co;
        }
        else if (x < co) {
            ans += co - x;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5120
/**
 *    author        : Saurav Paul 
 *    created       : August 03, 2020 11:41 AM
 *    Problem Name  : E - Logs
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc174/tasks/abc174_e
 *    @genarated by : ai-virtual-assistant
**/

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

int main(){
    ios_base::sync_with_stdio(false);

    int n , k ;
    cin >> n >> k ;

    vector<long long> v(n) ;

    for(auto &x : v){
        cin >> x ;
    }

    sort(v.begin(),v.end() , [](int a, int b){
            return (a>b) ;
    }) ;

    long long l = 1 , r = v[0] ;
    while(l <= r){
        long long mid = (l + r) >> 1;

        bool ok = true ;
        int temp = k ;

        for(int i = 0 ; i < n; i++){
            if(v[i] <= mid) break ;
            long long t = (v[i]-1)/mid  ;
            temp -= t ;
            if(temp < 0){
                ok = false ;
                break ;
            }
        }

        if(ok == false){
            l = mid + 1;
        }
        else {
            r = mid - 1;
        }

    }
    cout << l << endl ;
    return 0 ;
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<string>v;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        int cnt[26]={0};
        for(auto x: s)cnt[x-'a']++;
        string t="";
        for(int j=0;j<26;j++)t.push_back((cnt[j]+'0'));
        v.push_back(t);
    }
    ll sum=0;
    map<string,ll>mp;
    for(auto x: v)mp[x]++;
    for(map<string,ll>::iterator it=mp.begin();it!=mp.end();it++){
        ll y=it->second;
        sum+=(y*(y-1))/2;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 23452
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

int main(void){
  int max=0, length=0;
  map<string,int> word; //文字列と回数
  vector<string> w;
  string str;

  while(cin >> str){
    w.push_back(str);

    if(word.find(str) != word.end() ){ //単語が重複
      word[str]++;
    }else{
      word.insert( pair<string, int>(str, 1));
    }
  }

  map<string,int>::iterator p;
  for(p = word.begin() ; p != word.end() ; p++){
    if( max < p->second) {
      max = p->second;
    }
  }
  for(p = word.begin() ; p != word.end() ; p++){
    if( max == p->second){
      cout << p->first << " ";
      break;
    }
  }
  for(int i=0 ; i<w.size() ; i++){
    if( length < w[i].size() ) {
      length = w[i].size();
    }
  }
  for(int i=0 ; i<w.size() ; i++){
    if( length==w[i].size() ){
      cout << w[i] << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=1; i<(int)(n); i++)
int D, c[27], s[366][27];

int sco(vector<int> &t, int k, int x){
int S=0, L[27]={};
REP(i, D){
  if(i==k){ S+=s[i][x]; L[x]=i; }else{ S+=s[i][t[i]]; L[t[i]]=i; }
  REP(j, 27){ S-=c[j]*(i-L[j]); }
}
return S;
}

int saga(int d, vector<int> &L){
  int S=0;
  REP(i, 27){ S+=c[i]*(d-L[i]); }
  return S;
}

int main(){
  cin >> D; D++;
  REP(i, 27){ cin >> c[i]; }
  REP(i, D){ REP(j, 27){ cin >> s[i][j]; } }
  vector<int> t(D), last(27, 0);

  REP(i, D){
    int a=1, S=-1000000, u=0;
    REP(j, 27){
      u=s[i][j]; u-=saga(i, last); u+=c[j]*(i-last[j]);
      if(S<u){ a=j; S=u; }
    }
    t[i]=a; last[a]=i;
  }
  int S=sco(t, 0, 0), T=0, n=0;
  REP(i, D){ 
   REP(j, 27){ T=sco(t, i, j); if(S<T){ t[i]=j; S=T; if(n<=125){i=1; n++; break;} } }
  }
  
  REP(i, D){ cout << t[i] << "\n"; }
}


Measured memory_bytes: 3648
#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++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    int year = 19 * 5 + 20 * 5, year3 = 20 * 10;
    REP(i, n){
        int y, m, d; cin >> y >> m >> d;
        int san = 1000 / 3 - y / 3;
        int ans = (1000 - (y + 1) - san) * year + san * year3 + 1;
        if(y % 3 == 0){
            ans += (10 - m) * 20 + (20 - d);
        }
        else{
            if(m % 2 != 0) ans += ((10 - m) / 2) * 39 + 19 + (20 - d);
            else ans += ((10 - m) / 2) * 39 + (19 - d);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;

ll mod=998244353;
const int SIZE=2010000;
ll fac[SIZE], finv[SIZE], inv[SIZE], sum[260000];
void COMinit(ll m){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2; i<SIZE; ++i){
        fac[i]=(fac[i-1]*i)%m;
        inv[i]=m-(inv[m%i]*(m/i))%m;
        finv[i]=(finv[i-1]*inv[i])%m;
    }
}
ll COM(int n, int k, ll m){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return (fac[n]*((finv[k]*finv[n-k])%m))%m;
}

int main(void){
    int N, M;
    cin >> N >> M;
    COMinit(mod);
    ll ans=0;
    sum[0]=0;
    for(int i=0; i*2<=M; ++i){
        sum[i+1]=(sum[i]+COM(N-2+i, i, mod))%mod;
    }
    for(int i=M%2; i<=min(N, M); i += 2){
        ll num=COM((3*M-i)/2+N-1, N-1, mod);
        (num += mod-(sum[max((3*M-i)/2-M, 0)]*(N-i))%mod) %= mod;
        (num += mod-(sum[max((3*M-i)/2-M+1, 0)]*i)%mod) %= mod;
        (num *= COM(N, i, mod)) %= mod;
        (ans += num) %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 49280
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<deque>
using namespace std;
typedef long long ll;
ll n;
deque<int>ans;
int cnt;
void solve(ll n)
{
    if(n==1) return;
    if(n&1)  solve(n-1),ans.push_front(++cnt);
    else     solve(n>>1),ans.push_back(++cnt);
}
int main()
{
    cin>>n;
    ++n;
    solve(n);
    printf("%d\n",cnt*2);
    for(int i=0;i<cnt;i++)  printf("%d ",ans[i]);
    for(int i=1;i<=cnt;i++)  printf("%d ",i);
    puts("");
    return 0;
}

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

using namespace std;

//#define _FILES
#define PB push_back
#define MP make_pair

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


int main()
{
    ios_base::sync_with_stdio(false);

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    int n,ans,cur,type,x;
    cin>>n;
    cin>>cur;
    ans = 0;
    type = -1;
    for (int i=1;i<n;i++)
    {
        cin>>x;
        if (x==cur) continue;
        if (x<cur)
        {
            if (type!=1)
            {
                type = 0;
                cur = x;
                continue;
            }
        }
        else
        {
            if (type!=0)
            {
                type = 1;
                cur = x;
                continue;
            }
        }

        ans++;
        cur = x;
        type = -1;
    }
    ans++;
    cout<<ans<<endl;


    return 0;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <set>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    set<string> s;
    REP(i, 0, n) {
        string ss;
        cin, ss;
        s.insert(ss);
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 19240
n=gets.to_i
a=gets.split.map(&:to_i).sort
while true
  min=a[0]
  a=a.map{|m| m%min}
  if a[1..-1].all?{|v| v==0}
    break
  end
  a=a.select{|v| v>0}
  a << min
  a.sort!
end
puts min


Measured memory_bytes: 11632
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
	int n,m,x;
	cin>>n>>m;
	vector<int> X;
	rep(i,m){
		cin>>x;
		X.push_back(x);
	}
	//昇順
	sort(X.begin(),X.end());

	vector<int> sa;
	rep(i,X.size()-1){
		sa.push_back(X[i+1]-X[i]);
	}

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

	int ans = 0;
	rep(i,m-n){
		ans += sa[i];
	}

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


Measured memory_bytes: 1400
n=int(input())
A=[int(i) for i in input().split()]
total=sum([int(i) for i in input().split()])
add=[int(i) for i in input().split()]

for i in range(n-1):
    if A[i+1]==A[i]+1:
        total+=add[A[i]-1]

print(total)

Measured memory_bytes: 3060
/*
 * @author : ashish1610
 */
#include <bits/stdc++.h>
using namespace std;
#define ll	long long int
#define MOD	1000000007
ll solve(string s, int idx, ll cur_val, ll run_res) {
	if(idx == (int)(s.length())) {
		return cur_val + run_res;
	}
	ll res = solve(s, idx + 1, cur_val * 10 + (s[idx] - '0'), run_res);
	res = res + solve(s, idx + 1, 0, run_res + cur_val);
	return res;
}
int main() {
	string s;
	cin >> s;
	cout << solve(s, 0, 0, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/

int n, a[114514], ans = 1;
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	int b = 2;
	rep(i, n - 1) {
		if (b == 2 && a[i] < a[i + 1]) {
			b = 0;
		}
		else if (b == 2 && a[i] != a[i + 1]) {
			b = 1;
		}
		if (!b && a[i] > a[i + 1]) {
			ans++; b = 2;
		}
		else if (b == 1 && a[i] < a[i + 1]) {
			ans++; b = 2;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,a[5];
    for(i=0;i<3;i++)
    {
        cin>>a[i];
    }
    sort(a,a+3);
   if(a[0]==5&&a[1]==5&&a[2]==7)cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 2002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int dp[MAX_N][MAX_N]={};
int a[(1<<16)+1][30]={};

bool check(int j){
	bool r=true;
	rep(k,8){
		if(a[j][0]!=a[j][k+1])r=false;
	}
	rep(k,2){
		if(a[j][9]!=a[j][k+10])r=false;
	}
	rep(k,2){
		if(a[j][12]!=a[j][k+13])r=false;
	}
	rep(k,2){
		if(a[j][15]!=a[j][k+16])r=false;
	}
	rep(k,2){
		if(a[j][18]!=a[j][k+19])r=false;
	}
	rep(k,8){
		if(a[j][21]!=a[j][k+22])r=false;
	}
	return r;
}

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

	rep(i,n){
		rep(j,30)cin>>a[0][j];
		if(check(0)){
			cout<<"0"<<endl;
			continue;
		}
		REP(j,1,(1<<16)+1){
			rep(k,30)a[j][k]=a[(j-1)/4][k];
			if(j%4==0){
				swap(a[j][6],a[j][21]);
				swap(a[j][7],a[j][22]);
				swap(a[j][8],a[j][23]);
				swap(a[j][12],a[j][17]);
				swap(a[j][9],a[j][11]);
			}
			if(j%4==1){
				swap(a[j][0],a[j][27]);
				swap(a[j][1],a[j][28]);
				swap(a[j][2],a[j][29]);
				swap(a[j][14],a[j][15]);
				swap(a[j][18],a[j][20]);
			}
			if(j%4==2){
				swap(a[j][0],a[j][23]);
				swap(a[j][3],a[j][26]);
				swap(a[j][6],a[j][29]);
				swap(a[j][15],a[j][17]);
				swap(a[j][9],a[j][20]);
			}
			if(j%4==3){
				swap(a[j][2],a[j][21]);
				swap(a[j][5],a[j][24]);
				swap(a[j][8],a[j][27]);
				swap(a[j][11],a[j][18]);
				swap(a[j][12],a[j][14]);
			}
			if(check(j)){
				int r=0;
				while(j>0){
					r++;
					j-=(1<<(2*r));
				}
				cout<<r<<endl;
				break;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 6084
M, D = map(int, input().split())
w = str(D)
ans = 0
if len(w) == 2:
    d2 = str(w[0])
    d1 = str(w[1])
else:
    print(ans)
    exit()

for m in range(1, M+1):
    for a in range(1, int(d2)+1):
        for b in range(10):
            if a == int(d2) and int(d1) < b:
                continue
            if m == a * b and a >= 2 and b >= 2:
                ans += 1

print(ans)


Measured memory_bytes: 3064
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int t = sc.nextInt();

        if(x-t>=0){
        System.out.println(x-t);
        }else {
            System.out.println(0);
        }
    }

}


Measured memory_bytes: 23892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            var N = c2i(RL());
            var Ax = RL2IE().ToList();
            var Q = c2i(RL());
            var BCx = new List<Tuple<int, int>>();
            long sum = 0;
            var ret = new List<long>();
            foreach (var a in Ax)
            {
                sum += a;
            }
            var lst = new List<int>();
            for (int i = 0; i < 100001; i++)
            {
                lst.Add(0);
            }
            foreach (var x in Ax)
            {
                lst[x]++;
            }
            for (int i = 0; i < Q; i++)
            {
                var BC = RL2IE();
                var ch = BC.First();
                if (lst[ch] > 0)
                {
                    var af=BC.Last();
                    sum = sum + (-ch + af) * lst[ch];
                    lst[af] += lst[ch];
                    lst[ch] = 0;
                }
                ret.Add(sum);
                //BCx.Add(new Tuple<int, int>((int)BC.First(), (int)BC.Last()));
            }

            foreach (var a in ret)
            {
                Console.WriteLine(a);

            }
                
            //Console.WriteLine(sum);
            Console.ReadLine();

        }

        static IEnumerable<int> RL2IE() { return spr(RL()).Select(x => (int)c2i(x)); }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}


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

int main()
{
    string s;
    int n = 'z' - 'a';
    vector<int> number(n);

    while (getline(cin, s))
    {
        for (int i = 0; i < s.length(); i++)
        {
            if (isupper(s[i]))
            {
                s[i] = tolower(s[i]);
            }
            number[s[i] - 'a']++;
        }
}
    
    for(int i = 0; i <= n; i++)
    {
        char c = i + 'a';
        cout << c << " : " << number[i] << endl;
    }
    return 0;
}



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

int main(){
  string S;
  cin >> S;
  const int Nlen= S.size();

  int ans= 0;
  int offset= 0;
  string prev= "";
  while(offset < Nlen-2){
    string cand1= S.substr(offset, 1);
    string cand2= S.substr(offset, 2);
    if(cand1 != prev){
      ans++;
      offset+= 1;
      prev= cand1;
    }
    else{
      ans++;
      offset+= 2;
      prev= cand2;
    }
  }
  if(offset==Nlen-2 && prev != S.substr(offset, 1) && S.substr(offset, 1) != S.substr(offset+1, 1)){
    ans+= 2;
  }
  else{
    ans+= 1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int k; cin>>k;
    cout<<(k/2)*((k+1)/2)<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
int main(void)
{
  int n;
  std::cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  int min = 1000001, max = -1000001;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (min > a[i]) min = a[i];
    if (max < a[i]) max = a[i];
  }
  std::cout << min << " " << max << " " << sum << std::endl;
}

Measured memory_bytes: 1200
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = null;

		// エラトステネスの篩
		int MAX = 50000;
		int num = (MAX - 3) / 2;
		boolean[] prime = new boolean[MAX + 1];
		Arrays.fill(prime, true);
		int[] primeArray = new int[25000];
		int count = 1;
		primeArray[0] = 2;
		
		for (int i = 0; i < num; i++) {
			if (prime[i] == true) {
				int primeNum = i + i + 3;
				primeArray[count] = primeNum;
				count++;
				for (int j = i + primeNum; j <= MAX; j += primeNum)
					prime[j] = false;
			}
		}
		
		int[] ans = new int[50001]; 
		
		for (int i = 0; primeArray[i] >= 2; i++) {
			for (int j = i; primeArray[j] >= 2 && primeArray[i] + primeArray[j] <= MAX; j++) {
				ans[primeArray[i] + primeArray[j]]++;
			}
		}

		try {
			while ((line = br.readLine()) != null) {
				line = line.trim();
				if (line.equals("0"))
					break;

				int N = Integer.parseInt(line);

				System.out.println(ans[N]);
			}
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 25836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll k;
ll d;
int main(void){
    cin>>k;
    for(int i=1;i<=k;i++){
        d=(d*10+7)%k;
        if(d==0){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;

}



Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#define inf 0x3f3f3f3f
#define esp 1e-7
using namespace std;
long long read(){
    long long x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int n,m;
int k,num;
int mapp[110][110];

int main(){
	n=read();m=read();k=read();
	int i=1,j=1;
	for (int t=1;t<=k;t++){
		num=read();
		
		while(num--){
			if(j==m+1){
				i++;
				j=m;
			}
			else if (j==0){
				i++;
				j=1;
			}
			if(i&1){
				mapp[i][j++]=t;
			}
			else{
				mapp[i][j--]=t;
			}

		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			printf("%d%c",mapp[i][j]," \n"[j==m]);
		}
	}
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
)

func insertSort(buf []int) {

	for i := 1; i <= len(buf); i++ {

		//print
		for j := 0; j < len(buf); j++ {
			if j < (len(buf) - 1) {
				fmt.Printf("%d ", buf[j])
			} else {
				fmt.Printf("%d\n", buf[j])
			}
		}
		if i == len(buf) {
			break
		}

		//insert sort
		v := buf[i]
		for j := 0; j < i; j++ {

			if buf[j] > v {
				for k := i; k-1 >= j; k-- {
					buf[k] = buf[k-1]
				}
				buf[j] = v
				break
			}
		}
	}
}

func main() {

	var length int
	fmt.Scanln(&length)

	buf := make([]int, length)

	for i := range buf {
		fmt.Scanf("%d", &buf[i])
	}

	insertSort(buf)
}



Measured memory_bytes: 1184
import java.io.*;

class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int num = Integer.parseInt(str);
        int h = num / 3600;
        int m = (num % 3600) / 60;
        int s = (num % 3600) % 60;
        
        System.out.println(h + ":" + m + ":" + s);
    }
    
}


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

int main(){
   
   int A = 10;
   int B = 11;
   int C = 12;
   int D = 13;
   int E = 14;
   int F = 15;
   
   char x,y; cin>>x>>y;
   
   int a,b;
   
   if (x=='A') a = 10;
   if (x=='B') a = 11;
   if (x=='C') a = 12;
   if (x=='D') a = 13;
   if (x=='E') a = 14;
   if (x=='F') a = 15;
   
   if (y=='A') b = 10;
   if (y=='B') b = 11;
   if (y=='C') b = 12;
   if (y=='D') b = 13;
   if (y=='E') b = 14;
   if (y=='F') b = 15;
   
   if (a < b) cout << "<";
   if (a > b) cout << ">";
   if (a == b) cout << "=";
   
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

ll a, b, c, d, e, f;
vector<ll> ans = {0, 0};
map<vector<ll>, bool> mp;

void solve(ll w, ll s) {
	if (mp[{w, s}]) return;
	mp[{w, s}] = true;

	if (ans[1] * (w + s) <= s * (ans[0] + ans[1])) {
		ans = {w, s};
	}

	if (w + s + 100 * a <= f) {
		solve(w + 100 * a, s);
	}
	if (w + s + 100 * b <= f) {
		solve(w + 100 * b, s);
	}
	if (w + s + c <= f && (s + c) * (100 + e) <= e * (w + s + c)) {
		solve(w, s + c);
	}
	if (w + s + d <= f && (s + d) * (100 + e) <= e * (w + s + d)) {
		solve(w, s + d);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	cin >> a >> b >> c >> d >> e >> f;
	solve(0, 0);
	cout << ans[0] + ans[1] << " " << ans[1] << endl;
}


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

typedef long long ll;

int a, v;
int b, w;
int t;

int main()
{
    cin >> a >> v;
    cin >> b >> w;
    cin >> t;
    int dist = abs(a - b);
    int sp = v - w;
    if (sp <= 0) printf("NO\n");
    else if (ll(t) * sp >= dist) printf("YES\n");
         else printf("NO\n");
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INF 1000000000000 //10^12

int main(){
    ll k,a,b;
    cin >>k>>a>>b;
    for(ll i=a;i<=b;i++){
        if(i%k==0){
            cout <<"OK"<<endl;
            return 0;
        }
    }
    cout <<"NG"<<endl;
    
}

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

int n,q;
ll L,R;
ll a[300000];
ll ty[300000],x[300000],s[300000],t[300000];

ll calc(ll C){
	rep(i,q){
		if(ty[i]==1){
			if(C>=x[i])C=(C+s[i])*t[i];
		}
		else{
			if(C<=x[i])C=(C-s[i])/t[i];
		}
	}
	return C;
}

int calc2(ll t){//<=t
	int ok=-1,ng=n;
	while(ng-ok>1){
		int md=(ok+ng)/2;
		if(calc(a[md])<=t)ok=md;
		else ng=md;
	}
	return ok+1;
}
int main(){
	cin>>n>>q>>L>>R;
	rep(i,n)scanf("%lld",&a[i]);
	rep(i,q){
		scanf("%lld%lld%lld%lld",&ty[i],&x[i],&s[i],&t[i]);
	}
	sort(a,a+n);
	cout<<calc2(R)-calc2(L-1)<<endl;
}


Measured memory_bytes: 10852
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N; 
    cin >> N;

    VI A(N);
    rep(i, N){
        cin >> A.at(i);
    }

    ll sum = 0;
    rep(i, N){
      FOR(j, i+1, N){
        sum += A[i]*A[j];
      }
    }
    p(sum);
    
    return 0;
}

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

int main()
{
    std::vector<int> inputs;
    inputs.reserve(10000);

    int val;
    while (std::cin >> val && val) {
        inputs.push_back(val);
    }

    for (int i = 0; i < inputs.size(); i++) {
        std::cout << "Case " << i + 1 << ": " << inputs.at(i) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int fa[MAXN * 2],N,M,K;
int getfa(int x) {
    return x == fa[x] ? x : fa[x] = getfa(fa[x]);
}
void Solve() {
    read(N);read(M);
    for(int i = 1 ; i <= N + M ; ++i) fa[i] = i;
    int a;
    for(int i = 1 ; i <= N ; ++i) {
	read(K);
	for(int j = 1 ; j <= K ; ++j) {
	    read(a);
	    fa[getfa(i)] = getfa(a + N);
	}
    }
    for(int i = 1 ; i <= N ; ++i) {
	if(getfa(i) != getfa(1)) {puts("NO");return;}
    }
    puts("YES");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<string> b(a);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (b[i][j] == '#') continue;
            int cnt = 0;
            for (int k = i - 1; k <= i + 1; k++) {
                for (int l = j - 1; l <= j + 1; l++) {
                    if (k < 0 || k >= n || l < 0 || l >= m) continue;
                    cnt += (b[k][l] == '#');
                }
            }
            b[i][j] = (char)('0' + cnt);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << b[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> va(x), vb(y), vc(z);
    rep(i, 0, x) cin >> va[i];
    rep(i, 0, y) cin >> vb[i];
    rep(i, 0, z) cin >> vc[i];

    vector<ll> sumab;
    rep(i, 0, x) rep(j, 0, y) sumab.emplace_back(va[i]+vb[j]);
    sort(sumab.begin(), sumab.end(), greater<ll>());

    vector<ll> ans;
    rep(i, 0, min(k, (ll)sumab.size())) rep(j, 0, z) ans.emplace_back(sumab[i]+vc[j]);
    sort(ans.begin(), ans.end(), greater<ll>());
    rep(i, 0, k) cout << ans[i] << endl;
}

Measured memory_bytes: 43368