akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

using P = pair<int, int>;
using Data = pair<int, P>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i++) {
        cin >> s[i];
    }
    vector<int> sum(n), mn(n, INF);
    for(int i = 0; i < n; i++) {
        int nowSum = 0;
        string &t = s[i];
        int m = t.size();
        for(int j = 0; j < m; j++) {
            nowSum += (t[j] == '(' ? 1 : -1);
            chmin(mn[i], nowSum);
        }
        // print(nowSum, mn[i]);
        sum[i] = nowSum;
    }
    if(accumulate(ALL(sum), 0) != 0) {
        print("No");
        return 0;
    }
    vector<Data> v1, v2;
    for(int i = 0; i < n; i++) {
        if(sum[i] >= 0) {
            v1.emplace_back(Data(i, P(sum[i], mn[i])));
        } else {
            v2.emplace_back(Data(i, P(sum[i], mn[i])));
        }
    }
    sort(ALL(v1), [](const Data &x, const Data &y) {
        return x.second.second > y.second.second;
    });
    sort(ALL(v2), [](const Data &x, const Data &y) {
        return (x.second.first - x.second.second) >
               (y.second.first - y.second.second);
    });
    int now = 0;
    for(int k = 0; k < v1.size(); k++) {
        int i = v1[k].first;
        for(int j = 0; j < s[i].size(); j++) {
            now += (s[i][j] == '(' ? 1 : -1);
            if(now < 0) {
                print("No");
                return 0;
            }
        }
    }
    for(int k = 0; k < v2.size(); k++) {
        int i = v2[k].first;
        for(int j = 0; j < s[i].size(); j++) {
            now += (s[i][j] == '(' ? 1 : -1);
            if(now < 0) {
                print("No");
                return 0;
            }
        }
    }
    print("Yes");
}

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

