akhauriyash/Code-Regression huggingface dataset:
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n;
pair<int,int> a[100111];
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)geti(a[i].FF),a[i].SS=i;
	sort(a+1,a+n+1);
	int cnt0=0,cnt1=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i].SS%2!=i%2)
		{
			if(a[i].SS%2==0)cnt0++;
			else cnt1++;
		}
	}
	cout<<max(cnt0,cnt1)<<endl;
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int n, m, q;cin>>n>>m>>q;
  vector<vector<int>> cnt(n, vector<int>(n, 0));
  rep(i, m){
  	int l, r;cin>>l>>r;l--;r--;
    rep(j, l+1){
      cnt[j][r]++;
    }
  }
  rep(i, n){
  	rep(j, n-1){
      cnt[i][j+1]+=cnt[i][j];
    }
  }
  rep(i, q){
    int p, q;cin>>p>>q;p--;q--;
    cout<<cnt[p][q]<<endl;
  }
  return 0;
}



Measured memory_bytes: 1920
#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)

int m, k, a, d;
vector<string> g;

bool solve() {
  int x = k - 1;
  rep(y, d) {
    if(g[y][x]) x++;
    else if(x && g[y][x-1]) x--;
  }
  return x == a - 1;
}

int main() {

  while(cin >> m >> k >> a >> d && m) {
    g.clear(); g.resize(d);
    rep(i, d) cin >> g[i];
    rep(i, d) for(auto& e: g[i]) e -= '0';
    if(solve()) {
      cout << "0\n";
      goto next;
    }
    rep(i, d) rep(j, m - 1) {
      if(!g[i][j] && (j == 0 || !g[i][j-1]) && (j + 1 == m - 1 || !g[i][j+1])) {
        g[i][j] = 1;
        if(solve()) {
          cout << i + 1 << " " << j + 1 << endl;
          goto next;
        }
        g[i][j] = 0;
      }
    }
    cout << "1\n";
  next:;
  }
  
  return 0;
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int32_t main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ret=0;
    if(k>=a){
    	ret+=a;
    	k-=a;
    	if(k>=b){
    		k-=b;
    		ret-=k;
    	}
    }else{
    	ret+=k;
    }
    cout<<ret;
    return 0;
}



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

using namespace std;

class Dice //クラスのメンバの宣言はデフォルトでprivate
{
    int top;    //1
    int front;  //2
    int right;  //3
    int left;   //4
    int back;   //5
    int bottom; //6
public:
    void diceroll(char dir);
    Dice(int top, int front, int right, int left, int back, int bottom);
    void place_front(int q2);
    void if_front(int q1);
    void place_top(int q1);
    int show_right();
    bool is_same_dice(Dice d1);
};

void Dice ::diceroll(char dir)
{
    int tmp;
    switch (dir)
    {
    case 'E':
    {
        tmp = top;
        top = left;
        left = bottom;
        bottom = right;
        right = tmp;
        break;
    }
    case 'N':
    {
        tmp = top;
        top = front;
        front = bottom;
        bottom = back;
        back = tmp;
        break;
    }
    case 'S':
    {
        tmp = top;
        top = back;
        back = bottom;
        bottom = front;
        front = tmp;
        break;
    }
    case 'W':
    {
        tmp = top;
        top = right;
        right = bottom;
        bottom = left;
        left = tmp;
        break;
    }
    }
}

Dice ::Dice(int top, int front, int right, int left, int back, int bottom)
{
    this->top = top;
    this->front = front;
    this->right = right;
    this->left = left;
    this->back = back;
    this->bottom = bottom;
}

void Dice ::place_front(int q2)
{
    char direction[] = "NENEN";
    int i = 0;
    while (top != q2)
    {
        diceroll(direction[i]); //dicerollのNが無視される
        i++;
    }
    diceroll('S');
}

void Dice ::place_top(int q1)
{
    while (top != q1)
    {
        diceroll('W');
    }
}

void Dice ::if_front(int q1)
{
    if (top != q1)
    {
        place_top(q1);
    }
}

int Dice ::show_right()
{
    return right;
}

bool Dice ::is_same_dice(Dice d1)
{
    while (d1.front != this->front)
    {
        place_front(d1.front);
    }
    place_top(d1.top);

    return d1.right == this->right && d1.left == this->left && d1.back == this->back && d1.bottom == this->bottom;
}

