akhauriyash/Code-Regression huggingface dataset:
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < (int)n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

#if 1
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

stack<PP> ST;
int MAX;

int H, W;
string S[2000];
vector<bool> T[1999];
int U[2000][2000];

int main() {
	cin >> H >> W;
	REP(i, 0, H) {
		cin >> S[i];
	}

	REP(i, 0, H - 1) {
		T[i].resize(W - 1);
		REP(j, 0, W - 1) {
			T[i][j] = !((S[i][j] == S[i][j + 1]) == (S[i + 1][j] == S[i + 1][j + 1]));
		}
	}

	REP(j, 0, W - 1) {
		int tmp = 1;
		U[0][j] = 1;
		REP(i, 1, H) {
			tmp++;
			if (T[i - 1][j]) tmp = 1;
			U[i][j] = tmp;
		}
	}
	REP(i, 0, H) {
		U[i][W - 1] = 0;
	}

	REP(i, 0, H) {
		REP(j, 0, W) {
			if (ST.empty() || (!ST.empty() && ST.top().first < U[i][j])) {
				ST.push(PP(U[i][j], j));
			} else if (!ST.empty() && ST.top().first > U[i][j]) {
				PP p;
				while (!ST.empty() && ST.top().first >= U[i][j]) {
					p = ST.top(); ST.pop();
					if (p.first * (j + 1 - p.second) > MAX) {
						MAX = p.first * (j + 1 - p.second);
					}
				}
				ST.push(PP(U[i][j], p.second));
			}
		}
	}
	if (MAX < H) MAX = H;
	cout << MAX << endl;
	return 0;
}

Measured memory_bytes: 20608
#include<cstdio>
#include<vector>
#include<cstring>
#include "bits/stdc++.h"
#define CLR(x) memset(x,0,sizeof(x))
using namespace std;
const int maxn=2e5+5;
int dep[maxn];
int max_len,root,n;
int vis[maxn];
vector<int>ve[maxn];
int dfs(int x,int len)
{
    vis[x]=1;
    if(len >max_len) max_len=len,root=x;
    for(int i=0;i<ve[x].size();i++){
        if(!vis[ve[x][i]]){
            dfs(ve[x][i],len+1);
        }
    }
    return 0;
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        ve[u].push_back(v);
        ve[v].push_back(u);
    }
    max_len=0;
    CLR(vis);
    dfs(1,0);    //找到叶子结点之一,也许是最远.
    CLR(vis);
    dfs(root,0);    //以一个叶子结点开始搜素,则搜出来的长度一定是最长.
//    printf("%d\n",max_len);    //输出长度.
    int ans = max_len;
    if(ans == 0){
        cout<<"First"<<endl;
    }else{
        ans--;
        if(ans %3 == 0){
            puts("Second");
        }else{
            cout<<"First"<<endl;
        }
    }
    //ans = 10*ans + ans*(ans+1)/2;
    
    return 0;
    
}


Measured memory_bytes: 22016
#include<bits/stdc++.h>
using namespace std;
signed main(){
  string s;
  cin>>s;
  bool c=false,f=false;
  for(int i=0;i<s.size();++i){
    if(s[i]=='C')c=true;
    else if(s[i]=='F'&&c)f=true;
  }
  if(c&&f)cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a[10];
  int i,j,t;
  for(i=0;i<10;i++)
    {
      scanf("%d",&a[i]);
    }
  for(i=0;i<10;i++)
    {
      for(j=0;j<10-i-1;j++){
	if(a[j]<a[j+1])
	  {
	    t=a[j];
	    a[j]=+a[j+1];
	    a[j+1]=t;
	  }
      }
    }
      for(i=0;i<3;i++){
	printf("%d\n",a[i]);
	       }
      return 0;
}

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

#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define let const auto
#define USE_T template <typename T>
#define USE_Ti template <typename T = int>
#define USE_TU template <typename T, typename U>

