akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct treetype {
	int parent;
	int sibling;
	int left;
	int right;
};

int main(void) {
	int n;
	struct treetype tree[26];
	int i, j, k;
	int lr = 0;
	int number;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		tree[i].parent = -2;
		tree[i].sibling = -2;
	}

	for (i = 0; i < n; i++) {
		scanf("%d", &number);
		scanf("%d %d", &tree[number].left, &tree[number].right);

		tree[tree[number].left].parent = number; //親決定
		tree[tree[number].left].sibling = tree[number].right;
		tree[tree[number].right].parent = number;
		tree[tree[number].right].sibling = tree[number].left;
	}

	printf("Preorder\n");

	for (i = 0; 1; i++) {
		if (tree[i].parent ==  -2) {
			number = i;
			break;
		}
	}

	for (i = 0; i < n; i++) {
		printf(" %d", number);
		if (tree[number].left >= 0) {
			number = tree[number].left;
			lr = 0;
		}
		else if (tree[number].right >= 0) {
			number = tree[number].right;
			lr = 1;
		}
		else if (tree[number].sibling >= 0 && lr == 0) {
			number = tree[number].sibling;
			lr = 1;
		}
		else {
			k = tree[number].parent;
			while (i < n - 1) {
				if (k == tree[tree[k].parent].left) {
					lr = 0;
				}
				else {
					lr = 1;
				}
				if (tree[k].sibling >= 0 && lr == 0) {
					number = tree[k].sibling;
					lr = 1;
					break;
				}
				k = tree[k].parent;
			}
		}
	}

	printf("\nInorder\n");

	lr = 0;
	for (i = 0; 1; i++) {
		if (tree[i].parent == -2) {
			number = i;
			break;
		}
	}
	for (i = 0; 1; i++) {
		if (tree[number].left < 0) {
			break;
		}
		number = tree[number].left;
	}

	for (i = 0; i < n; i++) {
		printf(" %d", number);

		if (tree[number].right >= 0) {
			number = tree[number].right;
			lr = 1;
			while (1) {
				if (tree[number].left < 0) {
					break;
				}
				number = tree[number].left;
				lr = 0;
			}
		}else if (tree[number].parent >= 0) {
			k = number;
			while (i < n - 1) {
				if (k == tree[tree[k].parent].left) {
					lr = 0;
				}
				else {
					lr = 1;
				}
				if (lr == 0) {
					number = tree[k].parent;
					break;
				}
				k = tree[k].parent;
			}
		}
	}

	printf("\nPostorder\n");


	lr = 0;
	for (i = 0; 1; i++) {
		if (tree[i].parent == -2) {
			number = i;
			break;
		}
	}
	for (i = 0; 1; i++) {
		if (tree[number].left < 0) {
			if (tree[number].right < 0) {
				break;
			}
			else {
				number = tree[number].right;
			}
		}
		else {
			number = tree[number].left;
		}
	}

	for (i = 0; i < n; i++) {
		printf(" %d", number);

		if (tree[number].sibling >= 0 && lr == 0) {
			number = tree[number].sibling;
			lr = 1;
			while (1) {
				if (tree[number].left < 0) {
					if (tree[number].right < 0) {
						break;
					}
					else {
						number = tree[number].right;
						lr = 1;
					}
				}
				else {
					number = tree[number].left;
					lr = 0;
				}
			}
		}
		else if (tree[number].parent >= 0) {
			number = tree[number].parent;
			if (number == tree[tree[number].parent].left) {
				lr = 0;
			}
			else {
				lr = 1;
			}

		}

	}

	printf("\n");

	return 0;
}


Measured memory_bytes: 2048
n = int(input())
result = [2]
i = 1
while len(result) < n:
    num = 5*i -1
    for j in range(2, int(pow(num, 0.5))+1):
        while num%j==0:
            num //= j
    if num == 5*i-1:
        result.append(num)
    i += 1
print(*result)

Measured memory_bytes: 38512
N, M = map(int, input().split())
left = 1
right = N

for i in range(M):
	l, r = map(int, input().split())
	if l > left:
		left = l
	if r < right:
		right = r
		
if left > right:
	print(0)
else:
		print(right - left + 1)

Measured memory_bytes: 3060
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>

#define int uint64_t

using namespace std;

