akhauriyash/Code-Regression huggingface dataset:
res = []
def f(l):
    n = len(l)
    for i in range(n)[::-1]:
            if l[i] == i:
                res.append(i+1)
                l.pop(i)
                break
    return l

N = int(input())
a = [int(_)-1 for _ in input().split()]

for i in range(N):
    f(a)
if len(res) == N:
    for i in range(N)[::-1]:
        print(res[i])
else:
    print(-1)
        

Measured memory_bytes: 3060
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string as = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string ab = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

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



int main() {

  int n;
  cin >> n;

  for(int i=1; i<10; ++i) {
    if(n>=i&&n%i==0) {
      if(n/i<10) {
        yes();
        return 0;
      }
    }
  }

  no();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <limits>
#include <cmath>
#include <cfloat>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

using namespace std;

int w,n;
int val[2000], wg[2000];
int dp[2000]; //[wg] <= val


pair<int, int> solve()
{
	pair<int, int> p = make_pair<int,int>(0, 0);
	CLR(dp);
	
	FOR(j, 0, n)
	{
		RFOR(i, 0, w+1)
		{
			if(( i == 0 || dp[i] != 0)&&( i+wg[j] <= w))
			{
				dp[i+wg[j]] = max(dp[i+wg[j]], dp[i]+val[j]);
			}
		}
	}
	
	FOR(i, 0, w+1)
	{
		if( p.first < dp[i])
		{
			p.first = dp[i];
			p.second = i;
		}
	}
	
	return p;
	
}

int main()
{
	int c = 1;
	pair<int, int> q;
	char p;
	
	while(cin >> w, w)
	{
		cin >> n;
		
		FOR(i, 0, n)
		{
			cin >> val[i] >> p >> wg[i];
		}	
		
		solve();
		
		cout << "Case " << c << ":" << endl;
		c++;
		
		q = solve();
		
		cout << q.first << endl << q.second << endl;
		
	}
	
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    string s[n];
    rep(i, 0, n) cin >> s[i];

    int char_cnt[26];
    rep(i, 0, 26) char_cnt[i] = 1000000000;

    rep(i, 0, n)
    {
        int char_cnt_now[26] = {};
        rep(j, 0, s[i].size())
            char_cnt_now[s[i][j] - 'a']++;
        
        rep(j, 0, 26)
            char_cnt[j] = min(char_cnt[j], char_cnt_now[j]);
    }
    rep(i, 0, 26)
    rep(j, 0, char_cnt[i])
        putchar('a' + i);
    cout << endl;
    return 0;
}

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

int main(void) {
    int W,a,b;
    cin>>W>>a>>b;
    if (a > b) swap(a, b);
    int result = b - (a + W);
    if (result <= 0) cout << 0 << endl;
    else cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
long long toInt(string str){
  stringstream ss;
  ss<<str;
  long long ret;
  ss>>ret;
  return ret;
}
int main(void){
  long long ans = 0;
  string line;
  while(cin>>line){
    for(int i=0;i<line.size();i++){
      if(line[i]>='0'&&line[i]<='9'){
        for(int j=i;j<line.size();j++){
          if(line[j]<'0'||line[j]>'9'||j==line.size()-1){
            ans+=toInt(line.substr(i,j-i+1));
            i=j;
            break;
          }
        }
      }
    }      
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    for (int i = 0; i < n * 2; i++) {
        if (i * 108 / 100 == n) {
            cout << i << endl;
            exit(0);
        }
    }

    cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var q = o.a();
  var a = Array(1e5+1).fill(1);
  var b = [0,0];
  a[0] = a[1] = 0;
  for(var i = 2; i <= 1e5; i++){
    if(a[i]){
      for(var j = i+i; j <= 1e5; j += i){
        a[j] = 0;
      }
      if(a[(i+1)/2])b[i] = b[i-1] + 1;
      else b[i] = b[i-1];
    }else b[i] = b[i-1];
  }
  var ans = [];
  for(i = 0; i < q; i++){
    var t = o.l();
    ans[i] = b[t[1]] - b[t[0]-1];
  }
  return ans.join("\n");
}

Measured memory_bytes: 32912
#include<iostream>
#include "string"

using namespace std;
int N,M,K,w[100],v[100],start;
bool point[301][301],link[301][301],ans;
string S;
int abs(int x){
	if(x<0){
		return -x;
	}
	return x;
}

int min(int x,int y){
	if(x<y)return x;
	return y;
}
int max(int x,int y){
	if(x>y)return x;
	
	return y;
}

int main(){
	cin >>N>>M>>K;
	ans=false;

	if(K%N==0||K%M==0){
		ans=true;
	}else{

		for(int i=1;i<=M;i++){
			start=(N*i);
			for(int j=1;j<=N;j++){
				start-=i;
				start+=(M-i);
				if(start==K){
					ans=true;
				}
			}
	}
	}

	if(ans==true){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 1000000
int p[N+1];
void era(void){
	int i,j;
	for(i=2;i<N;i++){
		p[i]=1;
	}
	for(i=2;i*i<=N;i++){
		if(p[i]){
			for(j=2*i;j<=N;j=j+i){
				p[j]=0;
			}
		}
	}
}
int main(void){
	int n,ans,i;
	era();
	while(1){
		scanf("%d",&n);
		if(!n)
			break;
		ans=0;
		for(i=3;i<=n/2;i++){
			if(p[i]&&p[n-i])
				ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4504
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
using namespace std;

int main (void) {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int ans=0;
  int l=min(B,D);
  int r=max(A,C);
  cout << max(l-r,0);
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;

int main() 
{
	int c(0);
	int n;
	while(cin >> n , !(n==0))
	{
		if(c!=0){	cout << endl;}
		c++;
		
		int a[4];
		int b[4];
		cin >> a[0] >> a[1] >> a[2] >> a[3] ;
		
		int f = a[0] + a[1] + a[2] + a[3];
		
		int ans = 100000;
		
		for(int i=0;i<a[3]+1;i++)
		{
			for(int j=0;j<a[2]+1;j++)
			{
				for(int k=0;k<a[1]+1;k++)
				{
					for(int l=0;l<a[0]+1;l++)
					{
						if(-(n - i*500 - j*100 - k*50 - l*10)>=0){
						int out = (i+j+k+l);
						int otsuri = -(n - i*500 - j*100 - k*50 - l*10);
						int in = otsuri/500;
						in += (otsuri%500)/100;
						in += ((otsuri%500)%100)/50;
						in += (((otsuri%500)%100)%50)/10;
						
						if(ans > (f - out + in))
						{
							ans = f - out + in;
							b[0] = l;
							b[1] = k;
							b[2] = j;
							b[3] = i;
						}}
					}
				}
			}
		}
		if(b[0]!=0){cout << "10 " << b[0] << endl;}
		if(b[1]!=0){cout << "50 " << b[1] << endl;}
		if(b[2]!=0){cout << "100 " << b[2] << endl;}
		if(b[3]!=0){cout << "500 " << b[3] << endl;}

	}
	return 0 ;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cerr<<elem;}cerr<<endl;}

int main(){//解説参考. 二分探索.
	int n,k;
	cin>>n>>k;
	
	vi a(n);
	REP(i,n) cin>>a[i];
	
	int l=0,r=INF;
	while(r-l>1){//k以下となる最小の長さを見つける. r側が条件を満たす.
		int mid=(l+r)/2;
		debug(mid);
		
		llong cnt=0;
		REP(i,n) cnt+=(a[i]-1)/mid;
		
		if(cnt>k) l=mid;
		else r=mid;
	}
	
	cout<<r<<endl;
}

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

int n;
int a[200009];

main(){
	cin>>n;
	r(i,n)cin>>a[i];
	int l[n],r[n];

	r(i,n){
		l[i]=r[i]=a[i];
	}
	r(i,n-1)l[i+1]+=l[i];
	for(int i=n-1;i>0;i--)r[i-1]+=r[i];

	int sum= min(abs(r[0]-0),abs(l[n-1]-0));
	for(int i=0;i<n-1;i++){
		sum=min(sum,abs(l[i]-r[i+1]));
	}
	cout<<sum<<endl;
}



Measured memory_bytes: 4992
L, R = map(int, input().split())
R = min(L+2019, R)
ans = 2019
Flag = False

for i in range(L, R):
    for j in range(i+1, R+1):
        x = (i * j) % 2019
        ans = min(ans, x)
        if ans == 0:
            Flag = True
            break
    if Flag:
        break

print(ans)

Measured memory_bytes: 3064
## coding: UTF-8
N = int(input())
S = input()
#s = []
#print(N)
#print(S)

#自分の手前までで左を向いている人の累積和リストをとりあえず作ってみる
sum_up_W = []
counter = 0
for i in range(N):
    sum_up_W.append(counter)
    if(S[i] == 'W'):
        counter += 1    
sum_up_W.append(counter) #最後にcounterを足さないと右端の人の影響が出ない。
#print(sum_up_W)
#右Eに振り向かせたいのはsum_up_W[i]
#リーダーより右で左を向いている人数はsum_up_W[N](全体で左を向いている人数)-sum_up_W[i+1](リーダーも含め、リーダーまでで左を向いている人数)
#左Wに振り向かせたいのは、リーダーより右で右を向いている人数： N-(i+1)（リーダーより右の全人数） - 上行の人数（リーダーより右で左を向いている人数）

ans = []
for i in range(N):
    ans.append(sum_up_W[i] + N - (i+1) - (sum_up_W[N] - sum_up_W[i+1])    )
print(min(ans))
'''
#これでもTLEします
#まず右（E）を向いている人を1、左（W）を向いている人を0に変換する
for i in range(len(S)):
    if(S[i] == 'E'):
        s.append(1)
    else:
        s.append(0)
#print(s)

#その地点までで左(W)を向いている人数を累積和するリストを作ります。要は右に振り向かせる人数リスト
E_count = []
#その地点から先で右(E)を向いている人数を累積和するリストを作ります。要は左に振り向かせる人数リスト
#W_count = []
#ans = []
for i in range(len(s)):
    E_count.append(  len(s[:i]) - sum(s[:i])  +   sum(s[i+1:]))
    #W_count.append(  sum(s[i+1:])  )
    #ans.append( E_count[i] + W_count[i])
#print(min(ans))
#print(E_count)
#print(W_count)
#for i in range(len(s)):
    #ans.append(E_count[i] + W_count[i])
print(min(E_count))
'''
'''
#これでもTLEします
def count_tern_new(s, leader):
    counter = 0
    #leaderより小さい人は右に向かせる。 左を向いている人数　＝　人数-右を向いている人数
    counter += len(s[:leader]) - sum(s[:leader])
    #leaderより大きい人には左を向かせる。 右を向いている人数
    counter += sum(s[leader+1:])
    return counter

answer_list_new = []
for i in range(len(s)):
    answer_list_new.append(count_tern_new(s, i))
print(min(answer_list_new))
'''


'''
#これだとTLEします。
def count_tern(s, leader): #文字列とリーダーのインデックスを引数にとる
    counter = 0
    for i in range(leader):
        if(s[i] == 'W'):
            counter += 1            
            #print("tern to E, i = {}, counter = {}".format(i,counter))
    #print("leader:{}".format(leader))
    for j in range(leader+1, len(s)):
        if(s[j] == 'E'):
            counter += 1
            #print("tern to W, j = {}, counter = {}".format(j, counter))
    return counter

#answer = 1000
answer_list = []
for i in range(len(S)):
    answer_list.append(count_tern(S, i))

#for i in range(len(S)):
    #print(count_tern(S, i))
    #print()
    #if(count_tern(S, i) < answer):
        #answer = count_tern(S, i)

print(min(answer_list))
'''

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

using namespace std;

int main()
{
   string st; cin>>st;
   int ret = 0;
   for(int i=0;i+1<st.size();++i){
       if(st[i]!=st[i+1])ret++;
   }
   cout<<ret<<"\n";
   
   return 0;
}

Measured memory_bytes: 512
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef unsigned long ul;
const ul INF = 1LL<<60;
long N,i,c1,c2,ans;
vector<long> A,B,C;
inline void solve(){
  IN(N);
  A.resize(N);
  B.resize(N);
  C.resize(N);
  INS(i,N,A);sort(ALL(A));
  INS(i,N,B);sort(ALL(B));
  INS(i,N,C);sort(ALL(C));
  REP(i,N){
    c1=upper_bound(ALL(A),B[i]-1)-A.begin();
    c2=N-(lower_bound(ALL(C),B[i]+1)-C.begin());
    ans+=c1*c2;
    // cout<<c1<<" "<<c2<<" "<<ans<<endl;
  }
  OUT(ans);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 2560
#include <iostream>
#include <map>
using namespace std;
typedef map<char, string> A;
typedef map<string, char> B;

int main() {
  int p, q, l;
  string s, t, u;
  bool f;
  A a;
  B b;
  const char letters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
  const char *code1[]={
    "00000","00001","00010","00011","00100","00101","00110","00111",
    "01000","01001","01010","01011","01100","01101","01110","01111",
    "10000","10001","10010","10011","10100","10101","10110","10111",
    "11000","11001","11010","11011","11100","11101","11110","11111",
  };
  const char *code2[]={
    "100101","10011010","0101","0001","110","01001","10011011","010000",
    "0111","10011000","0110","00100","10011001","10011110","00101","111",
    "10011111","1000","00110","00111","10011100","10011101","000010","10010010",
    "10010011","10010000","101","010001","000011","10010001","000000","000001",
  };

  for (int i=0; i<32; i++) {
    a.insert(A::value_type(letters[i], string(code1[i])));
  }
  for (int i=0; i<32; i++) {
    b.insert(B::value_type(string(code2[i]), letters[i]));
  }

  while (getline(cin, s)) {
    t.clear();
    l = s.length();
    for (int i=0; i<l; i++) {
      t += a[s[i]];
    }
    f = false;
    p = 0;
    l = t.length();
    while (1) {
      q = 3;
      while (1) {
        u = t.substr(p, q);
        B::iterator it = b.find(u);
        if (it!=b.end()) {
          p += q;
          cout << it->second;
          break;
        }
        if (p+q>=l) {
          f = true;
          break;
        }
        q++;
      }
      if (f) break;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[100005], bad[100005];
int vis[100005], sz[100005];
void dfs(int x, int c)
{
    vis[x]= c;
    sz[c]++;
    for(int i=0; i<adj[x].size(); i++)
    {
        int y= adj[x][i];
        if(!vis[y])dfs(y, c);
    }
    return;
}
int main()
{
    int n, m, k, x, y;
    scanf("%d %d %d", &n, &m, &k);
    for(int i=0; i<m; i++)
    scanf("%d %d", &x, &y),
    adj[x].push_back(y),
    adj[y].push_back(x);
    for(int i=0; i<k; i++)
    scanf("%d %d", &x, &y),
    bad[x].push_back(y),
    bad[y].push_back(x);
    int g= 0;
    for(int i=1; i<=n; i++)
    if(!vis[i])dfs(i, ++g);
    for(int i=1; i<=n; i++)
    {
        x= sz[ vis[i] ]-1-adj[i].size();
        for(int j=0; j<bad[i].size(); j++)
        {
            y= bad[i][j];
            if(vis[y]==vis[i])x--;
        }
        printf("%d ", x);
    }puts("");
    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

const ll NONE = -1000;
ll Y, X, K;
string s[11];
ll gid[11];
ll sum[11];

signed main() {
  cin >> Y >> X >> K;
  rep(y, Y) {
    cin >> s[y];
  }
  ll ans = 1e10;
  rep(bit, ((ll)1) << (Y-1)) {
    bool validBit = true;
    ll t = 0;
    // cout << "bit = " << bit << endl;
    ll g = 0;
    rep(y, Y) {
      gid[y] = g;
      if ((bit>>y) & 1) {
        g++;
        t++;
      }
      // printf("gid[%ld]=%ld\n", y, gid[y]);
    }

    ll l = -1, r = -1;
    while(l <= X-2) {
      ll nextR = NONE;

      rep(i, 11)
        sum[i]=0;
      while (r+1 <= X-1 && nextR == NONE) {
        rep(y, Y) {
          ll g = gid[y];
          sum[g] += (s[y][r+1] - '0');
          if (sum[g] > K) {
            nextR = r;
          }
        }
        r++;
      }

      if (l == nextR) {
        validBit=false;
        break;
      }
      if (nextR == NONE || nextR < 0 || nextR > X-2) {
        break;
      }
      // cout << "nextR = " << nextR << endl;
      l = nextR;
      r = l;
      t++;
    }
    if (validBit)
      chmin(ans, t);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/* 
   AOJ 2197
   Sum of Consecutive Integers
   2015.4.26
 */

#include<stdio.h>

int search_ans(int num)
{
  int i, j, sum = 0, count = 0;
  for(i = 1; i < num; i++)
    {
      sum = 0;
      for(j = i; sum < num; j++)
	{
	  sum += j;
	  if(sum == num)
	    {
	      count++;
	    }
	}
    }
  
  return count;

}

int main(void)
{
  int num, ans;
  while(1)
    {
      scanf("%d", &num);
      if(num == 0)
	{
	  break;
	}
      ans = search_ans(num);
      printf("%d\n", ans);
    }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

const int maxh = 10000 + 2;
const int maxn = 1000 + 2;
int dp[maxh][maxn];
int a[maxn],b[maxn];
int main(){
    int h,n;
    cin >> h >> n;
    for (int i = 1;i <= h;i++) dp[i][0] = 1e9 + 7;
    for (int i = 1;i <= n;i++) cin >> a[i] >> b[i];
    for (int i = 1;i <= h;i++){
        for (int j = 1;j <= n;j++){
            dp[i][j] = min(dp[i][j - 1],dp[max(0,i - a[j])][j] + b[j]);
//            cout << i << ' ' << j << ' ' << dp[i][j] << endl;
        }
    }
    cout << dp[h][n] << endl;

    return 0;
}


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

int main(){
    int N;
    long long ans = 0;
    cin >> N;
    int A[N];
    for (int i=0; i<N; i++){
        cin >> A[i];
        ans += A[i];
    }

    cout << ans-N << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
 int a,b,c,needa,needb,money=0,minneed;
 scanf("%d %d %d %d %d",&a,&b,&c,&needa,&needb);
 if(2*c<(a+b)){
       minneed=(needa>needb)?needb:needa;
       needa-=minneed;
      needb-=minneed;
      money+=minneed*c*2;
        
  }
if(needa>0){
           if(2*c<a){
                  money+=2*c*needa;
              }
            else{
               money+=(a*needa);
    
             }
needa=0;
  }
if(needb>0){
           if(2*c<b){
                  money+=2*c*needb;
              }
            else{
               money+=b*needb;
             }
needb=0;
  }
printf("%d",money);
 return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    double[] numbers = new double[n];
    double sum = 0;
      for(int i = 0; i<n; i++){
        numbers[i] = 1.0/stdIn.nextInt();
        sum += numbers[i];
      }
    System.out.println(1/sum);
    stdIn.close();
  }
}



Measured memory_bytes: 21972
#include <stdio.h>

int main(){
  int a[3];
  for(int i = 0; i < 3; i++){
    scanf("%1d", &a[i]);
    if(a[i] == 1){
      a[i] = 9;
    }else{
      a[i] = 1;
    }
  }
  printf("%d%d%d", a[0], a[1], a[2]);
  return 0;
}

Measured memory_bytes: 128
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/19/20 21:54:21
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename T, T MOD>
class modint {
 private:
  T val_;

 public:
  constexpr modint() : val_(0) {}
  constexpr modint(T v) : val_(v%MOD) {}
  constexpr modint& operator=(T v) { val_ = v%MOD; return *this; }

  constexpr T val() const { return val_; }
  constexpr modint operator+(modint x) const { return (val() + x.val())%MOD; }
  constexpr modint operator+=(modint x) { return *this = *this + x; }
  constexpr modint operator++() { return *this += 1; }
  constexpr modint operator++(int) { modint c = *this; ++(*this); return c; }
  constexpr modint operator-(modint x) const { return (val() + MOD - x.val())%MOD; }
  constexpr modint operator-=(modint x) { return *this = *this - x; }
  constexpr modint operator--() { return *this -= 1; }
  constexpr modint operator--(int) { modint c = *this; --(*this); return c; }
  constexpr modint operator*(modint x) const { return (val() * x.val())%MOD; }
  constexpr modint operator*=(modint x) { return *this = *this * x; }
  friend constexpr modint pow(modint x, T p) {
    modint t = 1;
    modint u = x;
    while (p) {
      if (p & 1)
        t *= u;
      u *= u;
      p >>= 1;
    }
    return t;
  }
  constexpr modint operator/(modint x) const { return *this * pow(modint{x}, MOD-2); }
  constexpr modint operator/=(modint x) { return *this = *this / x; }

  constexpr bool operator==(modint x) const { return val() == x.val(); }
  constexpr bool operator!=(modint x) const { return val() != x.val(); }
  constexpr bool operator<(modint x) const { return val() < x.val(); };
  constexpr bool operator<=(modint x) const { return val() <= x.val(); };
  constexpr bool operator>(modint x) const { return val() > x.val(); };
  constexpr bool operator>=(modint x) const { return val() >= x.val(); };

  friend std::ostream& operator<<(std::ostream& os, const modint& x) {
    return os << x.val();
  }
  friend std::istream& operator>>(std::istream& is, modint& x) {
    return is >> x.val_;
  }

};

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

  using mint = modint<unsigned long long, (unsigned long long)1e9+7>;
  int n,k; cin>>n>>k;
  mint ans = 0;
  for (ll kk = k; kk <= n+1; kk++) {
    ans += n-kk+2;
    ans += mint(n-kk+1)*(kk-1);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3648
while True:
    H,W = map (int,input().split())   

    if H == 0 and W == 0:
        break

    else:
        for h_size in range(H):
            for w_size in range(W): 
                if h_size%2 == 0:
                    if w_size%2 == 0:
                        print("#",end="")
                    else:
                        print(".",end="")
                elif h_size%2 == 1:
                    if w_size%2 == 1:
                        print("#",end="")
                    else:
                        print(".",end="")                    


            print("")
        print("")


Measured memory_bytes: 7016
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


signed main(void) 
{
    ll n;
    cin >>n;
    ll r = 0;
    map <string, ll> m;
    string s;
    vs v;
    rep (i, n) {
        cin >>s;
        m[s]++;
    }
    for(auto i: m) {
        r = max(r, i.second);
    }

    for(auto i: m) {
        if(r == i.second) {
            v.pb(i.first);
        }
    }
    Sort(v);
    for(auto i: v) {
        cout <<i <<endl;
    }
    
   
}


Measured memory_bytes: 27200
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
///////////////////////////////////////

int main() {
	int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vector<int>r(A), g(B), n(C);
	REP(i, A)cin >> r[i];
	REP(i, B)cin >> g[i];
	REP(i, C)cin >> n[i];
	sort(r.begin(), r.end(), greater<int>());
	sort(g.begin(), g.end(), greater<int>());
	vector<int>key;
	REP(i, X)key.push_back(r[i]);
	REP(i, Y)key.push_back(g[i]);
	REP(i, C)key.push_back(n[i]);
	sort(key.begin(), key.end(), greater<int>());
	ll ans = 0;
	REP(i, X + Y) {
		ans += key[i];
	}
	cout << ans << endl;
	return 0;
}


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

const int INF = 1 << 28;

int n;
int memo[101][101];
int r[102];

int dfs(int i, int j){
    int res = INF;
    
    if(memo[i][j] != -1) return memo[i][j];
    
    if(i == j){
        return 0;
    }
    
    for(int k = i; k < j; ++k){
        res = min(res, dfs(i,k) + dfs(k + 1, j) + r[i] * r[k + 1] * r[j + 1]);    
    }
    
    return memo[i][j] = res;
}


int main()
{

    cin >> n;
    fill((int*)memo, (int*)(memo + n), -1);
    for(int i = 0; i < n; ++i){
        cin >> r[i] >> r[i + 1];
    }
    
    cout << dfs(0, n-1) << endl;
    
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
int main() {
	int k;
	long long res=0;
	cin>>k;
	for(int i=1;i<=k;++i)
		for(int j=1;j<=k;j++)
			for(int o=1;o<=k;o++)
				res+=__gcd(__gcd(i,j),o);
	cout<<res;
	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int m, f, r;
	int s;

	while (1) {
		scanf("%d%d%d", &m, &f, &r);
		if (m == -1 && f == -1 && r == -1) break;

		if (m < 0 || f < 0) puts("F");
		else {
			s = m + f;
			if (s >= 80) puts("A");
			else if (s >= 65) puts("B");
			else if (s >= 50) puts("C");
			else if (s < 30) puts("F");
			else puts(r >= 50 ? "C" : "D");
		}
	}
	return 0;
}


Measured memory_bytes: 2052
import sys
from collections import deque


def bfs(x1, y1, d):
    q = deque([])
    q.append((d, x1, y1))
    M[x1][y1] = d

    while q:
        d, x1, y1 = q.popleft()

        if [x1, y1] == [xg, yg]:
            print(d)
            return

        for dx, dy in ((0, 1), (1, 0), (0, -1), (-1, 0)):
            for k in range(1, K + 1):
                x2 = x1 + dx * k
                y2 = y1 + dy * k
                if x2 < 0 or x2 >= H:  # 枠外
                    break
                if y2 < 0 or y2 >= W:  # 枠外
                    break
                if m[x2][y2] == '@':  # 蓮の葉
                    break
                if M[x2][y2] < d + 1:  # より良い経路を探索済み。
                    break
                if M[x2][y2] == d + 1:  # 同等の良さの経路を探索済み。　飛び越えて次のマスを探索する。
                    continue

                q.append((d + 1, x2, y2))
                M[x2][y2] = d + 1

    print(-1)


H, W, K = map(int, sys.stdin.readline().strip().split())
xs, ys, xg, yg = map(int, sys.stdin.readline().strip().split())
xg -= 1
yg -= 1

m = []
for _ in range(H):
    m.append(list(map(str, sys.stdin.readline().strip())))

M = [[float('inf')] * W for _ in range(H)]

bfs(xs - 1, ys - 1, 0)


Measured memory_bytes: 45164
#include<stdio.h>



int main(void){
	int n,m,i,j,d[1000],c[1000],min[1001][1001];
	scanf("%d%d",&n,&m);
	for(i=0; i<n; i++){
		scanf("%d",&d[i]);
	}
	for(i=0; i<m; i++){
		scanf("%d",&c[i]);
	}
	for(i=0; i<=n; i++){
		for(j=0; j<=m; j++){
			min[i][j]=-1;
		}
	}
	min[0][0]=0;
	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(min[i][j]!=-1){
				if(min[i+1][j+1]==-1){
					min[i+1][j+1]=min[i][j]+d[i]*c[j];
				}else{
					min[i+1][j+1]=(min[i+1][j+1]<min[i][j]+d[i]*c[i])?min[i+1][j+1]:min[i][j]+d[i]*c[i];
				}
				if(min[i][j+1]==-1){
					min[i][j+1]=min[i][j];
				}else{
					min[i][j+1]=(min[i][j]<min[i][j+1])?min[i][j]:min[i][j+1];
				}
			}
		}
	}
	j=min[n][n];
	for(i=n+1; i<=m; i++){
		j=(j<min[n][i])?j:min[n][i];
	}
	printf("%d\n",j);
	return 0;
}

Measured memory_bytes: 3792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    ll n,m;
    cin >> n >> m;
    ll h[n];
    bool H[n] = {};
    for(ll i = 0;i < n;i++)
    {
        cin >> h[i];
    }
    for(ll i = 0;i < m;i++)
    {
        ll a,b;
        cin >> a >> b;
        if(h[a - 1] > h[b - 1])
        {
            H[b - 1] = true;
        }
        else if(h[a - 1] < h[b - 1])
        {
            H[a - 1] = true;
        }
        else
        {
            H[a - 1] = true;
            H[b - 1] = true;
        }
    }
    ll ans = 0;
    for(ll i = 0;i < n;i++)
    {
        if(!H[i])
        {
            ans++;
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 4504
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
const int maxn = 100005;
int R, C, N, n;
pair<int,int> v[maxn << 1];
stack<int> S;
int trans(int x, int y) {
	if(x == 0) return y;
	if(y == C) return C + x;
	if(x == R) return C + R + C - y;
	if(y == 0) return C + R + C + R - x;
	return -1;
}
int main() {
	scanf("%d%d%d", &R, &C, &N);
	for(int i = 1, x1, x2, y1, y2; i <= N; ++i) {
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		int t1 = trans(x1, y1), t2 = trans(x2, y2);
		if(t1 == -1 || t2 == -1) continue;
		if(t1 > t2) swap(t1, t2);
		v[++n] = make_pair(t1, i);
		v[++n] = make_pair(t2, -i);
	}
	sort(v + 1, v + n + 1);
	for(int i = 1; i <= n; ++i) {
		if(v[i].second > 0) S.push(v[i].second);
		else {
			if(-v[i].second != S.top()) {
				puts("NO"); return 0;
			} S.pop();
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void initialize();
int isEmpty();
int isFull();
void push(int x);
int pop();

int top;
int s[101];

int main()
{
  char x;
  int n;
  int i,j;
  int count=0;
  int sum=0;

  initialize();

  while(scanf("%c",&x) != EOF){
    switch(x){

    case' ':
      sum = 0;
      if(count > 1){
	for(i=0; i<count; i++){
	  n = 1;
	  for(j=1; j<=i; j++){
	    n *= 10;
	  }
	  sum += pop()*n;
	}
	push(sum);
      }
      count = 0;
      break;
 
    case'+':
      push(pop() + pop());
      break;
    
    case'-':
      n = pop();
      push(pop() - n);
      break;

    case'*':
      push(pop() * pop());
      break;

    case'\n':
      printf("%d\n",s[top]);
      exit(0);
      break;

    default:
      push(atoi(&x));
      count++;
      break;
    }
  }
  
    return 0;
}

void initialize(){
  top = 0;
}

int isEmpty(){
  return top == 0;
}

int isFull(){
  return top >= 100;
}

  
void push(int x){
  if(isFull()){
    exit(0);
  }
  top++;
  s[top] = x;
} 

int pop(){
  if(isEmpty()){
    exit(1);
  }
  top--;
  return s[top+1];
}



Measured memory_bytes: 2144
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

const int lim = 8;
int n,m;
bool G[lim][lim], visited[lim];

int dfs(int v){
  bool done = true;
  rep(i,n) if(!visited[i]) done=false;
  if(done) return 1;

  int ret = 0;
  rep(i,n){
    if(!G[v][i] || visited[i]) continue;
    visited[i] = true;
    ret += dfs(i);
    visited[i] = false;
  }
  return ret;
}

signed main(){
	cin>>n>>m;
  rep(i,m){
    int a,b; cin>>a>>b; a--; b--;
    G[a][b] = G[b][a] = true;
  }
  rep(i,n) visited[i] = false;
  visited[0] = true;
  cout << dfs(0) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long 
#define int long long 
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define MAX 1e18
#define PI 3.14159265
const int mod = 1e9 + 7;

int power(int x, int y) 
{ 
   int res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x); 
  
 
        y = y>>1; 
 
        if (x<=100000000)
        x = (long long)(x*x);
 
        //cout<<x<<'\n'; 
    } 
    return res; 
} 

void solve()
{
    int n;
    cin>>n;
    string s=" ";
    string ans="zabcdefghijklmnopqrstuvwxy";
    int x=26;
   while(n!=0){
    s=ans[n%x]+s;
    n=(n-1)/x;
}


cout<<s<<endl;
return;


}

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

Measured memory_bytes: 3640
#include<iostream>
#include<string>

using namespace std;

int main() {
	string a,e;
	int i,d[26];
	for (i = 0; i < 26; i++) {
		d[i] = 0;
	}
	char b;
	while (1) {
		getline(cin, e);
		a += e;
		if (e == "") {
			break;
		}
	}
	string::iterator s;
	for (s = a.begin(); s != a.end(); s++) {
		*s = tolower(*s);
	}
	for (i = 0; i < 26; i++) {
		for (s = a.begin(); s != a.end(); s++) {
			b = 97 + i;
			if (*s == b) {
				d[i] += 1;
			}
		}
	}
	for (i = 0; i < 26; i++) {
		b = 97 + i;
		cout << b << " : " << d[i] << endl;
	}
	return 0;
}

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

static const int MAX = 100;
static const int INF = (1<<30);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

int prim(){
  int u,minv,ii,vv;
  int d[MAX],p[MAX],color[MAX];

  //cout << "prim" << endl;
  //条件初期化
  for(ii=0;ii<n;ii++){
    d[ii] = INF;
    p[ii] = -1;
    color[ii] = WHITE;
  }

  d[0] = 0;

  while(1){

    minv = INF;
    u = -1;

    //起点の決定
    for(ii=0;ii<n;ii++){
      if(minv > d[ii] && color[ii] != BLACK){
        //cout << "ii:" << ii << endl;
        u = ii;
        minv = d[ii];
      }
    }

    if(u == -1){
      break;
    }

    //起点を探索済みに
    color[u] = BLACK;

    for(vv=0;vv<n;vv++){
      //未探索かつパスの繋っている位置
      if(color[vv] != BLACK && M[u][vv] != INF){
        if( d[vv] > M[u][vv]){
          d[vv] = M[u][vv];
          p[vv] = u;
          color[vv] = GRAY;
        }
      }
    }
  }

  int sum = 0;
  for(ii=0;ii<n;ii++){
    if(p[ii] != -1){
      sum += M[ii][p[ii]];
    }
  }
  
  return sum;
  
}

int main(){
  cin >> n;
  int ii,jj;

  for(ii=0;ii<n;ii++){
    for(jj=0;jj<n;jj++){
      int cost;
      cin >> cost;

      if(cost == -1){
        M[ii][jj] = INF;
      }
      else{
        M[ii][jj] = cost;
      }
    }
  }

  cout << prim() << endl;
  
}



Measured memory_bytes: 3120
#include <stdio.h>
#include <inttypes.h>

int N;
int A[200000];

uint64_t memo[200000][2];

uint64_t search(int pos, int aru) {
	uint64_t ret = 0;
	uint64_t candidate;
	if (pos >= N) return 0;
	if (memo[pos][aru]) return ~memo[pos][aru];
	/* 残す(あるのを使わない) */
	if (A[pos] > 0) {
		candidate = (A[pos] - 1) / 2;
		candidate += search(pos + 1, 1);
		if (candidate > ret) ret = candidate;
	}
	/* 残さない (あるのを使わない) */
	if (A[pos] % 2 == 0) { /* 奇数ならどうせ余るので捨てる道理は無い */
		candidate = A[pos] / 2;
		candidate += search(pos + 1, 0);
		if (candidate > ret) ret = candidate;
	}
	if (aru) {
		/* 残す (あるのを使う) */
		if (A[pos] >= 2) {
			candidate = A[pos] / 2;
			candidate += search(pos + 1, 1);
			if (candidate > ret) ret = candidate;
		}
		/* 残さない (あるのを使う) */
		if (A[pos] % 2 == 1) { /* 偶数で使うならどうせ余るので捨てる道理は無い */
			candidate = (A[pos] + 1) / 2;
			candidate += search(pos + 1, 0);
			if (candidate > ret) ret = candidate;
		}
	}
	return ~(memo[pos][aru] = ~ret);
}

int main(void) {
	int i;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
	}
	printf("%"PRIu64"\n", search(0, 0));
	return 0;
}

/*
1以下→同じか隣
隣のを2ペア以上→同じので組めばええやん
貪欲して問題が起こるか？→1残すか残さないかでDP

*/


Measured memory_bytes: 6784
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <functional>
using namespace std;
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#define	ll long long
#define	ull unsigned long long
#define	vi vector<int>
#define	vll vector<long long>
#define	pii pair<int,int>
#define	pll pair<long long,long long>
#define	PB push_back
#define	MP make_pair
#define	ff first
#define	ss second
#define	IT iterator
#define	IOS ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define	LB cout<<"\n"
#define	CS <<" "<<
#define	DB cout<<"> "
#define	endl "\n"
#define	loop(x,y) for(int x=0;x<y;++x)
#define	loop1(x,y) for(int x=1;x<=y;++x)
#define	MS(x,y) memset(x,y,sizeof(x))

int r,c;
int cnt;
int mn = INT_MAX;
char a[51][51];
int v[51][51];
queue<pair<pii,int> > q;

bool able(int x, int y){
	return (x>=0 && y>=0 && x<r && y<c && !v[x][y] && a[x][y]=='.');
}


int main(){
	cin >> r >> c;
	loop(i,r) loop(j,c){cin >> a[i][j]; if(a[i][j]=='#') ++cnt;}
	q.push({{0,0},1});

	while(!q.empty()){
		pair<pii,int> cur = q.front(); q.pop();
		if(cur.ff.ff==r-1 && cur.ff.ss==c-1){ mn = cur.ss; break;}

		if(v[cur.ff.ff][cur.ff.ss]++) continue;



		//DB << cur.ff.ff+1 CS cur.ff.ss << endl;
		if(able(cur.ff.ff+1,cur.ff.ss)) q.push({{cur.ff.ff+1,cur.ff.ss},cur.ss+1});
		//DB << cur.ff.ff-1 CS cur.ff.ss << endl;
		if(able(cur.ff.ff-1,cur.ff.ss)) q.push({{cur.ff.ff-1,cur.ff.ss},cur.ss+1});
		//DB << cur.ff.ff CS cur.ff.ss+1 << endl;
		if(able(cur.ff.ff,cur.ff.ss+1)) q.push({{cur.ff.ff,cur.ff.ss+1},cur.ss+1});
		//DB << cur.ff.ff CS cur.ff.ss-1 << endl;
		if(able(cur.ff.ff,cur.ff.ss-1)) q.push({{cur.ff.ff,cur.ff.ss-1},cur.ss+1});
	}

	if(mn == INT_MAX) cout << "-1\n";
	else cout << r*c - mn - cnt << endl;
}

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

int b[11]={3,5,7};
int ans=0;
set<int> c;

void permute(int t,int d,int h){
    int i,temp,n;
    if(h==d){
        for(i=0,n=0;i<d;i++)
            n=n*10+b[i];
        if(t>=n){
            c.insert(n);
        }
        return ;
    }
    for(i=h;i<d;i++){
        temp=b[i];b[i]=b[h];b[h]=temp;
        permute(t,d,h+1);
        temp=b[i];b[i]=b[h];b[h]=temp;
    }
}


void dfs(int t,int d){
    int n,j;
    int a[d];
    if(d>=10)
        return;
    for(j=0;j<d;j++)
        a[j]=b[j];
    sort(a,a+d);
    do{
        for(j=0,n=0;j<d;j++)
            n=n*10+a[j];
        if(t>=n)
            c.insert(n);
    }while(next_permutation(a,a+d));
    for(int i=0;i<3;i++){
        if(i==0) b[d]=3;
        if(i==1) b[d]=5;
        if(i==2) b[d]=7;
        dfs(t,d+1);
    }
}

int main(){
    int t,n;
    scanf("%d",&t);
    dfs(t,3);
    printf("%d",c.size());
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

int main() {
	string s;
	cin >> s;
	long long int sz = s.size();
	long long int sum = 0;
	sz--;
	long long int n = 1<<sz;
	for (long long int i = 0; i < n; i++) {
		long long int p = 0;
		//p = s[0]-'0';
		for (long long int j = 0; j < sz; j++) {
			p += s[j]-'0';
			if ((i&(1<<j)) != 0) {
				p *= 10;
			} else {
				//cout << p << ' ';
				sum += p;
				p = 0;
			}
		}
		//p *= 10;
		p += s[sz]-'0';
		//cout << p << endl;
		sum += p;
	}
	cout << sum << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  for (int i = 0; i < S.size() ; i++){
    S.at(i) += N;
    if(S.at(i)>'Z')
      S.at(i) -= 26;
    }
  cout << S << endl;
}

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

int main()
{
  string s;cin>>s;
  int len=s.size();
  
  for (int i=0;i<len;i++)
  {
    if (i%2==0)
    {
      cout<<s[i];
    }
  }
  cout<<endl;
}

Measured memory_bytes: 512
using System;

class Program
{
    static void Main()
    {
        bool result = false;
        string[] str = Console.ReadLine().Split(' ');

        int W = int.Parse(str[0]);
        int H = int.Parse(str[1]);
        int x = int.Parse(str[2]);
        int y = int.Parse(str[3]);
        int r = int.Parse(str[4]);

        // Calculate and compared
        if ((x - r) >= 0 && (x + r) <= W && (y - r) >= 0 && (y + r) <= H)
        {
            // Change result
            result = true;
        }

        // Output
        if (result == true)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 8892
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


void solve(){
    int k, a, b; cin>>k>>a>>b;
    if(a%k==0){
        cout<<"OK";
        return;
    }
    int x = (a/k)*k+k;
    if(x <= b){
        cout<<"OK";
    }
    else{
        cout<<"NG";
    }
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}





Measured memory_bytes: 3636
N = int(input())
lst = []
for i in range(1, N + 1):
    S, P = input().split()
    lst.append((S, int(P), i))

lst = sorted(lst, key=lambda x: x[1], reverse=True)
lst = sorted(lst, key=lambda x: x[0])

for _, _, num in lst:
    print(num)

Measured memory_bytes: 3064