USE_Ti using duo = std::pair<T, T>;
USE_Ti using vec = std::vector<T>;
using ll = long long;
// clang-format off
USE_TU inline bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE_TU inline bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE_Ti inline T in(){T x;std::cin>>x;return x;}
USE_Ti inline vec<T> in(int n){vec<T> v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE_T inline void in(T*x,int n){rep(i,n)x[i]=in<T>();}
struct IoSetup {
  IoSetup(){
    using namespace std;
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<setprecision(10);
    cerr<<setprecision(10);
  }
} iosetup;
// clang-format on
// }}}
using namespace std;
const int inf = 1001001001;
const ll infll = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

int D[99];

signed main() {
  int N = in();
  int K = in();
  for (int d : in(K)) {
    D[d] = 1;
  }

  rep(i, N, 10000000) {
    stringstream ss;
    ss << i;
    string s;
    ss >> s;
    bool ok = true;
    for (char c : s) {
      if (D[c - '0']) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Set<String> marchSet = new HashSet<>();
		int march[] = new int[5];

		for (int i = 0; i < n; i++) {
			String s = scanner.next();
			marchSet.add(s);
		}

		for (String s : marchSet) {
			if (s.charAt(0) == 'M')
				march[0]++;
			else if (s.charAt(0) == 'A')
				march[1]++;
			else if (s.charAt(0) == 'R')
				march[2]++;
			else if (s.charAt(0) == 'C')
				march[3]++;
			else if (s.charAt(0) == 'H')
				march[4]++;
		}

		long cnt = 0;
		for (int i = 0; i < 5; i++) {
			for (int j = i + 1; j < 5; j++) {
				for (int k = j + 1; k < 5; k++) {
					cnt += (long)march[i] *(long) march[j] *(long) march[k];
				}
			}
		}

		System.out.println(cnt);

	}
}

Measured memory_bytes: 53488
#include<bits/stdc++.h>
using namespace std;
#define int long long 

char table[15][1010];
//参照 k111111
const int inf = 1LL << 60;

signed main(void){ 
  
  int h,w,k; cin >> h >> w >> k;
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){ 
      cin >> table[i][j];
    }
  }
  
  int ans = inf;
  
  for(int bt = 0; bt < (1<<(h-1)); bt++){ 
   
    int cnt = 0;
    
    for(int i = 0; i < h; i++){
      if( bt >> i & 1 ){ cnt++;}
    }//1の個数を数えた
   
    
    bool impossible = false;
    
    int stock[12] = {}; 
     
    for(int j = 0; j < w; j++){
      
      
      int nw[12] = {}; int pos = 0;
      
      bool fold = false;
      
      for(int i = 0; i < h; i++){
        if( table[i][j] == '1' ){ nw[pos]++;}
        if( bt >> i & 1 ){ pos++;}
      }
      
      for(int i = 0; i < h; i++){ 
        
        if( nw[i]+stock[i] > k ){ fold = true;}
        if( nw[i] > k ){ impossible = true;}
        
      }
      
      if(impossible){break;}
      
      if(fold){ 
        
        for(int i = 0; i < h; i++){ 
          
          stock[i] = nw[i];
          
        }
          
        cnt++;
        
      }
      else{
        
        for(int i = 0; i < h; i++){ 
          
          stock[i] += nw[i];
          
        }
      }
      
    }
    
    if(impossible){ cnt = inf;}
    
    ans = min(ans,cnt);
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    vector<pair<int, int>> R(N);
    vector<pair<int, int>> B(N);

    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        R[i] = make_pair(a, b);
    }
    for (int i = 0; i < N; i++) {
        int c, d;
        cin >> c >> d;
        B[i] = make_pair(c, d);
    }

    sort(R.begin(), R.end());
    sort(B.begin(), B.end());

    vector<int> check(N, 0);

    for (int i = N-1; i >= 0; i--) {
        int temp = 1e9;
        int index = -1;
        for (int j = N-1; j >= 0; j--) {
            if ( B[j].first < R[i].first ) break;
            if ( R[i].second < B[j].second && check[j] == 0 ) {
                if ( temp > B[j].second ) {
                    temp = B[j].second;
                    index = j;
                }
            }
        }
        if ( index >= 0 ) {
            check[index] = 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += check[i];
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    ll dp[100002];
    int N,M, ss;cin>>N>>M;
    set<int> s; set<int>::iterator ite;
    for(int i=0; i<M;i++){
      cin>>ss; s.insert(ss);
    }
    dp[0]=1; dp[1]=1;
    for(int i=0; i<=1;i++){
      if(s.find(i) != s.end()) dp[i]=-1;
    }
    for(int i=2; i<=N;i++){
      if(s.find(i) != s.end()) dp[i]=-1;
      else if(dp[i-1]==-1 && dp[i-2]==-1) dp[i] = -1;
      else if(dp[i-1]==-1) dp[i]=dp[i-2];
      else if(dp[i-2]==-1) dp[i]=dp[i-1];
      else dp[i]= (dp[i-2]+dp[i-1])%MOD;
    }
    if(dp[N]==-1) cout<<0<<endl;
    else cout<<dp[N]<<endl;
    return 0;
}


Measured memory_bytes: 5760
#!/usr/bin/env python3
"""n = int(input())
l = list(map(int,input().split()))
sum_l = sum(l)
min_dif = abs(sum_l-2*l[0])
acum_sum = l[0]
for i in range(1,n-1):
    acum_sum += l[i]
    if min_dif > abs(sum_l - 2*acum_sum):
        min_dif = abs(sum_l - 2*acum_sum)
#print(acum_sum)
print(min_dif)"""
n = int(input())
a = list(map(int,input().split()))
cum_sum = [0]*n
cum_sum[0] = a[0]
for i in range(1,n):
  cum_sum[i] = cum_sum[i-1]+a[i]
ans = 5*10**9
for i in range(0,n-1):
  ans = min(ans,abs(cum_sum[n-1]-2*cum_sum[i]))
print(ans)


Measured memory_bytes: 23792
import numpy as np
def solve():
    s = input()
    s+="?"
    ind = 0
    bef = ""
    befbef=""
    ans = 0
    n = len(s)
    if n == 2:
        print(1)
        return 0
    while True:
        if s[ind] == "?":
            break
        if bef == s[ind]:
            bef = s[ind]+s[ind+1]
            ans += 1
            ind +=2
        else:
            bef = s[ind]
            ans += 1
            ind += 1
        if ind > n-1:
            break

    # print(ans)

    if len(bef)==2 and bef[-1] == "?":
        ans -= 1

    print(ans)
    return 0

if __name__ == '__main__':
    solve()



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

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

 int v[n];
 int w[n];

 for(int i=0;i<n;i++){
	cin>>v[i]>>w[i];
 }

 int DP[n+1][W+1];

 for(int j=0;j<=W;j++){
	DP[0][j]=0;
 }

 for(int i=1;i<=n;i++){
	for(int j=0;j<=W;j++){
		if(j<w[i-1]){
			DP[i][j]=DP[i-1][j];
		}else{
			if(DP[i-1][j]>DP[i][j-w[i-1]]+v[i-1]){
				DP[i][j]=DP[i-1][j];
			}else{
				DP[i][j]=DP[i][j-w[i-1]]+v[i-1];
			}
		}
	}
 }
 cout<<DP[n][W]<<endl;
return 0;
}

Measured memory_bytes: 7012
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 4005;

int n, a, b, tp, st[MAXN];
bool ans[MAXN];

inline bool Ask(int x, int y)
{
	string s;
	cout << "? " << x << " " << y << endl;
	cin >> s;
	return s == "Y";
}

inline void Ans()
{
	printf("! ");
	for (int i = 0; i < n; i ++)
		putchar(ans[i] + '0');
	cout << endl;
}

int main()
{
	a = Read(), b = Read(), n = a + b;
	if (a <= b)
		return cout << "Impossible" << endl, 0;
	for (int i = 0; i < n; i ++)
		if (tp && !Ask(st[tp], i))
			tp --;
		else
			st[++ tp] = i;
	for (int i = 0; i < n; i ++)
		ans[i] = Ask(st[tp], i);
	Ans();
	return 0;
}


Measured memory_bytes: 724
#include <stdio.h>

int main(){
   int n,k,i,j,K;
   long a[1000],aa[1000*1000],m,mm,ko;
    
   scanf("%d %d",&n,&K);
   for (i=0;i<n;i++) 
      scanf("%ld",&a[i]);
   k=0;
   for (i=0;i<n;i++)
      for (j=i;j<n;j++) {
         if (j==i) aa[k]=a[j];
         else      aa[k]=aa[k-1]+a[j];
         if (aa[k]>m) m=aa[k];
         k++;
      }
   for (mm=1;m>1;mm*=2) m/=2;
   for (ko=0;mm>0;mm/=2) {
      for (i=j=0;i<k;i++) 
         if ((aa[i]&mm)==mm) j++;
      if (j>=K) {
         ko+=mm;
         for (i=j=0;i<k;i++)
            if ((aa[i]&mm)==mm) aa[j++]=aa[i];
         k=j;
      }
   }
   printf("%ld\n",ko);
   return 0;
}


Measured memory_bytes: 6144
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main(){
long long a,b;cin>>a>>b;

long long ans=a;
long long i;

if(a%2==0){
  if((b-a+1)%4==0) ans=0;
  if((b-a+1)%4==1) ans=b;
  if((b-a+1)%4==2) ans=1;
  if((b-a+1)%4==3) ans=b^1;
}
else{
  if((b-a)%4==0) ans=a^0;
  if((b-a)%4==1) ans=a^b;
  if((b-a)%4==2) ans=a^1;
  if((b-a)%4==3) ans=a^b^1;
}

if(b==a) ans=a;
cout << ans << endl;

}


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

int main() {
int a,b,c,d;
cin >> a >> b >> c >> d;
int x = a*b;
int y = c*d;
int ans = max(x,y);
cout << ans << endl;
 }

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;




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

	vector<int> a(n);
	for (int i = 0; i < n;i++) {
		cin >> a[i];
	}

	vector<int> min_a(n);
	min_a[0] = a[0];
	for (int i = 1; i < n;i++) {
		min_a[i] = min(min_a[i - 1], a[i]);
	}

	map<int, int> m;
	for (int i = 1; i < n;i++) {
		if (min_a[i] < a[i]) {
			m[a[i] - min_a[i]]++;
		}
	}
	auto it = m.end();
	it--;

	cout << it->second << endl;
}


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