signed main()
{
    int n;
    int min = std::numeric_limits<int>::max();
    cin >> n;
    
    for (int i = 0; i < 5; i++) {
        int a;
        cin >> a;
        if (min > a) {
            min = a;
        }
    }
    
    if (n % min == 0) {
        n /= min;
    }
    else {
        n = n / min + 1;
    }
    
    std::cout << n - 1 + 5 << std::endl;
    return 0;
    
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    s= int(sys.stdin.readline())
    c=1
    l=[]

    while True:
        if l.count(s)>0:
            print(c)
            exit()
        else:
            l.append(s)

        if s%2==0:
            s//=2
        else:
            s=3*s+1
        c+=1




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

signed main(){
  int A,B;
  cin>>A>>B;
  if(A%2!=B%2){
    cout<<"IMPOSSIBLE"<<endl;
  }else{
    cout<<(A+B)/2<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<map>
#include<tuple>
#include<queue>

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define MAX_LEN 900

int main(){
    int w,h;
    while(1){
	    cin >> w >> h;
        int ans=0;
        
        //壁の配列作成
        if(w==0 && h==0)break;

        int wall[h*2-1][w*2-1];
        REP(i,0,h*2-1){
            REP(j,0,w*2-1){
                wall[i][j]=-1;
            }
        }
        REP(i,0,h*2-1){
            if(i%2==0){
                REP(j,0,w-1){
                    cin >> wall[i][j*2+1];
                }
            }else{
                REP(j,0,w){
                    cin >> wall[i][j*2];
                }
            }
        }

        int maze[h][w];
        REP(i,0,h){
            REP(j,0,w){
                maze[i][j]=0;
            }
        }

        maze[0][0]=1;
        int adx[4] = {1,-1,0,0};
        int ady[4] = {0,0,1,-1};
        tuple<int,int,int> point=make_tuple(0,0,1);
        queue<tuple<int,int,int>> que;
        que.push(point);
        int x,y,len;
        while(1){
            if(que.empty())break;
            point = que.front();
            que.pop();
            x=get<0>(point);
            y=get<1>(point);
            len=get<2>(point);
            REP(i,0,4){
                int nx=x+adx[i],ny=y+ady[i];
                if(nx<0||nx>=w||ny<0||ny>=h)continue;
                if(wall[y+ny][x+nx]==1)continue;
                if(maze[ny][nx]!=0)continue;

                if(ny==h-1 && nx==w-1){
                    ans=len+1;
                    goto LAST;
                }
                maze[ny][nx]=len+1;
                que.push(make_tuple(nx,ny,len+1));
            }
        }
                
        /**
        REP(y,0,h){
            REP(x,0,w){
                cout << maze[y][x] << " ";
            }
            cout << endl;
        }
        **/
        LAST:
        p(ans);
    }
}



Measured memory_bytes: 3076
n,m=map(int,input().split())


mod=10**9+7 

def nCr(n, r, mod):#mod=10**9+7 
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

if 2*n-m<0 or 2*m-n<0 or (2*n-m)%3!=0:
  print(0)
else:
  x=(2*n-m)//3
  y=(2*m-n)//3
  print(nCr(x+y,min(x,y),mod))



Measured memory_bytes: 3064
#include<iostream>
#include<unordered_map>
#include<vector>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  // ここでストリームに obj を書き込みます。
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  // ここでストリームに obj を書き込みます。
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}


li fact(li a){
  static unordered_map<li,li> f;
  f[0]=1;
  if(f.find(a)!=f.end())return f[a];
  return f[a]=fact(a-1)*a%MOD;
}

li inv(li a){
  static unordered_map<li,li> f;
  f[1]=1;
  if(f.find(a)!=f.end())return f[a];
  if(df)  print("inv",a);
  li s=MOD-inv(MOD%a);
  (s*=MOD/a)%=MOD;
  return f[a]=s;
}

const int M = 2e5 + 100;
vector<vector<int>> adj;
vector<pair<li,int>> w;
vector<li> ans;
int n;


void init(int parent=-1,int a=0){
  if(df)print("init",a);
  li s=1;
  int cnt=0;
  for(int x:adj[a]){
    if(df)print("x:",x);
    if(x==parent) continue;
    init(a,x);
    (s*=w[x].first)%=MOD;
    (s*=inv(fact(w[x].second)))%=MOD;
    cnt+=w[x].second;
  }
  (s*=fact(cnt))%=MOD;
  w[a]={s,cnt+1};
  if(df)print(w[a]);
}

void reverse(int a,int b){
  li& s=w[a].first;
  (s*=inv(fact(w[a].second-1)))%=MOD;
  (s*=fact(w[a].second-1-w[b].second))%=MOD;
  (s*=inv(w[b].first))%=MOD;
  (s*=fact(w[b].second))%=MOD;
  w[a].second-=w[b].second;
  //  w[b].second+=w[a].second;

  if(df)print("b/",w[b].second-1,"! *",w[a].second-1+w[b].second,"! *",w[a].first,"/",w[a].second,"!");
  li& t=w[b].first;
  (t*=inv(fact(w[b].second-1)))%=MOD;
  (t*=fact(w[a].second-1+w[b].second))%=MOD;
  (t*=w[a].first)%=MOD;
  (t*=inv(fact(w[a].second)))%=MOD;
  w[b].second+=w[a].second;
  if(df)print(a,"->",w[a],b,"->",w[b]);
}

void dfs(int parent=-1,int a=0){
  for(int x:adj[a]){
    if(x==parent) continue;
    reverse(a,x);
    if(df)print("w:",w);
    ans[x]=w[x].first;
    dfs(a,x);
    reverse(x,a);
  }
}
int main(){
  cin >>n;
  ans.resize(n);
  w.resize(n);
  adj.resize(n);
  rep(i,n-1){
    int a,b; cin >>a >>b; a--; b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  if(df)rep(i,n)print(adj[i]);
  init();
  if(df)print("w:",w);
  
  ans[0]=w[0].first;
  dfs();
  rep(i,n) print(ans[i]);
  
}


Measured memory_bytes: 86324
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vint;
typedef vector<uint> vuint;
typedef vector<ull> vull;
typedef vector<ll> vll;

#define init(type,var) type var;cin>>var;
#define vinit(vtype,var,n) vtype var((uint)n);loop(i,0,n)cin>>var[i];
#define range(container) container.begin(),container.end()
#define loop(i,first,end) for(ull i=(first);i<(end);i++)
#define outl(out) cout<<out<<endl;

const ull INF = (ull)(-1LL);

int main(void){
	init(string, s);
	init(string, t);

	int c = 0;
	loop(i, 0, 3)if (s[i] == t[i])c++;

	outl(c);

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    vi p(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i] >> p[i];
    }
    vi ord(n);
    iota(ord.begin(), ord.end(), 0);
    auto f = [&](int x, int y) {
        if (s[x] == s[y])
            return p[x] > p[y];
        else
            return s[x] < s[y];
    };
    sort(ord.begin(), ord.end(), f);
    for (int i = 0; i < n; ++i) {
        cout << ord[i] + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		TreeSet<Integer> S = new TreeSet<Integer>();
		int q = sc.nextInt();
		for(int i = 0; i < q; i++){
			int com = sc.nextInt();
			int x = sc.nextInt();
			if(com == 0){
				S.add(x);
				System.out.println(S.size());
			}else{
				if(S.contains(x)) System.out.println(1);
				else System.out.println(0);
			}
		}
	}
}



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

using namespace std;

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce



sys.setrecursionlimit(2147483647)
INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
L = sorted(LI())
l = 0
r = n - 1
A = []
while r >= 0:
    A += [abs(r - l)]
    l += 1
    r -= 1


if sorted(A) != L:
    print(0)
else:
    s  = len(set(L))
    if n % 2:
        s -= 1
    print(pow(2, s, mod))

Measured memory_bytes: 59812
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
//#include <bits/stdc++.h>
#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 SZ(x) ((int)(x).size())	//size() unsigned -> int
using namespace std;


int main(void) {
	int N, K;
	cin >> N >> K;
	int ans;
	ans = N % K;
	if (ans) cout << "1" << endl;
	else if(N==K) cout << "0" << endl;
	else cout << "0" << endl;
	return 0;
}


Measured memory_bytes: 256
"""
B - Grid Compression
ex in )
4 4
##.#
....
##.#
.#.#

ex out)
###
###
.##
"""

H, W = map(int, input().split())

matrix = []
for h in range(H):
    line = list(input())
    
    line_num = []
    for part in line:
        line_num.append(part)
    
    matrix.append(line_num)

leave_h = []
for h in range(H):
    for w in range(W):
        # 黒ならのこす
        if matrix[h][w] == "#":
            leave_h.append(h)
            break

leave_w = []
for w in range(W):
    for h in range(len(matrix)):
        
        # 黒ならのこす
        if matrix[h][w] == "#":
            leave_w.append(w)
            break


for h in range(H):
    if h not in leave_h:
        continue

    for w in range(W):
        if w not in leave_w:
            continue

        print(matrix[h][w], end="")
    
    print()


Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define mod 1e9+7

int main(){
      ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);    
    
   using namespace std;
    int N, A[3][3], b[10];
     bool appear[3][3];

        for(int i = 0; i < 3; i++) {
           for(int j = 0; j < 3; j++)
            cin >> A[i][j];
          }
               cin >> N;
             for(int i = 0; i < N; i++)
              cin >> b[i];
            for(int i = 0; i < N; i++) {
                for(int j = 0; j < N; j++) {
                       appear[i][j] = false;
                   for(int k = 0; k < N; k++) {
                     if(A[i][j] == b[k]) appear[i][j] = true;
                   }
                 }
              }
       string ANS = "No";
            for(int i = 0; i < 3; i++) {
               if(appear[i][0] and appear[i][1] and appear[i][2]) ANS = "Yes";
              }
            for(int i = 0; i < 3; i++) {
               if(appear[0][i] and appear[1][i] and appear[2][i]) ANS = "Yes";
            }
            if(appear[0][0] and appear[1][1] and appear[2][2]) ANS = "Yes";
            if(appear[0][2] and appear[1][1] and appear[2][0]) ANS = "Yes";
                    cout << ANS << endl;
 return 0;

    }


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			int root[][]=new int[n+1][n+1];
			for(int i=0;i<=n;i++)
				Arrays.fill(root[i], 100000);
			for(int i=0;i<n;i++)
			{
				int r=in.nextInt();
				int k=in.nextInt();
				for(int j=0;j<k;j++)
					root[r][in.nextInt()]=1;
			}
			for(int i=0;i<=n;i++)
				root[i][i]=0;
			for (int i=1;i<=n;i++)//ワーシャルフロイド
				for(int j=1;j<=n;j++)
					for(int k=1;k<=n;k++)
					{
						//j->kへ行くのにiを経由した方が良いかどうか
						int c=root[j][i]+root[i][k];
						root[j][k]=Math.min(root[j][k],c);
					}
			int p=in.nextInt();
			for(int i=0;i<p;i++)
			{
				int s=in.nextInt(),t=in.nextInt();
				int TTL=in.nextInt();
				int min=root[s][t]+1;
				System.out.println(min<=TTL ? min:"NA");
			}
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main()
{
    int a, b, k;
    scanf("%d%d%d", &a, &b, &k);
    int  i;
    for (i=0; i<k; i++)
    {
        if (a+i > b) continue;
        printf("%d\n", a + i);
    }
    for (i=k-1; i>=0; i--)
    {
        if (b-i <= a + (k-1) || b-i > b) continue;
        printf("%d\n", b - i);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
VVI g;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N,M; cin >>N>>M;
    g.resize(N);
    VI H(N);
    REP(i,N){
        cin >> H[i];
    }
    REP(i,M){
        int a,b; cin >> a >> b;
        a--; b--;
        g[a].eb(b);

        g[b].eb(a);
    }
    int ans = 0;
    REP(i,N){
        bool ok = true;
        for(int x : g[i]){
            if(H[i] <= H[x]) ok = false;
        }
        if(ok) ans++;

    }
    cout << ans << endl;

}

Measured memory_bytes: 8744
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
a_sum = sum(a)
ans = 'Yes'
for i, c in enumerate(a[:m]):
    if c < a_sum / (4 * m):
        ans = 'No'

print(ans)


Measured memory_bytes: 9096
import sys

N = int(input())
S = [None]*N
counter = {}
for i in range(N):
    tmp = input()
    if tmp in counter:
        counter[tmp] += 1
    else:
        counter[tmp] = 1

#sort by value
counter_sorted = sorted(counter.items(), key=lambda x:x[1], reverse = True)

tmp = counter_sorted[0][1]
output = []
L = len(counter)
for i in range(L):
    if tmp == counter_sorted[i][1]:
        output.append(counter_sorted[i][0])
    else:
        break

#sort by key
output = sorted(output)
for i in output:
    print(i)

Measured memory_bytes: 48860
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
//ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
int D[10], K;
bool IsOK(ll v) {
	while (v) {
		rep(i, 0, K) {
			if (v % 10 == D[i]) {
				return false;
			}
		}
		v /= 10;
	}
	return true;
}
int main() {
	ll N, c = 1;
	scanf("%lld%d", &N, &K);
	rep(i, 0, K)scanf("%d", &D[i]);
	while (!IsOK(N))N++;
	printf("%lld\n", N);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

const int MAXN = 105;

int a[5][MAXN], f[5][MAXN];

int n;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= 2; i++)
		for (int j = 1; j <= n; j++)
			cin >> a[i][j];
	memset(f, 0, sizeof(f));
	for (int i = 1; i <= 2; i++)
		for (int j = 1; j <= n; j++)
			f[i][j] = max(f[i - 1][j], f[i][j - 1]) + a[i][j];
	cout << f[2][n] << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
from heapq import heappush, heappop, heapify

def main():
  K = int(input())

  q = [i for i in range(1, 11)]
  heapify(q)
  used = set()

  while K:
      n = heappop(q)

      if n in used: continue
      used.add(n)
      K -= 1

      if K == 0:
          print(n)
          break

      last = n % 10

      if last == 0: 
          heappush(q, n*10)
          heappush(q, n*10+1)
      elif last == 9:
          heappush(q, n*10+last)
          heappush(q, n*10-1+last)
      else:
          heappush(q, n*10+last)
          heappush(q, n*10+1+last)
          heappush(q, n*10-1+last)
if __name__ == '__main__':
  	main()

Measured memory_bytes: 20416
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	int k,n;
	cin>>k>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ans = a[n-1]-a[0];

	for(int i=1;i<n;i++){
		int v = a[i] - a[i-1];
		ans = min(ans,k-v);
	}

	cout<<ans<<endl;



}

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


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

using namespace std;

int main()
{
	int a, b,c, i, n;
	cin >> n;
	for(i = 0; i < n; i++){
		cin >> a >> b >> c;
		if(a*a + b*b == c*c || b*b + c*c == a*a || a*a + c*c == b*b){
			cout << "YES" << endl;
		}
		else{
			cout <<"NO" << endl;
		}
	}
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-

from collections import Counter

N = input()
S = input().split('+')

dic_chr_num = Counter(S)
dic_num_kind = Counter(dic_chr_num.values())

ans = 4 * len(dic_chr_num) - 1
for num, kind in dic_num_kind.items():
    if num == 1:
        ans -= 2 * kind
    elif kind >= 2:
        ans -= 2 * (kind - 2)

print(ans)

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int m; cin >> m;
    ll k = 0, s = 0;
    FOR(i, 0, m) {
        ll d, c; cin >> d >> c;
        k += c;
        s += d * c;
    }
    cout << k - 1 + (s - 1) / 9 << "\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args){

		Scanner scan01 = new Scanner(System.in);

		int numbox[] = new int[3];
		for(int i=0; i<3; i++){
			numbox[i] = scan01.nextInt();
		}

		int num;
		num = numbox[1];
		numbox[1] = numbox[0];
		numbox[0] = numbox[2];
		numbox[2] = num;

		System.out.println(numbox[0]);
		System.out.println(numbox[1]);
		System.out.println(numbox[2]);

		scan01.close();
	}

}

