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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    map<string,int> Map;
    rep(i,N){
        string s; cin>>s;
        Map[s]++;
    }
    cout<<"AC x "<<Map["AC"]<<"\n";
    cout<<"WA x "<<Map["WA"]<<"\n";
    cout<<"TLE x "<<Map["TLE"]<<"\n";
    cout<<"RE x "<<Map["RE"]<<"\n";
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#define lli long long int
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);


using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;
const int M = 1e6 + 500;

lli dp[N];
lli w[N];
lli v[N];

void solve()
{
    lli n, wx;
    cin>>n>>wx;
    for(int i = 1; i <= n; i ++)
        cin>>w[i]>>v[i];
    for(int i = 0; i < N; i ++)
        dp[i] = 1e10;
    dp[0] = 0;
    lli mx = 0;
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 100000; j >= 1; j --)
        {
            if(j - v[i] >= 0)
                dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
            if(dp[j] <= wx)
                mx = max(mx, j * 1ll);
        }
    }
    cout<<mx<<endl;
    return ;
}
/*
10
6
10 3 2 5 7 8
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    lli t;
    t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 5248
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;

char ary[1010];
int main(){
	fgets(ary,1010,stdin);
	int n=strlen(ary);
	stack<int> pe,ap;
	for(int i=0;i<n-4;i++){
		if(ary[i]=='a'&&ary[i+1]=='p'&&ary[i+2]=='p'&&ary[i+3]=='l'&&ary[i+4]=='e') ap.push(i);
		else if(ary[i]=='p'&&ary[i+1]=='e'&&ary[i+2]=='a'&&ary[i+3]=='c'&&ary[i+4]=='h') pe.push(i);
	}
	while(!ap.empty()){
		int tmp=ap.top();ap.pop();
		ary[tmp]='p';
		ary[tmp+1]='e';
		ary[tmp+2]='a';
		ary[tmp+3]='c';
		ary[tmp+4]='h';
	}
	while(!pe.empty()){
		int tmp=pe.top();pe.pop();
		ary[tmp]='a';
		ary[tmp+1]='p';
		ary[tmp+2]='p';
		ary[tmp+3]='l';
		ary[tmp+4]='e';
	}
	printf("%s",ary);
	return 0;
}

Measured memory_bytes: 2588
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    K = int(readline())
    if K%2==0:
        print(-1)
    else:
        seven = 7
        amari = set([7])
        ans = 1
        while True:
            seven = seven%K
            if seven==0:
                print(ans)
                break
            else:
                seven = seven*10+7
                if seven in amari:
                    print(-1)
                    break
                ans += 1
                amari.add(seven)


if __name__ == '__main__':
    main()


Measured memory_bytes: 77856
import java.util.Scanner;

public class Main {

  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    if(n%2 ==0){
      System.out.println(n/2 -1);
    }else{
      System.out.println((n + 1)/2 - 1);
    }

  }

}


Measured memory_bytes: 21844
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
	ll n,k;
	cin >> n >> k;
	vector<ll> h(n);

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

	if (n <= k) {
		cout << 0 << endl;
		return 0;
	}

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

	ll count=0;

	for (int i = 0; i < n - k;i++) {
		count += h[i];
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 4776
program vjudge149349E;
const maxn=300000+10;
      maxm=100000+10;
var l,r,next:array[0..maxn] of longint;
    last,ans,bits:array[0..maxm] of longint;
    n,m,i,j:longint;
function ask(x:longint):longint;
var ans:longint;
begin
  ans:=0;
  while x>0 do
  begin
    ans:=ans+bits[x];
    x:=x-x and (-x);
  end;
  exit(ans);
end;
procedure add(x,d:longint);
begin
  while(x<=m+1) do
  begin
    bits[x]:=bits[x]+d;
    x:=x+x and (-x);
  end;
end;
begin
  readln(n,m);
  fillchar(last,sizeof(last),0);
  for i:=1 to n do
  begin
    readln(l[i],r[i]);
    next[i]:=last[r[i]-l[i]+1];
    last[r[i]-l[i]+1]:=i;
    inc(ans[1]);
    dec(ans[r[i]-l[i]+2]);
  end;
  for i:=1 to m do ans[i]:=ans[i]+ans[i-1];
  fillchar(bits,sizeof(bits),0);
  for i:=1 to m do
  begin
    ans[i]:=ans[i]+bits[1];
    for j:=1 to m div i do
      ans[i]:=ans[i]+ask(j*i+1);
    j:=last[i];
    while j>0 do
    begin
      add(l[j]+1,1);
      add(r[j]+2,-1);
      j:=next[j];
    end;
  end;
  for i:=1 to m do writeln(ans[i]);
end.

Measured memory_bytes: 5504
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int a, b;
    cin >> a >> b;

    vector<int> h(1000, 0);
    for (int i = 0; i < h.size(); ++i) {
        if (i == 0) {
            h[i] = 0;
        }
        else {
            h[i] = i * (i + 1) / 2;
        }
    }

    int ans = 0;
    for (int i = 2; i < h.size(); ++i) {
        if (h[i - 1] - a == h[i] - b) {
            ans = h[i] - b;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3536
N,Y = map(int,input().split())
res = (-1,-1,-1)
for x in range(N+1):
  for y in range(N+1-x):
    if N-x-y >=0 and 10000*x + 5000*y + 1000*(N-x-y) == Y:
      res = (x,y,N-x-y)
print(res[0],res[1],res[2])


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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L.at(i);
  sort(L.begin(), L.end());

  int ans = 0;

  for (int i = 0; i < N; i++) {
    int k = i;
    for (int j = i + 1; j < N; j++) {
      while (k < N && L.at(k) < L.at(i) + L.at(j)) k++;
      ans += k - j - 1;
    }
  }

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

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

namespace abc115_d
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long[] len = new long[x[0] + 1]; long[] p = new long[x[0] + 1];
            len[0] = 1; p[0] = 1;
            for (int i = 1; i <= x[0]; i++)
            {
                len[i] = len[i - 1] * 2 + 3;
                p[i] = p[i - 1] * 2 + 1;
            }
            long ret = 0; int now = (int)x[0]; bool middle = false;
            while (x[1] > 0)
            {
                if (middle)
                { x[1]--; ret++; middle = false; }
                else
                {
                    if (len[now] <= x[1])
                    {
                        x[1] -= len[now]; ret += p[now];
                        middle = true;
                    }
                    else { x[1]--; now--; }
                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int n;
    cin >> n;
	int a[n];
    REP(i,1,n+1) cin >> a[i];
  	int ans = 0;
    //処理
 	int button=1;
	REP(i,0,n){
      	button = a[button];
    	ans++;
    	if(button==2) break;
    }  
  
    //出力
    if(button==2) cout << ans << ENT;
    else cout << -1 << ENT;
    return 0;
}

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


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

using namespace std;

int main() {
  int a, b, k;
  vector<int> v;
  cin >> a >> b >> k;
  for (int i = a; i < a + k; i++) {
    if (i > b) {
      break;
    }
    v.push_back(i);
  } 
  for (int i = b; i > b - k; i--) {
    if (i < a || count(v.begin(), v.end(), i)) {
      break;
    }
    v.push_back(i);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll dp[60][100100];
int main(){
  for(ll i = 0; i < 60; i++){ for(ll j = 0; j < 100100; j++){ dp[i][j] = 0LL;}}
  
  ll N,A; cin >> N >> A;
  vector<ll> x(N);
 for(ll i = 0; i < N; i++){ ll a; cin >> a;  a -= A; x[i] = a;}
  
  dp[0][3000] = 1; dp[0][x[0]+3000] += 1;
  
  //dp[i][j+3000] で、　x[0],,x[i]までで合計jを作る場合の数を表すことに注意
  
  for(ll i = 0; i < N-1; i++){
   for(ll j = 0; j < 6000 ;j++){
    
     dp[i+1][j] += dp[i][j]; 
     dp[i+1][j+x[i+1]] += dp[i][j];;}}
  
  cout << dp[N-1][3000]-1 << endl; return 0;}
  

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

int main() {
	int h,n;cin>>h>>n;
	vector<int> a(n);
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>=h){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}


Measured memory_bytes: 640
N, D = map(int,input().split())

dot = []
ans = 0

for i in range(N):
    dot.append(list(map(int,input().split())))

    d = (((dot[i][0] ** 2) + (dot[i][1] ** 2) )** (1/2))

    if d <= D:
        ans += 1



print(ans)




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

int main()
{
    long long a, b;
    cin >> a >> b;

    long long bigger = max(a, b), smaller = min(a, b);

    long long r = bigger % smaller;
    long long gcd = smaller;
    while (r > 0)
    {
        bigger = smaller;
        smaller = r;
        gcd = smaller;
        r = bigger % smaller;
    }

    long long lcm = a * b / gcd;

    cout << lcm << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
// #define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const int INF = -1;
ll dp[100005][13];

signed main(void) {
	ll N;
	cin >> N;
	vector<int> L(N);
	rep(i, N) {
		cin >> L[i];
	}

	SORT(L);

	ll ans = 0;
	// it is clear that a < b+c and b < c+a if a < b < c
	// only check c < a+b
	for(int i=0; i<N; i++) {
		for(int j=i+1; j<N; j++) {
			for (int k=j+1; k<N; k++) {
				if (L[k] < L[i] + L[j]) {
					ans++;
				}
			}
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
//Built by Sabuj Jana(greenindia) from Jadavpur University,Kolkata,India 
// God is Great------------/////\\\\--------------------------------
 #include <bits/stdc++.h>
 using namespace std;
 #define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 #define endl "\n"
 // #define INF LLONG_MAX 
 const int INF=1e9+5;//billion
 #define pb push_back
 #define mp make_pair
 #define loop(i,a,b) for (ll i=a;i<=b;i++)
 
 typedef long long ll;
 typedef vector<ll> vi;
 #define int long long int
 	 
 int KSI(int wt[], int val[], int n, int W){

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

 	loop(i,0,n){
 		loop(w,0,W){

 			if(i==0 or w==0)
 					K[i][w]=0;
 			else if( w <wt[i-1] )
 					K[i][w]= K[i-1][w];
 			else {

 				K[i][w]= max( K[i-1][w], val[i-1]+ K[i-1][w-wt[i-1]]);

 			}


 		}
 	}

 	return K[n][W];


 }



 signed main() {

  
    crap;

                  
    int n,W;
    cin>>n>>W;

    int wt[n+7];
    int val[n+7];

    loop(i,0,n-1){

    	cin>>wt[i];
    	cin>>val[i];

    }

    cout<<KSI( wt,val,n,W)<<endl;

      
    return 0;
 }



Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int main()
{
    ll N, M;
    cin >> N >> M;
    vll K(N);
    vvll A;
    vi ans(M, 0);
    int cnt = 0;
    rep(i, N)
    {
        cin >> K[i];
        A.push_back(vll(K[i]));
        rep(j, K[i])
        {
            cin >> A[i][j];
            ans[A[i][j]-1]++;
            PRINT(ans);
        }
    }
    rep(i, M)
    {
        if(ans[i] == N)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int t=sc.nextInt();
    int a=sc.nextInt();
    double A=(t-a)*1000/6.0;
    double[] h=new double[n];
    for(int i=0;i<n;i++){
      h[i]=Math.abs(sc.nextInt()-A);
    }
    int idx=0;
    for(int i=1;i<n;i++){
      if(h[i]<h[idx]){
        idx=i;
      }
    }
    System.out.println(idx+1);
  }
}

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

void print(int* a, int n);
void print(int* a,int n)
{
	for (int i = 0; i < n; i++)
	{
		if (i > 0)
			cout << ' ';
		cout << a[i];
	}
	cout << endl;
}
int selectSort(int* a, int n)
{
	int m = 0;
	int min,t,k;
	for (int i = 0; i < n-1; i++)
	{
		min = a[i];
		k = i;
		for (int j = i + 1; j < n; j++)
		{
			if (a[j] < min)
			{
				min = a[j];
				k = j;
			}	
		}
		if (min != a[i])
		{
			t = a[k];
			a[k] = a[i];
			a[i] = t;
			m++;
		}	
	}
	return m;

}
int main()
{
	int a[100];
	int n = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int m = selectSort(a, n);
	print(a, n);
	cout << m << endl;
	return 0;
}


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

int main() {
  string a,b,c;
  cin >> a >> b >> c;
  if ( a.back()==b[0]&&b.back()==c[0] ) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}

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

int A, B, C;
long X, Y;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin >> A >> B >> C >> X >> Y;
    long long sum=0;
    if((A+B)/2 >= C){
        long long res1 =0, res2=0;
        long large = X > Y ? X: Y;
        res1 += C * large * 2;
        res2 += min(X, Y) * C * 2;
        long r = X > Y ? A : B;
        res2 += r * (max(X, Y) - min(X, Y));
        sum = min(res1, res2);
    }else{
        sum += A * X + B * Y;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long H, long long W, long long N){
	if (H > W) {
		cout << (N-1)/H+1 << endl;
	} else {
		cout << (N-1)/W+1 << endl;
	}
}

int main(){	
	long long H;
	long long W;
	long long N;
	scanf("%lld",&H);
	scanf("%lld",&W);
	scanf("%lld",&N);
	solve(H, W, N);
	return 0;
}



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

int main() {
  int N, a, q, odd = 0, lans = 0, ans = 999999;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> a;
    lans = 0;
    for (; 1;) {
      odd = a % 2;
      
      if (odd) break;
      
      lans++;
      a /= 2;
    }
    if (ans > lans) ans = lans;
  }
    cout << ans << endl;
  }


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

ll n,k,ar[N];
bool dp[N];

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

    cin >> n >> k;
    memset(dp,false,sizeof(dp));
    rep(i,0,n)
    {
        cin >> ar[i];
    }

    rep(i,1,k+1)
    {
        rep(j,0,n)
        {
            if(i-ar[j]<0)
                break;

            if(!dp[i-ar[j]])
            {
                dp[i]=true;
                break;
            }
        }
    }

    if(dp[k])
        cout << "First\n";
    else
        cout << "Second\n";

    return 0;
}



Measured memory_bytes: 3932
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,v = mi()
b,w = mi()
t = ii()

dis = abs(a-b)

if v<=w:
    print("NO")
    exit()

if dis <= abs(v-w)*t:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

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

using ll = long long;

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

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int x[5]; rep(i,5) std::cin >> x[i];
  
  int ans = 0;
  rep(i,5) {
    if ( x[i] == 0 ) ans = i+1;
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    int N,K;
    cin >> N >> K;
    int l[N];
    REP(i,N) cin >> l[i];

    sort(l,l+N);
    //REP(i,N)cout << l[i] << endl;
    int ans = 0;
    REP(i,K){
        ans += l[N-i-1];
    }
    fin(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> a(n);
    for(int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        a[i].resize(x);
        ffor(j,x){
            cin >> a[i][j].ff >> a[i][j].ss;
            a[i][j].ff--;
        }
    }

    int ans = 0;
    for(int i = 0;i < (1<<n); ++i){
        bool cool = true;
        for(int j = 0; j < n; ++j){
            if(!cool)break;
            if((1 << j)&i){
                
                for(int k = 0; k < a[j].size(); ++k){
                    if((((1<<a[j][k].ff)&i) != 0)^(a[j][k].ss)){
                        cool = false;
                        break;
                    }
                }
            }
        }
        if(cool){
            // cout << i << ' ';
            ans = max(ans,(int)__builtin_popcount(i));
        }
    }

    cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
int main(){
    ll n=in(),W=in();
    vecll w(n),v(n);
    vector<vecll> val(4);
    rep(i,n){
        w[i]=in();
        v[i]=in();
    }
    rep(i,n) val[w[i] - w[0]].pb(v[i]);
    rep(i,4)sort(ALL(val[i]),greater<int>());
    vector<vecll> sumVal(4,vecll(n));
    rep(i,4){
        sumVal[i][0]=0;
        rep(j,val[i].size()){
            sumVal[i][j+1]=sumVal[i][j]+val[i][j];
        }
    }
    ll ans=-1;
    rep2(i,0,val[0].size()){
        rep2(j,0,val[1].size()){
            rep2(k,0,sumVal[2].size()){
                if(i*w[0] + j*(w[0]+1) + k*(w[0]+2) > W)break;
                ll left = W - (i*w[0] + j*(w[0]+1) + k*(w[0]+2));
                ll num = left/(w[0]+3);
                ans = max(ans,sumVal[0][i] + sumVal[1][j] + sumVal[2][k] + sumVal[3][num]);
            }
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3680
while 1:
    n = int(input())
    if n == 0: break
    line = [list(input().split()) for _ in range(n)]
    k = input()
    words = {}
    for i in line:
        for word in i:
            if word in words:
                words[word] += 1
            else:
                words[word] = 1
    cand = {key: v for key, v in words.items() if key[0] == k}
    items = cand.items()
    sitems = sorted(items, key=lambda x: x[1], reverse=True)
    prev = 0
    tmp = []
    ans = []
    for i in sitems:
        if prev != i[1]:
            tmp.sort()
            ans.extend(tmp)
            tmp = []
        tmp.append(i[0])
        prev = i[1]
    tmp.sort()
    ans.extend(tmp)
    if len(ans) > 5: ans = ans[0:5]
    if len(ans) == 0:
        print("NA")
    else:
        print(' '.join(ans))

    


Measured memory_bytes: 5624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N, M; cin >> N >> M;
  vector<int> P(M), Y(M);
  rep(i, M) cin >> P[i] >> Y[i];
  map<int, vector<int>> m;
  rep(i, M) m[P[i]] = vector<int>();
  rep(i, M) {
    auto& v = m[P[i]];
    v.push_back(Y[i]);
  }
  map<int, map<int, int>> m2;
  rep(i, M) m2[P[i]] = map<int, int>();
  for (auto& e: m) {
    int p; vector<int> v; tie(p, v) = e;
    sort(v.begin(), v.end());
    auto& m2_ = m2[p];
    for (auto& y: v) {
      auto size = m2_.size();
      m2_[y] = size + 1;
    }
  }
  rep(i, M) {
    auto y = m2[P[i]][Y[i]];
    printf("%06d%06d\n", P[i], y);
  }
}


Measured memory_bytes: 27264
//#pragma comment(linker, "/STACK:102400000,102400000") 
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
 
typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
 
const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);
const ll hax = 1e6 + 7;
 
int n, k;
int vis[15], dig[15], res[15];
 
void solve()
{
    int i, j;
    sa(n), sa(k);
 
    repp(i, 1, k)
    {
        int x;
        sa(x);
        vis[x] = 1;
    }
    int cnt = 0;
    while (n)
    {
        ++cnt;
        dig[cnt] = n % 10;
        n /= 10;
    }
    vector<int>num;
    repp(i, 0, 9)
    {
        if (!vis[i])
            num.push_back(i);
    }
    vector<int>re;
    for (i = cnt; i >=1 ;i--)
    {
        int f = 0;
        for (j = dig[i]; j <= 9; j++)
        {
            if (!vis[j])
            {
                if (j != dig[i])
                {
                    printf("%d", j);
                    for (int h = i - 1; h >= 1; h--)
                    {
                        printf("%d", num[0]);
                    }
                    return;
                }
                else
                {
                    f = 1;
                    re.push_back(j);
                    break;
                }
            }
        }
        if (f == 0)
        {
            break;
        }
    }
    if (re.size() == cnt)
    {
        rep(i, 0, re.size())
        {
            printf("%d", re[i]);
        }
    }
    else
    {
        int f = num[0] == 0 ? num[1] : num[0];
        printf("%d", f);
        for (i = cnt; i >= 1; i--)
        {
            printf("%d", num[0]);
        }
    }
}
 
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const OFFSET: i64 = 1 << 62;
fn main() {
    let n = read::<i64>();
    let mut x = read::<i64>();
    let mut d = read::<i64>();
    if d == 0 {
        if x == 0 {
            println!("{}", 1);
        } else {
            println!("{}", n + 1);
        }
        return;
    }
    if d < 0 {
        x *= -1;
        d *= -1;
    }
    let mut opens = HashMap::<i64, Vec<(i64, i64)>>::new();
    for i in 0..n + 1 {
        let cnt = n - i;
        let dsum1 = i * (i - 1) / 2 * d;
        let dsum2 = n * (n - 1) / 2 * d - dsum1;
        let dsum3 = cnt * (cnt - 1) / 2 * d;
        let dsum4 = n * (n - 1) / 2 * d - dsum3;
        let l = OFFSET + i * x + dsum1 - (cnt * x + dsum2);
        let r = OFFSET + i * x + dsum4 - (cnt * x + dsum3);
        // println!("{} {}", l - OFFSET, r - OFFSET);
        let index = l % (2 * d);
        let entry = opens.entry(index).or_insert(vec![]);
        entry.push((l, r));
    }
    let mut ans = 0;
    // println!("{:?}", opens);
    for ranges in opens.values() {
        let mut ranges = ranges.clone();
        ranges.sort();
        let mut prev = -OFFSET;
        // println!("{:?}", ranges);
        for &(l, r) in ranges.iter() {
            ans += (std::cmp::max(prev, r + 2 * d) - std::cmp::max(prev, l)) / 2 / d;
            prev = std::cmp::max(prev, r + 2 * d);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 18208
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(usize);
    let vs = scan!(String;n);

    let mut nums = vec![0; 26];
    for c in vs[0].chars() {
        nums[c as usize - 'a' as usize] += 1;
    }

    for v in vs.iter().skip(1) {
        let mut nums0 = vec![0; 26];
        for c in v.chars() {
            nums0[c as usize - 'a' as usize] += 1;
        }

        for i in 0..nums.len() {
            nums[i] = min(nums[i], nums0[i])
        }
    }

    let mut chars = vec![];
    for (i, &n) in nums.iter().enumerate() {
        for _ in 0..n {
            chars.push((i as u8 + 'a' as u8) as char)
        }
    }
    chars.sort();

    println!("{}", chars.into_iter().collect::<String>());
}


Measured memory_bytes: 4352
N, M = map(int, input().split())
ans_list = [False] * N
WA = [0] * N

now = 0
false_count = 0
ans_false = 0
ans = 0



for i in range(M):
    p, s = input().split()
    if ans_list[int(p) - 1]:
        continue
    if s == "AC":
        ans += 1
        ans_false +=  WA[int(p) - 1]
        ans_list[int(p) - 1] = True
    else:
        WA[int(p) - 1] += 1
 
print(ans, ans_false)

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

bool isdislike(int n, vector<int> d) {
	while (n != 0) {
		if (count(d.begin(), d.end(), n % 10) != 0)
			return true;
		n /= 10;
	}
	return false;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> d(k);
	for (int i = 0; i < k; i++)
		cin >> d.at(i);

	while (isdislike(n++, d));
	cout << n - 1 << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 10000000), 1000000)
	var N int
	fmt.Scan(&N)
	n3 := N * 3
	a := make([]int, n3)
	scanner.Scan()
	inputs := strings.Split(scanner.Text(), " ")
	for i := 0; i < n3; i++ {
		n, _ := strconv.ParseInt(inputs[i], 10, 64)
		a[i] = int(n)
	}
	sort.Ints(a)
	var ans int
	for i := N; i < n3; i += 2 {
		ans += a[i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 17152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 2e5;

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

	int a,p;
	cin>>a>>p;
	p += 3*a;
	cout<<p/2;

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

string ss = "abcdefghijklmnopqrstuvwxyz";

int main()
{
    string s;
    map<char, int> mp;
    while (cin >> s)
    {
        int n = s.length();
        for (int i = 0; i < n; i++)
        {
            char c = tolower(s[i]);
            mp[c]++;
        }
    }
    for (int i = 0; i < 26; i++)
    {
        cout << ss[i] << " : " << mp[ss[i]] << endl;
    }
}



Measured memory_bytes: 3168
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	vector<int> b(4);
	int a;
	rep(i, 6) {
		scanf("%d", &a);
		--a;
		++b[a];
	}
	if (b[0] > 2 || b[1] > 2 || b[2] > 2 || b[3] > 2)printYN(false);
	else printYN(true);

	Please AC;
}


Measured memory_bytes: 256
n = int(input())
lst = []
for i in range(n):
    xi, yi, hi = map(int, input().split())
    lst.append([xi, yi, hi])

lst.sort(reverse=True, key=lambda x: x[2])

for cx in range(101):
    for cy in range(101):
        h = -1
        for i in range(n):
            xi, yi, hi = lst[i]
            if h == -1:
                h = hi + abs(xi-cx) + abs(yi-cy)
                continue
            if hi != max(h - abs(xi-cx) - abs(yi-cy), 0):
                h = -1
                break
        if h != -1:
            print(cx, cy, h)
            exit()

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

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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
	const int N = (int)1e5;
	vector<bool> isP(N, true);
    isP[0] = isP[1] = false;
	for(int i = 2; i * i < N; i++) if(isP[i]) for(int j = i; i * j < N; j++) isP[i * j] = false;

    vi primes;
    rep(i, N) if(isP[i]) primes.pb(i);

    for(int m, a, b, p, q; cin >> m >> a >> b, m; cout << p << " " << q << endl){
        p = 0; q = 0;
        rep(i, primes.size()){
            range(j, i, primes.size()){
                if(m < (ll)primes[i] * primes[j]) break;
                if((double)a / b <= (double)primes[i] / primes[j] && (double)primes[i] / primes[j] <= 1 && 
                    p * q <= (ll)primes[i] * primes[j] && (ll)primes[i] * primes[j] <= m){
                    p = primes[i]; q = primes[j];
                }
            }
        }
    }

	return 0;
}

Measured memory_bytes: 1336
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
#include <list>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n,l;cin>>n>>l;
    vector<string> s(n);
    rep(i,0,n)cin>>s[i];
    sort(s.begin(),s.end());
    string ans;
    rep(i,0,n){
        ans+=s[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
-- List of Top 3 Hills
import Control.Monad  -- replicateM
import Data.Ord       -- sortBy (comparing Down)
import Data.List      -- intercalate

main =
  replicateM 10 getLine >>= putStr . unlines . map show . solve

solve :: [String] -> [Int]
solve = take 3 . sortBy (comparing Down) . map read

-- import Control.Monad
-- replicateM :: Monad m => Int -> m a -> m [a]
-- perform the action n times, gathering the results

Measured memory_bytes: 3640
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve());
        Console.Out.Flush();
    }

    static object Solve() {
        var input = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
        int N = input[0], K = input[1];
        var l = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Array.Sort(l);
        var result = 0;
        for (int i = N - 1; i >= N - K; i--) {
            result += l[i];
        }
        return result;
    }
}

Measured memory_bytes: 27492
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const ll MAX_P = 2e5 + 1;

vector<ll> fact(MAX_P), factinv(MAX_P);

ll modpow(ll a,ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}


const int MAX = 2e5;
vector<int> G[MAX];
vector<ll> siz(MAX, 1), f(MAX, 1);
void dfs(int v, int p = -1) {
  for (int u: G[v]) {
    if (u == p) continue;
    dfs(u, v);
    siz[v] += siz[u];
  }
  f[0] = f[0] * siz[v] % mod;
}

int n;

void dfs2(int v, int p = -1) {
  for (int u: G[v]) {
    if (u == p) continue;
    f[u] = f[v] * (n - siz[u]) % mod * modpow(siz[u], mod - 2, mod) % mod;
    dfs2(u, v);
  }
}

int main() {
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(0);
  dfs2(0);
  ll ans = 1;
  FOR(i, 1, n + 1) ans = ans * i % mod;
  rep(i, n) cout << ans * modpow(f[i], mod - 2, mod) % mod << endl;

  




  
  return 0;
}

Measured memory_bytes: 20212
fun main() {
	val (n,k) = readLine()!!.split(" ").map {it.toInt()}
	val t = readLine()!!.split(" ").map {it.toInt()}
	val f = BooleanArray(n)
	for(i in 1..k) {
		val (a,b) = readLine()!!.split(" ").map {it.toInt()-1}
		f[a] = f[a]||t[a]<=t[b]
		f[b] = f[b]||t[b]<=t[a]
	}
	println(f.count {!it})
}


Measured memory_bytes: 62348
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


H, W = list(map(int, sys.stdin.buffer.readline().split()))
A = [list(sys.stdin.buffer.readline().decode().rstrip()) for _ in range(H)]

S = []
for a in A:
    S += a
counts = Counter(S)


def solve(counts, H, W):
    if H & 1 and W & 1:
        for c in string.ascii_lowercase:
            if counts[c] & 1:
                counts[c] -= 1
                break
        for c in string.ascii_lowercase:
            if counts[c] & 1:
                return False

        cnt = (H + W - 2) // 2
        for c in string.ascii_lowercase:
            if counts[c] % 4:
                counts[c] -= 2
                cnt -= 1
            if cnt < 0:
                return False

    if H & 1 or W & 1:
        if W & 1:
            H, W = W, H
        assert H & 1 == 1

        cnt = W // 2
        for c in string.ascii_lowercase:
            if counts[c] % 4:
                counts[c] -= 2
                cnt -= 1
            if cnt < 0:
                return False

    for c in string.ascii_lowercase:
        if counts[c] % 4:
            return False
    return True


ok = solve(counts, H, W)
if ok:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 23620
#include<stdio.h>

int main(void)
{
  int N,f[2],i,C,x,u;
  char c[3];

  for(;scanf("%d\n",&N),N;){
    for(i=f[0]=f[1]=C=u=0;i<N;i++){
      scanf("%s",c);
      x=c[0]=='r'?0:1;
      if(c[1]=='u'){
        f[x]=1;
        if(f[0]==1&&f[1]==1&&!u){
          u=1;++C;
        }
      } else {
        f[x]=0;
        if(f[0]==0&&f[1]==0&&u){u=0;++C;};
      }
    }
    printf("%d\n",C);
  }

  return 0;
}


Measured memory_bytes: 608
while True:
    n, k = [int(i) for i in input().split()]
    if n == 0 and k == 0:
        break
    a = [int(input()) for i in range(n)]
    s = sum(a[0:k])
    max = s
    for i in range(k, n):
        s = s + a[i] - a[i - k]
        if s > max:
            max = s
    print(max)


Measured memory_bytes: 9888