akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int LLu;

using namespace std;

const int N =  300000+5;
const int MOD = 998244353;
const int INF = 1e9+7;

inline int read() {
    int x = 0,f=1;char ch = getchar();
    for(; ch<'0'||'9'<ch; ch=getchar()) if(ch == '-') f=-1;
    for(; '0'<=ch&&ch<='9'; ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
    return x*f;
}

#define lal puts("****");
#define pb push_back
#define mp make_pair

/********************************************************/
int n,m;
char s[111];
int main(){
    scanf("%s",s);
    int l = strlen(s);
    printf("%c%d%c",s[0],l-2,s[l-1]);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int k;

void dfs(string num, int last, int len, int lm){
	if(len == lm){
		k--;
		if(!k){
			cout << num << endl;
			exit(0);
		}
		cerr << num << endl;
		return;
	}
	for(int i=last-1; i<last+2; i++){
		if(i >=0 && i<10){
			dfs(num + (char)(i+'0'), i, len+1, lm);
		}
	}
}

int main(void){
	cin >> k;
	int lm = 1;
	while(k>0){
		for(int i=1; i<10; i++){
        	dfs({(i+'0')},i, 1, lm);
        }
		lm++;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int a[10000000];

int ok(int id,int n1,int n2){
	int i;
	int sum = 0, ret = 1;

	for(i = 0 ; i < n1 ; i++){
		if(a[i] > id) return 0;
		sum += a[i];
		if(sum > id){
			sum = a[i];
			ret++;
		}
	}
	return ret <= n2;
}

int main(){
	int i;
	int n1, n2, m;
	int l=0,h=1LL<<30;

	scanf("%d%d",&n1,&n2);
	for(i = 0 ; i < n1 ; i++)scanf("%d", a + i);

	for(i = 0 ; l + 1 < h ;){
		m = (l + h) / 2;
		if(ok(m, n1, n2)){
			h = m;
		}else{
			l = m;
		}
	}
	printf("%d\n",l + 1);
	return 0;
}



Measured memory_bytes: 2144
#include <iostream>
using namespace std;
int main(void){
    int table[200][200] = {{0}};
    int c, r; // column, row
    cin >> r >> c;
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> table[i][j];
        }
    }
    //計算します
    for(int i = 0; i < r+1; i++){
        int sum = 0;
        for(int j = 0; j < c;j++){
            sum += table[i][j];
      }
      table[i][c] = sum;
   }
    //縦計算
    for(int j =0; j < c+1; j++){
        int sum = 0;
        for(int i = 0; i < r; i++){
            sum += table[i][j];
        }
        table[r][j] = sum;
   }    
    
      
      
    //先に出力を作る
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c; j++){
            cout << table[i][j] << " " ;
        }
        cout << table[i][c] << endl;
    }
}



Measured memory_bytes: 3244
#include <cstdio>
#include <algorithm>

int n,k,b[200001],cnt[200010];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",b+i);
	for(int i=1;i<=k;i++){
		for(int j=1;j<=n;j++)cnt[j]=0;
		for(int j=1;j<=n;j++){
			int l=std::max(j-b[j],1),r=std::min(j+b[j],n);
			++cnt[l],--cnt[r+1];
		}
		for(int j=1;j<=n;j++)cnt[j]+=cnt[j-1],b[j]=cnt[j];
		bool cando=0;
		for(int j=1;j<=n;j++)if(b[j]!=n)cando=1;
		if(!cando)break;
	}
	for(int i=1;i<=n;i++)printf("%d ",b[i]);
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int num = 0;
    for (int i = 0; i < 10; ++i) {
       for (int j = 0; j < 10; ++j) {
            for (int k = 0; k < 10; ++k) {
                size_t si = s.find(to_string(i));
                if(si == string::npos){
                    continue;
                }
                size_t sj = s.find(to_string(j), si+1);
                if(sj == string::npos){
                    continue;
                }
                size_t sk = s.find(to_string(k), sj+1);
                if(sk == string::npos){
                    continue;
                }
                else{
                    num++;
                }
            }
        }
    }
    cout << num << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,M;