Measured memory_bytes: 22740
#include<stdio.h>
int main(){
    int N,M;
    int A[10000];
    int sum=0;
    scanf("%d %d",&N,&M);
    for(int i=0;i<M;i++){
        scanf("%d",&A[i]);
    }
    for(int i=0;i<M;i++){
        sum=sum+A[i];
    }
    if(0<=N-sum){
        printf("%d\n",N-sum);
    }else if(N-sum<0){
        printf("-1\n");
    }
}

Measured memory_bytes: 1720
N = int(input())
ans = [0]*(N+1)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            n = x*x + y*y + z*z + x*y + y*z + z*x
            if n <= N:
                ans[n] += 1
print(*ans[1:], sep='\n')

Measured memory_bytes: 9308
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
vector<pair<int,int> >G[200005];
vector<int>all[1000005],newG[4000005];
int vis[4000005],x[4000005],dist[4000005],ptr[4000005];
int main(void)
{
	int i,color,n,m,newn;
	vector<int>::iterator j;
	scanf("%d%d",&n,&m);newn=n+1;
	for(i=1;i<=m;++i)
	{
		int x,y,v;
		scanf("%d%d%d",&x,&y,&v);
		G[x].emplace_back(v,y);
		G[y].emplace_back(v,x);
		all[v].push_back(x);
		all[v].push_back(y);
	}
	for(i=1;i<=n;++i)sort(G[i].begin(),G[i].end());
	for(color=1;color<=1000002;++color)
	{
		if(all[color].empty())continue;
		for(j=all[color].begin();j!=all[color].end();++j)
		{
			int v=*j;
			if(vis[v]==color)continue;
			int L=1,R=1;
			x[L]=v;vis[v]=color;
			while(L<=R)
			{
				while(ptr[x[L]]<G[x[L]].size())
				{
					int c=G[x[L]][ptr[x[L]]].first;
					if(c!=color)break;
					int u=G[x[L]][ptr[x[L]]].second;
					if(vis[u]!=color)
					{
						vis[u]=color;
						x[++R]=u;
					}
					++ptr[x[L]];
				}
				++L;
			}
			for(i=1;i<=R;++i)
			{
				newG[x[i]].push_back(newn);
				newG[newn].push_back(x[i]);
			}
			++newn;
		}
	}
	for(i=1;i<=newn;++i)dist[i]=-2;
	int L=1,R=1;x[1]=1;dist[1]=0;
	while(L<=R)
	{
		for(j=newG[x[L]].begin();j!=newG[x[L]].end();++j)
		{
			int u=*j;
			if(dist[u]==-2)
			{
				dist[u]=dist[x[L]]+1;
				x[++R]=u;
			}
		}
		++L;
	}
	printf("%d\n",dist[n]/2);
}