int main() {
	string s;
	char c;
	for (int i = 0; i < 3; i++)for (int j = 0; j < 3; j++) {
		cin >> c;
		if (i == j)s += c;
	}
	cout << s.c_str() << 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++)

vector<int> to[200000];
vector<int> ans;

void dfs(int v, int p=-1){
    for(int u : to[v]){
        if(u == p) continue;
        ans[u] += ans[v];
        dfs(u,v);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        --a, --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q){
        int p, x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0);
    rep(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 23424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i], a[i]--;

    vector<ll> cnt(n);
    REP(i, n) cnt[a[i]]++;
    sort(ALL(cnt));
    vector<ll> sum(cnt);
    FOR(i, 1, n) sum[i] += sum[i-1];

    vector<ll> f(n+1);
    FOR(x, 1, n+1) {
        ll itr = upper_bound(ALL(cnt), x) - cnt.begin();
        f[x] = ((itr==0?0:sum[itr-1]) + x*(n-itr)) / x;
    }

    FOR(k, 1, n+1) {
        auto check = [&](ll mid) { return k <= f[mid]; };
        ll lb = 0, ub = n+1;
        while(ub-lb>1) {
            ll mid = (lb+ub)/2;
            if(check(mid)) lb = mid;
            else ub = mid;  
        }
        cout << lb << endl;
    }

    return 0;
}

Measured memory_bytes: 10240
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<deque>
#include<numeric>
#include<algorithm>
#include<unordered_map>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;
using ll = long long int;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9 + 7);

int n;
vector<vector<int>> d;