int a[500005]; 
bool check1(int Now)
{
	int L=1,R=Now;
	while (a[L]+a[R]<M&&L<R)
	  L++,R--;
	if (a[L]+a[R]>=M) return false;
	return true;
}
bool check2(int Now)
{   
    int L=Now+1,R=N;
	while (a[L]+a[R]>=M&&L<R)
	  L++,R--;
	if (a[L]+a[R]<M)
	 return false;
     return true;
}
int main()
{
	scanf("%d%d",&N,&M);
	N*=2;
	for (int i=1;i<=N;i++)
	  scanf("%d",&a[i]);
	sort(a+1,a+N+1);
	int l=0,r=N,ans;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (check2(mid)&&check1(mid))
		  r=mid-1,ans=mid;
		else 
		if (!check1(mid))
		  r=mid-1;
		else
		l=mid+1;
	}
	if (ans%2) ans++;
	 int L=ans+1,R=N,anss=0;
	while (L<=R)
	  anss=max((a[L]+a[R])%M,anss),L++,R--;
	L=1,R=ans;
	while (L<=R)
	  anss=max((a[L]+a[R])%M,anss),L++,R--;
	printf("%d",anss);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n; cin>>n;
    list<ll> lst;
    string s;
    rep(i,n){
        cin>>s;
        if(s=="insert") {ll t; cin>>t; lst.push_front(t);}
        else if(s=="delete"){
            ll t; cin>>t;
            for(auto itr=lst.begin(); itr!=lst.end(); itr++){
                if(*itr==t){lst.erase(itr); break;}
            }
            //auto itr=find(lst.begin(),lst.end(),t);
            //if(itr!=lst.end()) lst.erase(itr);
        }
        else if(s=="deleteFirst") lst.pop_front();
        else if(s=="deleteLast") lst.pop_back();
    }
    for(auto itr=lst.begin(); itr!=lst.end(); itr++){
        if(itr!=lst.begin()) cout<<' ';
        cout<<*itr;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 34308
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

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

	string S;
	cin >> S;
	int n = S.length();
	int K;
	cin >> K;

	int l = 0, r = 1;
	vector<string> T(6);
	REP(i, 6) T[i] = 'z' + 1;

	while(l < n){
		if(n < r){
			l++; r = l + 1;
			continue;
		}
		string s = S.substr(l, r - l);
		// cerr << s << endl;
		if(s < T[5]){
			T[5] = s;
			sort(ALL(T));
			T.erase(unique(ALL(T)), T.end());
			r++;
			while(T.size() < 6) T.push_back("{");
		}
		else{
			l++; r = l + 1;
		}
	}

	// cerr << endl;
	// REP(i, K) cerr << T[i] << endl;

	cout << T[K - 1] << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I=int(A);I<int(B);I++)
#define SORT(x) (sort(x.begin(),x.end()))
#define REV(x) (reverse(x.begin(),x.end()))

ll ans=1000000;
ll res(ll n){
  ans = n-1;
  FOR(i,1,sqrt(n)+1){
    if(n%i==0){
      ll x = n/i;
      ans = min(ans,x-1+i-1);
    }
  }
}

int main(){
  ll n;
  cin >> n;
  res(n);
  cout << ans << endl;
}


Measured memory_bytes: 256
s = gets.chomp.to_i

@log = []

@log << s

def hoge(n)
  if n % 2 == 0
    n = n / 2
  else
    n = (3 * n) + 1
  end
  return @log.size + 1 if @log.include?(n)
  @log << n
  hoge(n)
end


puts hoge(s)

Measured memory_bytes: 1788
import sys
sys.setrecursionlimit(10**6)


def dfs(v, cur):
    color[v] = cur
    
    for next_v in Graph[v]:
        if color[next_v[0]] != -1:
            continue
        elif next_v[1] % 2 == 0:
            dfs(next_v[0], cur)
        else:
            dfs(next_v[0], 1-cur)


N = int(input())
uvw = [[int(_) for _ in input().split()] for _ in range(N-1)]
color = [-1]*N
Graph = [[] for _ in range(N)]

for i in uvw:
    Graph[i[0]-1].append([i[1]-1, i[2]])
    Graph[i[1]-1].append([i[0]-1, i[2]])

dfs(0, 0)

for i in color:
    print(i)

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

using namespace std;

