akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main()
{
    int a[9];
    bool c[9];
    rep(i, 9)
    {
        scanf("%d", &a[i]);
        c[i] = false;
    }
    int n;
    scanf("%d", &n);
    int b;
    rep(i, n)
    {
        scanf("%d", &b);
        rep(i, 9)
        {
            if (a[i] == b)
            {
                c[i] = true;
            }
        }
    }

    bool ans = false;
    if (c[0] && c[1] && c[2])
        ans = true;
    else if (c[3] && c[4] && c[5])
        ans = true;
    else if (c[6] && c[7] && c[8])
        ans = true;
    else if (c[0] && c[3] && c[6])
        ans = true;
    else if (c[1] && c[4] && c[7])
        ans = true;
    else if (c[2] && c[5] && c[8])
        ans = true;
    else if (c[0] && c[4] && c[8])
        ans = true;
    else if (c[2] && c[4] && c[6])
        ans = true;

    if (ans)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}

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

c = [0] * (N + 1)
Dx = [0] * (N + 1)
for a in A:
    c[a] += 1 #cは、aという数が出た回数を記録
    Dx[c[a]]+=1
    #Dxは、その回数のところに種類を記録。賢い。

Sx=[0]#初項は0
for j in range(1,N+1):
    Sx.append(Sx[j-1]+Dx[j])
#解法2を真似してみる。
for h in range(1,N+1):
    Sx[h]=Sx[h]/h

x=N
k=1
while k<N+1:
    if x<0:
        for _ in range(N-k+1):
            print(0)
        exit(0)
    if k<=Sx[x]:
        print(x)
        k+=1
    else:
        x-=1
        

Measured memory_bytes: 37884
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char rbuf[2800014];
char wbuf[699997];
int rbufl, wbufl;

#define getchar_unlocked() rbuf[rbufl++]
#define putchar_unlocked(c) wbuf[wbufl++]=(c)

inline uint32_t nextpint(void){ char c=getchar_unlocked(); uint32_t x=0; while('0'<=c){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
inline void printpint(int32_t x){ if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }

int edge[200000][2];

int qmem[400000];

int *e[100001];
int el[100001];

int prev[100001];

int s[100000];
int sl, sr;

int main(void){
	read(STDIN_FILENO, rbuf, sizeof(rbuf));
	int n=nextpint();
	int m=nextpint();
	for(int i=0; i<m; i++){
		int A=nextpint();
		int B=nextpint();
		edge[i][0]=A;
		edge[i][1]=B;
		el[A]++;
		el[B]++;
	}
	int ne=0;
	for(int i=1; i<=n; i++){
		e[i]=&qmem[ne];
		ne+=el[i];
		el[i]=0;
	}
	for(int i=0; i<m; i++){
		int A=edge[i][0];
		int B=edge[i][1];
		e[A][el[A]++]=B;
		e[B][el[B]++]=A;
	}
	int k=0;
	prev[1]=1;
	s[sr++]=1;
	while(sl<sr){
		k++;
		int from = s[sl++];
		for(int i=0; i<el[from]; i++){
			int to = e[from][i];
			if(prev[to]==0){
				prev[to]=from;
				s[sr++]=to;
			}
		}
	}
	if(k==n){
		putchar_unlocked('Y');
		putchar_unlocked('e');
		putchar_unlocked('s');
		putchar_unlocked('\n');
		for(int i=2; i<=n; i++){
			printpint(prev[i]);
		}
		write(STDOUT_FILENO, wbuf, wbufl);
	}else{
		puts("No");
	}
}


Measured memory_bytes: 9216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		
		int top = sc.nextInt();
		int under = sc.nextInt();
		int hight = sc.nextInt();
		
		System.out.println((top + under) * hight / 2);
	}
}


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

int abs(int x) {
    return (x > 0 ? x : -x);
}

int nwd(int a, int b) {
    return (b == 0 ? a : nwd(b, a % b));
}

int main() {
    int n, x;
    cin >> n >> x;
    int d;
    for(int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        if(i == 1) {
            d = abs(x - a);
        } else {
            d = nwd(d, abs(x - a));
        }
    }
    cout << d;
    return 0;
}

Measured memory_bytes: 256
import sys
f=lambda:tuple(map(int,sys.stdin.readline().split()))
n,m,k=f()
lta=[f() for _ in range(m)]
ltb=[f() for _ in range(k)]
p=[-1]*n
def root(x):
  while p[x]>=0: x=p[x]
  return x
def unite(x,y):
  x,y=root(x),root(y)
  if x==y: return
  if x>y: x,y=y,x
  p[x]+=p[y]
  p[y]=x
def same(x,y):
  return root(x)==root(y)
def size(x):
  return -p[root(x)]
l=[0]*n
for a,b in lta:
  unite(a-1,b-1)
  l[a-1]-=1
  l[b-1]-=1
for c,d in ltb:
  if same(c-1,d-1):
    l[c-1]-=1
    l[d-1]-=1
for i in range(n):
  l[i]+=size(i)-1
print(*l)


Measured memory_bytes: 38428
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int MAXI = 1e6 + 10;