int main()
{
    int top, front, right, left, back, bottom;
    cin >> top >> front >> right >> left >> back >> bottom;
    Dice d1(top, front, right, left, back, bottom);
    cin >> top >> front >> right >> left >> back >> bottom;
    Dice d2(top, front, right, left, back, bottom);

    if (d2.is_same_dice(d1))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3116
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;
    cin>>n;
    string s;cin>>s;
    int mm=0;
    
    for(int i=1;i<n-1;i++){
        int cnt=0;
        map<char,int>mp;
        for(int j=0;j<i;j++){
            if(mp[s[j]]>0)
                continue;
            char c=s[j];
            bool abc=false;
            for(int l=i;l<n;l++){
                if(s[l]==c)
                    abc=true;
            }
            if(abc==true){
                cnt++;
                mp[c]++;
            }
        }
        chmax(mm,cnt);
    }
    cout<<mm<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 892
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#define ll long long int
#define MOD 1000000007LL
using namespace std;
int main() {
    ll h,w,n;
    cin>>h>>w>>n;
    vector<pair<int,int>> p;
    int ans[11]={};
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if((a-j<1)||(a-j>h-2)||(b-k<1)||(b-k>w-2)){
                    continue;
                }
                p.push_back(pair<int,int>(a-j,b-k));
            }
        }
    }
    ll z=(h-2)*(w-2);
    sort(p.begin(),p.end());
    int c=1;
    int f=0;
    for(int i=1;i<(int)p.size();i++){
        f=1;
        if((p[i].first==p[i-1].first)&&(p[i].second==p[i-1].second)){
            c++;
        }else{
            ans[c]++;
            z--;
            c=1;
        }
    }
    if(f==1){
    ans[c]++;
    z--;
    }
    cout<<z<<endl;
    for(int i=1;i<=9;i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 10348
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int N = sc.nextInt();
   int[] a = new int[N];
   for(int i=0;i<N;i++) a[i]=sc.nextInt();
   
   int allsum = 0;
   int sumA = 0;
   
   Arrays.sort(a);
   for(int i=0;i<N;i++) allsum+=a[i];
   if(N%2==1)
   {
     for(int i=0;i<N;i+=2) sumA+=a[i];
   }
   else   
   {
     for(int i=1;i<N;i+=2) sumA+=a[i];
   }
   
   System.out.println(2*sumA-allsum);
 }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
   int n; cin >> n;
   vector<int> a(n);
   rep(i,n) cin >> a[i];
   vector<int> b(n + 1);

   int ans = -1;

    for (int i = 0; i <= n; ++i) {
        if(i == 0) {
            b[i + 1] = a[i];
        }else {
            b[i + 1] = a[b[i] - 1];
        }
        if(b[i + 1] == 2){
            ans = i + 1;
            break;
        }
    }
    print(ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios::sync_with_stdio(0),cin.tie(0);
int main()
{
	int N, M, X, Y,val,x=-200,y=200,z;
	cin >> N >> M >> X >> Y;
	while (N--)
	{
		cin >> val;
		x = max(val, x);
	}
	z = x + 1;
	while (M--)
	{
		cin >> val;
		y = min(val, y);
	}
	if (z <= y && z > X&&z <= Y)cout << "No War";
	else cout << "War";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	ll s;
	cin >> s;
	const ll v = 1e9;
	int y = (s + v - 1) / v;
	int x = v*y - s;
	cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
	return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m), ans(n, 0);
    for (int i = 0; i < m; i++) {
        cin >> a.at(i) >> b.at(i);
    }
    for (int i = 0; i < m; i++) {
        for (int j = 1; j <= n; j++) {
            if (a[i] == j || b[i] == j) {
                ans[j-1] += 1;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split(" "))

ac_flag = [0 for _ in range(N)]
wa = ac_flag.copy()

for i in range(M):

    question, result = input().split(" ")
    question = int(question)

    if not ac_flag[question-1] and result == 'WA':
        wa[question - 1] += 1
    
    if result == 'AC':
        ac_flag[question-1] = 1

wa = [x*y for x, y in zip(ac_flag, wa)]
print(sum(ac_flag), sum(x*y for x, y in zip(wa, ac_flag)))

Measured memory_bytes: 5540
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;
typedef pair<ll,ll>pl;

const int MAX_N = 40;

ll N,W;
ll v[MAX_N];
ll w[MAX_N];
vector<pl> x,y;

void func(int si,int ti,vector<pl> &x){
  int size=ti-si;
  rep(bit,1<<size){
    pl p=pl(0,0);
    rep(i,size){
      if(bit>>i&1){
        p.first+=w[si+i];
        p.second+=v[si+i];
      }
    }
    x.push_back(p);
  }
}
  
int main(){
  cin>>N>>W;
  rep(i,N){
  	cin>>v[i]>>w[i];
  }
 
  func(0,N/2,x);
  sort(x.begin(),x.end());
  func(N/2,N,y);
  sort(y.begin(),y.end());
    
  ll target=0,maxm=-(1LL<<60),ans=0;
    
  for(int i=x.size()-1;i>=0;i--){
    pl p=x[i];
    while(target<y.size() && p.first+y[target].first <=W ){
      maxm=max(maxm,y[target].second);
      target++;
    }
    ans=max(ans,maxm+p.second);
  }
  
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define SZ(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define pb			    push_back

typedef long long ll;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	int x;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		x--;
		v[x]++;
	}
	sort(all(v));
	int ans = 0;
	int len = n - k;
	for (int i = 0; i < len; ++i) {
		ans += v[i];
	}
	cout << ans;
	cout << endl;


	return 0;
}


Measured memory_bytes: 1024
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
import queue

INF = float("inf")

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

class BFS(object):
	def __init__(self, graph, s, N):
		self.g = graph.graph
		self.Q = queue.Queue()
		self.Q.put(s)
		self.dist = [INF] * N
		self.dist[s] = 0
		self.visit = ["No"] * N
		self.visit[s] = "Yes"
		while not self.Q.empty():
			v = self.Q.get()
			for i in self.g[v]:
				if self.visit[i] == "No":
					self.dist[i] = self.dist[v] + 1
					self.Q.put(i)
					self.visit[i] = "Yes"

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, u, v = getlist()
	u -= 1; v -= 1
	G = Graph()
	for i in range(N - 1):
		A, B = getlist()
		A -= 1; B -= 1
		G.add_edge(A, B)
		G.add_edge(B, A)
	BF_taka = BFS(G, u, N)
	BF_ao = BFS(G, v, N)
	taka_dist = BF_taka.dist
	ao_dist = BF_ao.dist
	dis = 0

	for i in range(N):
		val = taka_dist[i]
		xval = ao_dist[i]
		if val < xval:
			dis = max(dis, xval)
	
	print(dis - 1)


if __name__ == '__main__':
	main()

Measured memory_bytes: 87256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;


public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.peopleWalkedTheLongestDistanceSearch();
		return;
	}
	
	//一日で一番長い距離を歩いた人を探す
	private void peopleWalkedTheLongestDistanceSearch() {
		
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); //標準入力
		
		while (true) {
			
			try {
				
				String inputStr = bufferedReader.readLine();
				int patientsNum = Integer.parseInt(inputStr); //患者の数
				
				if (patientsNum == 0) {
					break;
				}
				
				HashMap<Integer, Integer> patientsMap = new HashMap<Integer, Integer>();
				
				for (int i = 0; i < patientsNum; i++) {
					String inputStr2 = bufferedReader.readLine();
					String[] patientsInformation = inputStr2.split(" ");
					int patientNum = Integer.parseInt(patientsInformation[0]);
					int d1 = Integer.parseInt(patientsInformation[1]);
					int d2 = Integer.parseInt(patientsInformation[2]);
					patientsMap.put(patientNum, d1 + d2);
				}
				
				int patientsLongestNum = 0; //最も長く歩いた患者の番号
				int theLongestTotalDistanceNum = 0; //最も長く歩いた患者の歩いた距離
				for(Map.Entry<Integer, Integer> e : patientsMap.entrySet()) {
					
					int tmp = e.getValue();
					
					if (tmp > theLongestTotalDistanceNum) {
						patientsLongestNum = e.getKey();
						theLongestTotalDistanceNum = e.getValue();
					}
					
				}
				
				System.out.printf("%d %d\n", patientsLongestNum, theLongestTotalDistanceNum);
				
			} catch (IOException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
			
		}
	}
}

Measured memory_bytes: 94572
n = int(input())
if n < 10:
    x = n
elif n < 100:
    x = 9
elif n < 1000:
    x = n - 90
elif n < 10000:
    x = 909
elif n == 100000:
    x = 90909
else:
    x = n - 9090
print(x)

Measured memory_bytes: 9148
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	vector<int> v(200002);
	vector<int> m(200004,0);
	rep(i, n) {
		cin >> v[i];
		m[v[i]]+=1LL;
	}
	int mans = 0;
	rep(i, n+1) {
		mans += m[i] * (m[i] - 1LL);
	}
	mans = mans / 2LL;
	rep(i, n) {
		int ans = mans;
		ans -= m[v[i]] - 1LL;
		cout << ans << "\n";
	}
}