Measured memory_bytes: 155008
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_left
from itertools import accumulate


n = ni()
a = list(li())

suma = sum(a)
cuma = [0] + list(accumulate(a))
half = suma / 2
halfidx = bisect_left(cuma, half) - 1
if halfidx == -1:
    print(cuma[1] - (cuma[n] - cuma[1]))
else:
    first = cuma[n] - cuma[halfidx] - cuma[halfidx]
    latter = cuma[halfidx+1] - (cuma[n] - cuma[halfidx+1])
    print(min(first, latter))




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


Measured memory_bytes: 3060
n,k = map(int,input().split())
s = [i for i in range(n+1)]
a = [0]*(n+1)
b = [0]*(n+1)
t = n+1-k
for i in range(0,n+1):
    if i < t+1:
        a[-(i+1)] = (i+1)*s[-(i+1)]
        b[-(i+1)] = (i+1)*s[i]
        c = i+1
    else:
        a[-(i+1)] = c*s[-(i+1)]
        b[-(i+1)] = c*s[i]
res = sum(b)-sum(a)+t+1
print(res%(10**9+7))

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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define debug_interval ','
#define dump_interval endl
#define debug_toggle 0

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}

int n,m;
char b;
string s,t;

int main(){
  ios::sync_with_stdio(false);
  cin>>n>>m;
  char a[n][n];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>a[i][j];
    }
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<m;j++){
      cin>>b;
      s+=b;
    }
  }
  for(int i=0;i<=n-m;i++){
    for(int j=0;j<=n-m;j++){
      for(int k=0;k<m;k++){
        for(int l=0;l<m;l++){
          t+=a[i+k][j+l];
        }
      }
      debug(s,t);
      if(s==t){
        dump("Yes");
        return 0;
      }
      t="";
    }
  }
  dump("No");
}

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

