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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e5+5; 

int main(){
	fast;
	ll t = 1; 
	//cin >> t;
	while(t--){
	    ll a,b; cin >> a >> b;
	    cout << a * b << endl;
	}
}

Measured memory_bytes: 3612
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 998244353
using namespace std;

void dfs(vector<int> adj[], int sv, vector<bool> &vis){
	vis[sv] = true;
	for(int i = 0; i < adj[sv].size(); i++){
		if(!vis[adj[sv][i]]){
			dfs(adj, adj[sv][i], vis);
		}
	}
}
ll power(ll x, ll y){  
	if(x == 1 || y == 0)
		return 1;
    ll res = 1;   
    x = x % mod; 
    if (x == 0) 
		return 0;  
    while (y > 0){  
        if (y & 1)  
            res = (res * x) % mod;  
        y = y >> 1; 
        x = (x * x) % mod;  
    }  
    return res;  
}  


int main(){
	FASTIO
	string s;
	cin >> s;
	int n = s.size();
	vi p(2019, 0);
	int curr = 0, f = 1;
	for(int i = n - 1; i >= 0; i--){
		curr = (curr + f * (s[i] - '0')) % 2019;
		p[curr]++;
		f = (f * 10) % 2019;
	}
	ll ans = p[0];
	rep(i, 0, 2019){
		ans += p[i] * (ll)(p[i] - 1) / 2;
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 3776
import sys
N,M,K= list(map(int, input().split()))
mod = 998244353

if N == 1:
    print(M)
    sys.exit()


def cmbinit(n):
    fac = [0]*n
    finv = [0]*n
    inv = [0]*n
    fac[0]=fac[1] = 1
    finv[0]=finv[1] = 1
    inv[1] = 1
    for i in range(2,n):
        fac[i] = fac[i-1]*i %mod
        inv[i] = mod - inv[mod%i] * (mod//i) %mod
        finv[i] = finv[i-1] * inv[i]%mod
    
    return fac,finv

def cmb(n,r,fac,finv):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0

    return fac[n] * (finv[r] * finv[n - r] % mod) %mod




ans = 0
fac,finv = cmbinit(N)
for k in range(K+1):
    ans += (M * pow(M-1, N-k-1, mod) * cmb(N-1,k,fac,finv))%mod


print(ans%mod)

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

int main(){
  int a,b,c,x;
  cin>>a>>b>>c>>x;
  int cnt=0;
  for (int i = 0; i < a+1; i++)
  {
    /* code */
    REP(j,b+1){
      REP(k,c+1){
        if (500*i+100*j+50*k==x)
        {
          /* code */
          cnt++;
        }
        
      }
    }
  }
  cout<<cnt<<endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;

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

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

    s = s.substr(0, s.size()-8);

    cout << s << endl;

    return 0;
}

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

int main(void) {
    int N;
    cin>>N;
    int current = 1;
    for (int i = 0; i < N; i++) {
        int n;
        cin>>n;
        if (n == current) current++;
    }
    if (current == 1) cout << -1 << endl;
    else cout << N - current + 1 << endl;
    return 0;
}

Measured memory_bytes: 384
ab = list(input().split())

if ab[0] == "H" and ab[1] == "H":
    print("H")
    
elif ab[0] == "H" and ab[1] == "D":
    print("D")
    
elif ab[0] == "D" and ab[1] == "H":
    print("D")
    
elif ab[0] == "D" and ab[1] == "D":
    print("H")

Measured memory_bytes: 3060
import collections
s = input()

l = [int(s[-1])]
d = 10
for i in range(len(s)-2, -1, -1):
  l.append((l[-1] + int(s[i])*d) % 2019)
  d *= 10
  d %= 2019
c = collections.Counter(l)
ans = 0  
for i in c.values():
  ans += i*(i-1)//2

ans += c[0]

print(ans)

Measured memory_bytes: 16580
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

int main()
{
    int food[5];
    for(int i=0; i<5; i++){
        cin >> food[i];
    }

    int min=10,tmp = 100;
    for(int i=0; i<5; i++){
        if(food[i]%10 != 0 && food[i]%10 < min){
            min = food[i]%10;
            tmp = i;
        }
    }

    int sum=0;

    for(int i=0; i<5; i++){
        if(i == tmp)    sum += food[i];
        else if(food[i]%10 == 0)    sum +=food[i];
        else    sum += (food[i] - (food[i]%10) + 10);
    }

    cout << sum;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;


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


int main(){
  int N;
  int b =0;
  int sum=0;
  cin >> N;
  vector<int> L(N);
  REP(i,N) {cin >> L[i];
  b = max(b,L[i]);
  sum += L[i];
}
  sum -= b;
  if(b < sum){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

string a, b;
int dp[3002][3002];
bool vis[3002][3002];
pair<int, int> nxt[3002][3002];

int func( int i, int j )  {
  if ( i >= a.size() || j >= b.size() ) return 0;
  if (vis[i][j]) return dp[i][j];
  vis[i][j] = 1;

  if (a[i] == b[j]) {
    nxt[i][j] = {i + 1, j + 1};
    return dp[i][j] = 1 + func(i + 1, j + 1);
  }

  int x = func(i + 1, j);
  int y = func(i, j + 1);

  if ( x > y ) {
    nxt[i][j] = {i + 1, j};
    return dp[i][j] =  x;
  }

  nxt[i][j] = {i, j + 1};
  return dp[i][j] = y;
}

int main() {
  cin >> a >> b;
  int x = func(0, 0);

  int i = 0, j = 0;
  while( 1 ) {
    if ( nxt[i][j].first == 0 && nxt[i][j].second == 0 ) break;
    if (a[i] == b[j]) cout << a[i];
    int x = nxt[i][j].first;
    int y = nxt[i][j].second;
    i = x, j = y;
  }

  cout << endl;
  return 0;
}


Measured memory_bytes: 115072
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
  #define all(v) v.begin(), v.end()
  #define mod INT_MAX 
  const int MOD=1e9+7;
  const int N=2e5+2;
 
  
int32_t main(){
    /*#ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
    #endif*/
       IOS
       string s;
       cin>>s;
       for(int i=0;i<s.length();i++)
       {
         if(s[i]=='?')
         {
            if(i and s[i-1]=='P')
            {
                s[i]='D';
            }
            else if(i+1<s.length() and s[i+1]=='D')
            {
               s[i]='P';
             
            }
            else if(i+1<s.length() and s[i+1]=='?')
            {
               s[i]='P';
               s[i+1]='D';
            }
             else
                {
                  s[i]='D';
                }
            }
         }
       
       cout<<s;
    return 0;
 }


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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


int main(){
    int N, K, C; cin >> N >> K >> C;
    string S; cin >> S;

    vi ord(N, -1);
    int cnt=0, pos=0;
    while(pos < N){
        if(S[pos] == 'o'){
            cnt++;
            ord[pos]=cnt;
            pos+=C+1;
        }
        else pos++;
    }

    cnt=K, pos=N-1;
    vi ans;
    while(pos >= 0){
        if(S[pos] == 'o'){
            if(ord[pos] == cnt) ans.push_back(pos+1);
            pos-=C+1;
            cnt--;
        }
        else pos--;
    }

    reverse(all(ans));
    for(auto x : ans) cout << x << endl;
    return 0;
}

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

int main(){
    char s[3];
    for(int i=0;i<3;i++)cin>>s[i];
    if(s[0]!=s[1]&&s[1]!=s[2]&&s[2]!=s[0])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int main(){
  set<tuple<int,int,int>> st;
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  int ans=0;
  while(1){
    sort(a,a+3);
    if(a[0]%2||a[1]%2||a[2]%2)break;
    if(st.count(tie(a[0],a[1],a[2]))){
      ans=-1;
      break;
    }
    st.insert(tie(a[0],a[1],a[2]));
    int x,y,z;
    x=a[1]/2+a[2]/2;
    y=a[0]/2+a[2]/2;
    z=a[1]/2+a[0]/2;
    a[0]=x;
    a[1]=y;
    a[2]=z;
    ans++;
    // cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
long long gcd(long long a,long long b){
	if(a<b)return gcd(b,a);
	else if(a%b==0)return b;
	else return gcd(b,a%b);
}
int main(){
    int n;
    long long ai,aj;
    scanf("%d%lld",&n,&ai);
    for(int i=1;i<n;i++){
        scanf("%lld",&aj);
        ai=gcd(ai,aj);
        if(ai==1){
            printf("1");
            return 0;
        }
    }
    printf("%lld",ai);
    return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    ll lead1 = (a1 - b1) * t1, lead2 = (a2 - b2) * t2;
    if (lead1 + lead2 == 0) {
        cout << "infinity" << endl;
        return 0;
    }
    if ((lead1 <= 0 && lead2 <= 0) || (lead1 >= 0 && lead2 >= 0)) {
        cout << 0 << endl;
        return 0;
    }

    if (abs(lead1) > abs(lead2)) {
        cout << 0 << endl;
        return 0;
    }

    if (lead1 < 0) {
        lead1 *= -1;
        lead2 *= -1;
    }
    ll sum = -(lead1 + lead2);
    ll x = lead1 / sum + 1;

    if (lead1 % sum != 0) {
        cout << 1 + (2 * (x - 1)) << endl;
    } else {
        cout << 2 * (x - 1) << endl;
    }

    return 0;
}



Measured memory_bytes: 3580
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int dp[40005];
int a[1005],b[1005];
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

   int h,n;
   cin>>h>>n;
   for(int i=1;i<=n;i++)
   {
      cin>>a[i]>>b[i];
   }
   fill_n(dp,40005,1e17);
   dp[0]=0;
   for(int i=1;i<=n;i++)
   {
      dp[a[i]]=min(dp[a[i]],b[i]);
      // cout<<dp[a[i]]<<'\n';
   }
   for(int i=1;i<=h+20000;i++)
   {
      for(int j=1;j<=n;j++)
      {
         if(i-a[j]>=0)
         {
            dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
         }
      }
   }
   int ans=1e9;
   for(int i=h;i<=h+20000;i++)
      ans=min(ans,dp[i]);
   cout<<ans;

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 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;
}

class UnionFind {
private:
	vector<int>par;
public:
	int Size;
	UnionFind(int n) {
		for (int i = 0; i < n; i++) par.push_back(-1);
		Size = n;
	}

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

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

	int size(int x) {
		return -par[root(x)];
	}
};

signed main() {
	int n, m;
	cin >> n >> m;
	UnionFind uf(n);
	rep(i, m) {
		int x, y, z;
		cin >> x >> y >> z;
		x--;
		y--;
		uf.unite(x, y);
	}
	cout << uf.Size << endl;
	return 0;
}


Measured memory_bytes: 1400
/* package whatever; // don't place package name! */
 
import java.util.*;
import java.lang.*;
import java.io.*;
 
public class Main
{
	public static void main (String[] args) throws Exception {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();

		long ans = 0;
		for(int i = 1; i <= n; ++i) {
			int s = sum(i);
			if(s >= a && s <= b)
				ans += i;
		}

		System.out.println(ans);
 	}

 	private static int sum(int n) {
 		int ret = 0;
 		while(n > 0) {
 			ret += n % 10;
 			n /= 10;
 		}

 		return ret;
 	}
}

Measured memory_bytes: 21204
W,H,m,c[10][11];
DP[11][10][10][10][51];//cà[yÀW][xÀW][¶[][E[][_fcÊ]
#define Update(tgt,val) ((val)>(tgt)?tgt=(val):0)
CalcO(o,x,y){//_fcÊÌvZ
	if(c[x][y]>0){
		o+=c[x][y];
		if(o>m)
			o=m;
	}
	return o;
}
CalcF(f,x,y){//càÌvZ
	if(c[x][y]<0)
		f+=c[x][y];
	return f;
}
main(){
	int x,y,range,d,dx,f,o,xl,xr,fn,on,f0;
	for(;scanf("%d%d",&W,&H),W;){
		scanf("%d%d%d",&f0,&m,&o);
		for(y=1;y<=H;y++)
			for(x=0;x<W;x++)
				scanf("%d",&c[x][y]);
		f0++;//cà0ÅàDPÍ1ÆµÄANAÉÈéÌðh®
		for(y=0,x=0;x<W;x++)
			DP[y][x][x][x][o]=f0;
		y=0;
		for(range=0;range<W;range++){//¶EÉ@éL³
			for(o=m;o>1;o--){
				for(d=0;d<2;d++){//»ÝÊuxð³¹é
					for(xl=0;xl<W-range;xl++){//¶[
						for(dx=0;dx<=range;dx++){//xÏÊ
							xr=xl+range;
							x=d?xl+dx:xr-dx;
							if(f=DP[y][x][xl][xr][o]){
								//ºÖ@é
								fn=CalcF(f,x,y+1);
								on=CalcO(o-1,x,y+1);
								Update(DP[y+1][x][x][x][on],fn);
							}
						}//dx
					}//xl
				}//d
			}//o
		}//range
		for(y=1;y<H;y++){
			for(range=0;range<W;range++){//¶EÉ@éL³
				for(o=m;o>1;o--){
					for(d=0;d<2;d++){//»ÝÊuxð³¹é
						for(xl=0;xl<W-range;xl++){//¶[
							for(dx=0;dx<=range;dx++){//xÏÊ
								xr=xl+range;
								x=d?xl+dx:xr-dx;
								if(f=DP[y][x][xl][xr][o]){
									//ºÖ@é
									fn=CalcF(f,x,y+1);
									on=CalcO(o-1,x,y+1);
									Update(DP[y+1][x][x][x][on],fn);
									if(y>0){
										if(x>0){
											if(x==xl){//¶Ö@é
												fn=CalcF(f,x-1,y);
												on=CalcO(o-1,x-1,y);
												Update(DP[y][x-1][x-1][xr][on],fn);
											}else{//¶ÖiÞ
												Update(DP[y][x-1][xl][xr][o-1],f);
											}
										}
										if(x<W-1){
											if(x==xr){//EÖ@é
												fn=CalcF(f,x+1,y);
												on=CalcO(o-1,x+1,y);
												Update(DP[y][x+1][xl][x+1][on],fn);
											}else{//EÖiÞ
												Update(DP[y][x+1][xl][xr][o-1],f);
											}
										}
									}
								}
							}//dx
						}//xl
					}//d
				}//o
			}//range
		}//y
		fn=0;
		for(x=0;x<W;x++){
			for(o=m;o>0;o--){
				f=DP[H][x][x][x][o];
				if(f>fn)
					fn=f;
			}
		}
		printf(fn?"%d\n":"NA\n",f0-fn);
		memset(DP,0,sizeof(DP));
	}
	//puts("");
	exit(0);
}

Measured memory_bytes: 0
n=int(input())
ans=[]
if n==0:
    print(0)
else:
    while n!=0:
        if n%-2==0:
            n=n//-2
            r=0
            ans.append('0')
        if n%-2==-1:
            n=n//-2+1
            r=1
            ans.append('1')
    print(''.join(reversed(ans)))

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

template<typename Abel> struct BIT {
    const Abel UNITY_SUM = 0;
    vector<Abel> dat;
    BIT(int n) : dat(n, UNITY_SUM) { }  // [0, n)
    inline void add(int i, Abel x) {
        while (i < dat.size()) { dat[i] += x; i |= i + 1; }
    }
    inline Abel sum(int i) {    // [0, i]
        Abel res = UNITY_SUM;
        while (i >= 0) { res += dat[i]; i = (i & (i + 1)) - 1; }
        return res;
    }
    inline Abel sum(int a, int b) { return sum(b - 1) - sum(a - 1); }   // [a, b)
    Abel operator[](int i) { return sum(i, i + 1); }
    friend ostream& operator<<(ostream& os, BIT<Abel> &bit) {
        for (int i = 0; i < bit.dat.size(); i++) os << bit[i] << " ";
        return os;
    }
};

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    map<int, vector<int>> m;
    BIT<long long> bit(n);
    for (int i = 0; i < n; i++) {
        m[a[i]].emplace_back(i);
        bit.add(i, 1);
    }
    long long cnt = 0;
    for (auto &p: m) {
        for (int i: p.second) bit.add(i, -1);
        for (int i: p.second) cnt += min(bit.sum(0, i), bit.sum(i + 1, n));
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 14848
N = int(input())
S1 = input()
S2 = input()
res = 6
idx = 0
s = []
mod = 1000000007
while idx < N:
    if S1[idx] == S2[idx]:
        s.append(0)
    else:
        s.append(1)
        idx += 1
    idx += 1

res = 3 if s[0] == 0 else 6

for idx in range(1, len(s)):
    prev, cur = s[idx-1], s[idx]
    if prev == 0:
        if cur == 0:
            res *= 2
        else:
            res *= 2
    else:
        if cur == 0:
            res *= 1
        else:
            res *= 3

res %= mod

print(res)


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

int main() {
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    
	int arr[5];
	for(int i=0; i<5; i++){
		cin>>arr[i];
	}
	for(int j=0; j<5; j++){
		if(arr[j]==0){
			cout<<j+1<<"\n";
		}
	}
	
	return 0;
}

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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

struct Edge {
  int to;
  ll cost;
};
using Graph = vector<vector<Edge>>;

vector<bool> can_reach(const Graph& G, int start) {
  ll n = G.size();
  vector<bool> ans(n);
  queue<int> que;

  que.push(start);
  ans[start] = true;

  while (!que.empty()) {
    int index = que.front();
    que.pop();
    for (const auto& it : G[index]) {
      if (ans[it.to] == false) {
        que.push(it.to);
        ans[it.to] = true;
      }
    }
  }

  return ans;
}

// Bellman Ford
// G: グラフ
// rev: 逆辺のグラフ(負の閉路検出用)
// start: 始点
// goal: 終点
// 戻り値: goalに行くまでの最小コスト。負の閉路が存在する場合は-INFとなる。
ll bellman_ford(const Graph& G, const Graph& rev, const int start, const int goal) {
  const int n = G.size();

  // 始点からそこまで行くのにかかるのコスト
  vector<ll> cost(n, INF);
  vector<ll> cost_middle;
  cost[start] = 0;

  // 閉路がなければn回のループで良いが、閉路検出用にn+1回回す
  for (int i = 0; i < n; i++) {
    // すべての辺を走査
    for (int from = 0; from < n; from++) {
      if (cost[from] == INF) {
        continue;
      }
      for (auto e : G[from]) {
        // 更新
        if (cost[e.to] > cost[from] + e.cost) {
          cost[e.to] = cost[from] + e.cost;
        }
      }
    }

    // 閉路検出用
    if (i == n - 2) {
      cost_middle = cost;
    }
  }

  // 始点から到達できるか
  auto can_reach_from_start = can_reach(G, start);
  // 終点へ到達できるか
  auto can_reach_from_goal = can_reach(rev, goal);

  for (int i = 0; i < n; i++) {
    if (can_reach_from_start[i] && can_reach_from_goal[i]) {
      // 始点から終点へ移動できる経路上のノードの内、値が更新されるものが存在したら負のループが存在する。
      if (cost_middle[i] != cost[i]) {
        return -INF;
      }
    }
  }

  return cost[goal];
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, m, p;
  cin >> n >> m >> p;

  Graph G(n + 1), rev(n + 1);

  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    G[a].push_back((Edge){b, -c + p});
    rev[b].push_back((Edge){a, -c + p});
  }

  ll ans = bellman_ford(G, rev, 1, n);
  ans *= -1;
  chmax(ans, 0ll);
  if (ans == INF) {
    ans = -1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define li 100005
#define mp make_pair
#define lo long long 
#define pb push_back
#define inf 1000000000
#define md 1000000007
lo int n,m;
vector<lo int> v;
int main(){
	cin>>n>>m;
	for(lo int i=1;i*i<=m;i++){
		if(m%i==0){
			if(i*i!=m){
				v.push_back(i);
				v.push_back(m/i);
			}
			else v.push_back(i);
		}
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	for(int i=0;i<(int)v.size();i++){
		if(v[i]*n<=m){
			cout<<v[i]<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

using namespace std;

signed main() {
  IOS;
  int N,V[50],C[50],i,ans=0;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> V[i];
  }
  for (i = 0; i < N; i++) {
    cin >> C[i];
    if ((V[i]-C[i]) > 0) ans += V[i]-C[i];
  }

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


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
int main(){
	long long k=gi(),a=gi(),b=gi();
	if(k<a||b-a<=1)return printf("%lld\n",k+1),0;
	k-=a-1;printf("%lld\n",a+(k>>1)*(b-a)+(k&1));
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll N; cin >> N;
    ll X, Y; cin >> X >> Y;
    if(X>Y) swap(X, Y);
    X--, Y--;
    vector<vector<ll>> dist(N, vector<ll>(N, INF));
    REP(i, N) dist[i][i] = 0;
    dist[X][Y] = dist[Y][X] = 1;
    REP(i, N) {
        FOR(j, i+1, N) {
            if(i<=X and Y<= j) {
                dist[i][j] = dist[j][i] = X-i + j-Y + 1;
            }
            else dist[i][j] = dist[j][i] = j-i;
            dist[i][j] = dist[j][i] = min(j-i, abs(X-i)+abs(Y-j)+ 1);
        }
    }
    vector<ll> res(N+10);
    REP(i, N){
        REP(j, N){
            res[dist[i][j]]++;
        }
    }
    FOR(k, 1, N){
        cout << res[k]/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>

#define MAX_N 100000

int N;
unsigned long int A[MAX_N];
unsigned long long int res;

unsigned long int solve( bool g ) {
    int l=0, r=N-1;
    unsigned long int lv, rv;
    if (g) {
    // res += abs(A[r] - A[l]) + abs(A[r] - A[l+1]);
        res = abs(A[l] - A[r]) + abs(A[l] - A[r-1]);
        lv = A[r];
        rv = A[r-1];
    // l += 2;
    // --r;
        ++l;
        r -= 2;
    // bool f = false; // true -> lv, rv は l で決めた, つぎはrからとる
    } else {
        res = abs(A[r] - A[l]) + abs(A[r] - A[l+1]);
        lv = A[l];
        rv = A[l+1];
        l += 2;
        --r;
    }
    bool f = !g;

    while (l <= r) {
        if (f) {
            // if (lv < rv) {
                res += abs(lv - A[r]) + abs(rv - A[r-1]);
                lv = A[r];
                rv = A[r-1];
            /* } else {
                res += abs(rv - A[r]) + abs(lv - A[r-1]);
                lv = A[r-1];
                rv = A[r];
             } */
            r -= 2;
        } else {
            // if (lv > rv) {
                res += abs(rv - A[l]) + abs(lv - A[l+1]);
                rv = A[l];
                lv = A[l+1];
            /* } else {
                res += abs(rv - A[l+1]) + abs(lv - A[l]);
                rv = A[l+1];
                lv = A[l];
            } */
            l += 2;
        }
        f = !f;
    }
    return res;
}

int main() {
    std::cin >> N;
    for (int i=0; i<N; i++) {
        std::cin >> A[i];
    }
    if (N == 2) {
        std::cout << abs(A[1] - A[0]) << std::endl;
    } else {
        unsigned long long int result;
        std::sort(A, A+N);
        result = std::max(solve(true), solve(false) );
        std::cout << result << std::endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stack>
  
int main(){
    std::stack<u_int> train;
    u_int num;
    while(std::cin >> num){
        if(num == 0){
            std::cout << train.top() << std::endl;
            train.pop();
        }
        else {
            train.push(num);
        }
    }
    return 0;
}

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

int main() {
  long long n,a,b;
  cin >> n >> a >> b;
  a = min(a,b);
  cin >> b;
  a = min(a,b);
  cin >> b;
  a = min(a,b);
  cin >> b;
  a = min(a,b);
  cin >> b;
  a = min(a,b);
  b = n / a;
  if(n % a != 0ll)
    b++;
  cout << b + 4ll << endl;
}

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

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

    int ans = 0;
    for (int i = 1; i * i < n; i++) {
        ans++;
        if (n / i > i) ans += (ceil(n / i) - (i + 1)) * 2;
    }

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


Measured memory_bytes: 3692
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cstring>
#include<vector>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<functional>
#include<unordered_map>
#define io ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
#define ll long long
#define P pair<int,int>
#define lc rt*2
#define rc rt*2+1
#define s_it set<node>::iterator
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const double PI = 3.1415926536;

using namespace std;


int main()
{
	int n;
	cin >> n;
	if (n % 2)
		cout << n / 2 + 1;
	else
		cout << n / 2;
	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define _USE_MATH_DEFINES
#define mp       make_pair
#define pb       push_back
#define fst      first
#define snd      second
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const int MOD=1000000007;
const double EPS=1e-9;

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


int main()
{
    int N; cin >> N;
    vi a(3*N);
    rep(i,3*N) cin >> a[i];

    priority_queue<int> a1, a2;
    rep(i,N) {
        a1.push(-a[i]);
        a2.push(a[N*2+i]);
    }

    vector<ll> sum_a1(N+1), sum_a2(N+1);
    sum_a1[0] = accumulate(a.begin(), a.begin()+N, 0LL);
    sum_a2[0] = accumulate(a.rbegin(), a.rbegin()+N, 0LL);

    rep(i,N) {
        if(a[N+i] > -a1.top()) {
            sum_a1[i+1] = sum_a1[i] + a1.top() + a[N+i];
            a1.pop();
            a1.push(-a[N+i]);
        } else {
            sum_a1[i+1] = sum_a1[i];
        }

        if(a[N*2-1-i] < a2.top()) {
            sum_a2[i+1] = sum_a2[i] - a2.top() + a[2*N-1-i];
            a2.pop();
            a2.push(a[2*N-1-i]);
        } else {
            sum_a2[i+1] = sum_a2[i];
        }
    }

    ll ans = sum_a1[0] - sum_a2[N]; 
    rep(i,N+1) {
        ans = max(sum_a1[i]-sum_a2[N-i], ans);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3956
#include <stdio.h>

 int main(){
 int a,b;scanf("%d%d",&a,&b);
 if(a<b){
 for(int i=0;i<b;i++)printf("%d",a);
 }else{
 for(int i=0;i<a;i++)printf("%d",b);
 }
 printf("\n");
 }


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int64 N, K;
  cin >> N >> K;
  N -= N / K * K;
  cout << min(llabs(N - K), N) << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

const i64 mod = 1e9 + 7;
i64 ipow(i64 a, i64 b) {
    i64 x = a, y = 1;
    for (; b > 0; b >>= 1) {
        if (b & 1) (y *= x) %= mod;
        (x *= x) %= mod;
    }
    return y;
}
i64 inv(i64 x) {
    return ipow(x, mod - 2);
}
i64 fact(i64 x) {
    static vector<i64> f;
    i64 i = f.size();
    if (x >= i) {
        f.resize(x + 1);
        for (; i <= x; ++i) {
            f[i] = i == 0 ? 1 : i * f[i - 1] % mod;
        }
    }
    return f[x];
}
i64 perm(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(n - k)) % mod : 0;
}
i64 comb(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(k) * fact(n - k) % mod) % mod : 0;
}
int n;
vector<vector<int>> g;
vector<i64> dp1, sizes;

void dfs1(int u, int p) {
    dp1[u] = 1;
    sizes[u] = 1;
    for (int v : g[u]) {
        if (v == p) continue;
        dfs1(v, u);
        sizes[u] += sizes[v];
        (dp1[u] *= dp1[v] * comb(sizes[u] - 1, sizes[v]) % mod) %= mod;
    }
}
void dfs2(int u, int p) {
    for (int v : g[u]) {
        if (v == p) continue;
        (dp1[v] *= dp1[u] * inv(dp1[v] * comb(n - 1, sizes[v]) % mod) % mod * comb(n - 1, sizes[v] - 1) % mod) %= mod;
        dfs2(v, u);
    }
}

int main() {
    cin >> n;
    g.resize(n + 1);
    sizes.resize(n + 1);
    dp1.resize(n + 1);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs1(1, 0);
    dfs2(1, 0);

    for (int u = 1; u <= n; ++u) {
        cout << dp1[u] << '\n';
    }
    return 0;
}

Measured memory_bytes: 19068
#include <bits/stdc++.h>
#define N 105
#define LL long long
#define end1 "\n"
#define sp " "
using namespace std;
int n,mn=103,k,ar[N],sum;
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>ar[i];
		sum+=ar[i];
		if(ar[i]%10!=0)
			mn=min(mn,ar[i]);
		
		
	}
	if(mn==103)
	{
		cout<<0;
		return 0;
	}
	if(sum%10!=0)
		cout<<sum;
	else
		cout<<sum-mn;
}	


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long P = sc.nextLong();
		if(N == 1) {
			System.out.println(P);
		}else {
			long m = 12/N + 1;
			int n = 1;
			int mlcm = 1;
			for(int i = 0; i < m;i++)n *= 10;
			for(int i = 1;i < n + 1;i++) {
				if(P % (Math.pow(i, N)) == 0) {
					mlcm = i;
				}
			}
			System.out.println(mlcm);
		}
	}
}


Measured memory_bytes: 24020
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,M; cin >> N >> M;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<ll> cnt(100001);
    rep(i,N) cnt[A[i]]++;
    for (int i = 100000; i > 0; i--) cnt[i-1] += cnt[i];

    ll left = 0;
    ll right = 200001;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        ll c = 0;
        rep(i,N) {
            ll k = max(mid - A[i],0LL);
            if (k > 100000) continue;
            c += cnt[k];
        }
        if (c < M) right = mid;
        else left = mid;
    }

    sort(all(A));
    vector<ll> B(N+1);
    rep(i,N) B[i+1] = B[i]+A[i];
    
    ll c = 0;
    ll ans = 0;
    rep(i,N) {
        ll k = max(left - A[i],0LL);
        if (k > 100000) continue;
        c+= cnt[k];
        ans += (B[N] - B[N-cnt[k]] + cnt[k]*A[i]);
    }
    ans -= (c - M)*left;

    cout << ans << endl;
}

Measured memory_bytes: 2560
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(list:[i64]));
    let mut list = list;
    list.sort();
    ((list[0] - list[1]).abs() + (list[2] - list[1]).abs()).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "1 6 3" => "5",
    test2: "11 5 5" => "6",
    test3: "100 100 100" => "0",
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
ll rec(ll a){
	ll m=-1,k=10;
	while(1){
		if(a/k==0)break;
		m=max(m,a/k*(a%k));
		k*=10;
	}
	return m;
}
int main(){
	ll q,n;
	cin>>q;
	while(q--){
		int cnt=0;
		cin>>n;
		while(n>=10){
			n=rec(n);
//			cout<<n<<endl;
			cnt++;
		}
		cout<<cnt<<endl;
	}
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int L[] = new int[N];
		int answer = 0;

		for (int i = 0; i < N; i++) {
			L[i] = scan.nextInt();
		}

		for (int i = 0; i < N; i++) {
			for (int k = i; k < N; k++) {
				for (int n = k; n < N; n++) {
					if (L[i] != L[k] && L[k] != L[n] && L[n] != L[i]) {
						if (L[i] + L[k] > L[n] && L[k] + L[n] > L[i] && L[n] + L[i] > L[k]) answer++;
					}
				}
			}
		}

		System.out.println(answer);

 	}
}

Measured memory_bytes: 35980
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a[] = new long[3];
		for(int i = 0; i < 3; i ++) {
			a[i] = sc.nextLong();
		}
		long max = 0;
		long sum = 0;
		for(int i = 0; i < 3; i ++) {
			max = Math.max(max, a[i]);
			sum += a[i];
		}
		System.out.println(sum == max * 2 ? "Yes" : "No");
	}
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll X, Y;
    cin >> X >> Y;
    vector<ll> v;
    v.push_back(X);
    while (true)
    {
        ll t = v[v.size() - 1] * 2LL;
        if (t > Y)
            break;
        v.push_back(t);
    }

    cout << v.size() << endl;
    return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A, B;
    for (int i = 0; i < M; ++i)
    {
        int a, b;
        cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
    }
    int ans[60] = {0};
    for (int i = 0; i < M; ++i)
    {
        ++ans[A[i] - 1];
        ++ans[B[i] - 1];
    }
    for (int i = 0; i < N; ++i)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3600
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int hp = Integer.parseInt(sc.next());
        int at = Integer.parseInt(sc.next());
        if(hp % at == 0){
            System.out.println(hp/at);
        }else{
        System.out.println(hp / at + 1);
        }
    } 
}

Measured memory_bytes: 23636
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

const long long MAX = 210000;

void check(vector<int> &A, vector<int> &data, int N, int K, int b){
	vector<int> ans;
	
	for(int i = b; i < N*K; i++){
		if(data[i%N]+i > N*K){
			ans.push_back(A[i%N]);
		} else {
			i += data[i%N]-1;
		}
	}
	
	for(int i = 0; i < ans.size(); i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
}

void solve(vector<int> &A, int N, int K){
	vector<vector<pair<int,int>>> storage(MAX+10);
	vector<int> used(N+10, -1), data(N+10,0);
	int maximum = 0, minimum = INF;
	
	for(int i = 0; i < N; i++){
		storage[A[i]].push_back(make_pair(i,0));
		maximum = max(maximum, A[i]);
		minimum = min(minimum, A[i]);
	}
	for(int i = minimum; i <= maximum; i++){
		for(int j = 0; j < storage[i].size(); j++){
			if(j == storage[i].size()-1){
				storage[i][j].second = storage[i][0].first + (N - storage[i][j].first);
			} else {
				storage[i][j].second = storage[i][j+1].first - storage[i][j].first;
			}
			data[storage[i][j].first] = storage[i][j].second+1;
		}
	}
	
	for(int i = 0, now = 0, con = 0;;){
		if(used[now] != -1){
			int num = con - used[now];
			if((N*K-con)%num) con = N*K - (N*K-con)%num;
			else con = N*K;
			now = con%N;
			
			for(;;){
				if(data[now] + con > K){
					check(A,data,N,K,con);
					break;
				} else {
					con += data[now];
				}
			}
			break;
		}
		used[now] = con;
		
		if(data[now] + con > K){
			check(A,data,N,K,con);
			break;
		} else {
			con += data[now];
			now = (con)%N;
		}
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, K;
	vector<int> A;
	
	cin>>N>>K;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
	}
	
	solve(A,N,K);
	
	
	return 0;
}

Measured memory_bytes: 19060
#include <set>
#include <vector>
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

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

int main() {
	ll q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	q <<= 3, h <<= 2, s <<= 1;
	cout << (n / 2) * min({ q, h, s, d }) + (n & 1) * min({ q, h, s }) / 2 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		boolean flg = false;
		for(int i = 1;i<10;i++){
			for(int j = 1;j<10;j++){
				if(i*j ==n){
					flg = true;
				}
			}
		}
if(flg){
    System.out.println("Yes");
}else{
	System.out.println("No");
}
	}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

signed main(){
    int h, w;
    cin >> h >> w;
    
    vector<vector<int>> coins(h+1,vector<int>(w+1));
    rep(i,h)rep(j,w) cin >> coins[i+1][j+1];
    
    vector<int> x(h*w), y(h*w);
    rep(i,h*w){
        x[i] = i / w + 1;
        y[i] = (x[i] % 2) ? (i%w + 1) : (w - i%w);
    }
    
    queue<string> q;
    bool record = false;
    int operation = 0;
    
    rep(i,h*w-1){
        bool is_odd = coins[x[i]][y[i]] % 2 == 1;
        if(is_odd || record){
            if(is_odd && record){
                record = false;
            }else{
                string str = "";
                str += to_string(x[i]) + " ";
                str += to_string(y[i]) + " ";
                str += to_string(x[i+1]) + " ";
                str += to_string(y[i+1]);
                q.push(str);
                operation++;
                record = true;
            }
        }
    }
    
    cout << operation << endl;
    while(!q.empty()){
        cout << q.front() << endl;
        q.pop();
    }
}

Measured memory_bytes: 13568
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define SWAP(a,b) (a+=b,b=a-b,a-=b)
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT(' ');
}
int main(void)
{
  int N=IN(),A[N],B[N],j=0,did=-1;
  rep(i,N){A[i]=IN();}rep(i,N){B[i]=IN();}
  rep(i,N)
  {
    if(did!=A[i]){j=0;}
    if(A[i]==B[i])
    {
      while(j<N){if(A[j]!=A[i]&&B[j]!=A[i]){SWAP(B[i],B[j]);break;}j++;}
      if(A[i]==B[i]){return puts("No"),0;}
    }
    did=A[i];
  }
  puts("Yes");rep(i,N){OUT(B[i]);}return puts(""),0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
int main(){
  char c;
  cin >> c;
  c+=1;
  cout << c << endl;
  return 0;
  
}

Measured memory_bytes: 256
N = int(input())
t = 1
a = 1
TA = [0]*N
for i in range(N):
    TA[i] = map(int,input().split(" "))

for T,A in TA:
    n = max(t//T+(t%T and 1),a//A+(a%A and 1))
    t = n * T
    a = n * A

print(t+a)

Measured memory_bytes: 3444