Measured memory_bytes: 5760
def smaller(x, y):
	if x < y: return x
	return y

N, Ma, Mb = map(int, input().split())
a = []
b = []
c = []
suma = 0
sumb = 0
for i in range(0, N):
	inpt = list(map(int, input().split()))
	a.append(inpt[0])
	b.append(inpt[1])
	c.append(inpt[2])
	suma += inpt[0]
	sumb += inpt[1]
dp = []
for i in range(0, N+1):
	lst1 = []
	for j in range(0, suma+1):
		lst2 = []
		for k in range(0, sumb+1):
			lst2.append(-1)
		lst1.append(lst2)
	dp.append(lst1)
dp[0][0][0] = 0
for i in range(0, N):
	for j in range(0, suma+1):
		for k in range(0, sumb+1):
			if dp[i][j][k] != -1:
				if dp[i+1][j][k] == -1:
					dp[i+1][j][k] = dp[i][j][k]
				else:
					dp[i+1][j][k] = smaller(dp[i][j][k], dp[i+1][j][k])
				if dp[i+1][j+a[i]][k+b[i]] == -1:
					dp[i+1][j+a[i]][k+b[i]] = dp[i][j][k] + c[i]
				else:
					dp[i+1][j+a[i]][k+b[i]] = smaller(dp[i][j][k]+c[i], dp[i+1][j+a[i]][k+b[i]])