template<class T>
inline T gcd(T a, T b) {
    if (b == 0) return a;
    return  gcd(b, a % b);
}

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n; cin >> n;
	vector<int> cnt(MAXI, 0);
	int d = 0;
	REP(i, n) {
		int a; cin >> a;
		cnt[a]++;
		d = gcd(d, a);
	}
	if (d > 1) {
		cout << "not coprime" << '\n';
		return 0;
	}

	for (int i = 2; i < MAXI; i++) {
		int sum = 0;
		for (int j = i; j < MAXI; j += i)
			sum += cnt[j];
		if (sum > 1) {
			cout << "setwise coprime" << '\n';
			return 0;
		}
	}

	cout << "pairwise coprime" << '\n';
    return 0;
}


Measured memory_bytes: 7152
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y;
    fact();
    cin >> X >> Y;
    if((X + Y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    int t = (X + Y) / 3;
    X -= t; Y -= t;
    cout << C((X + Y), X) << endl;


    return 0;
}


Measured memory_bytes: 16640
x=int(input())
if x==2 or x==3:
    print(x)
    exit()
for i in range(x,10**6):
    if i%2==0:
        continue
    cnt=0    
    for j in range(3,x,2):
        if i%j==0:
            cnt+=1
            break
    if cnt==0:
        print(i)
        exit()    

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
#define N 1000000
int gcd(int n, int m)
{
    return m==0?n:gcd(m , n%m);

}
int a[N];
int main()
{
    long long  x,y;
    while(cin >>x >>y)
    {
        long long  sum = 1;
        while(x <=y/2)
        {
            sum ++;
            y/=2;
        }
        cout <<sum <<endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.math.*

fun main(args: Array<String>) {
    val numList = readLine()!!.split(" ")
    val numN = BigInteger(numList[0])
    val numK = BigInteger(numList[1])

    var modA = numN % numK
    var modB = numK - modA

    println(modA.min(modB))
}

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

int main()
{
    string s, t;
    cin >> s >> t;
    int l = s.size();
    int cnt = 0;
    rep(i, l) {
        if (s[i] != t[i]){
            cnt += 1;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);


  int n,k;cin>>n>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  sort(v.begin(), v.end());
  int ans=0;
  for(int i=0;i<k;i++){
    ans+=v[i];
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3620
def main(h: int, n: int, a: list):
    for i in sorted(a):
        h -= i
        if h <= 0:
            print("Yes")
            return

    print("No")


if __name__ == "__main__":
    h, n = map(int, input().split())
    a = list(map(int, input().split()))

    main(h, n, a)


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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

int main(){
    int K;
    string S;
    cin >> K >> S;
    if(S.size()<=K){
      printl(S);
    }else{
      string result = S.substr(0,K) + "...";
      printl(result);
    }
}


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

int main(){
  string s;
  cin >> s;
  string rs,rsa,rsb,sa,sb;
  int n=s.size();
  sa=s.substr(0,(n-1)/2);
  sb=s.substr((n+1)/2,(n-1)/2);
  rs=s;rsa=sa;rsb=sb;
  reverse(rs.begin(),rs.end());
  reverse(rsa.begin(),rsa.end());
  reverse(rsb.begin(),rsb.end());
  if(rs==s&&rsa==sa&&rsb==sb)
    cout <<"Yes"<<endl;
  else
    cout <<"No"<< endl;
  return 0;
}

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

const int MAX = 200000;
const int MOD = 1000000007;

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main (){   
    COMinit(); 
    int N;
    cin>>N;
    vector<ll> A(N);
    
    for(int i=0; i<N; i++){
        cin>>A[i];
    }
    sort(A.begin(), A.end(), greater<ll>());
    ll Sum=0;
    for(int i=0; i<N; i++){
        ll T=0;
        Sum += A[i]*(i+2);
        Sum%=MOD;
    }
    for(int i=0; i<N-1; i++){
        Sum*=4;
        Sum%=MOD;
    }
    cout<<Sum;
}

Measured memory_bytes: 6528
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        final int MOD = 1000000007;
        long result = Math.abs(n - m) <= 1 ? factorial(n) * factorial(m) % MOD : 0;
        if ((n + m) % 2 == 0) {
            result *= 2;
            result %= MOD;
        }

        // 出力
        System.out.println(result);
    }

    public static long factorial(long n) {
        long x = 1;
        final long MOD = 1000000007L;
        for (long i = 2; i <= n; i++) {
            x *= i;
            x %= MOD;
        }
        return x;
    }
}


Measured memory_bytes: 21332
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
typedef ll Weight;
struct Edge {  //src:辺の始点,dst:辺の終点,weight:辺の重さ
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : //辺は重さが重いものを"小さい"と定義する
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
//引数 g:隣接リスト,s:始点,dist:各頂点までの距離が入る(負閉路を含む場合,-INF),prev:最短路木の親頂点が入る
//戻値 負閉路が存在しない場合:true,そうでないとき:false
bool shortestPath(const Graph &g,int s,vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF+INF); dist[s] = 0;
  prev.assign(n, -2);
  bool negative_cycle = false;
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(auto e=g[i].begin();e!=g[i].end();e++){
        if(dist[e->dst] > dist[e->src] + e->weight) {
          dist[e->dst] = dist[e->src] + e->weight;
          prev[e->dst] = e->src;
          if (k == n-1) {
            dist[e->dst] = -INF;
            negative_cycle = true;
          }
        }
      }
    }
  }
  return !negative_cycle;
}

//引数 prev:最短路木の親頂点集合,t:終点
//戻値 path:sからtへの最短経路
vector<int> buildPath(const vector<int> &prev, int t) {
  vector<int> path;
  for (int u = t; u >= 0; u = prev[u])
    path.push_back(u);
  reverse(path.begin(), path.end());
  return path;
}
Graph g;    //頂点数vの空隣接リストgを生成
ll n,m;
bool dfs(ll now,vector<bool> have){
    if(now==n-1){
        return true;
    }
    for(auto e=g[now].begin();e!=g[now].end();e++){
        ll k=e->dst;
        if(have[k]){
            continue;
        }
        have[k]=true;
        if(dfs(k,have)){
            return true;
        }
    }
}
int main(){
  int a,b;
  cin>>a>>b;
  cout<<a*b<<endl;
  // ...
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {


    private static int[] solve(Graph graph) {
        int n = graph.getSize();
        int[] dist = new int[n + 1];
        int[] parent = new int[n + 1];
        boolean[] visited = new boolean[n + 1];
        Arrays.fill(dist, Integer.MAX_VALUE);
        dist[1] = 0;
        parent[1] = 0;
        Queue<Integer> pq = new LinkedList<>();
        pq.offer(1);
        while (!pq.isEmpty()) {
            Integer node = pq.poll();
            visited[node] = true;
            List<Node> childNodes = graph.getAdjacentList(node);
            for (Node child : childNodes) {
                if (visited[child.end])
                    continue;
                int newDist = dist[node] + child.weight;
                if (dist[child.end] > newDist) {
                    dist[child.end] = newDist;
                    pq.offer(child.end);
                    parent[child.end] = child.start;
                }
            }
        }
        return parent;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        Graph graph = new Graph(N);
        for (int i = 0; i < M; i++) {
            int start = Integer.parseInt(sc.next());
            int end = Integer.parseInt(sc.next());
            graph.addEdge(start, end);
        }
        int[] res = solve(graph);
        for (int i = 2; i <= N; i++) {
            if(res[i] == Integer.MAX_VALUE){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
        for (int i = 2; i <= N; i++) {
            System.out.println(res[i]);
        }
    }

    static class Graph {

        private final Map<Integer, List<Node>> adjacentList = new HashMap<>();

        Graph(int capacity) {
            for (int i = 1; i <= capacity; i++) {
                adjacentList.put(i, new LinkedList<>());
            }
        }


        public void addEdge(int start, int end) {
            adjacentList.get(start).add(new Node(start, end));
            adjacentList.get(end).add(new Node(end, start));
        }

        public List<Node> getAdjacentList(int node) {
            return adjacentList.get(node);
        }

        public int getSize() {
            return adjacentList.size();
        }
    }

    static class Node {
        int start;
        int end;
        int weight = 1;

        Node(int s, int e) {
            this.start = s;
            this.end = e;
        }
    }
}


Measured memory_bytes: 82056
s=int(input())
x=s
list=[]
for i in range(1000000000000000000):
    y=x%(-2)
    if y == -1:
        x = (x-1)//(-2)
        y = 1
    else:
        x=x//(-2)
    list.insert(0, y)
    if x == 0:
        print(*list, sep="")
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
using namespace std;
int gcd(int a, int b)
{
    if (a < b)
        return gcd(b, a);
    else if (a % b)
        return gcd(b, a % b);
    else
        return b;
}
main() 
{
    int n;
    cin >> n;
    int a[n];
    int u[n],v[n],w[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a,a+n);
    int x = a[0], y = a[1],z=a[n-1];
    for (int i = 0; i < n; i++)
    {
       u[i]=gcd(x,a[i]);
       v[i]=gcd(y,a[i]);
       w[i]=gcd(z,a[i]);
    }
    sort(u,u+n);
    reverse(u,u+n);
    sort(v,v+n);
    reverse(v,v+n);
    sort(w,w+n);
    reverse(w,w+n);
    int s = u[0], t = v[0],k=w[0];
    for (int i = 0; i < n - 1; i++)
    {
        s = gcd(s, u[i]);
        t = gcd(t, v[i]);
        k = gcd(k ,w[i]);
    }
    cout << max(max(s, t),k) << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;


void solve()
{
	int n;
	cin>>n;
	vector<int>a(n);
	rep(i,n)cin>>a[i];
	int ans=0;
	rep(i,n){
		if((i+1)%2==1&&a[i]%2==1)++ans;
	}
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 1e4 + 5, mod = 1e9 + 7;
typedef long long ll;
ll dp[maxn][2][105];
int k[maxn];
char tmp[maxn];
int main()
{
//    freopen("in", "r", stdin);
    int d;
    scanf("%s", tmp);
    int n = strlen(tmp);
    scanf("%d", &d);
    for(int i = 0; i < n; i++)
        k[i] = tmp[n-i-1] - '0';
    for(int i = 0; i <= 9; i++){
        if(i <= k[0]){
            dp[0][0][i%d] += 1;
        }else{
            dp[0][1][i%d] += 1;
        }
    }
    for(int i = 1; i < n; i++){
        for(int r = 0; r < d; r++){
            for(int x = 0; x < k[i]; x++){
                int q = ((r-x)%d + d) % d;
                dp[i][0][r] =(dp[i][0][r] + dp[i-1][0][q] + dp[i-1][1][q]) % mod;
            }
            int q = ((r-k[i])%d + d) % d;
            dp[i][0][r] = (dp[i][0][r] + dp[i-1][0][q])%mod;
            dp[i][1][r] = (dp[i][1][r] + dp[i-1][1][q])%mod;
            for(int x = k[i] + 1; x <= 9; x++){
                int q = ((r-x)%d + d) % d;
                dp[i][1][r] =(dp[i][1][r] + dp[i-1][0][q] + dp[i-1][1][q]) % mod;

            }
        }
    }
    cout<<(dp[n-1][0][0] + mod - 1) % mod<<endl;
    return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#include <map> 
#include <algorithm>
#include <string.h>
#include <limits.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

typedef long long int ll;



void pre_process(string p, int *back_table){
    int i = 0, j = -1, length = p.length();
    back_table[0] = -1;

    while(i <= length) { 
        while(j != -1 && p[i] != p[j]) j = back_table[j];
        i++; j++;
        back_table[i] = j;
    }

}

void _search(string p, string t, int *back_table){
    int i = 0, j = 0, length = t.length(), m = p.length();

    while(i <= length){
        while(j != 0 && t[i] != p[j]) j = back_table[j];
        i++; j++;
        if(j == m) { cout << "Pattern at: " << i - j << endl; j = back_table[j]; }
    }
}

int func(int arr[],int n,int m) {
    int maxsum;
    int incl[n];
    int excl[n];
    incl[0] = arr[0];
    excl [0] = 0;
    for(int i=1;i<n;i++) {
        if(i-m-1 >=0) {
            incl[i] = max(incl[i-m-1],excl[i-m-1]) + arr[i];
        }
        else
            incl[i] = arr[i];
        
        excl[i] = max(excl[i-1],incl[i-1]);
        maxsum = max(maxsum,max(incl[i],excl[i]));
    }

    return maxsum;
}

int show(int x, float y){
    return x + y;
}


int show(int x){ return x; }

float fn_(int x = show(2, 3.3)){
    return x;
}

int fn(int x = show(2)){
    return x;
}

ll solve(){
    ll n;
    cin >> n;
    ll a[n];
    ll rsum = 0;
    
    ll lsum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        rsum += a[i];
    }

    ll res = 1e18;
    for(int i = 0; i < n - 1; i++){    
        rsum -= a[i];
        lsum += a[i];    
        res = min(res, abs(lsum - rsum));
    }
    return res;
    // }
}


int main() {
    cout << solve();
}



// akasakaakas 
// akasakaakas


// akasakaakasaka

// kesav696@sbi
// kesav1096@sbi








Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
int inf=1000000000;
ll INF=10000000000000000;


int main(){
    int h,w,k;
    cin >> h >> w >> k;
    ll dp[h+1][w];
    rep(i,h+1){
        rep(j,w) dp[i][j]=0;
    }
    dp[0][0]=1;
    rep(i,h){
        rep(j,pow(2,w-1)){
            int u=j;
            vector<int> a(0);
            rep(k,w-1){
                if (u&1 == 1) a.push_back(k);
                u/=2;
            }
            bool t=true;
            //cout << a.size() << endl;
            if (a.size()==0) {
                rep(k,w){
                    dp[i+1][k]=(dp[i+1][k]+dp[i][k])%MOD;
                }
                continue;
            }
            rep(k,a.size()-1){
                if (a.at(k)==a.at(k+1)-1) t=false;
            }
            if (t){
                int y=0;
                rep(k,w){
                    if (y==a.size()) {
                    dp[i+1][k]=(dp[i+1][k]+dp[i][k])%MOD;
                    }
                    else if (k==a.at(y)){
                    dp[i+1][a.at(y)+1]=(dp[i+1][a.at(y)+1]+dp[i][a.at(y)])%MOD;
                    dp[i+1][a.at(y)]=(dp[i+1][a.at(y)]+dp[i][a.at(y)+1])%MOD;
                    //cout << dp[i+1][a.at(k)+1] << endl;
                    k++;
                    y++;
                    }
                    else {
                        dp[i+1][k]=(dp[i+1][k]+dp[i][k])%MOD;
                    }
                    //cout << dp[h][0];
                }
            }

            //cout << dp[h][0] << endl;
        }
    }
    if (w==1) {cout << 1 << endl;return 0;}
    cout << dp[h][k-1] << endl;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N;
	cin >> N;

	int ans = 0;
	for(int i = 0; i < N; i++){
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
'use strict'
const Main = input => {

  let tmp = input.split('\n');
  let Num = tmp[0].split(' ').map(Number)[0];
  let Kji = tmp[0].split(' ').map(Number)[1];
  let Str = tmp[1].trim();
  // console.log({ Num });
  // console.log({ Kji });
  // console.log({ Str });

  let Change = Str[Kji - 1];

  switch (Change) {
    case 'A': Change = 'a';
      break;
    case 'B': Change = 'b';
      break;
    case 'C': Change = 'c';
      break;
  }

  let StrArr = Str.split('');
  StrArr[Kji - 1] = Change;
  Str = StrArr.join('');

  console.log(Str);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i=(a); i<(n); ++i)
#define rrep(i,a,n) for(ll i=(a); i>(n); --i)
#define erep(i,a,n) for(ll i=(a); i<=(n); ++i)
#define rerep(i,a,n) for(ll i=(a); i>=(n); --i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int) x.size())
#define print (X) cout << (X) << endl
#define _ << " " <<
static const int INF = 1e+9+7;
ll n,x;
str s,t;
int M[100];

int main(){
  int small = INF;
  cin >> n >> x;
  rep(i,0,n){
    cin >> M[i];
    x -= M[i];
    if(M[i]<small) small = M[i];
  }

  int ans=0;
  while(true){
    x-=small;
    if(x<0) break;
    ++ans;
  }

  cout << ans+n << endl;

  









  return 0;
}





Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
typedef pair<LL, LL> P;

int main() {
  LL N; cin >> N;
  vector<P> pc(N), pr(N);
  for (int i = 0; i < N; ++i) {
    int x, y; cin >> x >> y;
    pc[i] = {x + y, x - y};
    pr[i] = {x - y, x + y};
  }
  sort(pc.begin(), pc.end());
  sort(pr.begin(), pr.end());

  LL ans = 0;
  ans = max(ans, abs(pc[0].first - pc[N-1].first));
  ans = max(ans, abs(pr[0].first - pr[N-1].first));
  ans = max(ans, abs(pc[0].second - pc[N-1].second));
  ans = max(ans, abs(pr[0].second - pr[N-1].second));
  cout << ans << endl;


}


Measured memory_bytes: 9588
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i=(a);i<(b);++i)
using namespace std;

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

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795;

int main()
{
	int a,b,c,x,ans = 0;
	cin >> a >> b >> c >> x;
	for (int i1 = 0; i1 < a + 1; ++i1)
	{
		for (int i2 = 0; i2 < b + 1; ++i2)
		{
			for (int i3 = 0; i3 < c + 1; ++i3)
			{
				if (i1 * 500 + i2 * 100 + i3 * 50 == x)
				{
					ans++;
				}
			}
		}
	}
	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 str=sc.next();
      
      	String[] input=str.split("");
      
      	int length=input.length-2;
      
      	String result=input[0]+String.valueOf(length)+input[input.length-1];
      
      	System.out.println(result);
      	
    }

}

Measured memory_bytes: 23252
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        double ans = 0.0;
        int b = 1;
        int r = 0;
        while(b < k) {
            b *= 2;
            r++;
        }
        for (int i = 1; i <= n; i++) {
            if(1 < b && k <= (b / 2) * i){
                b /= 2;
                r--;
            }
            ans += (Math.pow(0.5, r)) / n;
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long int
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define N 200005
#define mod 1000000007
using namespace std;
vector<int>adj[N];
bool vis[N];
int c=0;
map<pii,bool>mp;
void dfs(int x){
    vis[x]=1;
    c++;
    for(int i=0;i<adj[x].size();i++){
        int y=adj[x][i];
        if(vis[y]) continue;
        dfs(y);
    }
}
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(mp[{x,y}]) continue;
        mp[{x,y}]=mp[{y,x}]=1;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        c=0;
        if(!vis[i]) dfs(i);
        ans=max(ans,c);
    }
    cout<<ans;
}
int main()
{
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 45948
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define mod 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
int main()
{
	ios;
	ll n,k;
	cin>>n>>k;
	cout<<min(n%k,k-n%k)<<endl;
}


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

int main()
{
    ll D, G, ans = 1e9;
    int p[10], c[10];
    cin >> D >> G;
    rep(i, D) cin >> p[i] >> c[i];

    for (int bit = 0; bit < (1 << D); bit++) {
        ll score = 0, cnt = 0;
        vector<int> solved(D, 0);
        for (int i = 0; i < D; i++) {
            if (bit & (1 << i)) {
                score += (p[i] * (i+1) * 100) + c[i];
                cnt += p[i];
                solved[i] = 1;
            }
        }
        int i;
        for (i = D-1; i >= 0; i--) {
            if (solved[i]) continue;
            for (int j = 0; j < p[i]; j++) {
                if (score >= G) break;
                score += 100*(i+1);
                cnt++;
            }
            if (score < G) {
                score += c[i];
                solved[i] = 1;
            }
            else break;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <vector>

using namespace std;

static const int n_max = 200000;


int main(){
    int n;
    int r_max,r_min;
    cin >> n;

    vector<int> r(n);

    for (int i = 0; i < n;i++){
        cin >> r.at(i);
    }

    r_min = r.at(0);
    r_max = -2000000000;

    for (int i = 1; i < n; i++)
    {
        r_max = max(r_max, r.at(i)-r_min);
        r_min = min(r_min, r.at(i));
        }
    cout << r_max << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;

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

        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        while(true){
            c -= b;
            if(c <= 0)
                break;
            a -= d;
            if(a <= 0)
                break;
        }

        if(a <= 0){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 27000
import scala.io.StdIn

object Main extends App {

  val Array(n, k) = StdIn.readLine().split(" ").map(_.toInt)
  val a = StdIn.readLine().split(" ").map(_.toInt)
  val as = a.sorted(Ordering[Int].reverse)
  println(as.take(k).sum)
  
}


Measured memory_bytes: 27204
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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; }
 
ll MOD = 1000000007;
ll INF =1<<30;



int main(){
    int n;
    cin >> n;
    vector<int>d(n);
    rep(i,n){
        d[i] = i;
    }
    vector<int>x(n),y(n);
    rep(i,n)cin >> x[i]>>y[i];
    vector<double>ans;
    do{
        double dist = 0;
        rep(i,n-1){
            dist+=sqrt(((x[d[i]]-x[d[i+1]])*(x[d[i]]-x[d[i+1]])+
            (y[d[i]]-y[d[i+1]])*(y[d[i]]-y[d[i+1]])));
        }
        ans.push_back(dist);
    }while(next_permutation(d.begin(),d.end()));
    double tot = 0;
    rep(i,ans.size()){
        tot+=ans[i];
    }
    cout << fixed <<setprecision(8) << tot/ans.size() <<endl;
}

Measured memory_bytes: 3984
#!/usr/bin/env python
# coding: utf-8

# In[8]:


# import copy
#import numpy as np
import heapq

N, M = map(int, input().split())

def int_minus(s):
    return -int(s)

As = list(map(int_minus, input().split()))
"""
3 3
2 13 8

4 4
1 9 3 5
"""


# In[10]:


heapq.heapify(As)


# In[17]:


for i in range(M):
    mx = heapq.heappop(As)
    heapq.heappush(As, -(-mx//2))


# In[19]:


#print(As)
print(-sum(As))


# In[ ]:






Measured memory_bytes: 14180
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  long N;
  cin >> N;
  vector<long> Hs(N);
  rep (i, N) cin >> Hs[i];
  long highest = 0;
  long result = 0;
  rep (i, N) {
    if (highest <= Hs[i]) {
      highest = Hs[i];
      result++;
    }
  }
  cout << result << endl;
  return 0;
}


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

int main(){
    int N, M, ans = 0, buf1, buf2;
    cin >> N >> M;
    vector<priority_queue<int>> Q(N+1);
    vector<int> H(N+1);
    for(int i = 1; i <= N; ++i)cin >> H[i];
    for(int j = 0; j < M; ++j){
        cin >> buf1 >> buf2;
        Q[buf1].push(H[buf2]);
        Q[buf2].push(H[buf1]);
    }
    for(int i = 1; i <= N; ++i){
        if(Q[i].empty())++ans;
        else if(Q[i].top() < H[i]) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9544
// PrintTestCases.cs

// ??\?????????????????°?????????????????????????±??????£?????¢?????§????????????????????°?????????
// ??\??????????????????0????????£???????????\?????????????????????
using System;

class PrintTestCases{
    static void Main(){
        int i = 0;
        int[] x;
        x = new int[20000];
        while (true) // C#??§???while(1)??¨?¨???°????????????????????????
        {
            x[i] = int.Parse(Console.ReadLine());
            if (x[i] == 0) break;
            
            i++;
        }
        for (var j = 0; j < i; j++)
        {
            Console.WriteLine("Case {0}: {1}", j+1, x[j]);
        }
    }
}

Measured memory_bytes: 9460
#include <iostream>
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  long ans = 0;
  long a = 0;
  long b = 0;
  if (K % 2 == 0)
  {
    for (int i = 1; i <= N; i++)
    {
      if (i % K == 0)
        a++;
      if (i % K == K / 2)
        b++;
    }
    ans = a * a * a + b * b * b;
  }
  else
  {
    for (int i = 1; i <= N; i++)
    {
      if (i % K == 0)
        a++;
    }
    ans = a * a * a;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int card[4][13] = {0};
	for (int i = 0; i < n; i++) {
		int number;
		char mark;
		cin >> mark >> number;
		switch (mark) {
		case 'S': card[0][number - 1] = 1; break;
		case 'H': card[1][number - 1] = 1; break;
		case 'C': card[2][number - 1] = 1; break;
		case 'D': card[3][number - 1] = 1; break;
		}
	}
	
	for (int k = 0; k < 13; k++) {
		if (card[0][k] == 0) 
			cout << 'S' << " " << k + 1 << endl;
	}

	for (int k = 0; k < 13; k++) {
		if (card[1][k] == 0)
			cout << 'H' << " " << k + 1 << endl;
	}

	for (int k = 0; k < 13; k++) {
		if (card[2][k] == 0)
			cout << 'C' << " " << k + 1 << endl;
	}

	for (int k = 0; k < 13; k++) {
		if (card[3][k] == 0)
			cout << 'D' << " " << k + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3120
#include<stdio.h>
	int isprime(int n){
		for(int i=2;i*i<=n;i++){
			if(n%i==0)return 0;
		}
		return 1;
	}
	int main(){
		int v,k;
		while(1){
			scanf("%d",&v);
			if(v==0)break;
			for(k=v;k>=0;k--){
				if(isprime(k)==1 && isprime(k-2)==1){
					printf("%d %d\n",k-2,k);
					break;
				}
			}
		}
		return 0;
	}

Measured memory_bytes: 2576
// {{{ include
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
// }}}

using namespace std;

typedef long long ll;
inline int in(){int x;scanf("%d",&x);return x;}

string S;
int memo[512][512];

// [)
bool is_cat(int s, int l){
  if (s == l) return true;
  if (S[s] != 'm' || S[l - 1] != 'w') return false;
  if (memo[s][l] != -1) return memo[s][l];
  for (int ep = s + 1; ep < l - 1; ep++){
    if (S[ep] != 'e') continue;
    if (is_cat(s + 1, ep) && is_cat(ep + 1, l - 1)) return memo[s][l] = true;
  }
  return memo[s][l] = false;
}

int main()
{
  memset(memo, -1, sizeof(memo));
  cin >> S;
  if (is_cat(0, S.size())) puts("Cat");
  else puts("Rabbit");
  return 0;
}

Measured memory_bytes: 2200
function main(input){
  input = input.split('\n');

  const [N, X, T] = input[0].split(' ').map(Number);
  let count = Math.trunc(N/X);
  if(N%X != 0) count += 1;

  console.log(count*T);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());


Measured memory_bytes: 29688
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,b,i,ans=0;
  cin>>n;
  vector<int64_t> a(n);
  for(i=0;i<n;i++){
    cin>>b;
    a.at(i)=b-i-1;
  }
  sort(a.begin(),a.end());
  b=a.at((n-1)/2);
  for(i=0;i<n;i++) ans+=abs(a.at(i)-b);
  cout<<ans<<endl;
}

Measured memory_bytes: 4840
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))

ans = 0
minimum = float('inf')

for i,v in enumerate(h):
    temp = abs(a - (t - v*0.006))
    if temp < minimum:
        minimum = temp
        ans = i

print(ans+1)


Measured memory_bytes: 3060
#include <stdio.h>
         
int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<=b&&b<=c){
            printf("%d %d %d\n",a,b,c);
       }
    else if(a<=c && c<=b){
            printf("%d %d %d\n",a,c,b);
       }
    else if(b<=a && a<=c){
            printf("%d %d %d\n",b,a,c);
       }
    else if(b<=c && c<=a){
            printf("%d %d %d\n",b,c,a);
       }
    else if(c<=a && a<=b){
            printf("%d %d %d\n",c,a,b);
       }
    else if(c<=b && b<=a){
            printf("%d %d %d\n",c,b,a);
       }
    return 0;
}

Measured memory_bytes: 596
let N = Int(readLine()!)!

enum Status: String, CaseIterable {
    case ac = "AC"
    case wa = "WA"
    case tle = "TLE"
    case re = "RE"
}

var results = [Status: Int]()
Status.allCases.forEach {
    results[$0] = 0
}

for _ in stride(from: 0, to: N, by: 1) {
    let S = readLine()!
    results[Status(rawValue: S)!]! += 1
}

Status.allCases.forEach {
    print("\($0.rawValue) x \(results[$0]!)")
}


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

int main(void){
  int n,num,w,takata,vic = 0;
  int p[20] = {0};

  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> num >> w;
    p[num-1] = w;  
  }

  takata = p[0];
  for(int i = 1 ; i < n ; i++){
    if(takata < p[i]){
      takata = p[i];
      vic = i;
    } 
  }
  vic++;
  cout << vic << ' ' << takata << endl;

  return 0;
}

Measured memory_bytes: 1164
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define ll long long
 
using namespace std;

const int x=1000;

int W,H,w,h,sum;
int a[510][510];
 
int main(){
	scanf("%d%d%d%d",&W,&H,&w,&h);
	for (int i=1;i<=W;++i)
		for (int j=1;j<=H;++j)
			a[i][j]=x;
	sum=W*H*x;
	for (int i=w;i<=W;i+=w)
		for (int j=h;j<=H;j+=h){
			a[i][j]=-w*h*x+x-1;
			sum=sum-w*h*x-1;
		}
	if (sum<=0) puts("No");
	else{
		puts("Yes");
		for (int i=1;i<=W;++i){
			for (int j=1;j<=H;++j) printf("%d ",a[i][j]);
			puts("");
		}
	}
}
	

Measured memory_bytes: 2560
n = int(input())
nodes = [None] * n
rootIdx = None

class Node:
    parent = property
    node_type = property
    depth = property

    def __init__(self, ID, k, c):
        self.parent = -1
        self.ID = ID
        self.k = k
        self.c = c

    def print_self(self):
        print('node {}: parent = {}, depth = {}, {}, '.format(self.ID, self.parent, self.depth, self.node_type) + str(self.c))

def trace(node, depth):
    node.depth = depth
    if len(node.c) > 0:
        for i in range(len(node.c)):
            child = nodes[node.c[i]]
#            child.parent = node.ID
            trace(child, depth + 1)

for i in range(n):
    s = list(map(int, input().split()))
    ID = s[0]
    k = s[1]
    c = s[2:]
    node = Node(ID, k, c)
    nodes[ID] = node

    # if rootIdx in c:
    #     rootIdx = ID

#print(nodes)
#trace(nodes[0], 0)
for i in range(n):
    node = nodes[i]
    if len(node.c) > 0:
        for i in range(len(node.c)):
            child = nodes[node.c[i]]
            child.parent = node.ID

for i in range(n):
    node = nodes[i]
    if node.parent == -1:
        rootIdx = node.ID

trace(nodes[rootIdx], 0)

for i in range(n):
    node = nodes[i]

    if node.parent == -1:
        node.node_type = 'root'
    elif len(node.c) > 0:
        node.node_type = 'internal node'
    else:
        node.node_type = 'leaf'

for i in range(n):
    nodes[i].print_self()



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

int main(){
	int N,A,B;
	cin>>N>>A>>B;
	string str;
	cin>>str;
	vector<string> res(N);
	int counter=0;
	int bcounter=0;
	int i,j,k;
	for(i=0;i<N;i++){
		if(str[i]=='c'){
			res[i]="No";
		}
		else if(str[i]=='a'){
			if(counter<A+B){
				res[i]="Yes";
				counter++;
			}
			else res[i]="No";
		}
		else{
			if(counter<A+B&&bcounter+1<=B){
				counter++;
				bcounter++;
				res[i]="Yes";
			}
			else res[i]="No";
		}
	}
	for(i=0;i<N;i++){
		cout<<res[i];
		if(i<N-1) cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 6144
#-- alds1-12-a :: MinimumSpanningTree
INF = 2001

n = gets.to_i
graph = []       # Graph
ps = [nil] * n   # parents
ws = [INF] * n   # weights (input : 0 <= w <= 2000)
vs = [false] * n # validates (true : validated)

# create graph
n.times { graph << gets.split.map(&:to_i) }

# prim algorithm
while vs.include? false
  ps[0] = -1
  ws[0] = 0
  mv = -1
  minimum = INF

  # wsの中で未検証かつ最小の重みを持つノード(mv = minimum vertex)を見つける
  ws.each_with_index do |w, i|
    if (vs[i] == false) && (w < minimum)
      minimum = w
      mv = i
    end
  end

  # mvから未検証の隣接点までの重みを調べ、隣接点の現在の重み(wsの値)より小さいなら重みを更新する
  # その際、接続元のノード(psの値)も更新する
  graph[mv].each_with_index do |nw, i|
    if (vs[i] == false) && (nw != -1) && (nw < ws[i])
      ws[i] = nw
      ps[i] = mv
    end
  end

  # mvまでの最短は検証済にする
  vs[mv] = true
end

puts ws.sum


Measured memory_bytes: 6976
#include<cstdio>
using namespace std;
int n,m,k;
int main(void){
	register int i;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;++i){
		if(k-i*m==0){
			puts("Yes");
			return 0;
		}
		if(n==2*i)continue;
		if(k-i*m>0&&n-2*i>0)
			if((k-i*m)%(n-2*i)==0&&(k-i*m)/(n-2*i)<=m){
				puts("Yes");
				return 0;
			}
		if(k-i*m<0&&n-2*i<0)
			if((i*m-k)%(2*i-n)==0&&(i*m-k)/(2*i-n)<=m){
				puts("Yes");
				return 0;
			}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;

const int maxn = 200 + 10;
int X[maxn][maxn];

bool judge(int n) {
	int t = sqrt(n);
	return t * t == n;
}
int main(void)
{
	int N, D; cin >> N >> D;
	int cnt = 0;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= D; ++j)
			cin >> X[i][j];
		for (int j = 1; j < i; ++j) {
			int t = 0;
			for (int k = 1; k <= D; ++k)
				t += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			if (judge(t))
				cnt++;
		}

	}
	cout << cnt << endl;



	return 0;
}

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

const int N=200100,mod=1000000007;
inline void reduce(int&x){x+=x>>31&mod;}
int n,l[N],r[N],f[N],b[N];
pair<int,int>a[N];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i].first>>a[i].second,b[i]=a[i].second;;
	sort(a+1,a+n+1);sort(b+1,b+n+1);
	for(int i=1;i<=n;++i)a[i].second=lower_bound(b+1,b+n+1,a[i].second)-b;
	for(int i=1,j=1;i<=n;++i)r[i]=j=max(j,a[i].second);
	for(int i=n,j=n;i;--i)l[i]=j=min(j,a[i].second);
	int L=0,R=0,sum=1;f[0]=1;
	for(int i=1;i<=n;++i){
		for(;L<l[i]-1;reduce(sum-=f[L++]));
		for(;R<r[i];reduce(sum+=f[++R]-mod));
		reduce(f[R]+=sum-mod);reduce(sum+=sum-mod);
	}
	cout<<f[n]<<'\n';
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <map>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100000;
int v[1 + nmax], red[1 + nmax];

int main() {
  int n, q;
  std::cin >> n >> q;
  for(int i = 1;i <= n; i++) 
    v[i] = 1;
  red[1] = 1;
  for(int i = 1;i <= q; i++) {
    int x, y;
    std::cin >> x >> y;
    if(1 == red[x]){
      red[y] = 1;
      if(1 == v[x]) 
        red[x] = 0;
    }
    v[x]--;
    v[y]++;
  }
  int result = 0;
  for(int i = 1;i <= n; i++)
    result += red[i];
  std::cout << result;
  return 0;
}


Measured memory_bytes: 4316