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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "DRUL";
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/
struct Timer {
    int64_t start;
    const int64_t CYCLES_PER_SEC = 2800000000;
    Timer() { reset(); }
    void reset() { start = getCycle(); }
    inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
    inline int64_t getCycle() {
        uint32_t low, high;
        __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
        return ((int64_t)low) | ((int64_t)high << 32);
    }
};

Timer timer;

bool multicase = false;

ll n, m, k, w, num, a, b, c, d, e, h, q, ans, sum, l;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

string s, t;
ll x[200005];

void solve() {
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    for(int i=k;i<n;i++){
        Yes(x[i] > x[i-k]);
    }
    
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



Measured memory_bytes: 5204
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = False
show_flg = True


def lcm(a, b):
    return a * b // gcd(a, b)


def coprime(a, b):
    return gcd(a, b) == 1


def main():
    N, M = MI()
    S = input()
    T = input()

    LMC = lcm(N, M)

    if S[0] != T[0]:
        print(-1)
    else:
        a = LMC / N
        b = LMC / M
        abl = lcm(a, b)
        cur = 1
        while True:
            i = int(cur * abl * N // LMC)
            j = int(cur * abl * M // LMC)

            # print(i, j)

            if i >= N or j >= M:
                break

            if S[i] != T[j]:
                print(-1)
                return
            cur += 1

        print(LMC)


if __name__ == '__main__':
    main()


Measured memory_bytes: 65516
#include<iostream>
using namespace std;
int main()
{
  int A,B,C;
  cin>>A>>B>>C;
  if(A==5)
    {
      if(B==5)
        {
          if(C==7)
            {
              cout<<"YES"<<endl;
            }
          if(C==5)
            {
              cout<<"NO"<<endl;
            }
        }
      if(B==7)
        {
          if(C==5)
            {
              cout<<"YES"<<endl;
            }
          if(C==7)
            {
              cout<<"NO"<<endl;
            }
        }
    }
 if(A==7)
    {
      if(B==5)
        {
          if(C==5)
            {
              cout<<"YES"<<endl;
            }
          if(C==7)
            {
              cout<<"NO"<<endl;
            }
        }
      if(B==7)
        {
          cout<<"NO"<<endl;
        }
    }
  return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


int n, k;
int a[maxn];
vector<int> v;


bool useful(int i) {
    int x = v[i];
    vector<bool> dp(k+x+10, false);
    dp[0] = true;
    int len = dp.size();
    for (int j=0;j<n;j++) {
	if (i==j) continue;
	for (int val=k+x; val>=0; val--) {
	    if (!dp[val]) continue;
	    if (val+v[j]<len) {
		dp[val+v[j]]=true;
	    }
	}
    }
    for (int val=len-1; val>=k; val--) {
	if (val-x<k && dp[val-x]) return true;
    }
    return false;
}

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

    for (int i=0; i<n; i++) {
	cin>>a[i];
	if (a[i]>=k) continue;
	v.push_back(a[i]);
    }
    if (v.empty()) out(0);

    
    sort(v.begin(), v.end());
    n = v.size();

    int lo = -1;
    int hi = n-1;
    while (hi - lo > 1) {
	int mid = (hi+lo)/2;
	if (useful(mid)) {
	    hi = mid;
	} else {
	    lo = mid;
	}
    }


    int ans = 0;
    
    //hi is first useful item
    if (hi<n-1) {
	ans = hi;
    } else {
	if (!useful(hi)) {
	    ans = n;
	} else {
	    ans = n-1;	    
	}
    }

    cout<<ans<<endl;  

    return 0;
}


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

int N, K;
vector<int> a, win;
int main() {
  cin >> N >> K;
  a.resize(N), win.resize(K + 1, 0);
  rep(i, N) cin >> a[i];

  win[0] = false;

  for (int k = 1; k <= K; ++k) {
    win[k] = false;
    for (int i = 0; i < N && k - a[i] >= 0; ++i) {
      win[k] = win[k] || !win[k - a[i]];
    }
  }

  cout << (win[K] ? "First" : "Second") << endl;

  return 0;
}


Measured memory_bytes: 640
#%%
N = int(input())
A = list(map(int, input().split()))

l = []
for i in range(N):
    tmp = [A[i], i]
    l.append(tmp)

l.sort()
ans = []
for i in range(N):
    ans.append(str(l[i][1]+1))
ans = ' '.join(ans)
print(ans)

Measured memory_bytes: 27260
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    int N,M,Q;
    cin >> N >> M >> Q;
    int left[N]={};
    int right[N]={};
    int left2[N][N]={}; //左端i,右端jの数
    rep(i,M){
        int l,r;
        cin >> l >> r;
        l--,r--;
        left[l]++,right[r]++;
        left2[l][r]++;
    }
    int leftsum[N+1][N]={};
    rep(i,N) rep(j,N) leftsum[j+1][i]=leftsum[j][i]+left2[j][i]; //左端について累積和
    rep(i,Q){
        int ans=M;
        int l,r;
        cin >> l >> r;
        l--,r--;
        for(int j=0;j<l;j++) ans-=left[j];
        for(int j=r+1;j<N;j++) ans-=right[j],ans+=leftsum[l][j];
        cout << ans << endl;
    }
}

Measured memory_bytes: 2944
from collections import defaultdict,Counter
n=int(input())
s =[input() for i in range(n)]
dic = Counter(s[0])

for i in range(1,n):
    dic2 = Counter(s[i])
    for k,v in dic.items():

        dic[k] = min(dic[k],dic2[k])

s = ''
for k,v in dic.items():
    s+=k*v
s = sorted(s)
print(''.join(s))

            

        
            
        
    

Measured memory_bytes: 3316
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int getdigit(long long int n)
{
	while(n > 9){
		n /= 10;
	}
	return n;
}

int ketanum(long long int n)
{
	int ans = 0;
	while(n > 0){
		n /= 10;
		ans++;
	}
	return ans;
}

bool allnine(long long int n)
{
	if(n == 0) return false;
	while(n > 0){
		if(n % 10 != 9) return false;
		n /= 10;
	}
	return true;
}

int main()
{
	long long int n;
	cin >> n;
	if(ketanum(n) == 1){
		cout << n << endl;
	} else if(getdigit(n) == 9){
		if(allnine(n)) cout << 9 * ketanum(n) << endl;
		else cout << 9 * ketanum(n) - 1 << endl;
	} else if(allnine(n - getdigit(n) * (long long int)pow(10, (ketanum(n) - 1)))){
		cout << 9 * (ketanum(n) - 1) + getdigit(n) << endl;
	} else {
		cout << 9 * (ketanum(n) - 1) + getdigit(n) - 1 << endl;
	}
	return 0;
}

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


int main() {
  int a, b;
  cin >> a >> b;
  int ans;
  ans = max(a+b, max(a-b, a*b));
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}



int main() {
	//int a, b, c,d; cin >> a>>b>>c>>d ;
	string s,t,u; cin >> s>>t>>u;
	cout << s[0] << t[0] << u[0];

	cout << endl;
	return 0;
}

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

int main(){
  long long n,x,y;
  long long queries;
  cin>>n>>queries;
  vector<long long> counter(n,0);
  vector<vector<long long>> v(n);
  for(int i=0;i<n-1;i++){
      cin>>x>>y;
      x--;y--;
      v[x].push_back(y);
      v[y].push_back(x);
  }
  while(queries--){
      cin>>x>>y;
      x--;
      counter[x]+=y;
  }
  
  vector<bool> visited(n,false);
  queue<long long>q;
  q.push(0);
  visited[0]=true;
  while(!q.empty()){
      for(auto i : v[q.front()]){
          if(!visited[i]){
              visited[i]=true;
              counter[i]+=counter[q.front()];
              q.push(i);
          }
      }
      q.pop();
  }
  
  for(auto i : counter) cout<<i<<" ";
}
  

Measured memory_bytes: 17904
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
struct edge{ int to, time, cost; };
const double eps = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;
const double infd = (double)1e+9;

char put = 'A';

int main(){
	char a, b, c;
	while (std::cin >> a >> b >> c){
		if (a == put)put = c;
		else if (c == put)put = a;
	}
	std::cout << put << std::endl;
	return 0;
}

Measured memory_bytes: 1132
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

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

  vector<int> v(n);

  REP(i,n){
    cin >> v[i];
  }

  SORTV(v);
  int ans = 0;
  REP(i,k){
   ans += v[i];
  }
  cout << ans << endl;
  return 0;

}





Measured memory_bytes: 3200
#include <iostream>
#include <string>
using namespace std;
int main(){
  string n;
  cin >> n;
  if(n[n.size()-1]=='3'){
    cout << "bon";
  }else if(n[n.size()-1]=='0' || n[n.size()-1]=='1' || n[n.size()-1]=='6' || n[n.size()-1]=='8'){
    cout << "pon";
  }else{
    cout << "hon";
  }
}

Measured memory_bytes: 3596
import * as fs from 'fs';

namespace AtCoder.abc007 {

    class Program {
        /**
         * in
         *  4 2
         * out
         *  3
         */
        main(inp: string): void {
            const [n,i] :number[] = inp.split(' ').map(Number);
            console.log(n-i+1);
        } 
    }

    const prg = new Program();
    prg.main(fs.readFileSync('/dev/stdin', 'utf8').trim());
}




Measured memory_bytes: 7372
#include<iostream>

using namespace std;
int main(){
	char x[1000];
	while(1){
		 scanf("%s",&x);
		 int len = 0;
		 for(int i=0;x[i] != '\0';i++)len++;
		if(x[0]== '0')break;
		int res = 0;
		for(int i = 0;i<len;i++){
			   if(x[i] == '0')res+=0;
		 	  if(x[i] == '1')res+=1;
			   if(x[i] == '2')res+=2;
			   if(x[i] == '3')res+=3;
			   if(x[i] == '4')res+=4;
			   if(x[i] == '5')res+=5;
			   if(x[i] == '6')res+=6;
			   if(x[i] == '7')res+=7;
			   if(x[i] == '8')res+=8;
			   if(x[i] == '9')res+=9;
			   
			
			};
			cout<< res<<endl;
		  
		}
		
	return 0;
}  


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
int h,w,k;
  cin>>h>>w>>k;
  vector<string> c(h);
  rep(i,0,h) cin>>c[i];
  int ans=0;
  /////
  
  for (int bit = 0; bit < (1 << (h+w)); ++bit) {
        int sum = 0;
    vector<string> d(h);
    d=c;
        for (int i = 0; i < h+w; ++i) {
            if (bit & (1 << i)) {
              if(i<h){
                rep(j,0,w) d[i][j]='o';
              }
              else{
                rep(j,0,h){
                  d[j][i-h]='o';
                }
              }
            }
        }
      rep(i,0,h){
        rep(j,0,w){
          if(d[i][j]=='#')sum++; 
        }
      }
        // 判定
        if (sum == k) {
          ans++;
          rep(i,0,h){
         //  cout<<d[i]<<endl;
          }
         // cout<<endl;
        }
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    if(b%a!=0) return gcd(b%a,a);
    else return a;
}
int main(){
    int n;
    int a[100001];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=a[0];
    for(int i=1;i<n;i++){
        ans=gcd(ans,a[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,d,x,q,a,c[100010];
int main(){
	while(cin>>d&&d){
	cin>>n>>m;c[0]=0;
	for(int i=1;i<n;i++)cin>>c[i];
	sort(c,c+n);
	a=0;
	while(m--){
		cin>>q;
		x=lower_bound(c,c+n,q)-c;
		if(x==n)a+=min(d-q,q-c[n-1]);
		else a+=min(c[x]-q,q-c[x-1]);
	}
	cout<<a<<endl;
	}
	return 0;
}

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

int main()
{
	string S;
	long long K;
	char T;
	long long cnt = 0;

	cin >> S >> K;

	int len = (int)(S.length());
	if(len == 1){
      	cout << (int)(K/2);
		return 0;
    }
  	if (S[0] == S[len - 1]) {
      bool isRepKisuuEnd = false;
      bool isRepKisuuStart = false;
      bool tmp = false;      
      for(int i = 1; i < len; i++){
        if(S[len - 1 - i] != S[len - 1]){
          isRepKisuuEnd = (bool)((int)(i%2));
          tmp = true;
          break;
        }
      }
      if(tmp == false){
        isRepKisuuEnd = (bool)((int)(len%2));
      }
      tmp = false;
      for(int i = 1; i<len;i++){
        if(S[i] != S[0]){
          isRepKisuuStart = (bool)((int)(i%2));
          tmp = true;
          break;
        }
      }
      if(tmp == false){
        isRepKisuuStart = (bool)((int)(len%2));
      }
      if(isRepKisuuEnd == true){
        if(isRepKisuuStart == true){
		  if(tmp == false){
            cnt += (int)(K/2);
          }
          else{
            cnt += K - 1;
          }
        }
      }
    }

    long long cntCont = 1;
  	long long cntSRpl = 0;

    for (int i = 1; i < len; i++) {
		if (S[i] == S[i - 1]) {
			cntCont += 1;
		}
		else {
			if (cntCont != 1) {
				cntSRpl += (int)(cntCont / 2);
				cntCont = 1;
			}
		}
	}
  if (cntCont != 1) {
    cntSRpl += (int)(cntCont / 2);
  }
  
  cout << cnt + cntSRpl * K;
  return 0;
}



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

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

  ll N; cin >> N;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  ll ans = 0;
  while (true) {
    vector<ll> cnt(N, 0);
    ll sum = 0;
    for (ll i = 0; i < N; i++) {
      cnt[i] = A[i] / N;
      sum += cnt[i];
    }
    ans += sum;
    if (sum == 0) break;
    for (ll i = 0; i < N; i++) {
      A[i] = A[i] - N * cnt[i] + (sum - cnt[i]);
    }
  }

  cout << ans << '\n';

  return 0;
}

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

int main(){
    deque<int> dq;
    int q, a, b, c;
    cin >> q;

    for(int i = 0; i < q; i++){
        scanf("%d", &a);
        if(a == 0){
            scanf("%d", &b);
            scanf("%d", &c);
            if(b == 0)  dq.push_front(c);
            else if(b == 1) dq.push_back(c);
        }else if(a == 1){
            scanf("%d", &b);
            printf("%d\n", dq[b]);
        }else if(a == 2){
            scanf("%d", &b);
            if(b == 0)  dq.pop_front();
            else if(b == 1) dq.pop_back();
        }
    }

    return 0;
}


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

int main()
{
  int n;
  int m;
  
  while(cin >> m && m != 0){

    for (int i = 0; i < 9; i++){
      cin >> n;
      m -= n;
    }
    cout << m << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var N = Int64.Parse(Console.ReadLine());
        var length = Math.Sqrt(N);
        var count = 0L;
        for (long i=1;i<=length;++i)
        {
            if (N % i == 0)
            {
                long num = i - 1;
                if (num!=0 && (N % num) == (N / num)) count += num;
                num = N / i - 1;
                if (num != 0 && (N % num) == (N / num)) count += num;
            }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13140
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    String input = sc.nextLine();
	    int count = 0;
	    StringBuilder sb1 = new StringBuilder();
	    StringBuilder sb2 = new StringBuilder();
	    for (char a : input.toCharArray()) {
	    	sb1.append(a);
	    	if (sb1.toString().equals(sb2.toString())) {
	    		continue;
	    	}
	    	sb2 = sb1;
	    	sb1 = new StringBuilder();
	    	count++;
	    }
	    System.out.println(count);
	}
}


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

int main() {

  int N;
  
  cin >> N;
  
  int a = N / 100;
  int b = (N / 10) % 10;
  int c = N % 10;
  
  if( a == 7 || b == 7 || c ==7) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_N = 3005;

namespace modOp {
    int add(int a, int b, int mod = MOD) { return (a + b) % mod; }
    int sub(int a, int b, int mod = MOD) { return (a - b + mod) % mod; }
    int mul(int a, int b, int mod = MOD) { return (ll)a * b % mod; }
}
using namespace modOp;

int N;
string s;
ll dp[MAX_N][MAX_N];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> s;
	dp[1][1] = 1;
	for (int i = 2; i <= N; ++i) {
		for (int j = 1; j < i; ++j) {
			dp[i - 1][j] = add(dp[i - 1][j - 1], dp[i - 1][j]);
		}
		for (int b = 1; b <= i; ++b) {
			int L, R;
			if (s[i - 2] == '<') {
				L = 1, R = b - 1;
			}
			else {
				L = b, R = i - 1;
			}
			if (L <= R) {
				dp[i][b] = add(dp[i][b], sub(dp[i - 1][R], dp[i - 1][L - 1]));
			}
		}
	}

	ll ans = 0;
	for (int i = 1; i <= N; ++i) ans = add(ans, dp[N][i]);
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 69120
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define DEB 0

int edge[128][128];
int vertex[128];
int used[128];
set<int> st;

void dfs(int node){
  used[node] = 1;
  for(int i=1; i<128; i++){
    if( edge[node][i] && !used[i] ){
      dfs(i);
    }
  }
}

int main(){
  int a,b;
  while(~scanf("%d%d",&a,&b)){
    if( a==0 && b==0 ){
      bool f = true;
      int cnt = 0;
      dfs(1);
      set<int>::iterator it;
      for(it=st.begin(); it!=st.end(); it++){
	if( used[*it]==0 ){
	  f = false; break;
	}else{
	  if( vertex[*it]%2 ){
	    cnt++;
	  }
	}
      }
      if( f ){
	if( !(cnt==2 && vertex[1]%2 && vertex[2]%2) ){
	  f = false;
	}
      }
      puts(f ? "OK" : "NG");
      
      
      memset(used,0,sizeof(used));
      memset(vertex,0,sizeof(vertex));
      memset(edge,0,sizeof(edge));
      st.clear();
    }else{
      edge[a][b] = edge[b][a] = 1;
      vertex[a]++; vertex[b]++;
      st.insert(a);
      st.insert(b);
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

int main()
{
    int x, y, z, cnt = 0; std::cin >> x >> y >> z;
    x -= z;
    while(true) {
        if (x - (y + z) >= 0) {
            cnt++;
            x -= (y + z);
        } else {
            break;
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main(){
	int n;
	cin>>n;
	ll a[n],b[n];
	FOR0(i,n){
		cin>>a[i]>>b[i];
	}
	pi arr[n];
	FOR0(i,n){
		arr[i].ff = a[i]+b[i];
		arr[i].ss = i;
	}
	sort(arr,arr+n,greater<pi>());
	ll x=0,y=0;
	FOR0(i,n){
		if (i%2==0)x+=a[arr[i].ss];
		else y+=b[arr[i].ss];
	}
	cout<<x-y;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

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

		int AB = sc.nextInt();
		int BC = sc.nextInt();
		int CA = sc.nextInt();
		int ans = 0;

		ans = AB * BC / 2;
		System.out.println( ans );
	}
}

Measured memory_bytes: 21972
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 305;
int n, m, k;
string s[maxn];

vector<int> pos[maxn];

int ans[maxn][maxn];

void ReadInput()
{
    cin >> n >> m >> k;
    for(int i = 0; i < n; ++i)
        cin >> s[i];
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j)
            if(s[i][j] == '#') pos[i].push_back(j);
}

void Solve()
{
    fill_n(&ans[0][0], sizeof(ans) / sizeof(ans[0][0]), -1);
    int cur = 0;
    int pre_row = -1;
    int cur_row = 0;
    while(cur_row < n)
    {
        while(cur_row < n && pos[cur_row].empty())
            ++cur_row;
        if(cur_row == n) break;
        int pre_col = -1;
        for(int cur_col: pos[cur_row])
        {
            ++cur;
            for(int i = pre_row + 1; i <= cur_row; ++i)
                for(int j = pre_col + 1; j <= cur_col; ++j)
                    ans[i][j] = cur;
            pre_col = cur_col;
        }
        for(int i = pre_row + 1; i <= cur_row; ++i)
            for(int j = pre_col; j < m; ++j)
                ans[i][j] = cur;
        pre_row = cur_row;
        ++cur_row;
    }

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
        {
            if(ans[i][j] == -1) ans[i][j] = ans[i - 1][j];
            cout << ans[i][j] << ' ';
        }
        cout << '\n';
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


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

int N;
bool pri[60000] = {true};
vector<int> V;

int main()
{
    scanf("%d",&N);
    for(int i = 2; i < 60000; i++)
    {
        if(!pri[i])
        {
            if(i % 10 == 1)V.push_back(i);
            for(int j = i + i; j < 60000; j += i)pri[j] = true;
        }
    }

    for(int i = 0; i < N; i++)
    {
        printf("%d",V[i]);
        if(i != N - 1)printf(" ");
    }printf("\n");

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int r,d,x[2011]={0},i;
    scanf("%d%d%d",&r,&d,&x[2000]);
    for(i=1;i<=10;i++){
        x[2000+i]+=r*x[2000+i-1]-d;
        printf("%d\n",x[2000+i]);
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;

#define INF 987654321
#define ll long long

int K;
deque<pair<int, int> > dq; //n, cost
vector<int> dist(100101);

int BFS()
{
	dq.push_front({ 1, 1 });
	while (!dq.empty())
	{
		int n = dq.front().first, cost = dq.front().second, next;
		dq.pop_front();

		if (dist[n]) continue;
		dist[n] = cost;

		next = n * 10 % K;
		if (dist[next] == 0)
			dq.push_front({ next, cost });

		next = (n + 1) % K;
		if (dist[next] == 0)
			dq.push_back({ next, cost + 1 });
	}

	return dist[0];
}

int main()
{
	scanf("%d", &K);
	printf("%d", BFS());
	return 0;
}

Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(10**8)
N = int(input())
AB = [tuple(map(int,input().split())) for i in range(N-1)]
C = list(map(int,input().split()))
C.sort()
es = [[] for i in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

score = 0
vscore = [-1]*N
vscore[0] = C.pop()

def dfs(v,p=-1):
    global score
    for to in es[v]:
        if to==p: continue
        vscore[to] = C.pop()
        score += min(vscore[v], vscore[to])
        dfs(to,v)
dfs(0)

print(score)
print(*vscore)

Measured memory_bytes: 17244
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
import java.math.BigInteger;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		//String text = scan.next();
		int n = scan.nextInt();
		while(n != 0){
			BigInteger kaizyou = new BigInteger("1");
			for(long i = 1 ; i <= n ; i++){
				kaizyou= kaizyou.multiply(BigInteger.valueOf(i));
			}
			String bun = kaizyou.toString();
			int cun = 0;
			while(bun.length() != 0){
				if(bun.endsWith("0")){
					++cun;
					bun = bun.substring(0, bun.length()-1);
				}else{
					break;
				}
			}
			System.out.println(cun);
			n = scan.nextInt();
		}
	}
}

Measured memory_bytes: 291064
(let ((k (read))
      (s (read))
      (ans 0))
  (defun lp (a b)
    (if (<= 0 (- s a b) k)
        (setq ans (1+ ans))
        nil))
  (loop :for a :from 0 :upto k :do
    (loop :for b :from 0 :upto k :do(lp a b)))
  (princ ans))

Measured memory_bytes: 4064
#include<iostream>
using namespace std;
typedef long long ll;
ll a[123456];
const int mod=998244353;
ll fun(ll x,ll y){
	ll res=1;
	while(y)
	{
		if(y&1)	res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res%mod;
}//快速幂x的y次方 
int main()
{
	ll n;
	cin>>n;
	ll x,sum=1,s=0;
	for(int i=1;i<=n;i++){
		cin>>x;
		if(i==1&&x!=0)	sum=0;
		a[x]++;
		s=max(s,x);//标记 
	}
	for(int i=s;i>=0;i--)
	{
		if(a[i]==0)	sum=0;
		if(i>1)
			sum=sum*fun(a[i-1],a[i])%mod;
	}
	if(a[0]>1)	sum=0;//当出现数字不连续时 
	cout<<sum%mod<<endl;
	return 0;
}
//记录从根到底部有多少条路 

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;
ll n, k, x, y, ans;
int main(void)
{
	ll i;
	cin>>n>>k>>x>>y;
	for(i=1 ; i<=n ; i++)
	{
		if(i<=k)
		{
			ans+=x;
		}
		else
		{
			ans+=y;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int const N=1e5+5;
int n,cunt=0;
long long arr[N];
int diff[N];
int main()
{
   cin >> n;
   for(int i=0;i<n;i++){
    cin >> arr[i];
   }
   int j=0,i=0;
   for(i=0,j=0;i<n;i++){
        if(arr[i]<=arr[i-1]){
            cunt++;
        }else{
            diff[j]=cunt;
            cunt=0;
            j++;
        }
   }
   diff[j]=cunt;
   int *sum;
   //for(int i=0;i<n;i++) cout << diff[i];
   sum=max_element(diff,diff+N);
   cout << *sum;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <vector>
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

using namespace std;
#define int long long
using ll = long long;
const int MX = 1e6;
const ll inf = 1e13;
const int mod = 1e9+7;
char g[100][100];
int a[100][100];
signed main() {
    int h,w;
    cin >> h >> w;
    int ans = h*w;
    FOR(i,1,h+1) {
        string s;
        cin >> s;
        FOR(j,1,w+1) {
            g[i][j]=s[j-1];
            if(g[i][j]=='#')ans--;
        }
    }
    queue<pair<pair<int,int>,int>> q;
    q.push({{1,1},1});
    a[1][1]=0;

    while(q.size()>0) {
        pair<pair<int,int>,int> now = q.front();
        int x = now.first.first;
        int y = now.first.second;
        int d = now.second;
        q.pop();
        if(a[x][y]>0) continue;
        a[x][y]=1;

        if(x==h&&y==w) {
            ans -= d;
            break;
        }
        if(g[x+1][y]=='.') {
            q.push({{x+1,y},d+1});
        }
        if(g[x-1][y]=='.') {
            q.push({{x-1,y},d+1});
        }
        if(g[x][y+1]=='.') {
            q.push({{x,y+1},d+1});
        }
        if(g[x][y-1]=='.') {
            q.push({{x,y-1},d+1});
        }
    }
    if(a[h][w]>0)cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 3660
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            var s2 = ReadLine().Split(' ');
            var list = new List<int>();
            int ans = 0;
            for (int i = 0; i < n;i++)
            {
                list.Add(int.Parse(s2[i]));
            }
            list.Sort();
            for (int i = 0; i < k;i++)
            {
                ans += list[i];
            }


                WriteLine(ans);
            Out.Flush();
        }

    }

    public static class MyMath
    {
        public static long Factorical(long n)
        { return n <= 1 ? 1L : n * Factorical(n - 1); }
        public static long Permutation(long n, long m)
        { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); }
        public static long Combination(long n, long m)
        { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); }
        public static long Gcd(long n, long m)
        { return n % m == 0 ? m : Gcd(m, n % m); }
        public static long Lcm(long n, long m)
        { return n * m / Gcd(n, m); }
        public static long Pow(long n, long m)
        { return (m == 1 || m == 0) ? 1L : n * Pow(n, m - 1); }
    }
}

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

using ll=long long;
using namespace std;

#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}

const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

char BigAlphaToSmall(char a){
    if (a >= 65 && a <= 90){
        return a + 32;
    }
    return a;
}

char SmallAlphaToBig(char a){
    if (a >= 97 && a <= 122){
        return a - 32;
    }
    return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    string t;
    int ans = 0;
    bool f;
    while(cin >> t) {
        if(t.length() != s.length())continue;
        f = true;
        for (int i = 0; i < s.length(); i++){
            if(SmallAlphaToBig(s[i]) != SmallAlphaToBig(t[i])) f = false;
        }
        if(f)ans++;
    }
    say(ans)
}


Measured memory_bytes: 3196
import sys
import numpy as np
input = sys.stdin.readline


def main():
    N, W = map(int, input().split())
    w = np.zeros(N, dtype=int)
    v = np.zeros(N, dtype=int)
    for i in range(N):
        w[i], v[i] = map(int, input().split())

    dp = np.zeros((N+1, W+1), dtype=np.int64)

    for i in range(0, N):
        dp[i+1][:w[i]] = dp[i][:w[i]]
        dp[i+1][w[i]:] = np.maximum(dp[i][w[i]:], dp[i][:-w[i]] + v[i])

    print(dp[N][W])


if __name__ == "__main__":
    main()


Measured memory_bytes: 92832
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  ll N;
  cin>>N;
  vector<ll> A(N);
  cin>>A;
  priority_queue<pll> Q;
  set<ll> S;
  for(int i=0;i<N;i++){Q.push({A[i],i});}
  ll ans=0;
  while(!Q.empty()){
    ll u=Q.top().F;
    ll lf=Q.top().S,rg=Q.top().S+1,mid=Q.top().S,lff=Q.top().S,rgg=Q.top().S+1;
    Q.pop();
    auto I=S.lower_bound(mid);
    if(I!=S.end()){
      rgg=*I;
      auto U=I; U++;
      if(U==S.end()){rg=N;}
      else{rg=*U;}
    }
    else{rg=N; rgg=N;}
    if(!S.empty() && I!=S.begin()){
      --I;
      lff=(*I);
      if(I!=S.begin()){
        --I;
        lf=(*I);
      }
      else{
        lf=-1;
      }
    }
    else{lf=-1; lff=-1;}
    if(lf!=rg){
      //cout<<mid<<" "<<rg<<" "<<rgg<<" "<<lff<<" "<<lf<<" "<<(rg-rgg)*(mid-lff)<<" "<<(rg-mid)*(lff-lf)<<endl;
      ans+=u*(rg-rgg)*(mid-lff);
      ans+=u*(rgg-mid)*(lff-lf);
      //cout<<(rg-rgg)<<" "<<(mid-lff)<<" "<<(rg-mid)<<" "<<(lff-lf)<<endl;
      //cout<<ans<<endl;
      //ans-=u*(mid-lff+1)*(rgg-mid);
      //ans+=u*(mid-lf+1)*(rg-mid);
      //ans-=u*(rg-rgg)*(lff-lf);
    }
    S.insert(mid);
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 7280
A, B, C, D, E, F = map(int, input().split())
memo = []

for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                w = (100*A)*a + (100*B)*b
                s = C*c + D*d
                if w+s > F:
                    break
                else:
                    if w/100 * E >= s:
                        memo.append([w+s,s])

print(*sorted(memo, key=lambda x: (100*x[1] / x[0] if x[0] else 0))[-1])

Measured memory_bytes: 45316
#include <cstdio>
#include <cstring>
#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>

using namespace std;
#define whole(xs) xs.begin(), xs.end()

int N;
vector<int> r, w;
bool input() {
    cin >> N;
    if (N == 0) return false;
    r.resize(N); w.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> r[i] >> w[i];
    }
    return true;
}

int sum(const vector<int>& v) {
    int ret = 0;
    for (int i = 0; i < v.size(); i++) ret += v[i];
    return ret;
}

int dfs(int y) {
    int INF = 1<<28;
    int dp[y + 1]; 
    for (int i = 0; i <= y; i++) dp[i] = INF;
    dp[0] = 0;
    for (int i = 0; i <= y; i++) {
        if (dp[i] == INF) continue;
        for (int j = dp[i]; j < w.size(); j++) {
            if (i + w[j] > y) continue;
            dp[i + w[j]] = min(dp[i + w[j]], j + 1);
        }
    }
    int ret = 0;
    for (int i = 1; i <= y; i++) {
        if (dp[i] < INF) ret = max(ret, i);
    }
    return ret;
}

int main() {
    while (input()) {
        int mr = *max_element(whole(r));
        int sr = sum(r);
        int sw = sum(w);
        int x = sr - mr;
        if (mr >= x) {
            int index = max_element(whole(r)) - r.begin();
            w.erase(w.begin() + index);
            int y = mr - x;
            cout << sr + sw + (y - dfs(y)) << endl;
        } else {
            cout << sr + sw << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1232
#include <cstdio>
#include <random>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <chrono>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long


using namespace std;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;

const int maxn = 5000;
int d[maxn];
int u[maxn], v[maxn], c[maxn];
bool vis[maxn];
signed main()
{
#ifndef ONLINE_JUDGE
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    int n, m, p;
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m >> p;
    for(int i = 0; i < m; ++i) {
        cin >> u[i] >> v[i] >> c[i];
        c[i] -= p;
        c[i] = -c[i];
        // cout << c[i] << ' ';
    }
    // cout << endl;
    bool ok = 1;
    int cnt = 0;
    for(int i = 1; i <= n; ++i) {
        d[i] = inf;
    }
    d[1] = 0;
    int f = 0;
    std::vector<int> vec;
    int t = 3 * n + 5;
    while(t--) {
        for(int i = 0; i < m; ++i) {
            int x = u[i], y = v[i];
            if(d[x] < inf && d[x] + c[i] < d[y]) {
                d[y] = d[x] + c[i];
                ok = 1;
                // cout << x << ' ' << d[x] << ' ' << y << ' ' << d[y] << endl;
                if(y == n) {
                    ++f;
                    // cout << x << ' ' << d[x] << ' ' << y << ' ' << d[y] << endl;
                }
            }
        }
        vec.pb(d[n]);
    }
    // cout << f << endl;
    if(vec[n] != vec[3 * n] || d[n] == inf) {
        cout << -1 << endl;
    }
    else cout << max(-d[n], 0LL) << endl;



    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long n,x[100010],y[100010],mod=1000000000+7,k[100010],h1[100010],h2[100010];
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>x[i];
        k[i]=1;
    }
    for(int i=0;i<n+5;i++){
        h2[i]=1;
        h1[i]=1;
    }
    for(int i=1;i<n;i++){
        y[i]=x[i]-x[i-1];
    }
    for(int i=1;i<=n-1;i++){
        h1[i]=(h1[i-1]*i)%mod;
    }
    for(int i=n-1;i>=1;i--){
        h2[i]=(h2[i+1]*i)%mod;
    }
    for(int i=1;i<=n-1;i++){
        k[i]=(h1[i-1]*h2[i+1])%mod;
    }
    long long ans=0,b=0;
    for(int i=1;i<n;i++){
        b=(b+k[i])%mod;
        ans=(ans+(b*y[i])%mod)%mod;
    }
    cout<<ans;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> dish(5);
  for(int i=0;i<5;i++){
    cin>>dish[i];
  }
  vector<int> d(5);
  for(int i=0;i<5;i++){
    d[i]=dish[i]%10;
  }
  sort(d.begin(),d.end());
  int x;
  for(int i=0;i<5;i++){
    if(d[i]==0){
      ;
    }
    else{
      x=d[i];
      break;
    }
  }
  int ans=0;
  int z=0;
  for(int i=0;i<5;i++){
    if(dish[i]%10==0){
      ans+=dish[i];
    }
    else if(dish[i]%10==x&&z==0){
      z++;
      ans+=dish[i];
    }
    else{
      ans+=dish[i]+(10-dish[i]%10);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N = 1e6+5;
int c[N][2],rem[N];
int n;string s[N];
int sum[2],S[2],SUM[2];//sum为单项 
int tree[N],qwq;
inline int lowbit(int x){return x&(-x);}
void update(int now)
{
	while(now<=1e6)
	{
		tree[now]++;
		now+=lowbit(now);
	}
}
int ask(int now)
{
	int res=0;
	while(now)
	{
		res+=tree[now];
		now-=lowbit(now);
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	getline(cin,s[0]);
	for(int i=0;i<n;i++)
	{
		getline(cin,s[i]);
		int cnt=0;
		for(int j=0;j<s[i].size();j++)
		{
			if(s[i][j]=='(')cnt++;
			else if(s[i][j]==')')
			{
				if(cnt)cnt--;
				else c[i][0]++;
			}
		}
		c[i][1]=cnt;
		if(cnt&&c[i][0])sum[0]+=c[i][0],sum[1]+=cnt,qwq++,rem[cnt]++,update(cnt);
		else S[0]+=c[i][0],S[1]+=c[i][1];
	}
	SUM[0]=S[0]+sum[0];
	SUM[1]=S[1]+sum[1];
	if(SUM[0]!=SUM[1])
	{
		cout<<"No\n";
		return 0;
	}
	if(!qwq)
	{
		cout<<"Yes\n";
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		if(c[i][0]&&c[i][1])
		{
			int A=ask(S[0]);
			if(S[1]>=c[i][0]&&((A==1&&qwq==1)||A>1))
			{
				cout<<"Yes\n";
				return 0;
			}
		}
	}
	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 42720
n = int(input())
d = int(len(str(n)))
c = 0
for k in range(3,d):
  c += 3**k-3*2**k+3
u = int(str(n)[0])
if u >= 8:
  c += 3**d-3*2**d+3
  print(c)
  exit()
if u >= 6:
  c += (3**(d-1)-2**d +1)*2
  i = 2*3**(d-1)
elif u >= 4:
  c += 3**(d-1)-2**d + 1
  i = 3**(d-1)
elif u <= 2:
  print(c)
  exit()
else:
  i = 0
x = [3,5,7]
while True:
  s = 0
  y = [0,0,0]
  p = i
  for j in range(d):
    s += x[p%3]*(10**j)
    y[p%3] = 1
    p = p//3
  if s <= n:
    if sum(y) == 3:
      c += 1
    i += 1
  else:
    break
print(c)
  

Measured memory_bytes: 41580
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int people=0;
  scanf("%d",&people);
  int * height=(int *)malloc((people+1)*sizeof(int));
  int tmp=0;
  for(int i=0;i<people;i++){
	  scanf("%d",&tmp);
	  height[tmp]=i+1;
  }
   for(int i=1;i<=people;i++){
	   printf("%d ",height[i]);
   }
  return 0;
}

Measured memory_bytes: 1152