ans = -1
index = 1
while index * Ma <= suma and index * Mb <= sumb:
	if dp[N][index*Ma][index*Mb] != -1:
		if ans == -1: ans = dp[N][index*Ma][index*Mb]
		else: ans = smaller(ans, dp[N][index*Ma][index*Mb])
	index += 1
print(ans)

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

#define rep(i, n) for (int i = 0; i < n; ++i)

std::string s;

int main()
{
    int k;
    std::cin >> k >> s;

    if (s.size() <= k)
        std::cout << s << std::endl;
    else
    {
        std::cout << s.substr(0, k) << "..." << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3588
"use strict";
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"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var a = o.l();
  var sum = 0;
  for(var i = 0; i < n; i++){
    sum += a[i];
  }

  var l = 0, r = 0;
  for(var i = 0; i < n; i++){
    if(l < sum/2)l += a[i];
    if(l < sum/2)r += a[i];
  }
  return Math.min(l*2-sum,sum-r*2);
}

Measured memory_bytes: 35156
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    string s;
    cin>>s;
    int ans=99999999;
    
    for(int i=1;i<s.size()-1;i++){
        int pre=(s.at(i-1)-'0')*100+(s.at(i)-'0')*10+s.at(i+1)-'0';
        ans=min(ans,abs(753-pre));
    }
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.contains("a") && s.contains("b") && s.contains("c")) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
            
        }
    }
}