int main(void) {
	cin >> n;
	d = vector<vector<int>>(n, vector<int>(2));
	for (int i = 0; i < n; i++)
		cin >> d[i][0] >> d[i][1];

	string ret = "No";
	for (int i = 0; i < n - 2; i++) {
		if (d[i][0] == d[i][1] && d[i + 1][0] == d[i + 1][1] && d[i + 2][0] == d[i + 2][1]) {
			ret = "Yes";
			break;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3632
N,M=map(int,input().split())
data=[0]*(N+1)

for _ in range(M):
    L,R=map(int,input().split())
    L=L-1
    R=R-1
    data[L]+=1
    data[R+1]-=1

for i  in range(N+1):
    if i==0:
        data[i]=data[i]
    else:
        data[i]+=data[i-1]
print(data.count(M))


Measured memory_bytes: 6900
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>

#define NIL -1
#define MAX 5000

typedef long long int lli;

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

void multipleLCM(int A[], int i, int less, lli A0, lli *ans)
{
	if(A[i+1] == NIL){
		*ans = A0;
		return;
	}
	if(i+1 != less){
		int x = A0*A[i+1];
		A0 = gcd(A0, A[i+1]);	
		A0 = x/A0;		
	}
	multipleLCM(A, i+1, less, A0, ans);
}

int main()
{
	int N, A[MAX];
	lli ans, sum=0;
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		scanf("%d", &A[i]);
	}
	A[N] = NIL;
	for(int i=0; i<N; i++){
		sum += (A[i]-1);
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 128
import Control.Applicative ((<$>))
import Control.Monad (replicateM)

main :: IO ()
main = do
  [h, w] <- map read . words <$> getLine
  ass <- replicateM h (map read . words <$> getLine)
  print $ solve h w ass
  
solve :: Int -> Int -> [[Int]] -> Int
solve h w ass = minimum [ sum [ (dist i j k l) * (ass !! (k - 1)) !! (l - 1) | k <- [1 .. h], l <- [1 .. w] ] | i <- [1 .. h], j <- [1 .. w] ]
  where
    dist i j k l = (abs (i - k)) `min` (abs (j - l)) 


Measured memory_bytes: 4552
#include<bits/stdc++.h>
using namespace std;
int main(){
  
   int K;
   string S;
    cin>>K>>S;

    if(S.size()>K){
       int x=S.size()-K;
       S.erase(K,S.size()-1);
       
         S.append("...");
       
       cout<<S;
    }
    else
      cout<<S;
      


   return 0;
}

Measured memory_bytes: 3596
import sys
sys.setrecursionlimit(4100000)

n = int(input())
a = [[int(i) for i in input().split()] for i in range(n)]
a.sort(key = lambda x:x[1])
timer = 0
goodbad = 0
for i in range(n):
    timer += a[i][0]
    if timer > a[i][1]:
        goodbad = 1
if goodbad == 1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 41176
import sys

M, K = map(int, input().split())
if K >= pow(2, M) or (M==1 and K==1):
    print(-1)
    sys.exit()
ans = []
if K == 0:
    for i in range(pow(2, M)):
        ans.append(i)
        ans.append(i)
else:
    for i in range(pow(2, M)):
        if i != K:
            ans.append(i)
    ans.append(K)
    for i in range(pow(2, M)-1, -1, -1):
        if i != K:
            ans.append(i)
    ans.append(K)
print(' '.join(map(str, ans)))


Measured memory_bytes: 97564
#include <queue>
#include <string>
#include <utility>
#include <iostream>
using namespace std;

int main(void) {
	// read number of processer and quantum
	int n,q;
	cin >> n >> q;
	// read name and time of each process
	pair<string,int> pro;
	queue< pair<string,int> > pros;
	for (int i = 0;i < n;++i) {
		cin >> pro.first >> pro.second;
		pros.push(pro);
	}
	// calculate and output name and using time of each process
	int sum_time = 0;
	while (!pros.empty()) {
		auto curr_pro = pros.front();
		if (curr_pro.second > q) {
			curr_pro.second -= q;
			pros.push(curr_pro);
			sum_time += q;
		} else {
			sum_time += curr_pro.second;
			cout << curr_pro.first << " " << sum_time << endl;
		}
		pros.pop();
	}
	return 0;
}

Measured memory_bytes: 6184
import sys
import numpy as np
i4 = np.int32
i8 = np.int64
u4 = np.uint32

if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    from numba import njit
    from numba.types import Array, int32, int64, uint32
    cc = CC('my_module')

    @njit
    def get_factorization(n):
        """
        nまでの割り切れる最小の素数を返す。
        """
        sieve_size = (n - 1) // 2
        sieve = np.zeros(sieve_size, u4)
        for i in range(sieve_size):
            if sieve[i] == 0:
                value_at_i = i*2 + 3
                for j in range(i, sieve_size, value_at_i):
                    if sieve[j] == 0:
                        sieve[j] = value_at_i
        return sieve


    @cc.export('solve', (Array(uint32, 1, 'C'),))
    @njit('(u4[::-1],)', cache=True)
    def solve(A):
        a = np.sort(A)
        p_max = a[-1]
        p = get_factorization(p_max)
        primes_num = 1
        for i in range(p.shape[0]):
            if i*2 + 3 == p[i]:
                primes_num += 1
        a_start = 0
        while a[a_start] == 1:
            a_start += 1
            if a_start == a.shape[0]:
                return 0
        a = a[a_start:]
        if len(a) > primes_num:
            return 1
        check = np.zeros(p_max + 1, u4)
        for d in a:
            if d & 1 == 0:
                check[2] += 1
                d //= 2
                while d & 1 == 0:
                    d //= 2
            prev = 2
            while d > 1:
                i = (d - 3) // 2
                f = p[i]
                if f > prev:
                    check[f] += 1
                    prev = f
                d //= f

        if check.max() > 1:
            return 1
        else:
            return 0

    cc.compile()
    exit(0)

else:
    from my_module import solve


def main(in_file):
    stdin = open(in_file)
    stdin.readline()
    A = np.fromstring(stdin.readline(), u4, sep=' ')
    ans = solve(A)
    if ans:
        g = np.gcd.reduce(A)
        if g > 1:
            ans = 2
        else:
            ans = 1
    p = ['pairwise coprime', 'setwise coprime', 'not coprime']
    print(p[ans])


main(0)


Measured memory_bytes: 42584
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}

#define ALL(a)  (a).begin(),(a).end()



int main() {

	ll N, M, K;
	cin >> N >> M >> K;
	vector<ll> A(N);
	vector<ll> AS(N + 1);
	vector<ll> B(M);
	vector<ll> BS(M+1);
	ll S = 0;
	AS.at(0) = 0; BS.at(0) = 0;
	rep(i, N) {
		cin >> A.at(i);
		AS.at(i + 1) = AS.at(i) + A.at(i);
	}
	rep(i, M) {
		cin >> B.at(i);
		BS.at(i + 1) = BS.at(i) + B.at(i);
	}
	ll an =0;
	rep(i, N+1) {
		if (AS.at(i) > K) {

		}
		else {
			ll z = K - AS.at(i);
			auto Iter1 = lower_bound(ALL(BS), z+1);
			
			an = max(an, i+ll(Iter1 - BS.begin())-1);
		}

	}
	
	cout << an << endl;
}


Measured memory_bytes: 9584
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long int

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    int N; cin>>N;
    cout << (N/10==9 || N%10==9 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
x1,y1,x2,y2 = map(float, raw_input().split())

q = int(raw_input())
for _ in xrange(q):
  x,y = map(float, raw_input().split())
  if x1 == x2:
    print "%f %f" % (x1, y)
  elif y1 == y2:
    print "%f %f" % (x, y1)
  else:
    a0 = (y2 - y1) / (x2 - x1)
    b0 = y1 - a0 * x1
    ap = -1 / a0
    bp = y - ap * x
    xe = (bp - b0) / (a0 - ap)
    ye = a0 * xe + b0

    print "%.12f %.12f" % (xe, ye)

Measured memory_bytes: 6480
N = int(input())
s_list = []
for i in range(N):
  s_list.append(input())
M = int(input())
t_list = []
for i in range(M):
  t_list.append(input())
dict_index = set(s_list + t_list)
s_count = [s_list.count(i) for i in dict_index]
t_count = [t_list.count(i) for i in dict_index]
dict_count = [i - n for i, n in zip(s_count, t_count)]
if max(dict_count) < 0:
  print(0)
else:
  print(max(dict_count))

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

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

    ll a[n];
    ll ma = 0;
    ll mi = 10000000000;
    rep(i, n){
        cin >> a[i];
        ma = max(a[i], ma);
        mi = min(a[i], mi);
    }


    cout << ma - mi << endl;
    return 0;
}


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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define nl "\n"
#define fat 1000000007

int main()
{
    boost
    int h, w, n;
    cin >> h >> w >> n;

    int mx = max(h, w);
    cout << ceil(1.0*n / mx) << nl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from itertools import product

def judge(co,m,k,s,p):
    flag = True
    for i in range(m):
        _s = s[i]
        _p = p[i]
        _k = k[i]
        amount = sum([co[_s[j]-1] for j in range(_k)])
        if amount % 2 != _p:
            flag = False
    return flag 



def solve(n,m,k,s,p):
    b = product((0,1),repeat=n)
    c = 0
    for co in b:
        if judge(co,m,k,s,p):
            c += 1
    return c



def main():
    N,M = map(int,input().split())
    k = []
    s = []
    for _ in range(M):
        tmp = list(map(int,input().split()))
        k.append(tmp[0])
        s.append(tmp[1:])
    p = list(map(int,input().split()))
    print(solve(N,M,k,s,p))
    return

if __name__ == '__main__':
    main()


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

template<long long M>
class modint {
    public:
        long long a;
        modint(const long long x = 0LL) : a((x % M + M) % M) {}
        long long &value() { return a; }
        modint operator+(const modint rhs) const {
            return modint(*this) += rhs;
        }
        modint operator-(const modint rhs) const {
            return modint(*this) -= rhs;
        }
        modint operator*(const modint rhs) const {
            return modint(*this) *= rhs;
        }
        modint operator/(const modint rhs) const {
            return modint(*this) /= rhs;
        }
        modint &operator+=(const modint rhs) {
            a += rhs.a;
            if (a >= M) {
                a -= M;
            }
            return *this;
        }
        modint &operator-=(const modint rhs) {
            if (a < rhs.a) {
                a += M;
            }
            a -= rhs.a;
            return *this;
        }
        modint &operator*=(const modint rhs) {
            a = a * rhs.a % M;
            return *this;
        }
        modint pow(long long n) const {
            modint ret(1);
            modint x = *this;
            while (n) {
                if ((n & 1) == 1) {
                    ret *= x;
                }
                n >>= 1;
                x *= x;
            }
            return ret;
        }
        modint inv() const {
            return pow(M - 2);
        }
        modint &operator/=(const modint rhs) {
            return *this *= rhs.inv();
        }
};

const long long M = 1000000007;

using mint = modint<M>;


using namespace std;

class Combination {
    std::vector<mint> fact, ifact;
    public:
        Combination(long long n) : fact(n + 1), ifact(n + 1) {
            fact[0] = 1;
            for (long long i = 1; i <= n; i++)
                fact[i] = fact[i - 1] * i;
            ifact[n] = fact[n].inv();
            for (long long i = n ;i >= 1; i--)
                ifact[i - 1] = ifact[i] * i;
        }
        mint comb(long long n, long long k) {
            if (k < 0 || k > n)
                return 0;
            return fact[n] * ifact[k] * ifact[n - k];
        }
        mint perm(long long n, long long k) {
            return fact[n] * ifact[n - k];
        }
} c(1000005);




using ll = long long;


int main(void) {
    ll N, M;

    cin >> N >> M;

    mint comp = 0;
    for (ll k = 1; k <= N; k++) {
        if ((k - 1) % 2 == 0) {
            comp += c.comb(N, k) * c.perm(M - k, N - k);
        } else {
            comp -= c.comb(N, k) * c.perm(M - k, N - k);
        }
    }
    comp *= c.perm(M, N);
    mint ans = c.perm(M, N) * c.perm(M, N);
    ans -= comp;
    cout << ans.a << endl;
}


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

int main() {
  
  long long n,m,k,x;
  cin >> n >> k;
  
  m = n;
  
  x = m % k;
  
  if ( x == 0 ){
    cout << 0 << endl;
  }else{
    while( x >= abs(x-k) ){
      x = abs(x-k);
    }
    cout << x << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int x; cin >> x;
	int ans = (x == 0) ? 1 : 0;
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3620
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

const int MOD=1e9+7;

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  
  int d,e,f;
  d=abs(a-b);
  e=abs(b-c);
  f=abs(c-a);
  
  cout<<min({d+e,e+f,f+d});
  
  return 0;
}

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

ll mod=1e9+7;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

int main() {
  string l;
  cin >> l;
  vector<vector<ll>> dp(l.size(),vector<ll>(2));
  dp[0][0]=1;
  dp[0][1]=2;
  for(ll i=1;i<l.size();i++) {
    if(l[i]=='1') {
      dp[i][1]=dp[i-1][1]*2%mod;
      dp[i][0]=dp[i-1][1];
    }
    else {
      dp[i][1]=dp[i-1][1];
    }
    dp[i][0]=(dp[i][0]+dp[i-1][0]*3)%mod;
  }
  ll ans=(dp[l.size()-1][0]+dp[l.size()-1][1])%mod;
  cout << ans << endl;
}

Measured memory_bytes: 5760
N, M = map(int, input().split())
ans = 0
if N >= 3:
    if M >= 3:
        ans = (N-2)*(M-2)
    else:
      if M == 2:
        ans=0
      else:
        ans=N-2
else:
    if N == 2:
      ans=0
    else:
      if M == 2:
        ans=0
      elif M == 1:
        ans=1
      else:
        ans=M-2
print(ans)

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

using namespace std;

int main() {
  int s, cnt = 1, m = 0;
  map<int, int> list;
  
  cin >> s;
  
  int a = s;
  
  while (true) {
    if (list.find(a) != list.end()) {
      break;
    } else {
      list[a] = 1;
    }
    
    if (a % 2 == 0) {
      a = a / 2;
    } else {
      a = 3 * a + 1;
    }
    
    cnt++;
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;
void swap(int &a, int &b);

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

	int *a = new int[number];

	int min = 100000000000, max = -10000000000;
	long int sum = 0;
	for (int i = 0; i < number; ++i)
	{
		cin >> a[i];
	}
	for (int i = 0; i < number; ++i)
	{
		if (min > a[i])
			min = a[i];
		if (max < a[i])
			max = a[i];
		sum += a[i];
	}
	cout << min << " " << max << " " << sum << endl;

	delete a;
	return 0;
}




Measured memory_bytes: 3112
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

bool isPrime(ll n) {
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }

  return true;
}

int dfs(ll a, ll b, ll c, ll x, ll y, ll z) {
  // 終了条件
  if (a == x && b == y && c == z) return 1;

  ll ans = 0;

  if (x < a) {
    ans += dfs(a, b, c, x + 1, y, z);
  }

  if (x > y && y < b) {
    ans += dfs(a, b, c, x, y + 1, z);
  }

  if (y > z && z < c) {
    ans += dfs(a, b, c, x, y, z + 1);
  }

  return ans;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll K;
  cin >> K;
  vector<ll> lunlun;
  for (ll i = 1; i <= 9; i++) {
    lunlun.push_back(i);
  }

  ll k = K;
  while (1) {
    // for (auto l : lunlun) {
    //   cout << l << " ";
    // }
    // cout << endl;

    if (k <= (ll)lunlun.size()) {
      cout << lunlun[k - 1] << endl;
      return 0;
    }
    k -= lunlun.size();

    vector<ll> old;
    swap(lunlun, old);

    for (ll x : old) {
      for (ll i = -1; i <= 1; i++) {
        ll d = x % 10 + i;
        if (d < 0 || d > 9) {
          continue;
        }
        lunlun.push_back(x * 10 + d);
      }
    }
  }

  return 0;
}


Measured memory_bytes: 1712
#include <iostream>

using namespace std;

bool num[1001010];

int main() {
    int s;
    cin >> s;
    num[s] = true;
    for (int i = 1; ; ++i) {
        if (s % 2 == 0) {
            s /= 2;
        }
        else {
            s = 3 * s + 1;
        }
        if (num[s] == true) {
            cout << i + 1 << endl;
            break;
        }
        else {
            num[s] = true;
        }
    }
}

Measured memory_bytes: 256
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC132
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__




void solve(void){
  
  string S;
    
  cin >> S;
  
  char a, b;
  int a1=1;
  int b1=0;
  
  a=b=S[0];
  
  REP2(i,1,S.size()){
    if(S[i]==a){a1++;}
    else if(b1==0){b=S[i]; b1++;}
    else if(S[i]==b){b1++;}
  }
  
  if(a1==2 && b1==2){cout << "Yes" << endl;}else {cout << "No" << endl;}

  return;
}

#define TESTCASES 1

int main(int argc, const char * argv[]) {


    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			final int LEN = 6;
			String in = sc.next();
			int count = 0;
			for (int i = 0; i < LEN; i++) {
				if ("1".equals(in.substring(i, i + 1))) {
					count++;
				}
			}
			// 出力
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
int N, K;
int memo[1111][1111];

int solve(int n, int k){
    if(k != -1 && memo[n][k] != -1){
        return memo[n][k];
    }
    if(n == N){
        return 1;
    }
    int res = 0;
    for(int i = 0; i < K; i++){
        if(i == k) continue;
        res += solve(n+1, i);
    }
    memo[n][k] = res;
    return res;
}

int main(void){
    cin >> N >> K;
    for(int i = 0; i  < 1111; i++) for(int j = 0; j < 1111; j++) memo[i][j] = -1;

    int ans = 0;
    cout << solve(0, -1) << endl;
}


Measured memory_bytes: 5120
#要素の数入力
n = gets.to_i
#数値の入力
a = gets.chomp.split(" ").map(&:to_i)
#各要素２で割れる回数を計算
result = []
a.map do |i|
  count = 0
  while i % 2 == 0 do
    i = i / 2
    count += 1
  end
  result.push(count)
end
#出力
puts result.min

Measured memory_bytes: 1788
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) ((x)&1)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define rep_it(it,x) for (__typeof((x).begin()) it=(x).begin(); it!=(x).end(); it++)
#define ____ puts("\n_______________\n\n") 
#define debug(x) ____; cout<< #x << " => " << (x) << endl
#define debug_pair(x) cout<<"\n{ "<<(x).fir<<" , "<<(x).sec<<" }\n"
#define debug_arr(x,n) ____; cout<<#x<<":\n"; rep(i,0,n) cout<<#x<<"["<<(i)<<"] => "<<x[i]<<endl
#define debug_set(x) ____; cout<<#x<<": \n"; rep_it(it,x) cout<<(*it)<<" "; cout<<endl
#define debug_map(x) ____; cout<<#x<<": \n"; rep_it(it,x) debug_pair(*it)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const double PI=acos(-1);
const double eps=1e-9;
int o(int x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

int n,m,b[305][305],r[305],x,t,pos,ans=oo,p[305];
bool check[305];

int main() {
    //file_put(); 
    
    scanf("%d%d",&n,&m);
	rep(i,1,n) rep(j,1,m) scanf("%d",&b[i][j]);
	rep(i,1,n) r[i]=1;
	x=m;
	while (x--) {
		t=0,pos=0;
		memset(p,0,sizeof(p));
		rep(i,1,n) p[b[i][r[i]]]++;
		rep(i,1,m) 
			if (p[i]>t){
				t=p[i];
				pos=i;
			}
		if (t) ans=min(ans,t);
		check[pos]=true;
		rep(i,1,n) while (check[b[i][r[i]]]) r[i]++;
	}
	printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 640
from collections import defaultdict

n, m = map(int, input().split())
d = defaultdict(int)
for _ in range(n):
  a_, b_ = map(int, input().split())
  d[a_] += b_

res = 0
for k in sorted(d):
  if d[k] <= m:
    res += d[k]*k
    m -= d[k]
  elif m > 0:
    res += m*k
    m = 0
  else:
    break
print(res)

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

using namespace std;
typedef long long LL;


int main(){
    LL n, a, b;
    cin>>n>>a>>b;

    LL t=n/(a+b);

    LL ans=0;
    ans+=t*a;
    ans+=min(a,n-t*(a+b));

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())

dic = {}

for index in range(N):
    temp = "".join(sorted(list(input())))
    if temp in dic:
        dic[temp] = dic[temp] + 1
    else:
        dic[temp] = 1
ans = 0
for k in dic.values():
    cnt = 0
    for i in range(k):
        cnt += i
    ans += cnt

print(ans)

Measured memory_bytes: 17804
#include <iostream>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

using ll = long long;

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

	ll n; cin >> n;
	ll ans = n + 1;
	for (ll i = 1; i * i <= n; ++i)
		if (n % i == 0)
			ans = min(ans, i + n / i - 2);
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#define MOD 998244353
#define forn(a, n) for(int a = 0; a<(int) (n); ++a)
#define dforn(a, n) for(int a = (n)-1; a>=0; --a)
#define forall(a, all) for(__typeof(all.begin()) a = all.begin(); a != all.end(); ++a)
#define EPS 0.000000000001
using namespace std;
typedef long long tint;
typedef pair<tint, tint> pii;
typedef vector<tint> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;

int gcd(int a, int b) {
	return b ? gcd(b, a%b) : a;
}

void dfs(int voy, int ceros, int unos, string s, vvvi &reach) {
	//cout << voy << " " << ceros << " " << unos << endl;
	if(reach[voy][ceros][unos]) {
		return;
	}
	reach[voy][ceros][unos] = 1;
	
	int n = s.size();
	if(n - voy >= 2) {
		if(s[voy] == '0' || s[voy+1] == '0') {
			dfs(voy+2, ceros+1, unos, s, reach);
		}
		if(s[voy] == '1' || s[voy+1] == '1') {
			dfs(voy+2, ceros, unos+1, s, reach);
		}
	}
	
	if(n - voy >= 1) {
		if(ceros) dfs(voy, ceros-1, unos, s, reach);
		if(unos) dfs(voy, ceros, unos-1, s, reach);
		if(ceros && s[voy] == '1') dfs(voy+1, ceros-1, unos+1, s, reach);
		if(unos && s[voy] == '0') dfs(voy+1, ceros+1, unos-1, s, reach);
		if(ceros || unos || n-voy >= 2) dfs(voy+1, ceros, unos, s, reach);
	}
	
	if(ceros+unos >=2) {
		if(ceros) dfs(voy, ceros-1, unos, s, reach);
		if(unos) dfs(voy, ceros, unos-1, s, reach);
	}
}

tint solvedp(int voy, int ceros, int unos, string s, vvvi &dp) {
	int n = s.size();
	if(voy == n+1) {
		return ceros == 0 && unos == 0;
	}
	
	if(dp[voy][ceros][unos] != -1) {
		return dp[voy][ceros][unos];
	}
	
	tint ans = 0;
	if(s[voy-1] == '1' && ceros) {
		ans += solvedp(voy, ceros-1, unos, s, dp);
	}
	if(s[voy-1] == '0' && unos) {
		ans += solvedp(voy, ceros, unos-1, s, dp);
	}
	ans += solvedp(voy+1, ceros, unos, s, dp);
	ans %= MOD;
	dp[voy][ceros][unos] = ans;
	return ans;
}

int main()
{
	string s;
	cin >> s;
	tint n = s.size();
	
	vvvi reach(n+1, vvi(n, vi(n, 0)));
	vvvi dp(n+1, vvi(n, vi(n, -1)));
	dfs(0, 0, 0, s, reach);
	
	tint ans = 0;
	forn(i, n+1) forn(j, n) forn(k, n) {
		if(reach[i][j][k]) {
			//cout << i << " " << j << " " << k << " " << solvedp(i, j, k, s, dp) << " " << endl;
			ans += solvedp(i, j, k, s, dp);
			ans %= MOD;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 434216
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <numeric>
#include <limits>
#include <utility>
using namespace std;
typedef long long longlong;
typedef long long LL;

int main(void) {
	int i, j = 0, n, ans, l = 0, r = 0, s = 0;
	string a, b, c;
	cin >> n;
	cin >> a;
	for (i = 0; i < n; i++) {
		if (a[i] == '(') {
			for (j = max(i,j+1); j < n; j++) {
				if (a[j] == ')') {
					s++;
					break;
				}
			}
		}
		if (a[i] == '(')l++;
		if (a[i] == ')')r++;
	}
	r -= s; l -= s;
	for (i = 0; i < r; i++)b += '(';
	for (i = 0; i < l; i++)c += ')';
	b += a;
	b += c;
	cout << b << endl;
	/*
	LL n, i, j, k, mi = 0, ma = 0;
	vector<int> c(8);
	cin >> n;
	vector<LL> a(n);
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (i = 0; i < n; i++) {
		if (a[i] >= 1 && a[i] <= 399 && c[0] < 1)c[0]++;
		if (a[i] >= 400 && a[i] <=799  && c[1] < 1)c[1]++;
		if (a[i] >= 800 && a[i] <= 1199 && c[2] < 1)c[2]++;
		if (a[i] >= 1200 && a[i] <= 1599 && c[3] < 1)c[3]++;
		if (a[i] >= 1600 && a[i] <= 1999 && c[4] < 1)c[4]++;
		if (a[i] >= 2000 && a[i] <= 2399 && c[5] < 1)c[5]++;
		if (a[i] >= 2400 && a[i] <= 2799 && c[6] < 1)c[6]++;
		if (a[i] >= 2800 && a[i] <= 3199 && c[7] < 1)c[7]++;
		if (a[i] >= 3200)ma++;
	}
	for (i = 0; i < 8; i++)mi += c[i];
	if (mi == 0 && ma > 0) {
		cout << 1 << " " << ma << endl;
	}
	else {
		cout << mi << " " << ma + mi << endl;
	}*/

	return 0;
}

Measured memory_bytes: 256