int main() {
  string S;
  cin >> S;
  for (int i = 0; i < (int) S.size() - 1; i++) {
    if (S[i] == 'A' && S[i + 1] == 'C') {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
/*input
5
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

vector<int> v;

int main()
{
	IOS;
	int l;
	cin>>l;
	while(l){
		v.pb(l%2);
		l>>=1;
	}
	int cnt=-1;
	REP(i,SZ(v)) if(v[i]==1) cnt++;
	cout<<SZ(v)<<' '<<2*SZ(v)-2+cnt<<'\n';
	reverse(ALL(v));
	int cur=1;
	for(int i=1;i<SZ(v);i++){
		cout<<i<<' '<<i+1<<' '<<0<<'\n';
		cout<<i<<' '<<i+1<<' '<<cur<<'\n';
		cur<<=1;
		if(v[i]==1){
			cout<<1<<' '<<i+1<<' '<<cur<<'\n';
			cur++;
		}
	}
	return 0;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int N,M;
	cin>>N>>M;
	int n1,n2,n3;
	int a,b,c;
	a=10000;b=5000;c=1000;
	int s1=-1,s2=-1,s3=-1;
	if(N*a<M||c*N>M)
	{
		s1=s2=s3=-1;
	}
	else
	{
		
		n1 = M/a;
		for(int i=n1;i>=0;i--)
		{
			int flag=0;
			n2 = (M-i*a)/b;
			for(int j=n2;j>=0;j--)
			{
				n3=(M-i*a-j*b)/c;
				if(i+j+n3==N&&i*a+j*b+n3*c==M)
				{
					s1=i;
					s2=j;
					s3=n3;
					flag=1;
					break;
				}
			}
			if(flag==1) break;
		}
	}
	cout<<s1<<" "<<s2<<" "<<s3<<endl;
	return 0;
}

Measured memory_bytes: 256
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;
void solve(){
	string s;
	cin >> s;
	int a = 0, b = 0;
	for(char c : s){
		if(c == 'A')
			a++;
		else
		 b++;
	}
	if(b == 3 || a == 3)
		cout << "No";
	else
		cout << "Yes";
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> t;
		while(t--){
			solve();
		}
	return 0;
}


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

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
int ans = 0;
int N;
vector<int> v;

void dfs(int n){
    if(n > N) return;
    v.push_back(n);

    if(n >= pow(10, 8)) return;
    dfs(n*10 + 3);
    dfs(n*10 + 5);
    dfs(n*10 + 7);
    return;
}

int main(){
    cin >> N;

    dfs(0);

    int ans = 0;
    for(int i=0; i<v.size(); i++){
        if(v[i] == 0) continue;
        int t = v[i];

        set<int> s;
        while(t != 0){
            int d = t - (t/10)*10;
            s.insert(d);
            t /= 10;
        }
        if(s.size() == 3) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2")
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<set>
#include<unordered_map>
#include<assert.h>
#include<time.h>
#include<stdlib.h>
#include<random>
#include<queue>
using namespace std;
using lld = long long int;
using pll = pair<lld, lld>;
using lf = double;
using pff = pair<lf, lf>;
using pii = pair<int, int>;
using pli = pair<lld, int>;
using pil = pair<int, lld>;
#define M 1000000007
char a[2000009];
int main() {
	int i, j, k, l;
	int t = 1, tv = 0;
	//scanf("%d", &t);
	while (t--) {
		lld b;
		b = 0;
		scanf("%s", a);
		for (i = 0; a[i]; i++) {
			b = (b + a[i] - '0') % 9;
		}
		printf("%s\n", b ? "No" : "Yes");
	}
	return 0;
}

Measured memory_bytes: 1796
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    const numbers = arg.slice(1, N+1);
    
    const map = [];
    
    for(let i in numbers) {
        let temp = numbers[i].split(" ").map(n=>parseInt(n));
        
        let number = temp[0];
        let amount = temp[1];
        
        map.push({number: number, amount: amount})
    }
    
    map.sort((a,b)=>a.number - b.number);
    
    let sum = 0;
    let i   = 0;
    
    while(sum < K) {
        sum += map[i].amount;
        i++;
    }
    
    console.log(map[i - 1].number);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 53544
N,X=map(int,input().split())
x=list(map(int,input().split()))
x.append(X) #len(x)=N+1
x.sort()

def gcd(a,b):
    if b%a==0:
        return a
    else:
        return gcd(b%a,a)

init=x[0]
x=[i-init for i in x]
d=x[1]
for i in range(N-1):   # 0 2 4 6 10 14   N=5
    if d==0:
        d=x[i+2]
    else:
        d=gcd(d,x[i+2])
print(d)

Measured memory_bytes: 14252
h, w, n = map(int, input().split())
sh, sw = map(int, input().split())
S = list(input())
T = list(input())

for [s, t, d, l] in [["L", "R", sw, w], ["R", "L", w-sw+1, w], ["U", "D", sh, h], ["D", "U", h-sh+1, h]]:
#  print(s, t, d)
  x = d
  for i in range(n):
#    print(x)
    if S[i] == s:
      x -= 1
    if x == 0:
      print("NO")
      exit()
    if T[i] == t and x < l:
      x += 1
    

print("YES")

Measured memory_bytes: 8024
#include <iostream>
#include <unordered_set>

int main()
{
	int A, B, C;
	std::cin >> A >> B >> C; std::cin.ignore();

	std::unordered_set<int> hash;
	hash.emplace(A);
	hash.emplace(B);
	hash.emplace(C);

	bool boolValue = hash.size() == 2;
	std::string output = boolValue ? "Yes" : "No";
	std::cout << output << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <queue>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    ll N, M;
    cin >> N >> M;
    
    priority_queue<ll> v;
    for(int i = 0; i < N; i++){
        ll a;
        cin >> a;
        v.push(a);
    }

    for(int i = 0; i < M; i++){
        ll tmp = v.top();
        v.pop();
        tmp = tmp / 2;
        v.push(tmp);
    }

    ll ans = 0;
    for(int i = 0; i < N; i++){
        ll tmp = v.top();
        v.pop();
        ans += tmp;
    }
    cout << ans << endl;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 110;
int vis[maxn];
void run_case()
{
    int x, n;
    cin >> x >> n;
    for (int i = 1; i <= n; i++)
    {
        int cur;
        cin >> cur;
        vis[cur] = 1;
    }
    for (int d = 0;; d++)
    {
        if (!vis[x - d])
        {
            cout << x - d << "\n";
            return;
        }
        if (!vis[x + d])
        {
            cout << x + d << "\n";
            return;
        }
    }
    //cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

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

int main(){
int N;
cin >> N;
int A[N];
int i,v,j,k;
for(i=0;i<N;i++)cin>>A[i];
for(i=0;i<N-1;i++)cout << A[i] << " ";
cout << A[N-1];
cout << endl;
for(i=1;i<N;i++)
{

  v=A[i];
  j=i-1;
  while((j>=0)&&(A[j]>v))
  {
  A[j+1] = A[j];
   j--;
  }
  A[j+1] = v;
  for(k=0;k<N-1;k++)cout << A[k] << " ";
  cout << A[N-1];
  cout << endl;

}



}


Measured memory_bytes: 3104
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<string.h>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<complex>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
#define EPS (long double) 1e-8
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

int main(void) {
	while(1) {
		int n, a, b, c, x;
		cin>>n>>a>>b>>c>>x;
		if(n == 0 && a == 0 && b == 0 && c == 0 && x == 0) break;
		int roc = 0;
		vector<int> y(n);
		REP(i, n) cin>>y[i];
		int res = 0;
		while(res < 10001) {
			if(x == y[roc]) {
				++roc;
				if(roc == n) break;
			}
			x = (a * x + b) % c;
			++res;
		}
		if(res != 10001) cout<<res<<endl;
		else cout<<-1<<endl;
	}
}

Measured memory_bytes: 3124
#include <iostream>
#include <math.h>
#include <sstream>
#include <vector>

using namespace std;
struct wait_que {
	string name;
	int time;
	int cmp_flg;
};
void completeProcess(int size, int q);

static vector<struct wait_que> wqs;

int main()
{
	string str;
	getline(cin, str);
	// get number
	int cnt = 0;
	int num[2];
	string buff;
	stringstream ss(str);
	while (getline(ss, buff, ' ')) {
		stringstream ss_buf(buff);
		ss_buf >> num[cnt];
		cnt++;
	}

	int counter = 0;
        int total_time = 0;
	cnt = num[0];
        int q = num[1];
	int target_num = 0;
	while (true) {
		if (counter < num[0]) {
		getline(cin, str);

		struct wait_que obj;

		int split_num = str.find_first_of(' ');
		obj.name = str.substr(0, split_num);

		string time_str = str.substr(split_num + 1, str.size() - split_num);
		stringstream time_ss(time_str);
		time_ss >> obj.time;
		
		obj.cmp_flg = 0;

                wqs.push_back(obj);
                counter++;
                }

                // check target element.
		struct wait_que *tmp = &wqs[target_num];

		if ((*tmp).time - q > 0) {
			(*tmp).time -= q;
			total_time += q;
			target_num = (target_num + 1) % cnt;
		} else {
			total_time += (*tmp).time;
			cout << (*tmp).name << " " << total_time << endl;
			wqs.erase(wqs.begin() + target_num);
			cnt--;
			if (cnt == 0) {
				break;
			} else {
				target_num = target_num % cnt;
			}
		}
	}
	//completeProcess(ary, num[0], num[1]);

}

void completeProcess(int size,  int q) {
	int total_time = 0;
	int cnt = size;
	int target_num = 0;
	while (true) {
		// check target element.
		struct wait_que *tmp = &wqs[target_num];

		if ((*tmp).time - q > 0) {
			(*tmp).time -= q;
			total_time += q;
			target_num = (target_num + 1) % cnt;
		} else {
			total_time += (*tmp).time;
			cout << (*tmp).name << " " << total_time << endl;
			wqs.erase(wqs.begin() + target_num);
			cnt--;
			if (cnt == 0) {
				break;
			} else {
				target_num = target_num % cnt;
			}
		}
	}
	return;
}

Measured memory_bytes: 4004
using System;

    class Program
    {
        static void Main()
        {
            int num = int.Parse(Console.ReadLine());
            int[] score = new int[2];
            for (int i = 0; i < num; i++)
            {
                string[] card = Console.ReadLine().Split(' ');
                int flg = card[0].CompareTo(card[1]);
                switch (flg)
                {
                    case 0:
                        score[0]++;
                        score[1]++;
                        break;
                    case 1:
                        score[0] += 3;
                        break;
                    case -1:
                        score[1] += 3;
                        break;
                }
            }
            Console.WriteLine(score[0].ToString() + " " + score[1].ToString());
        }
    }

Measured memory_bytes: 6324
import java.util.Arrays;
import java.util.Scanner;

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

        long sumA = 0; long sumB = 0;
       Pair[] pairs = new Pair[n];
       int[] aa = new int[n];
       int[] ba = new int[n];
       for (int i = 0 ; i < n ; i++) {
           aa[i] = sc.nextInt();

       }
       for (int i = 0 ; i < n ; i++) {
           ba[i] = sc.nextInt();

       }
        for (int i = 0 ; i< n ; i++) {
            int a = aa[i];
            int b = ba[i];
            int dif = a -b;
            sumA += a;
            sumB += b;
            Pair pair = new Pair();
            pair.a = a;
            pair.b = b;
            pair.dif = dif;
            pairs[i] = pair;
        }
        if (sumA  < sumB) {
            System.out.println(-1);
            return;
        }

        Arrays.sort(pairs);
        long difTotal = 0;
        int count = 0;
        for (int i = 0 ; i < n ; i ++) {
            if (pairs[i].dif < 0) {
                difTotal += pairs[i].dif;
                count++;
            }
        }
        for (int i = n - 1 ; i >= 0 ; i--) {
            if (difTotal < 0) {
                difTotal += pairs[i].dif;
                count++;
             } else {
                 System.out.println(count);
                 return;
             }

        }


        System.out.println(count);
    }

}

class Pair implements Comparable<Object> {
    int a;
    int b;
    int dif;
    @Override
    public int compareTo(Object other) {
        Pair otherpair = (Pair) other;
        return dif - otherpair.dif;
    }
}

Measured memory_bytes: 91560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 100005
#define pie 3.14159265358979323
#define minuss 1e-6
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 100000000
#define N 10000
ll tra[10000];

int main()
{
    ll n, k, m = 1000000007, result = 0;
    cin >> n >> k;
    n++;
    for (ll i = k; i <= n; i++) {
        result += n * (n - 1) / 2 - (n - i) * (n - i - 1) / 2 - i * (i - 1) / 2 + 1;
        result %= m;
    }
    cout << result;
    return 0;

}


Measured memory_bytes: 3632
#include <stdio.h>

int main(){
    
    // ??\????????¨????????°
    int x;
    
    // ??????????????????????????\????????´??°??¨??????????????????
    scanf("%d", &x);
    
    // ?????¢?????´??°??§??????
    printf("%d\n", x*x*x);
    
    // ??????????????????????????????
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    int n;
    cin>>n;
    int a[n];
    int maxsofar = INT_MIN;
    long long ans = 0;
    for(int i = 0; i < n; i++){
        cin>>a[i];
        if(a[i] < maxsofar){
            ans += maxsofar - a[i];
        }
        maxsofar = max(maxsofar, a[i]);
    }
    cout<<ans;
    return 0;
}

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

int main() {
    int n, a, b;
    cin >> n;
    if (n == 1) cout << "Hello World" << endl;
    else {
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
s=input()
s_len=len(s)
ans="WA"
t=""
if s[0]!="A":
    print(ans)
else:
    t+=s[0].lower()
    t+=s[1]
    count=0
    for i in range(2,s_len-1):
        if s[i]=="C":
            count+=1
            t+=s[i].lower()
        else:
            t+=s[i]
    t+=s[s_len-1]
    if count!=1 or t!=s.lower():
        print(ans)
    else:
        print("AC")

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

void solve() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    VI pos(n);
    REP(i,0,n) pos[a[i]-1] = i;
    set<int> s;
    LL ans = 0;
    REP(i,0,n) {
        int l,r;
        auto it = s.lower_bound(pos[i]);
        if (it == s.begin()) l = -1;
        else l = *(--it);
        it = s.lower_bound(pos[i]);
        if (it == s.end()) r = n;
        else r = *it;
        ans += 1LL * (i+1) * (pos[i] - l) * (r - pos[i]);
        s.insert(pos[i]);
    }
    cout << ans << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 11136
import heapq as hq


def solve(n, m, jobs):
    """
    n: jobの数
    m: 期限
    jobs: (期日、報酬)のリスト
    """

    jobs.sort()

    sal = 0
    j = 0
    heap = []
    for d in range(1, m + 1):
        while j < n:
            job = jobs[j]
            if job[0] > d:
                break
            hq.heappush(heap, -job[1])
            j += 1
        # print(d, heap)
        if len(heap) > 0:
            sal = sal - hq.heappop(heap)
    return sal


n, m = [int(x) for x in input().split()]

jobs = []
for _ in range(n):
    a, b = [int(x) for x in input().split()]
    jobs.append((a, b))

print(solve(n, m, jobs))

Measured memory_bytes: 20800
def D_160():
    N, X, Y = map(int, input().split())
    #count_list = [[0]*N for i in range(N)]
    ans = [0 for i in range(N-1)]
    for i in range(0,N):
        for j in range(1+i,N):
            ans_i = min(j-i,abs((X-1)-i) + abs(j-(Y-1)) + 1)
            ans[ans_i-1] += 1
    
    
    for i in ans:
        print(i)

D_160()

Measured memory_bytes: 45660
import itertools
def f(s):
 for a,b,c,d in itertools.permutations(s):
  for x,y,z in itertools.product('+-*',repeat=3):
   for t in[f"({a} {x} {b}) {y} ({c} {z} {d})",f"(({a} {x} {b}) {y} {c}) {z} {d}",f"{a} {x} ({b} {y} ({c} {z} {d}))",f"({a} {x} ({b} {y} {c})) {z} {d}",f"{a} {x} (({b} {y} {c}) {z} {d})"]:
    if eval(t)==10:return t
 else:return 0
for e in iter(input,'0 0 0 0'):
 s=list(map(int,e.split()));a=f(s)
 if a:print('('+a+')')
 else:print(a)


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

using namespace std;

int main()
{
	string s;
	bool isBad = false;
	cin >> s;
	for (int i = 0; i < 3; i++)
	{
		if (s[i] == s[i + 1])isBad = true;
	}

	if (isBad)cout << "Bad" << endl;
	else cout << "Good" << endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int day = sc.nextInt();
        int k = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int sum = 0;
        
        if(day <= k){
            for(int i = 0;i < day;i++){
                sum += X;
            }
        }else{
            for(int i = 0;i < k;i++){
                sum += X;
            }
            for(int i = 0;i < day - k;i++){
                sum += Y;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n;
ll a[200000];
ll p = 1000000007;
 
typedef ll MOD_POW_TYPE;
MOD_POW_TYPE mod_pow(MOD_POW_TYPE x, MOD_POW_TYPE n, MOD_POW_TYPE mod) {
	MOD_POW_TYPE res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod; // 最下位ビットが立っているときにx^(2^i)を掛ける
		x = x * x % mod; // xを順次二乗していく
		n >>= 1;
	}
	return res;
}
 
ll C(ll n,ll k) {
	if(n < 0) {
		return 0;
	}
	if(n == 0) {
		return 1;
	}
 
	ll shi = 1;
	REP(i,k) {
		shi *= (n - i);
		shi %= p;
	}
	ll bo = 1;
	REP(i,k) {
		bo *= (i + 1);
		bo %= p;
	}
 
	shi *= mod_pow(bo,p - 2,p);
	shi %= p;
	return shi;
}
 
int cou[200000];
 
int main(){
	cin >> n;
	REP(k,n + 1) {
		cin >> a[k];
	}
 
	REP(k,n + 1) {
		cou[a[k]]++;
	}
 
	int dob;
	FOR(k,1,n + 1) {
		if(cou[k] == 2) {
			dob = k;
			break;
		}
	}
	int i = -1,j = -1;
	REP(k,n + 1) {
		if(a[k] == dob) {
			if(i == -1) 
				i = k;
			else
				j = k;
		}
	}
 
	ll x = 1;//C(n + 1,1);
	ll y = 1;//C(i - j + n,0);
 
	FOR(k,1,n + 2) {
		x *= (n + 1 - k + 1);
		x %= p;
		x *= mod_pow(k,p - 2,p);
		x %= p;
 
		if(k - 1 == 0) {
			y = 1;
		}else if(i - j + n >= k - 1) {
			y *= (i - j + n - (k - 1) + 1);
			y %= p;
			y *= mod_pow(k - 1,p - 2,p);
			y %= p;
		}else {
			y = 0;
		}
		ll ans = x - y + p;
		ans %= p;

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


Measured memory_bytes: 2432
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including seg_tree_order_statistics_node_update
#include <stdio.h>
#include <cassert>
using namespace std;
//using namespace __gnu_pbds;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for(lo(a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for(lo(a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto it : a)
#define INF 500
#define MOD 1000000007
#define M 1000000007
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define pb(a) push_back((a))
#define endl "\n"
#define eps 1e-9
#define PI 3.141592653589793
template<typename T> ostream& operator<< ( ostream &o,vector<T> v ) {
    if ( v.size() >0 )o<<v[0];
    for ( unsigned   i=1; i<v.size(); i++ )o<<" "<<v[i];
    return o<<endl;
}
template<typename U,typename V> ostream& operator<< ( ostream &o,pair<U,V> p ) {
    return o<<"("<<p.first<<", "<<p.second<<") ";
}
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {
    for ( unsigned   i=0; i<v.size(); i++ )in>>v[i];
    return in;
}
template<typename T> istream& operator>> ( istream &in,pair <T,T> &p ) {
    in>>p.X;
    in>>p.Y;
    return in;
}
#define debug(x) cout<<#x<<"="<<x<<endl;
vl ans(INF,0);
vl siz(INF,0);
vl g[INF];
void dfs(lo node,lo par){
    siz[node]=1;
    lo other=0;
    lo temp=1;
    TRV(g[node])if(it!=par){
        dfs(it,node);
        temp*=ans[it];
        other+=siz[it];
    }
    ans[node]=temp;
    TRV(g[node])if(it!=par){
        if(ans[node]<(siz[it]+1)*(temp/siz[it])){
            ans[node]=(temp/siz[it])*(siz[it]+1);
            siz[node]=siz[it]+1;
        }
    }
    if(ans[node]<other+1){
        ans[node]=siz[node]=other+1;
    }
}
int main(){
    std::ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);cout.precision(20);
	lo n;
	cin>>n;
	vl a(n);
	cin>>a;
	lo ans=0;
	lo num=0;
	while(num<pow(3,n)){
        lo no=num;
        lo prod=1;
        lo i=0;
        while(i<n){
            if(no%3==0){
                prod*=(a[i]%2);
            }
            else if(no%3==1){
                prod*=(a[i]+1)%2;
            }
            else {
                prod*=(a[i]-1)%2;
            }
            no/=3;
            i++;
        }
        if(!prod)ans++;
        num++;
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int T = sc.nextInt();
		sc.nextLine();
		int[] a = new int[T];
		for (int i=0;i<T;i++){
			a[i] = sc.nextInt();
		}
		int count = 0;
		if (T==1){
			count = K-1;
		}
		else if (T==2){
			Arrays.sort(a);
			if (a[0]==a[1]){
				count = 0;
			}
			else{
				count = a[1]-a[0]-1;
			}
		}
		else{
			Arrays.sort(a);
			int head = 0;
			while(true){
				if (head==a.length-2&&a[a.length-1]==a[a.length-2]){
					count = 0;
					break;
				}
				else if(head==a.length-2&&a[a.length-1]!=a[a.length-2]){
					count = a[a.length-1]-a[head]-1;
					break;
				}
				else{
					a[a.length-1] -= a[head];
					a[head] -=a[head];
					head++;
					Arrays.sort(a);
				}

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

}

Measured memory_bytes: 10572
import math
n = int(input())
prices = []
for i in range(n):
    prices.append(int(input()))

i = prices.index(max(prices))
prices[i] = math.ceil(prices[i]/2)

def wa(list):
    a = 0
    for i in range(len(list)):
        a = a+list[i]
    return a

print(wa(prices))



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std ;
int main()
{
	int array[10] ;
	for(int i=0;i<10;i++)
	{
		cin>>array[i] ;
	}
	sort(array,array+10) ;
	for(int i=9;i>=7;i--)
	{
		cout<<array[i]<<endl ;
	}

}

Measured memory_bytes: 3120
#include <cstdio>
using namespace std;

int main(){
  int a,b,x;
  int r,s;
  r=s=0;
  while(scanf("%d,%d,%d",&a,&b,&x)>0){
    if(x*x==a*a+b*b) r++;
    if(a==b) s++;
  }
  printf("%d\n%d\n",r,s);
  return 0;
}

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


int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if((a*100 + b*10 + c)%4 == 0){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
n,q=map(int,input().split())
s=input()
count_arr=[0]*n

for i in range(1,n):
  count_arr[i]=count_arr[i-1]+(1 if s[i-1]=='A' and s[i]=='C' else 0)

for _ in range(q):
  l,r=map(int,input().split())
  print(count_arr[r-1]-count_arr[l-1])

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

int main()
{
    int x, y;

    while (true)
    {
        cin >> x >> y;
        if (x == 0 && y == 0)
        {
            break;
        }

        if (x < y)
        {
            cout << x << ' ' << y << endl;
        }
        else
        {
            cout << y << ' ' << x << endl;
        }
    }
}



Measured memory_bytes: 3084
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

int main() {
  int n, C;
  cin >> n >> C;
  vector<int> s(n), t(n), c(n);
  for(int i = 0; i < n; i++) cin >> s[i] >> t[i] >> c[i];
  vector<vector<pair<int, int>>> u(30), v(30);
  for(int i = 0; i < n; i++) u[c[i] - 1].push_back(make_pair(s[i], t[i]));
  for(int i = 0; i < 30; i++) sort(u[i].begin(), u[i].end(), [](const pair<int, int> &lhs, const pair<int, int> &rhs) {return lhs.first < rhs.first; });
  for(int i = 0; i < 30; i++) {
    if(u[i].size() == 0) continue;
    v[i].push_back(u[i][0]);
    for(int j = 1; j < u[i].size(); j++) if(v[i][v[i].size() - 1].second == u[i][j].first) v[i][v[i].size() - 1].second = u[i][j].second;
    else v[i].push_back(u[i][j]);
    for(int j = 0; j < v[i].size(); j++) v[i][j].first--;
  }

  vector<pair<int, int>> ps;
  for(int i = 0; i < 30; i++) for(int j = 0; j < v[i].size(); j++) ps.push_back(v[i][j]);
  sort(ps.begin(), ps.end(), [](const pair<int, int> &lhs, const pair<int, int> &rhs) {return lhs.first < rhs.first; });
  for(int i = 1; i < 31; i++) {
    vector<int> p(i);
    bool bb = false;
    for(int j = 0; j < ps.size(); j++) {
      bool b = false;
      for(int k = 0; k < i; k++) if(p[k] <= ps[j].first) {
        p[k] = ps[j].second;
        b = true;
        break;
      }
      if(!b) bb = true;
    }
    if(bb) continue;
    cout << i << endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 4600
#include <bits/stdc++.h>
#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
    int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    return x * fh;
}

inline int Sum(int x) {
	int res = 0;
	while (x) res += x % 10, x /= 10;
	return res;
}

int main () {
	int n = read(), ans = 1e8;
	For (a, 1, n - 1)
		chkmin(ans, Sum(a) + Sum(n - a));
	printf ("%d\n", ans);
    return 0;
}


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


int main() {
	int n;
	cin >> n;
	const ll MOD = 1000000007;

	ll ans = 1;
	rrep (i, n) {
		ans *= i;
		ans %= MOD;
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

int main() {
  // vector<int> X(5);
  // int x1, x2, x3, x4, x5;
  char c;
  cin >> c;

  if (c >= 65 && c <= 90) {
    cout << "A" << endl;
    return 0;
  }

  if (c >= 97 && c <= 122) {
    cout << "a" << endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main() {
    ios_base::sync_with_stdio(false);
        ll x,k,d;
        cin>>x>>k>>d;
          x=fabs(x);
          ll temp=x/d;
          ll ans=0;
          if(k>=temp)
           {ans=x-temp*d;
           k-=temp;
           if(k>0&&k%2==1)
            ans=x-(temp+1)*d;
           }
           else if(k<temp)
           {ans=x-k*d;}
           else;
           ans=fabs(ans);
           cout<<ans;

        }


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;
//const int mod = 1e9+9;
/*ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }
*ll lcm(ll x, ll y){return x*(y/gcd(x,y));}
*void exEuclid(int a, int b){
	if(b==0){x = 1; y=0; d=a; return ;}
	exEuclid(b, a%b);
	int x1=y;
	int y1=x-(a/b)*y;
	x=x1; 100000
	y=y1;
} 
* */
//===========================================================//
int n, k;
const int nx = 1e5+5;
ll ac[nx][2];
ll dp[105][nx];
ll go(ll i, ll w){
	if(w>k) return -oo;
	if(i == n) return 0;
	if(dp[i][w] != -1) return dp[i][w];
	ll& ans = dp[i][w];
	ans = max(ans, go(i+1,w));
	if(w+ac[i][0]<=k) ans = max(ans, go(i+1,w+ac[i][0])+ac[i][1]);
	return ans;
}
int main(){
	
	cin>>n>>k;
	memset(dp, -1, sizeof dp);
	for(int i=0; i<n; i++) cin>>ac[i][0]>>ac[i][1];
	cout<<go(0,0)<<"\n";
}

Measured memory_bytes: 82304
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    string s;
    cin>>s;
    int n = s.length();
    auto f = [&](int k)
    {
        for (int i = max(0,n - k + 1);i < min(n,k);++i)
            if (s[n - k] != s[i])
                return 0;
        return 1;
    };
    int ans = 0;
    for (int t = 1 << 20;t;t /= 2)
        if (ans + t <= n && f(ans + t))
            ans += t;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
using namespace std;
#define X 10000000
int main() {
	int n, m; while (cin >> n >> m&&n&&m) {
		vector<int>taro, hanako;
		fill(taro.begin(), taro.end(), X);
		fill(taro.begin(), taro.end(), X);
		int num;
		for (int i = 0; i < n; i++) {
			cin >> num; taro.push_back(num);
		}
		for (int i = 0; i < m; i++) {
			cin >> num; hanako.push_back(num);
		}
		sort(taro.begin(), taro.end());
		sort(hanako.begin(), hanako.end());
		int sum1 = accumulate(taro.begin(), taro.end(), 0);
		int sum2 = accumulate(hanako.begin(), hanako.end(), 0);
		int sa = (sum1 - sum2);
		if (abs(sa) % 2 == 1) { cout << -1 << endl; continue; }
		sa /= 2;
		int f = 0;
		for (int i = 0; i < n; i++) {
			if (f)break;
			for (int j = 0; j < m; j++) {
				if (taro[i] - hanako[j] == sa) {
					cout << taro[i] << " " << hanako[j] << endl;
					f = 1;
					break;
				}
			}
		}
		if (!f)cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
import numpy as np

def isPrime_np(n):
    maxp = int(np.sqrt(n))
    searchlist = [i for i in range(2,n+1)]
    primeNum = []

    while searchlist[0] <= maxp:
        primeNum.append(searchlist[0])
        tmp = searchlist[0]
        searchlist = [i for i in searchlist if i % tmp != 0]
    primeNum.extend(searchlist)
    
    return primeNum

MaxQ = 10**5+1
Q = int(input())
lr = [list(map(int,input().split())) for _ in range(Q)]

a = [0]*MaxQ
s = [0]*MaxQ
prime = isPrime_np(MaxQ)
pset = set(prime)
for p in prime:
    if (p+1)/2 in pset:
        a[p] = 1

ans = []
for i in range(MaxQ-1):
    s[i+1] = s[i] + a[i]
    
for l,r in lr:
    ans.append(s[r+1] - s[l])
print(*ans,sep="\n")

Measured memory_bytes: 53800
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func kaibun(s string) bool {
	i := 0
	j := len(s) - 1
	for i < len(s)/2 {
		if s[i] != s[j] {
			return false
		}
		i = i + 1
		j = j - 1
	}

	return true
}

func check(s string) bool {
	if len(s)%2 == 0 {
		if kaibun(s[:len(s)/2]) == false || kaibun(s[len(s)/2:]) == false {
			return false
		}
	} else {
		if kaibun(s[:len(s)/2]) == false || kaibun(s[len(s)/2+1:]) == false {
			return false
		}
	}
	return true
}

func kosuu(n int) int {
	return n * (n - 1) / 2
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	N := sc.nextStr()

	isSeven := false
	for _, c := range N {
		if c == '7' {
			isSeven = true
			break
		}
	}

	if isSeven {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
#define io_optimized ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main () {
	io_optimized
	long long int n,sum,ct;
	while(cin>>n)
	{
		sum=0;
		ct=0;
		while(n>1)
		{
			n/=2;
			sum+=pow(2,ct);
			ct++;
		}
		sum+=pow(2,ct);
		cout<<sum<<"\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int N, K;
  scanf("%d", &N);
  scanf("%d", &K);
  std::vector<int > A(N);
  std::vector<long long > Asum(N+2);
  Asum[0]=0;
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
    Asum[i+1]=Asum[i]+(long long)A[i];
  }
  std::vector<long long > cand;
  for (int i=0; i<N; i++){
    for (int j=i+1; j<N+1; j++){
      cand.push_back(Asum[j]-Asum[i]);
      //printf("cand=%lld\n", cand[cand.size()-1]);
    }
  }
  
  for (int i=45; i>=0; i--){
    std::vector<long long > cand_orig(cand.size());
    std::copy(cand.begin(), cand.end(), cand_orig.begin());
    cand.clear();
    long long unit = (long long )1<<i;
    for (int j=0; j<cand_orig.size(); j++){
      if ((unit & cand_orig[j]) !=0) cand.push_back(cand_orig[j]);
    }
    //printf("i=%d,size()=%ld\n", i, cand.size());    
    if (cand.size()<K){
      std::swap(cand, cand_orig);
    }
  }
  long long ans=((long long)1<<45)-1;
  for (int j=0; j<K; j++){
    ans = (ans & cand[j]);
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 8300