Measured memory_bytes: 21844
//
//  main.cpp
//  5
//
//  Created by 5201-mac on 17/8/12.
//  Copyright © 2017年 5201-mac. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;
int main() {
    int n;
    cin>>n;
    n/100==n%10?printf("Yes\n"):printf("No\n");
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


Measured memory_bytes: 256
#実はDPと割り切るとわかりやすい
mod=10**9+7
h,w,K=map(int,input().split())
dp=[[0]*w for j in range(h+1)]
dp[0][0]=1
for i in range(1,h+1):
    for k in range(2**(w-1)):
        for l in range(w-2):
            if ((k>>l)&1) and ((k>>(l+1))&1):
                break
        else:
            for l in range(w):
                if l==0:
                    if ((k>>l)&1):
                        dp[i][l+1]+=dp[i-1][l]
                    else:
                        dp[i][l]+=dp[i-1][l]
                elif l==w-1:
                    if ((k>>(l-1))&1):
                        dp[i][l-1]+=dp[i-1][l]
                    else:
                        dp[i][l]+=dp[i-1][l]
                else:
                    if ((k>>l)&1) or ((k>>(l-1))&1):
                        if ((k>>l)&1):
                            dp[i][l+1]+=dp[i-1][l]
                        else:
                            dp[i][l-1]+=dp[i-1][l]
                    else:
                        dp[i][l]+=dp[i-1][l]
            #dp[i][l]%=mod
print(dp[h][K-1]%mod)

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll func(ll a) {
  if (a <= 1) return 0;
  return a * (a - 1) / 2;
}

void solve() {
  int n;
  cin >> n;
  vector<ll> v(n);
  vector<int> mp(n);
  rep(i,n){
    cin >> v[i];
    mp[v[i] -  1]++;
  }
  ll sum = 0;
  for(ll p: mp) {
    sum += func(p);
  }
  rep(i,n) {
    ll temp = sum;
    temp -= func(mp[v[i] - 1]);
    temp += func(mp[v[i] - 1] - 1);
    cout << temp << endl;
  }
}

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

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

char v[103];

int main(){

    int n;
    scanf("%d", &n);
    for(int i=0; i<n; ++i){
        scanf("%c ", v+i);
    }
    bool G=0, P=0, W=0, Y=0;
    for(int i=0; i<n; ++i){
        if(v[i]=='G')
            G=1;
        else if(v[i]=='P')
            P=1;
        else if(v[i]=='W')
            W=1;
        else if(v[i]=='Y')
            Y=1;
    }

    if(G&&P&&W&&Y)
        puts("Four");
    else
        puts("Three");



    return 0;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        super().__init__()
        self.rank = [0] * n
        self.parent = [i for i in range(n)]

    def print_set(self):
        print(self.parent)
        print(self.rank)

    def find_set(self, x):
        if x != self.parent[x]:
            self.parent[x] = self.find_set(self.parent[x])
        
        return self.parent[x]
    
    def unite(self, x, y):
        x_parent = self.find_set(x)
        y_parent = self.find_set(y)

        if self.rank[x_parent] > self.rank[y_parent]:
            self.parent[y_parent] = x_parent
        else:
            self.parent[x_parent] = y_parent
            if self.rank[x_parent] == self.rank[y_parent]:
                self.rank[y_parent] += 1

n, q = map(int, input().split())
u = UnionFind(n)

for _ in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        u.unite(x, y)
    else:
        if u.find_set(x) == u.find_set(y):
            print(1)
        else:
            print(0)



Measured memory_bytes: 6040
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) 0;
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  int x = (n * 100 + 107) / 108;
  bool ok = n == x * 108 / 100;
  if (!ok) {
    std::cout << ":(" << std::endl;
  } else {
    std::cout << x << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	int a, b;
	int sa, sb;
	while (1) {
		scanf("%d", &n);
		if (n == 0) {
			break;
		}
		sa = sb = 0;
		for (i = 0; i < n; ++i) {
			scanf("%d %d\n", &a, &b);
			if (a < b) {
				sb += (a + b);
			} else if ( a > b) {
				sa += (a + b);
			} else {
				sa += a;
				sb += b;
			}
		}
		printf("%d %d\n", sa, sb);
	}
	return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<vector>
#define pb push_back
using namespace std;
const int DN=2e5+5;
int n,a[2][DN],ls,ld;
long long arb[4*DN],dp[DN],ma,val,poz;
void query(int nod,int st,int dr)
{
	if(ld<st)
		return;
	if(ls>dr)
		return;
	if(ls<=st&&dr<=ld)
	{
		ma=max(ma,arb[nod]);
		return;
	}
	int mij=(st+dr)/2;
	query(2*nod,st,mij);
	query(2*nod+1,mij+1,dr);
}
void update(int nod,int st,int dr)
{
	if(dr<poz)
		return;
	if(st>poz)
		return;
	if(st==dr)
	{
		arb[nod]=val;
		return;
	}
	int mij=(st+dr)/2;
	update(2*nod,st,mij);
	update(2*nod+1,mij+1,dr);
	arb[nod]=max(arb[2*nod],arb[2*nod+1]);
}
int main() 
{
	cin>>n;
	for(int i=0;i<2;i++)
		for(int j=1;j<=n;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
	{
		ma=0;
		ls=1;
		ld=a[0][i]-1;
		query(1,1,n);
		dp[i]=ma+a[1][i];
		poz=a[0][i];
		val=dp[i];
		update(1,1,n);
		dp[i]=max(dp[i],dp[i-1]);
	}
	cout<<dp[n];
}

Measured memory_bytes: 9600
S = list(input())

#print(S)

n = 1 if S[0] == "W" else 0# number of white string
count = 0
for i in range(1, len(S)):
    if S[i] == "W":
        count += i - n
        n += 1
        #print("n is", n)
        #print("count is ", count)
print(count)




Measured memory_bytes: 4840
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;

map<ll,int> prime_factor(ll n) {
    map<ll,int> res;
    repr(i,2,sqrt(n)+1) {
        while (n%i==0) {
            ++res[i];
            n/=i;
        }
    }
    if(n!=1) ++res[n];
    return res;
}


int main() {
    ios_base::sync_with_stdio(false);

    ll n;
    cin >> n;
    map<ll,int> pf=prime_factor(n); 
    cout << n << ": "; 
    repitr(itr,pf) {
        rep(j,itr->second) {
            cout << itr->first;
            if (!(next(itr,1)==pf.end() && j==itr->second-1)) cout << ' ';
        }
    }
    cout << endl;

    return 0;   
}



Measured memory_bytes: 3220
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	mod int = 1e9 + 7
)

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	N := getInt()
	K := getInt()

	var A []int
	for i := 0; i < N; i++ {
		A = append(A, getInt())
	}

	internalCnt := 0
	externalCnt := 0
	for i, a := range A {
		for _, a2 := range A[i+1:] {
			if a > a2 {
				internalCnt++
			}
		}

		for _, a2 := range A[:i] {
			if a > a2 {
				externalCnt++
			}
		}
	}

	ans := calcMod(internalCnt) * calcMod(K * (K+1) / 2)
	ans += calcMod(externalCnt) * calcMod((K-1) * K / 2)
	fmt.Println(calcMod(ans))
}

func getInt() int {
	sc.Scan()
	str := sc.Text()
	value, _ := strconv.Atoi(str)
	return value
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
 
int64 N, D;
int64 X[30], Y[30];
 
vector< pair< int64, int64 > > data[2];
priority_queue< pair< int64, int64 > > Que;
 
 
inline void Greedy(int idx, const int end, int64 Value, int64 Precious, const bool in)
{
  if(idx == end) {
    data[in].push_back(make_pair(Value, Precious));
  } else {
    Greedy(idx + 1, end, Value + X[idx], Precious + Y[idx], in);
    Greedy(idx + 1, end, Value         , Precious,          in);
    Greedy(idx + 1, end, Value - X[idx], Precious - Y[idx], in);
  }
}
 
int main()
{
  srand((unsigned)time(NULL));
  cin >> N >> D;
  for(int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
  }
  Greedy(0, N >> 1, 0, 0, false);
  Greedy(N >> 1, N, 0, 0,  true);
  sort(data[0].begin(), data[0].end());
  sort(data[1].begin(), data[1].end());
 
  int64 ret = 0;
  for(int i = 0, cur = 0; i < data[0].size(); i++) {
    while(cur < data[1].size() && data[1][cur].first <= data[0][i].first + D) {
      if(rand() % 6 <= 4) Que.push(make_pair(-data[1][cur].second, data[1][cur].first));
      ++cur;
    }
    while(!Que.empty() && Que.top().second < data[0][i].first - D) {
      Que.pop();
    }
    if(!Que.empty()) {
      ret = max(ret, data[0][i].second + Que.top().first);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 566044
#include<iostream>
using namespace std;
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int main(){
  int m,n;
  while(cin>>m>>n) cout << gcd(m,n) << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Feb  9 21:00:00 JST 2020
 **/

signed main() {
    string s, t; cin >> s >> t;
    Int a, b; cin >> a >> b;
    string u; cin >> u;
    (s == u ? a : b)--;
    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
N, W = map(int, input().split())

weight = [None] * N
value = [None] * N
dp = [[None] * (W+1) for _ in range(N+1)]

for i in range(N):
  weight[i], value[i] = map(int, input().split())

for j in range(W+1):
  dp[0][j] = 0

for i in range(N):
  for w in range(W+1):
    if w >= weight[i]:
      dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w])
    else:
      dp[i+1][w] = dp[i][w]

ans = dp[N][W]
print(ans)

Measured memory_bytes: 257416
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    int x;
    cin >> x;
    vector<bool> e(x+1);

    e[1] = true;

    for(int i = 2; i <= x; ++i){
        int v = i * i;
        while(v <= x){
            e[v] = true;
            v *= i;
        }
    }
    for(int i = x; i >= 1; --i)if(e[i]){
        cout << i << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
def intinput():
    return map(int,input().split())

def gcd(x,y):  #最大公約数
    if x==0:
        return y
    else:
        return gcd(y%x,x)

a,b,k=intinput()
f = gcd(a,b)
x=0
for i in range(f):
    if a%(f-i)==0 and b%(f-i)==0:
        x+=1
        if x==k:
            print(f-i)
            break

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

const ll MOD = 998244353;
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

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;
}

int main() {
	ll N, M, K;
	cin >> N >> M >> K;

	COMinit();

	ll ans = 0;
	for (ll ii = 0; ii <= K; ++ii){
		ll cnt = COM(N-1, ii);
		ans = (ans + modpow(M-1, N-1-ii, MOD) * cnt) % MOD;
	}

	ans = (ans * M ) % MOD;

	cout << ans << "\n";

	return 0;
}


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

using namespace std;

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

const int N = 1e6 + 10;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(a * b, c);
}

Measured memory_bytes: 256
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
//#include<ext/rope>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
const double PI=acos(-1.0);
const double eps=1e-6;
int a[100005],ans[100005];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
template<typename T> void debug(T x)
{
    cout<<"value="<<x<<endl;
    return;
}
signed main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    int n=read();
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=1;i<=n;i++) ans[a[i]]=i;
    for(int i=1;i<=n;i++) printf("%d ",ans[i]);
	return 0;
}


Measured memory_bytes: 4448
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)

using namespace std;

constexpr int kMaxN = 100000;
constexpr int kMaxQ = 100000;

///-----
int ma[kMaxN];
int urank[kMaxN];
int color[kMaxN];
void init() {
  rep (i,kMaxN) {
    ma[i] = i;
    urank[i] = 0;
    color[i] = i;
  }
}

int find(int x) {
  if (ma[x] == x)return x;
  return ma[x] = find(ma[x]);
}

void unite(int x, int y) { // xの方の色にする
  x = find(x);
  y = find(y);

  if (x == y) return;

  color[y] = color[x];

  if (urank[x] < urank[y]) {
    ma[x] = y;
  } else {
    ma[y] = x;
    if (urank[x] == urank[y]) urank[x]++;
  }
}

int get_now_color(int x) {
  x = find(x);
  return color[x];
}

///-----
using P = pair<char,int>;

struct Op {
  char com;
  int idx;
};

int N,Q;
int par[kMaxN];
vector<int> col;
vector<int> G[kMaxN];
vector<Op> ops;
vector<bool> used;

void Init(void) {
  used.resize(N);
  fill(used.begin(), used.end(), false);

  col.resize(N);
  rep (i,N) col[i] = -1;
  set<int> S;
  for (auto &op:ops) {
    if (op.com == 'Q') continue;
    if (S.find(op.idx) != S.end()) {
      op.idx = -1;
    } else {
      S.insert(op.idx);
    }
  }
  for (auto op : ops) if (op.com == 'M' && op.idx >= 0) col[op.idx] = op.idx;
  col[0] = 0;
}

void dfs(int i, int c) {
  if (used[i]) return;
  used[i] = true;
  if (col[i] >= 0) c = col[i];
  else col[i] = c;

  for (auto e : G[i]) {
    dfs(e, c);
  }
}
void solve(void) {
  Init();

  dfs(0,0);

  init();
  int ans = 0;
  for (int i = Q - 1; i >= 0; i--) {
    auto& op = ops[i];

    if (op.com == 'M') {
      if (op.idx < 0) continue;
      int j = op.idx;
      unite(col[par[j]],col[j]);
    } else {
      ans += get_now_color(col[op.idx]) + 1;
    }
  }
  cout << ans << endl;
}

signed main(void) {
  while(true) {
    cin >> N >> Q;
    if ( N == 0 && Q == 0) break;
    rep (i,N) G[i].clear();
    par[0] = 0;
    rep (i, N-1) {
      cin >> par[i + 1];
      par[i + 1]--;
      G[par[i+1]].push_back(i+1);
    }
    ops.resize(Q);
    rep (i,Q) {
      cin >> ops[i].com >> ops[i].idx;
      ops[i].idx--;
    }
    solve();
  }

}


Measured memory_bytes: 19964
//  LINK ZADATKA: http://abc069.contest.atcoder.jp/tasks/arc080_b

#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <fstream>
#include <cstring>
#include <string>
#include <climits>

using namespace std;

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;


#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define INF 999999999
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define _gcd __gcd
#define eps 1e-9
int polje[110][110];
int n, m, boje, boja, smed, pun, iks, ips, check;
int mX[4] = {0, 1, 0, -1}, mY[4] = {1, 0, -1, 0};




vector<pair<int,int> > kek;
void dfs(int x, int y, int flag){
	boja--;
	pun++;
	//printf("%d %d\n", x, y);
	polje[x][y] = flag;
	REP(k, 4){
		if(x+mX[k] >= 0 && y + mY[k] >= 0 && x + mX[k] < n && y + mY[k] < m && polje[x+mX[k]][y+mY[k]] == 0 && boja > 0){
			dfs(x+mX[k], y+mY[k], flag);
			
		} else if(x+mX[k] >= 0 && y + mY[k] >= 0 && x + mX[k] < n && y + mY[k] < m && polje[x+mX[k]][y+mY[k]] == 0 && boja == 0 && check == 0){
			iks = x+mX[k];
			ips = y+mY[k];
			check = 1;
			break;
		}
	}
	
	
	return;
}

bool cmp(const pair<int,int>&left, const pair<int,int>&right){
	return left.first > right.first;
}

int main(){
	memset(polje, 0, sizeof(polje));
	scanf("%d %d", &n, &m);
	
	scanf("%d", &boje);
	int a;
	REP(i, boje){
		scanf("%d", &a);
		kek.PB(MP(a, i+1));
	}
	 
	sort(kek.begin(), kek.end(), cmp);
	//REP(i, kek.size()) printf("%d %d\n", kek[i].first, kek[i].second);
 
	while(pun < n*m){
		check = 0;
		boja = kek.begin() -> first;
		smed = kek.begin() -> second;
		kek.erase(kek.begin());
		//printf("%d %d", iks, ips);
 		dfs(iks, ips, smed);
	}
	
 
	
	REP(i, n){
		REP(j, m) printf("%d ", polje[i][j]);
		printf("\n");
	}
	
	
	
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
    int main() {    	
		int a,b,c,d;
    	cin >> a >> b >> c >>d;
    	
    	if (a == c){
    		cout << 0 << endl;
    	}
    	else {
    		cout << 1 << endl;
    	}
    }

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

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;
 
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;

int main() {
  
  int n,d,x;
  cin >> n >> d >> x;
  
  int count = 0;
  
  vector<int> a(n);
  for ( int i = 0; i < n; i++){
    cin >> a[i];
    int j = 0;
    while( j * a[i] + 1 <= d ){
      count++;
      j++;
    }
  }
  
  cout << x + count << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) 
{
    int i, count;
    int a, b, sum, input_rc;

    while(1) {
        input_rc = scanf("%d%d", &a, &b);
        if (input_rc < 0) break;

        sum = a + b;
        count = 0;
        while(1) {
            count++;
            if (sum < 10) break;
            sum /= 10;
        }

        printf("%d\n", count);
    }
    return 0;
}

Measured memory_bytes: 600
while True:
	n = int(input())
	if n == 0: break
	ans = 0
	for i in range(1,n//2+2):
		sumnum = i
		if sumnum >= n:
			continue
		j = i+1
		while j <= n//2+1:
			sumnum += j
			j += 1
			if sumnum >= n:
				if sumnum == n:
					ans += 1
				break
	print(ans)


Measured memory_bytes: 5592
def main():
	n, m = (int(a) for a in input().split())
	a = []
	b = []
	for i in range(n):
		for j in input().split():
			a.append(int(j))
	for i in range(m):
		b.append(int(input()))

	for i in range(n):
		c = 0
		for j in range(m):
			c += a[i*m + j] * b[j]
		print(c)

main()



Measured memory_bytes: 5944
;;(declaim (optimize (speed 0) (safety 3) (debug 3)))
#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))
(declaim (optimize (speed 3) (safety 0) (debug 0)))

(declaim (type fixnum *x*))
(defvar *x* (read))

;; 100 * 1.01^n > x
;; 1.01^n > x/100
;; n log(1.01) > log(x/100)
;; n = ceiling(log(x/100) / log(1.01))

;; x = 10^18 then n = ceiling(16/log(1.01)) = 3703, acceptable

(princ (let ((x 100)
	     (i 0))
	 (loop
	  (if (>= x *x*)
	      (return i)
	    (psetf i (1+ i) x (floor (* x 101/100)))))))




Measured memory_bytes: 24852
n,k = map(int,input().split())
L = []
for i in range(n):
    a,b = map(int,input().split())
    L.append([a,b])
L.sort()
ans = 0
sum1 = 0
for i in range(n):
    sum1 +=L[i][1]
    ans = L[i][0]
    if sum1 >=k:
        print(ans)
        exit()


Measured memory_bytes: 20100
#include <stdio.h>

int main() {	
	int rankN;
	int colRowL[101];
	int min[100][100];
	int left, right;
	int temp;
	int i, j, k;

	scanf("%d", &rankN);
	for (i = 0; i < rankN; i++) {
		scanf("%d %d", &colRowL[i], &colRowL[i + 1]);
	}

	for (i = 0; i < rankN; i++) {
		min[i][i] = 0;
	}
	for (i = 1; i < rankN; i++) {
		for (j = 0; j < rankN - i; j++) {
			left = j;
			right = j + i;
			min[left][right] = 1000000000;

			for (k = left; k < right ; k++) {
				temp = min[left][k] + min[k + 1][right] 
		                    +colRowL[left] * colRowL[k + 1] * colRowL[right + 1];
				if (temp < min[left][right]) {
					min[left][right] = temp;
				}
			}
		}
	}

	printf("%d\n", min[0][rankN - 1]);

	return 0;
}

Measured memory_bytes: 2788
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
//#define P pair<int,int>

signed main(){
    int N;
    cin >> N;
    REP(i,30){
        REP(j,20){
            if(4*i+7*j==N){
                cout << "Yes" << endl;return 0;
            }
        }
    }
    cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  int n;
  while(cin >> n,n){
    vector <ll> a(n);
    REP(i,n)
      cin >> a[i];
    sort(a.begin(),a.end());
    ll sum = 0;
    rep(i,1,a.size()-1){
      sum += a[i];
    }
    cout << sum/(n-2) << endl;
  }
  return 0;
}



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

int main(){
	int n, k;
	cin >> n >> k;
	int h[100010];
	for(int i=0; i<n; i++) cin >> h[i];
	int cnt=0;
	for(int i=0; i<n; i++){
		if(h[i] >= k) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 640