int main() {
	long long a, b, k;
	cin >> a >> b >> k;
	vector<long long>ans;
	for (int i = a; i < min(b+1,a + k); i++) {
		ans.push_back(i);
	}
	for (int i = b; i > max(a-1,b - k); i--) {
		ans.push_back(i);
	}
	sort(ans.begin(), ans.end());
	ans.erase(unique(ans.begin(), ans.end()),ans.end());
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        if(i%2!=0 &&  a%2!=0)
            ans++;

    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3548
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    dp = [[0] * (N + 1) for _ in range(N + 1)]
    for i in range(N - 1, -1, -1):
        for j in range(N - 1, -1, -1):
            if S[i] == S[j]:
                dp[i][j] = dp[i + 1][j + 1] + 1

    ans = 0
    for i in range(N):
        for j in range(N):
            if ans < min(dp[i][j], j - i):
                ans = min(dp[i][j], j - i)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 270220
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <queue>
#include <stack>

typedef long long ll;
using namespace std;

int main(){
  ll i,j,k,p[3][2],cnt[5]={};
  for(i=0;i<3;i++){
    cin >> p[i][0] >> p[i][1];
    cnt[p[i][0]]++;
    cnt[p[i][1]]++;
  }
  sort(cnt,cnt+5);
  for(i=1;i<5;i++){
    if(i==1 || i==2){
      if(cnt[i]!=1){
        cout << "NO" << endl;
        return 0;
      }
    }
    if(i==3 || i==4){
      if(cnt[i]!=2){
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}


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

ll a, b;

int main()
{
    cin >> a >> b;
    ll x = __gcd(a, b);
    int tot = 0;
    for (ll i = 2; i * i <= x; i++)
    {
        if (x % i == 0)
        {
            tot++;
            while (x % i == 0)
                x /= i;
        }
    }
    if (x > 1)
        tot++;
    cout << tot + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
N,A,B,C=map(int,input().split())
S=[input() for _ in range(N)]
ans=''
for i in range(N):
    if S[i]=='AB':
        if A==0 and B==0:
            print('No')
            exit()
        elif A==1 and B==0:
            A-=1
            B+=1
            ans+='B'
        elif A==0 and B==1:
            A+=1
            B-=1
            ans+='A'
        elif A==1 and B==1 and i<N-1:
            if 'A' in S[i+1]:
                A+=1
                B-=1
                ans+='A'
            else:
                A-=1
                B+=1
                ans+='B'
        elif A>B:
            A-=1
            B+=1
            ans+='B'
        else:
            A+=1
            B-=1
            ans+='A'
    elif S[i]=='AC':
        if A==0 and C==0:
            print('No')
            exit()
        elif A==1 and C==0:
            A-=1
            C+=1
            ans+='C'
        elif A==0 and C==1:
            A+=1
            C-=1
            ans+='A'
        elif A==1 and C==1 and i<N-1:
            if 'A' in S[i+1]:
                A+=1
                C-=1
                ans+='A'
            else:
                A-=1
                C+=1
                ans+='C'
        elif A>C:
            A-=1
            C+=1
            ans+='C'
        else:
            A+=1
            C-=1
            ans+='A'
    else:
        if B==0 and C==0:
            print('No')
            exit()
        elif B==1 and C==0:
            B-=1
            C+=1
            ans+='C'
        elif B==0 and C==1:
            B+=1
            C-=1
            ans+='B'
        elif B==1 and C==1 and i<N-1:
            if 'B' in S[i+1]:
                B+=1
                C-=1
                ans+='B'
            else:
                B-=1
                C+=1
                ans+='C'
        elif B>C:
            B-=1
            C+=1
            ans+='C'
        else:
            B+=1
            C-=1
            ans+='B'
print('Yes')
for c in ans:
    print(c)

Measured memory_bytes: 16404
#include <iostream>
#include <vector>

using namespace std;

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

    vector<long long> v(n + 1);
    v[0] = 2;
    v[1] = 1;
    for (int i = 2; i <= n; ++i)
        v[i] = v[i - 1] + v[i - 2];
    cout << v[n] << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>

/*

5/7

57=0...5
507=7...1
107=1...3
307=4...2
c

5/7=0.714c

*/

int main(void){
	int a, b, n, sum;
	
	while(~scanf("%d %d %d",&a,&b,&n)){
		sum=0;
		
		a=a%b*10;
		for(;n--;) sum+=a/b, a=a%b*10;
		
		printf("%d\n",sum);
	}
	
	return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

signed main()
{
	int N, K;
	cin >> N >> K;

	
	int cnt = 0;
	while (N > 0)
	{
		cnt++;
		N /= K;
	}

	cout << cnt << endl;
}




Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    LLONG X; cin >> X;
    set<LLONG> divs;
    for (LLONG d = 1; d * d <= X; ++d)
    {
        if (X % d == 0)
        {
            divs.insert(d);
            divs.insert(X / d);
            //divs.insert(-d);
            //divs.insert(-X / d);
        }
    }
    for (const LLONG d : divs)
    {
        LLONG X2 = X / d - d * d * d * d;
        if (X2 % 5 == 0)
        {
            X2 /= 5;
            if (X2 == 0)
            {
                cout << d << ' ' << 0 << endl;
                return 0;
            }
            set<LLONG> BCands;
            for (LLONG B = 1; B * B <= abs(X2); ++B)
            {
                if (abs(X2) % B == 0)
                {
                    for (LLONG b : {B, X2 / B, -B, -X2 / B})
                    {
                        LLONG X3 = X2 / b - d * d * d;
                        if (b * b * b + 2 * d * b * b + 2 * d * d * b == X3)
                        {
                            cout << b + d << ' ' << b << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;

int n,a,b,c,m,INF=(1<<24);
P A,B;
vector<PP> t[10000];

P now,now2;
PP Z = PP(P(-1,-1),P(-1,-1));
PP get_next();
PP get_next2();

int main(){
  while(cin>>n>>a>>b&&a&&b){
    A=P(a/100,a%100);
    B=P(b/100,b%100);
    for(int i=0;i<n;i++){
      t[i].clear();
      cin>>m;
      for(int j=0;j<m;j++){
	cin>>a>>b;
	t[i].push_back(PP(P(a/100,a%100),P(b/100,b%100)));
      }

      t[i].push_back(PP(B,B));
      sort(t[i].begin(),t[i].end());

    }
    
    PP next;
    int cnt=0,ans=0;
    now=A;
    while(now<B){
      next=get_next();
      
      if(next.first==now){//cout<<'a'<<endl;
	next=get_next2();
	//cout<<next.first.first<<' '<<next.first.second<<' '<<next.second.first<<' '<<next.second.second<<endl;
	now=next.second;
	cnt=0;
      }else{//cout<<'b'<<endl;
	cnt+= (next.first.first*60+next.first.second)-(now.first*60+now.second);
	ans=max(ans,cnt);
	now=next.first;now2=next.second;
      }
    }

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

PP get_next(){
  PP res=PP(now,P(0,0));
  for(int i=0;i<n;i++){
    if(t[i].size()==0)continue;
    if(res < t[i][0]){
      res=t[i][0];
    }
  }
  for(int i=0;i<n;i++){
    while(t[i].size()>0&&t[i][0].second<=res.first)t[i].erase(t[i].begin());
  }
  return res;
}

PP get_next2(){
  int tmpI=-1;
  PP res = PP(P(INF,INF),P(INF,INF));
  for(int i=0;i<n;i++){
    if(t[i].size()==0)continue;
    if(res.second>t[i][0].second){
      res=t[i][0];
      tmpI=i;
    }
  }
  if(tmpI==-1)return res;
  t[tmpI].erase(t[tmpI].begin());
  return res;
}

Measured memory_bytes: 1432
#include <stdio.h>
 
int main()
{
  int i, n, minv, maxv;
  int R[200000];
 
  scanf("%d", &n);
  for(i=0; i<n; i++) {
    scanf("%d", &R[i]);
  }
 
  minv = R[0];
  maxv = R[1]-R[0];
  for(i=1; i<n; i++) {
    if(maxv < R[i]-minv)
      maxv = R[i]-minv;
    if(minv > R[i])
      minv = R[i];
  }
  printf("%d\n", maxv);
  return 0;
}

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

int N;
char S[305][305];

bool check(int k){
    bool res = true;

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if((i-k+N)%N == j) continue;
            if(S[i][j] != S[(j+k)%N][(i-k+N)%N]) res = false;
        }
    }

    return res;
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++) cin >> S[i][j];

    int ans = 0;
    for(int i=0;i<N;i++)
        if(check(i)) ans++;

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


Measured memory_bytes: 512
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
# 昇順でソート
h.sort()
ans = float("inf")
for i in range(n - k + 1):
    # 最適な選び方は、連続した並びの木k本となる
    ans = min(ans, h[i + k - 1] - h[i])
print(ans)

Measured memory_bytes: 7384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int M = Integer.parseInt(tokens[1]);
		int[] L = new int[M];
		int[] R = new int[M];
		int lMax = Integer.MIN_VALUE;
		int rMin = Integer.MAX_VALUE;
		for(int i = 0; i < M; ++i) {
			tokens = in.readLine().split(" ");
			L[i] = Integer.parseInt(tokens[0]);
			R[i] = Integer.parseInt(tokens[1]);
			lMax = Math.max(L[i], lMax);
			rMin = Math.min(rMin, R[i]);
		}
		int result = rMin - lMax + 1;
		if(result< 0) {
			result = 0;
		}
		System.out.println(result);
		in.close();
	}
}

Measured memory_bytes: 46824
#include <cstdio>

int n,k;
int f[2005][2005],s[2005];
const int p=1000000007;

int main()
{
    scanf("%d%d",&n,&k),f[0][n+1]=1;
    for(int i=1;i<=k;++i)
    {
        s[n+1]=f[i-1][n+1];
        for(int j=n;j>=1;--j)s[j]=(s[j+1]+f[i-1][j])%p;
        for(int j=1;j<=n-i+1;++j)f[i][j]=s[j];
    }
    int Ans=(f[k][1]-f[k-1][1]+p)%p;
    for(int i=n-k-1;i>=1;--i)Ans=(Ans<<1)%p;
    printf("%d\n",Ans);
    return 0;
}

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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 100100;
int a[N];

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	int n;
	cin >> n;
	ll sum = 0;
	forn(i, n) {
		scanf("%d", &a[i]);
		sum += a[i];
	}	
	ll add = 1ll * n * (n + 1) / 2;
	if (sum % add != 0) {
		puts("NO");
		return 0;
	}	
	ll kol = 0;
	ll tot = sum / add;
	forn(i, n) {
		ll diff = -a[(i + 1) % n] + a[i];
		if ((diff + tot) % n != 0) {
			puts("NO");
			return 0;
		}	
		kol += abs(diff + tot) / n;
	}	
	if (kol == tot) {
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}


Measured memory_bytes: 640