int main(){
	int n;
	cin >> n;
	vector<int>v;
	for(int i=0;i<n;i++){
		int inp;
		cin >> inp;
		v.push_back(inp);
	}
	// sort(v.begin(),v.end());
	int ans=0;
	for(int i=0;i<(int)v.size();i++){
		for(int j=i+1;j<(int)v.size();j++){
			int tot=v[i]+v[j];
			for(int k=j+1;k<(int)v.size();k++){
				if(v[k]<tot && k!=i && k!=j && v[i]!=v[j] && v[j]!=v[k] && v[i]!=v[k]) {
					// cout << v[k] << ' ' << tot << '\n';
					if(v[i]+v[j]>v[k] && v[i]+v[k]>v[j] && v[k]+v[j]>v[i]) ans++;
					// cout << i << ' ' << j << ' ' << k << ' ' << tot << '\n';
				}
			}
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3636
N = int(input())
L = [list(map(int,input().split())) for k in range(N-1)]
c = sorted(list(map(int,input().split())))
a = sum(c) - c[-1]
T = [[] for k in range(N)]
for e in L:
    T[e[0]-1].append(e[1]-1)
    T[e[1]-1].append(e[0]-1)

kyori = [-1 for k in range(N)]
que = [L[0][0]]
kyori[L[0][0]] = c.pop()

while len(que) > 0:
    now = que.pop()
    for tsugi in T[now]:
        if kyori[tsugi] == -1:
            kyori[tsugi] = c.pop()
            que.append(tsugi)
print(a)
print(*kyori, sep=" ")


Measured memory_bytes: 7804
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   if(pow < 0) return 0;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(2e6 + 7)] , inv_fac[(int)(2e6 + 7)];
void precomp_factorial(){fac[0] = 1;for(ll i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(ll i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};


int main() {
    map <int,int> mp;
    mp[0] = 0;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        int mask = 0;
        for(int j = 0; j < b; j++){
            int c;
            cin >> c;
            mask ^= (1<<(c-1));
        }
        map <int,int> mp1;
        mp1 = mp;
        for(auto x:mp1){
            int mask1 = x.first|mask;
            int cost = x.second+a;
            if(mp.count(mask1)){
               mp[mask1] = min(mp[mask1], cost);
            } else{
               mp[mask1] = cost;
            }
        }
        // cout << i << "|" << mask << endl;
        // for(auto x:mp){
        //     cout << x.first << " " << x.second << "||";
        // }
        // cout << endl;
    }
    if(mp.count((1<<n)-1)){
        cout << mp[(1<<n)-1];
    } else{
        cout << -1;
    }
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;

namespace abc176_c
{
  class Program
  {
    static void Main(string[] args)
    {
      var N = CIn.ReadInt();
      var A = CIn.ReadIntArray(N);

      var max = A[0];
      var ans = 0L;

      for (int i = 1; i < N; i++)
      {
        if (max > A[i]) ans += max - A[i];
        max = Math.Max(max, A[i]);
      }

      Console.WriteLine(ans);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


Measured memory_bytes: 49912
#include<cstdio>
using namespace std;
bool check[250000]={0};
int main(){
    bool f = 1;
    for(int i = 3;i <= 250000; i+=2){
        f = 1;
        for(int j = 2;j * j <= i; j++){
            if(i % j == 0){
                f = 0;
                break;
            }
        }
        if(f == 1)check[i] = 1;
    }

    check[2] = 1;

    int n;
    while(scanf("%d",&n),n){
        if(n == 1){
            printf("1\n");
            continue;
        }
        bool flg = 0;
        int ans = 0;
        for(int i = n;i <= 2*n; i++){
            if(i % 2 == 0){
                flg = 1;
                continue;
            }
            if(flg == 1){
                flg = 0;
                if(check[i] == 1)ans++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1284
N,K=map(int, input().split())
V=list(map(int, input().split()))
ans=0
from heapq import heapify,heappop
for j in range(1,min(N,K)+1):
    for k in range(j+1):
        x=V[:k]+V[N-j+k:]
        heapify(x)
        b=K-j
        while len(x)>0 and x[0]<0 and b>0:
            heappop(x)
            b-=1
        ans=max(ans,sum(x))
print(ans)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main(){
	
	int N;
	long long int P;
	cin >> N >> P;
	
	long long int A[200000];
	long long int sum = 0;
	
	for(int i = 0; i < N; i++){
		long long int w, b;
		cin >> w >> b;
		A[i] = -(100 - P) * w - P * b;
		sum += P * b;
	}
	
	sort(A, A + N);
	
	int ans = 0;
	for(int i = 0; i < N; i++){
		sum += A[i];
		if(sum <= 0){
			ans = i + 1;
			break;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
(let* ((n (read))
    (k (read))
    (a (make-array n)))
    (loop for i below n do
        (setf (aref a i) (read))
    )
    (loop for i from k below n do
        (if (> (aref a i) (aref a (- i k)))
            (format t "Yes~%")
            (format t "No~%")
        )
    )
)

Measured memory_bytes: 77788
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int a,b;
  while((a = getInt()) + (b = getInt())){
    int c = b - a;
    int t1, t2, t3;
    t1 = c / 1000;
    c  = c % 1000;
    t2 = c / 500;
    c  = c % 500;
    t3 = c / 100;
    printf("%d %d %d\n",t3,t2,t1);
  }
  return 0;
}

Measured memory_bytes: 0
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()
	}
	return ints
}
func calcEV(max int) float64 {
	total := (1 + max) * max / 2
	return float64(total) / float64(max)
}

func calcTotalEV(k int, dices []int) float64 {
	l := len(dices)

	total := 0

	start := 0
	end := start + k
	ds := dices[start:end]
	for _, d := range ds {
		total += d
	}
	max := total

	for end < l {
		s := dices[start]
		next := dices[end]
		total = total - s + next
		if max < total {
			max = total
		}
		start++
		end++
	}

	return float64(max+k) / 2.0
}

func main() {
	n, k := nextInt(), nextInt()
	dices := nextInts(n)
	t := calcTotalEV(k, dices)
	fmt.Println(t)
}


Measured memory_bytes: 3072
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline


def main():
    n = get_int()
    A = get_li()
    B = get_li()
    ans = 0
    left = 0
    for i, a in reversed(list(enumerate(A))):
        if i == 0:
            ans += min(left, A[0])
            break
        a_ = max(0, a - left)
        ans += a - a_
        left = max(0, B[i-1] - a_)
        ans += B[i-1] - left
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()


Measured memory_bytes: 105184
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, K: int):
    return min(N % K, abs(N % K - K))


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(f'{solve(N, K)}')


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
	int n, m = 0, a, sum = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a;
		m = max(m, a);
		sum += a;
	}
	if (m < sum - m) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 256
X = int(input())

def Sum_Digit(X):
  SUM = 0
  while X >= 1:
    SUM += X%10
    X = int((X - X%10)/10)
  return SUM

S = Sum_Digit(X)
if X%S == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
# include <iostream>
# include <queue>
# include <cctype>
typedef std::pair<int, int> P;

const int INF = 100000;
const int MAX_H = 1000;
const int MAX_W = 1000;
const int MAX_N = 9;

int dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
int h, w, n;
int d[MAX_H][MAX_W];
char ch[MAX_H][MAX_W];
P p[MAX_N + 1];

int bfs(P s, P g) {
	for (int i = 0; i<h; ++i) {
		for (int j = 0; j<w; ++j)
			d[i][j] = INF;
	}
	std::queue<P> que;
	que.push(s);
	d[s.second][s.first] = 0;
	while (!que.empty()) {
		P x = que.front(); que.pop();
		if (x == g)
			break;
		for (int i = 0; i < 4; ++i) {
			int nx = x.first + dx[i];
			int ny = x.second + dy[i];
			if (nx >= 0 && ny >= 0 && nx < w && ny < h && d[ny][nx] == INF && ch[ny][nx] != 'X') {
				que.push(P(nx, ny));
				d[ny][nx] = d[x.second][x.first] + 1;
			}
		}
	}
	return d[g.second][g.first];
}

int solve() {
	int res = 0;
	for (int i = 1; i <= n; ++i) {
		res += bfs(p[i - 1], p[i]);
	}
	return res;
}

int main() {
	std::cin >> h >> w >> n;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			std::cin >> ch[i][j];
			if (std::isdigit(ch[i][j])) {
				p[atoi(&ch[i][j])].first = j;
				p[atoi(&ch[i][j])].second = i;
			}
			else if (ch[i][j] == 'S') {
				p[0].first = j;
				p[0].second = i;
			}
		}
	}
	std::cout << solve() << std::endl;
	return 0;
}

Measured memory_bytes: 7856
from bisect import bisect
from collections import deque

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

csumA = [0]
csumB = [0]

s = 0
for i in A:
    s += i
    csumA.append(s)
s = 0
for i in B:
    s += i
    csumB.append(s)

ans = 0
for i in range(N+1):
    if K - csumA[i] >= 0:
        ##print(i,i+bisect(csumB,max(0,K-csumA[i])))
        ans = max(ans,i-1+bisect(csumB,max(0,K-csumA[i])))

for i in range(M+1):
    if K - csumB[i] >= 0:
        ans = max(ans,i-1+bisect(csumA,max(0,K-csumB[i])))

print(ans)
    

Measured memory_bytes: 131212
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}





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

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

    int ans = 0;
   if (n >= 2) ans += n*(n-1) / 2;
   if (m >= 2) ans += m*(m-1) / 2;

   cout << ans << endl;
}

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

int main()
{
        ll maxv = 1000000000000001;
//      cout << maxv << endl;
        ll N; cin >> N;
        ll S = N / 26;
        ll A = N % 26;
        vector<char> ans;
        if (A == 0) {
                S--;
                ans.push_back('z');
        }
        else {
                ans.push_back('a'+A-1);
        }

        while (1) {

                if (S == 0) {
                        break;
                }
                ll tmp = S/26;
                A = S%26;
                if (A == 0) {
                        tmp--;
                        ans.push_back('z');
                }
                else {
                        ans.push_back('a'+A-1);
                }
                S = tmp;
        }

        for (int i = ans.size()-1; i >= 0; --i) {
                cout << ans[i];
        }
        cout << endl;





}


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class FactInvMOD:
    """ 階乗たくさん使う時用のテーブル準備 """

    def __init__(self, MAX, MOD):
        """ MAX：階乗に使う数値の最大以上まで作る """
        
        MAX += 1
        self.MAX = MAX
        self.MOD = MOD

        # 階乗テーブル
        factorial = [1] * MAX
        factorial[0] = factorial[1] = 1
        for i in range(2, MAX):
            factorial[i] = factorial[i-1] * i % MOD
        # 階乗の逆元テーブル
        inverse = [1] * MAX
        # powに第三引数入れると冪乗のmod付計算を高速にやってくれる
        inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
        for i in range(MAX-2, 0, -1):
            # 最後から戻っていくこのループならMAX回powするより処理が速い
            inverse[i] = inverse[i+1] * (i+1) % MOD
        self.fact = factorial
        self.inv = inverse
    
    def nCr(self, n, r):
        """ 組み合わせの数 (必要な階乗と逆元のテーブルを事前に作っておく) """
        if n < r: return 0
        # 10C7 = 10C3
        r = min(r, n-r)
        # 分子の計算
        numerator = self.fact[n]
        # 分母の計算
        denominator = self.inv[r] * self.inv[n-r] % self.MOD
        return numerator * denominator % self.MOD

    def nPr(self, n, r):
        """ 順列 """
        if n < r: return 0
        return self.fact[n] * self.inv[n-r] % self.MOD

N,K=MAP()
nodes=[[] for i in range(N)]
for i in range(N-1):
    a,b=MAP()
    nodes[a-1].append(b-1)
    nodes[b-1].append(a-1)

fim=FactInvMOD(max(N, K), MOD)

visited=[False]*N
ans=1
def rec(u):
    if visited[u]:
        return
    visited[u]=True
    global ans
    # 子ノードの数
    cldcnt=len(nodes[u])
    # 根だけは自分と子を両方決める
    if u==0:
        ans*=fim.nPr(K, cldcnt+1)
    # 他は子について決める
    else:
        # 親の分を引く
        cldcnt-=1
        ans*=fim.nPr(K-2, cldcnt)
    ans%=MOD
    for v in nodes[u]:
        rec(v)

rec(0)
print(ans)


Measured memory_bytes: 96116
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());
    let x = it.next().unwrap();

    if x == 7 || x == 5 || x == 3 {
        println!("YES");
    } else {
        println!("NO");
    }
}

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

using namespace std;
vector<int>pos,baad;

int main()
{
    int n,k;
    cin>>n>>k;
    string str;
    cin>>str;

    int pp=0;
    for(int i=1  ; i<n ; i++){
        if(str[i-1]=='0' and str[i]=='1'){
            baad.push_back(i-pp);
            pp=i;
        }
    }

    int Ans=0,ct=0,id=0;
    for(int i=0 ; i<n ; ){
        if(str[i]=='0'){
            if(k==0){
                k++;
                Ans=max(Ans,ct);
                ct-=baad[id++];
                //cout<<ct<<endl;
            }
            k--;
            while(str[i]=='0' and i<n){
                i++;
                ct++;
            }
        }
        else{
            i++;
            ct++;
        }

        if(i==n){
            Ans=max(Ans,ct);
        }

    }

    cout<<Ans<<endl;

    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
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; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);
//const int INF=(1<<29);

class UnionFindTree{
  public:
    vector<int> rank,p,count;

    UnionFindTree() {}

    UnionFindTree(int size){
      rank.assign(size, 0);
      p.assign(size, 0);
      count.assign(size,1);
      REP(i,size)makeSet(i);
    }

    void makeSet(int x){
      p[x] = x;
      rank[x] = 0;
    }

    bool same(int x, int y){
      return findSet(x) == findSet(y);
    }

    void unite(int x, int y){
      if(findSet(x) == findSet(y))return;

      x = findSet(x);
      y = findSet(y);
      
      if(rank[x] > rank[y]){
        p[y] = x;
      }else{
        p[x] = y;
        if(rank[x] == rank[y]){
          rank[y]++;
        }
      }

      int tmp = count[x] + count[y];
      count[x] = tmp;
      count[y] = tmp;
    }

    int findSet(int x){
      if(x != p[x]){
        p[x] = findSet(p[x]);
      }
      return p[x];
    }

    int getCount(int x){
      return count[findSet(x)];
    }

    void print(){
      REP(i,p.size()){
        cout << p[i] << " ";
      }
      cout << endl;
      REP(i,p.size()){
        cout << rank[i] << " ";
      }
      cout << endl;
    }

};


int main(){
  int n,k,l;
  cin >> n >> k >> l;

  UnionFindTree uft1(n);
  UnionFindTree uft2(n);

  REP(i,k){
    int p,q;
    cin >> p >> q;
    p--; q--;
    uft1.unite(p,q);
  }

  REP(i,l){
    int r,s;
    cin >> r >> s;
    r--; s--;
    uft2.unite(r,s);
  }

  map<P, int> mp;
  REP(i,n){
    mp[make_pair(uft1.findSet(i), uft2.findSet(i))]++;;
  }

  REP(i,n){
    cout << mp[make_pair(uft1.findSet(i), uft2.findSet(i))] << (i==n-1 ? "\n" : " ");
  }
}



Measured memory_bytes: 16640
import math

#input
n,d = map(int,input().split())
x = []
ans = 0

for i in range(n):
	xd = list(map(int,input().split()))
	x.append(xd)

#cal
for i in range(len(x)):
	for j in range(i+1,len(x)):
		cnt = 0
		for k in range(d):
			cnt += (x[i][k]-x[j][k])**2
		cnt = math.sqrt(cnt)
		if cnt.is_integer():
			ans += 1

print(ans)

Measured memory_bytes: 3064
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import re

def dist(x, y):
    d = 0
    for xi, yi in zip(x, y):
        d += (xi - yi) ** 2
    return math.sqrt(d)

def main():
    N, D = map(int, input().split())
    X = []
    for _ in range(N):
        x = list(map(int, input().split()))
        X.append(x)

    num = 0
    for i in range(N):
        for j in range(i+1, N):
            d = dist(X[i], X[j])
            if d.is_integer():
                num += 1
    print(num)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
ll a[300005];
int main(){
    ll t;   
    boost;
  
    	ll n,m;
    	cin>>n;
    	ll u=(n+999)/1000;
    	cout<<u*1000-n;
		
    	
		
		
    
			
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll act=7%n;
    ll cont = 1e7;
    ll cont2=cont;
    while(cont--){
        if(act==0){
            cout<<cont2-cont<<"\n";
            return 0;
        }
        act=(act*10)%n;
        act=(act+7)%n;
    }
    cout<<-1<<'\n';
    return 0;  
}   

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

int main(){
    ll n, t, q, b, e;
    vector<ll> v;
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++){
        scanf("%lld", &t);
        v.push_back(t);
    }
    scanf("%lld", &q);
    for (ll i = 0; i< q; i++){
        scanf("%lld %lld %lld", &b, &e, &t);
        swap_ranges(v.begin() + b, v.begin() + e, v.begin() + t);
    }
    for (auto i = v.begin(); i != v.end(); i++){
        if (i != v.begin()){
            printf(" ");
        }
        printf("%lld", *i);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> cou(n, 0);
    a[0] = 0;
    for (int i = 1; i < n; i++)
    {
        cin >> a[i];
        cou[a[i] - 1] += 1;
    }
    rep(i, n)
    {
        cout << cou[i] << endl;
    }
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) (v.begin(),v.end())
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int n,d;
    cin >> n >> d;
    vector<vector<int>> X(n, vector<int>(d));
    REP(i, n){
        REP(j, d){
            cin >> X[i][j];
        }
    }

    int ans = 0;
    REP(ni, n){
        Rep(nii, ni+1, n){
            int t = 0;
            REP(di, d){
                t += (X[nii][di] - X[ni][di]) * (X[nii][di] - X[ni][di]); 
            }
            double td = sqrt((double)t);
            if(td == int(td))ans++;
        }
    }
    pr(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <fstream>
using namespace std;

#define REP(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define fi first
#define sc second
#define pb push_back
#define double long double
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const i64 MOD = 1000000007;
const i64 INF = 2e15;

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

	int n, x;
	cin >> n >> x;

	vi l(n + 1), d(n + 2);
	REP(i, 1, n) {
		cin >> l[i];
	}

	int ans = 1;

	REP(i, 2, n + 1) {
		d[i] = d[i - 1] + l[i - 1];
		if (d[i] <= x) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.TreeMap;

public class Main {
	//FastScannerクラス、普通の Scannerクラスだとメモリと時間を大幅に喰らうので高速化する内部クラス。
	
	public static void main(String[]args) {
		FastScanner sc = new FastScanner(System.in);
		int N = Integer.valueOf(sc.next());
		int K = Integer.valueOf(sc.next());
		int []A = new int[N];
		
		Map<Integer,Integer>map = new TreeMap<Integer,Integer>();
		
		for(int i = 0;i<N;i++) {
			A[i] = Integer.valueOf(sc.next());
			if(map.containsKey(A[i])) {
				map.put(A[i], map.get(A[i])+1);
			}else {
				map.put(A[i], 1);
			}
		}
		
		//System.out.println(map.size());
		
		
		if(map.size()<=K)System.out.println(0);
		else {
			int []shu = new int[map.size()];
			int j = 0;
			for(Integer key:map.keySet()) {
				shu[j] = map.get(key);
				j++;
			}
			Arrays.sort(shu);
			
			int kesu = map.size()-K;
			int goukei = 0;
			for(int i = 0;i<kesu;i++) {
				goukei+=shu[i];
			}
			
			System.out.println(goukei);
		}

	}
	
	
	
	static class FastScanner {
		 
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
 
		public FastScanner(InputStream source) {
			in = source;
		}
 
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte()) return buffer[ptr++];
			else return -1;
		}
 
		private static boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}
 
		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
		}
 
		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}

}


Measured memory_bytes: 51808
#include <iostream>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
int main()
{
  int K, T;
  cin >> K >> T;
  int ma = -1;
  REP(i, T) {
    int a;
    cin >> a;
    ma = max(a, ma);
  }
  cout << max(ma - 1 - (K - ma), 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 100005
#define INF 3000000000
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

ll V, E;
vector<edge> es;
int par[MAX];  //親
int depth[MAX]; //深さ

bool mylesser(pair<Pll,int> a, pair<Pll,int> b){
    return a.first.second < b.first.second;
}
//初期化
void init(int n){
    rep(n){
        par[i] = i;
        depth[i] = 0;
    }
}

//根を求める
int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

//xとyの属する集合の併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    
    if(depth[x] < depth[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(depth[x] == depth[y]) depth[x]++;
    }
}

//同じ集合に属するか否か
bool same(int x, int y){
    return find(x) == find(y);
}

bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}

ll kruskal(){
  sort(all(es), comp);
  init(V);
  ll res = 0;

  rep(E){
    edge e = es[i];
    if(!same(e.from, e.to)){
      res += e.cost;
      unite(e.from, e.to);
    }
  }
  
  return res;
}

int main(){
    scanf("%lld", &V);
    vector< pair<Pii, int> > p(V);
    rep(V){
        scanf("%d %d", &p[i].first.first, &p[i].first.second);
        p[i].second = i;
    }
    sort(all(p));
    rep(V-1){
        Pll vvi = p[i].first, wwi = p[i+1].first;
        ll cost = (ll)min(abs(vvi.first - wwi.first), abs(vvi.second - wwi.second));
        edge e = {p[i].second, p[i+1].second, cost};
        es.pb(e);
        swap(e.from, e.to);
        es.pb(e);
    }
    sort(all(p), mylesser);
    rep(V-1){
        Pll vvi = p[i].first, wwi = p[i+1].first;
        ll cost = (ll)min(abs(vvi.first - wwi.first), abs(vvi.second - wwi.second));
        edge e = {p[i].second, p[i+1].second, cost};
        es.pb(e);
        swap(e.from, e.to);
        es.pb(e);
    }
    E = 4 * (V-1);
    printf("%lld\n", kruskal());
    return 0;
}

Measured memory_bytes: 11756
#include <iostream>

int main(){
  using namespace std;
  long long n, d, ans = 0;
  long long x, y;
  cin >> n >> d;
  for(int i = 0; i < n; i++){
    cin >> x >> y;
    if(d*d >= x*x + y*y) ++ans;
  }
  cout << ans << endl;
  
}

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

int main()
{
    int n;
    cin>>n;
    int x=n%10;
    if(x==2||x==4||x==7||x==9||x==5) cout<<"hon";
    else if(x==3) cout<<"bon";
    else cout<<"pon";
    return 0;

}


Measured memory_bytes: 3496
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

struct SqrtDecomposition {
private:
    ll N, K, sqrtN;
    vector<ll> data, bucket;

public:
    SqrtDecomposition(ll n){
        N = n;
        sqrtN = sqrt(n);
        K = (N + sqrtN - 1) / sqrtN;
        data.assign(n+10, 0);
        bucket.assign(K+10, 0);
    }

    void add(ll x, ll y){
        ll k = x / sqrtN;
        data[x] += y;
        bucket[k] += y;
    }

    // [x, y)
    ll getSum(ll x, ll y){
        ll sum = 0;
        rep(k,0,K){
            ll lv = k * sqrtN, rv = (k+1) * sqrtN;
            if(rv <= x || y <= lv) continue;
            if(x <= lv && rv <= y){
                sum += bucket[k];
            }else{
                for(ll i = max(x, lv); i < min(y, rv); i++){
                    sum += data[i];
                }
            }
        }
        return sum;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, Q;
    cin >> N >> Q;
    SqrtDecomposition sd(100010);
    while(Q--){
        ll c,x,y;
        cin >> c >> x >> y;
        if(c == 0){
            x--;
            sd.add(x, y);
        }else{
            x--; y--;
            print(sd.getSum(x, y+1));
        }
    }
}


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

using namespace std;

int main(){

  vector<int> c0;  
  int tmp;
  // cout << x <<endl;
  // cout << a <<endl;
  // cout << b <<endl;
  for(int i =0; i< 9;i++)
  {
    cin >> tmp;
    c0.push_back(tmp);
  }
  // for(int a:c0)
  //   cout << a<<endl;
  string f = "Yes";
  int d1,d2,d3;
  for(int i=0;i<2;i++)
  {
    d1 = c0[0] - c0[3+i*3];
    d2 = c0[1] - c0[4+i*3];
    d3 = c0[2] - c0[5+i*3];
    if ((d1!=d2)||(d2!=d3)||(d3!=d1))
      f = "No";
  }
  d1 = c0[3] - c0[3+3];
  d2 = c0[4] - c0[4+3];
  d3 = c0[5] - c0[5+3];
  if ((d1!=d2)||(d2!=d3)||(d3!=d1))
    f = "No";
  for(int i=0;i<2;i++)
  {
    d1 = c0[0] - c0[i+1];
    d2 = c0[3] - c0[i+4];
    d3 = c0[6] - c0[i+7];
    if ((d1!=d2)||(d2!=d3)||(d3!=d1))
      f = "No";
  }
  d1 = c0[1] - c0[2];
  d2 = c0[4] - c0[5];
  d3 = c0[7] - c0[8];
  if ((d1!=d2)||(d2!=d3)||(d3!=d1))
    f = "No";
  cout<< f<<endl;
}


Measured memory_bytes: 256
n , m = map(int,input().split())
p = []
q = []
for i in range(n):
    x = list(map(int,input().split()))
    p.append(x)
for j in range(m):
    y = list(map(int,input().split()))
    q.append(y)
for a,b in p:
    cou = 0
    ans = 0
    kar = 10**9
    for c,d in q:
        cou += 1
        if (abs(a-c)+abs(b-d)) < kar:
            ans = cou
            kar = (abs(a-c)+abs(b-d))
    print(ans)

Measured memory_bytes: 3064
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
from functools import reduce

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

def gcd_list(l):
    return reduce(gcd, l)

N, X = i_l()
x = i_l()

arr = []
for i in range(N-1):
    arr.append(abs(x[i]-x[i+1]))

x = gcd_list(arr + [abs(x-X) for x in x])

print(x)

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

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

    int arr[n];

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


    int k=1;
    int s=0,e=0;
    for(int i=0;i<n;i++){
        if(arr[i]==k)
            {
               k++;
               e=1;
            }

        else
            s++;
    }

    if(e==0)
     cout<<"-1"<<endl;

    else
        cout<<s<<endl;



}


Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
B = list(map(int,readline().split()))
Q = int(readline())
m = map(int,read().split())
LR = sorted(zip(m,m))

class MaxSegTree():
    def __init__(self,raw_data):
        N = len(raw_data)
        self.size = 1<<(N.bit_length()) # 葉の要素数
        self.data = [0] * (2*self.size)
        self.build(raw_data)
        
    def build(self,raw_data):
        for i,x in enumerate(raw_data):
            self.data[self.size+i] = x
        for i in range(self.size-1,0,-1):
            x = self.data[i+i]; y = self.data[i+i+1]
            self.data[i] = x if x>y else y
    
    def update(self,i,x):
        i += self.size
        self.data[i] = x
        i >>= 1
        while i:
            x = self.data[i+i]; y = self.data[i+i+1]
            self.data[i] = x if x>y else y
            i >>= 1
    
    def get_data(self,i):
        return self.data[i+self.size]

    def get_max(self,L,R):
        # [L,R] に対する値を返す
        L += self.size
        R += self.size + 1
        # [L,R) に変更
        x = 0
        while L < R:
            if L&1:
                y = self.data[L]
                if x < y: x = y
                L += 1
                
            if R&1:
                R -= 1
                y = self.data[R]
                if x < y: x = y
            L >>= 1; R >>= 1
        return x

"""
・あるから先を全て0で埋めた場合
・あるから先を全て1で埋めた場合
"""
add1 = [0] * (N+1)
add1[0] = sum(B)
for i,x in enumerate(B,1):
    if x:
        add1[i] = add1[i-1] - 1
    else:
        add1[i] = add1[i-1]
add0 = [N - i - x for i,x in enumerate(add1)]

add0,add1

# ある場所を最後の右端まで使ったとする。残りを全て 0 / 1 で埋めたときのスコア
dp0 = MaxSegTree([0] * (N+1))
dp1 = MaxSegTree([0] * (N+1))
dp0.update(0,add0[0])
dp1.update(0,add1[0])

for L,R in LR:
    a = dp1.get_data(R)
    b = dp0.get_max(0,L-1) + add1[L-1] - add0[L-1]
    c = dp1.get_max(L,R-1)
    if b < c:
        b = c
    if a < b:
        dp1.update(R, b)
        dp0.update(R, b - add1[R] + add0[R])

answer = N - dp0.get_max(0,N)
print(answer)

Measured memory_bytes: 135792
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define For(i,x,y) for(int i=((int)x);i<=((int)y);i++)
#define Dep(i,y,x) for(int i=((int)y);i>=((int)x);i--)
#define Rep(i,x) for (int y,i=head[x];i;i=E[i].nxt) if (!vis[y=E[i].to])
using namespace std;

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

int rd() {
	char c=getchar(); int t=0,f=1;
	while (!isdigit(c)) f=(c=='-')?-1:1,c=getchar();
	while (isdigit(c)) t=t*10+c-48,c=getchar(); return t*f;
}
void wt(int x) {
	if (x<0) putchar('-'),wt(-x);
	else { if (x>9) wt(x/10); putchar(x%10+48); }
}

const int N=300035;

int n,m,head[N],cnt;
struct Edge { int to,nxt; }E[N<<1];
void Link(int u,int v) {
	E[++cnt]=(Edge){v,head[u]}; head[u]=cnt;
	E[++cnt]=(Edge){u,head[v]}; head[v]=cnt;
}

int stk[N],top,vis[N];

bool dfs1(int x) {
	vis[x]=1,stk[++top]=x;
	Rep (i,x) if (dfs1(y)) return 1;
	return 1;
}

bool dfs2(int x) {
	vis[x]=1,stk[++top]=x;
	Rep (i,x) if (dfs2(y)) return 1;
	return 1;
}

int main() {
	n=rd(),m=rd();
	For (i,1,m) Link(rd(),rd());
	dfs1(1);
	reverse(stk+1,stk+top+1); top--;
	dfs2(1);
	
	printf("%d\n",top);
	while (top) printf("%d ",stk[top--]);
	
	return 0;
}






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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int N;
	string S;
	cin >> N >> S;

	
	ll ans = 0;
	vector<map<char, int>> total(N);
	for (int i = 0; i < N; i++)
	{
		
		for (int j = i; j < N; j++)
		{
			if(S[i]==S[j]) continue;
			char c;
			if(S[i]!='R'&&S[j]!='R')c='R';
			if(S[i]!='G'&&S[j]!='G')c='G';
			if(S[i]!='B'&&S[j]!='B')c='B';
			total[j][c]++;
		}
		
	}
	for (int i = N; i > 0; i--)
	{
		for (int j = i; j > 0; j--)
		{	
			if(S[i]==S[j]) continue;
			char c;
			if(S[i]!='R'&&S[j]!='R')c='R';
			if(S[i]!='G'&&S[j]!='G')c='G';
			if(S[i]!='B'&&S[j]!='B')c='B';
			ans += total[j][S[i]];
		}
		
	}

	for (int i = 0; i < N; i++)
	{
		for (int j = i; j < N; j++)
		{
			if(2*j-i>=N)break;
			char a=S[i];
			char b=S[j];
			char c=S[2*j-i];
			if(a!=b&&b!=c&&c!=a)ans--;
		}
		
	}
	cout << ans << endl;
}


Measured memory_bytes: 4136
#include <stdio.h>
void trace(int[], int);
void insertionSort(int[], int);

int main(void) {
    int N, i;
    int A[100];
    scanf("%d", &N);
    for(i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    
    trace(A, N);
    insertionSort(A, N);
    return 0;
}

/* 配列の要素を順番に出力 */
void trace(int A[], int N) {
    int i;
    for(i = 0; i < N; i++) {
        /* 隣接する要素の間に1つの空白を出力 */
        if(i > 0) {
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n");
}

/* 挿入ソート(0オリジン配列) */
void insertionSort(int A[], int N) {
    int i,j,v;
    for(i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A, N);
    }
}


Measured memory_bytes: 2148