akhauriyash/Code-Regression huggingface dataset:
//正难则反 
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstring>
#include<iostream>
using namespace std;
#define N 200005
#define LL long long
inline int rd()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return f*x;
}
char n[105];
int k,len;
LL s[N],ans;
LL ksm(LL a,int b)
{
	LL res=1;
	for(int i=1;i<=b;i++)
		res*=a;
	return res;
}
void Pre() 
{
    s[0]=1;
    for(int i=1;i<=105;i++)
        s[i]=s[i-1]*i;
}
/*LL C(int a,int b) 
{
    if(a<0||b<0) return 1;
    return s[a]/s[b]/s[a-b];
}*/
LL C(LL a,int b)
{
	if(b<0) return 0;
	if(b==0) return 1;
	if(b==1) return a;
	if(b==2) return max(a*(a-1)/2,0ll);
	if(b==3) return max(a*(a-1)*(a-2)/6,0ll);
}
int main()
{
    scanf("%s",n+1);
	k=rd();
    //Pre();
    len=strlen(n+1);
    int t=0;
    for(int i=1;i<=len;i++)
    {//减去大于n的数 
    	int x=n[i]-'0';
    	ans+=(9-x)*C(len-i,k-i+t)*ksm(9,k-i+t);
    	if(!x) t++;
	}
	LL all=C(len,k)*ksm(9,k);//位数有len位的有k个数位恰好不为0的数 
	printf("%lld\n",max(all-ans,0ll));
    return 0;
}
/*#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstring>
#include<iostream>
using namespace std;
#define N 200005
#define LL long long
inline int rd()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return f*x;
}
char n[105];
int k,len;
LL s[N],ans;
LL ksm(LL a,int b)
{
	LL res=1;
	while(b)
	{
		if(b&1) res=res*a;
		a=a*a;
		b>>=1;
	}
	return res;
}
void dfs(int x/*现在到第几位,int y/*已经有y位不为0,LL res,bool f) 
{
	printf("%lld %lld %d\n",res,ans,x); 
	//if(res==-1) printf("%d\n",x);
	if(y>k) return ;
	if(f==1)
	{
		if(y==k) ans+=res;
		return ;
	}
	if(x==len+1)
	{
		if(y==k) ans+=res;
		return ;
	}
	dfs(x+1,y,res,f);//1让这一位为0
	if((n[x]-'0')>1) 
		dfs(x+1,y+1,res*(n[x]-'0'-1)*ksm(9,k-(y+1)),1);//这一位为小于n[x]的数 
	if(n[x]!='0') dfs(x+1,y+1,res,f);//让这一位为n[x] 
	return ;
}
void Pre() 
{
    s[0]=1;
    for(int i=1;i<=N;i++)
        s[i]=s[i-1]*i;
}
LL C(int a,int b) 
{
    if(a<0||b<0) return 1;
    return s[a]/s[b]/s[a-b];
}
int main()
{
    scanf("%s",n+1);
	k=rd();
    Pre();
    len=strlen(n+1);
    int x=n[1]-'0';
    //每个位置都有9个选择 
    if(x!=1) ans=ksm(9,k-1)*C(len-1,k-1)*(x-1);//第1位小于x 可以随便选
    if(len-1>=k) ans+=ksm(9,k)*C(len-1,k);//第1位没有(为0 
	printf("%lld\n",ans);
    dfs(2,1,1,0);//第1位为x 
    printf("%lld\n",ans);
    return 0;
}*/

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

int main()
{ 
  int n;
  cin >> n;
  cout << (n < 105 ? 0 : n < 135 ? 1 : n < 165 ? 2 : n < 189 ? 3 : n < 195 ? 4 : 5) << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<cmath>
#include<vector>
#include<map>
#include<random>
using namespace std;

int main(){
    int n,m;cin >> n >> m;
    int k[n];
    int a[n+1][m+1];
    int ans = 0;
    int t[35] = {};
    for(int i = 0;i < n;i++){
        cin >> k[i];
        for(int j = 0;j < k[i];j++){
            cin >> a[i][j];
            t[a[i][j]] += 1;
        }
    }
    for(int i = 0;i < m+1;i++){
        //cout << t[i] << " ";
        if(t[i] == n)ans++;
    }
    cout << endl;

    cout << ans << endl;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0576

"""
import sys
from sys import stdin
from math import ceil
input = stdin.readline


def main(args):
    L = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())

    days_to_finish_A = ceil(A / C)
    days_to_finish_B = ceil(B / D)
    print(L - max(days_to_finish_A, days_to_finish_B))


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7780
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

X = i()
A = i()
B = i()
X -= A
print(X%B)

Measured memory_bytes: 9992
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int[][][] undirectedGraph(int n, int[] v1, int[] v2, int[] cost) {
		int[] cnt = new int[n];
		for (int i : v1) cnt[i]++;
		for (int i : v2) cnt[i]++;

		int[][][] g = new int[n][][];
		for (int i=0; i<n; i++) g[i] = new int[cnt[i]][2];
		for (int i=0; i<v1.length; i++) {
			int s = v1[i];
			int t = v2[i];

			g[s][--cnt[s]][0] = t;
			g[s][cnt[s]][1] = cost[i];

			g[t][--cnt[t]][0] = s;
			g[t][cnt[t]][1] = cost[i];
		}

		return g;
	}

	static int[] dijkstra(int[][][] g, int source) {
		int n = g.length;

		final int[] d = new int[n];
		Arrays.fill(d, 1<<30);
		d[source] = 0;

		TreeSet<Integer> pQ = new TreeSet<Integer>(new Comparator<Integer>(){
			public int compare(Integer a, Integer b) {
				if (d[a] != d[b]) return d[a] - d[b];
				return a - b;
			}
		});
		pQ.add(source);

		while (!pQ.isEmpty()) {
			int cur = pQ.pollFirst();

			for (int i=0; i<g[cur].length; i++) {
				int next = g[cur][i][0];
				int dist = d[cur] + g[cur][i][1];
				if (dist < d[next]) {
					pQ.remove(next);
					d[next] = dist;
					pQ.add(next);
				}
			}
		}

		return d;
	}

	static int h, w;

	static int n(int i, int j) {
		return i*w+j;
	}

	static boolean solve() {
		w = in.nextInt();
		h = in.nextInt();
		if (w + h == 0) return false;

		int n = w*h;
		ArrayList<Integer> s = new ArrayList<>();
		ArrayList<Integer> t = new ArrayList<>();
		for (int k=0; k<2*h-1; k++) {
			int i = k/2;
			if (k%2 == 0) {
				for (int j=0; j<w-1; j++) {
					int x = in.nextInt();
					if (x == 0) {
						s.add(n(i,j));
						t.add(n(i,(j+1)));
					}
				}
			} else {
				for (int j=0; j<w; j++) {
					int x = in.nextInt();
					if (x == 0) {
						s.add(n(i,j));
						t.add(n((i+1),j));
					}
				}
			}
		}

		int m = s.size();
		int[] ss = new int[m];
		int[] tt = new int[m];
		int[] cc = new int[m];
		for (int i=0; i<m; i++) {
			ss[i] = s.get(i);
			tt[i] = t.get(i);
			cc[i] = 1;
		}

		int[][][] g = undirectedGraph(n, ss, tt, cc);

		int[] d = dijkstra(g, 0);
		dump(d);
		out.println(d[n-1] == 1<<30 ? "0" : (d[n-1]+1));

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 70244
#include<stdio.h>
int n,m,c;
int a,b[21];
int val;
int count=0;
int main(){
    int i,j;
    scanf("%d%d%d",&n,&m,&c);
    for(i=0;i<m;i++)scanf("%d",&b[i]);
    // for(i=0;i<n;i++){
    //     for(j=0;j<m;j++){
    //         scanf("%d",&a[i*n+j]);
    //     }
    // }
    for(i=0;i<n;i++){
        val=0;
        for(j=0;j<m;j++){
            scanf("%d",&a);
            val+=(a*b[j]);
        }
        if(val+c>0)count++;
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# ????????????????????°???????????°????????????????????\??????????????¢?????´???????????¨??????????§???????

import array
import collections


class TopologicalSortError(Exception):
    pass


def topological_sort(num_vs, adj_vs):
    in_deg = array.array("L", (0 for _ in range(num_vs)))
    for dests in adj_vs:
        for dest in dests:
            in_deg[dest] += 1
    visited = array.array("B", (False for _ in range(num_vs)))
    sorted_vs = array.array("L")
    for s in range(num_vs):
        if in_deg[s] == 0 and not visited[s]:
            q = collections.deque()
            q.append(s)
            visited[s] = True
            while q:
                u = q.popleft()
                sorted_vs.append(u)
                for v in adj_vs[u]:
                    in_deg[v] -= 1
                    if in_deg[v] == 0 and not visited[v]:
                        visited[v] = True
                        q.append(v)
    if all(x == 0 for x in in_deg):
        return sorted_vs
    else:
        raise TopologicalSortError("The graph has a cycle")


def main():
    v, e = map(int, input().split())
    adj_vs = [set() for _ in range(v)]
    for _ in range(e):
        s, t = map(int, input().split())
        adj_vs[s].add(t)
    for u in topological_sort(v, adj_vs):
        print(u)


if __name__ == '__main__':
    main()

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

using namespace std;

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

    int n;
    cin >> n;
    switch (n)
    {
    case 5:
    case 7:
    case 3:
        cout << "YES" << endl;
        break;
    default:
        cout << "NO" << endl;
        break;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] xab = scanner.nextLine().split(" ", 3);
        long x = Long.parseLong(xab[0]);
        long a = Long.parseLong(xab[1]);
        long b = Long.parseLong(xab[2]);

        if (b - a <= 0) {
            System.out.println("delicious");
        } else if (b - a > x) {
            System.out.println("dangerous");
        } else {
            System.out.println("safe");
        }
    }
}


Measured memory_bytes: 21332
package main

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

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

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

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

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

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

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

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

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

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


func main() {
	N := oneInt()
	fmt.Print(180 * (N - 2))
}


Measured memory_bytes: 640
def test(original: list, nums: str, index: int,
         remain_count: int, results: set, results_1, results_2):
    # 3桁抽出したら終了
    if len(nums) == 1:
        if nums in results_1:
            return
        results_1.add(nums)
    if len(nums) == 2:
        if nums in results_2:
            return
        results_2.add(nums)
    if len(nums) == 3:
        # print("".join(array))
        results.add(nums)
        return
    # 最終桁に到達したら終了
    if index == len(original):
        return
    for i in range(index, len(original), 1):
        test(
            original,
            nums + original[i],
            i + 1,
            remain_count,
            results,
            results_1,
            results_2)

    # この桁を抽出対象としないパターン
    # test(original, array[:], index + 1, remain_count - 1, results)


N = int(input())
S = list(input())

results = set()
results_1 = set()
results_2 = set()

# N個の要素
# N-3個を削除
# 3個の組み合わせが何通りあるか？
test(S, "", 0, N - 3, results, results_1, results_2)

print(len(results))


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

int main(){
    int n;
    
    cin >> n;
    vector<int> vc(n);
    set<int> st;    
    rep(i, n) {
        int a = 0;
        cin >> a;
        if(a%2 == 0){
            st.insert(a);
        }
    }
    int cnt = 0;
    for (auto itr = st.begin(); itr != st.end(); ++itr) {
        int cntt = 0;
        if(*itr%3 != 0){
            cntt++;
        }
        if(*itr%5 != 0){
            cntt++;
        }
        if (cntt == 2){
            cnt++;
        }
        // cout << *itr;
    }

    if(cnt >= 1){
        cout << "DENIED" << endl;
    }
    else{
        cout << "APPROVED" << endl;
    }

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        
        long ans = x;
        if (x % y == 0) {
            ans = -1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <functional>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
//#include <iostream>
//#include <sstream>
using namespace std;
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define pf printf
#define sf scanf
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str()
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)
#define deb(x) cout << #x" = " << x << '\n'
#define debd(x) pf("%s = %d\n", #x, x)
#define debs(x) pf("%s = %s\n", #x, s)
#define debll(x) pf("%s = %lld\n", #x, x)
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
//bitmask
int onbit(int x, int pos) {x |= (1 << pos); return pos;}
int offbit(int x, int pos) {x &= ~(1 << pos); return x;}
int test(int x, int pos) {return x & (1 << pos);}
int flip(int x, int pos) {x ^= (1 << pos); return x;}
int lsb(int x) {return x & (-x);}
int onbitall(int x, int pos) {x = (1 << pos)-1; return x;}
//constants
const double EPS = 1e-9;
const double PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
//moves
const int dx1[] = {0, 1, 0, -1};
const int dy1[] = {1, 0, -1, 0};
const int dx2[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy2[] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
//    freopen("input.in", "r", stdin);
	int a, b, c;
	sf("%d %d %d", &a, &b, &c);
	a *= 100;
	b *= 10;
	puts((a+b+c) % 4 == 0 ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<pair<int, int>> tasks;
  rep(i,n){
    int a,b;
    cin >> a >> b;
    tasks.emplace_back(b,a);
  }
  sort_1(tasks);
  int sum = 0;
  bool isyes = true;
  for(auto v:tasks){
    sum += v.second;
    if(sum > v.first){
      isyes = false;
      break;
    }
  }
  cout << (isyes ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 2420
N, M = map(int, input().split())
L = []
R = []
for _ in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
l = max(L)
r = min(R)
print(r-l+1 if r-l+1 > 0 else 0)

Measured memory_bytes: 10996
#include <iostream>
#include <vector>
#define rep(i, n)for(int i=0; i<n; i++)
using namespace std;

int main(){
    int n, ans=0;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    for(int i=0; i<n; i+=2){
        if(a[i]%2 != 0) ans++;
    }

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


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 100100;
int n;
ll a[N];
ll b[N];

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lld", &a[i]);
    ll sum = 0;
    for (int i = 0; i < n; i++)
        sum += a[i];
    ll m = (ll)n * (n + 1) / 2;
    if (sum % m != 0)
    {
        printf("NO\n");
        return 0;
    }
    m = sum / m;
    for (int i = 0; i < n; i++)
    {
        ll d = a[i] - (i == 0 ? a[n - 1] : a[i - 1]);
        d -= m;
        if (d > 0)
        {
            printf("NO\n");
            return 0;
        }
        d = -d;
        if (d % n != 0)
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <functional>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;
vector<int> p;
vector<int> rk;

void make(int x) {
    p[x] = x;
    rk[x] = 0;
}

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

int lk(int x, int y) {
    if(rk[x] > rk[y]) {
        p[y] = x;
    }
    else {
        p[x] = y;
        if(rk[x] == rk[y]) {
            rk[y]++;
        }
    }
}

void un(int x, int y) {
    lk(fset(x), fset(y));
}



bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
    return (a.second < b.second);
}

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int, int>> pts, bx, by;
    p = vector<int> (n);
    rk = vector<int> (n);
    int x, y;
    int i;
    for(i = 0; i < n; i++) {
        cin >> x >> y;
        pts.push_back({x, y});
        bx.push_back({x, i});
        by.push_back({y, i});
        make(i);

    }
    sort(bx.begin(), bx.end());
    sort(by.begin(), by.end());
    vector<pair<int, pair<int, int>>> adj;
    for(i = 0; i < n - 1; i++) {
        adj.push_back({bx[i + 1].first - bx[i].first, {bx[i].second, bx[i + 1].second}});
        adj.push_back({by[i + 1].first - by[i].first, {by[i].second, by[i + 1].second}});
    }
    sort(adj.begin(), adj.end());
    ll ans = 0;
    for(auto iter: adj) {
        if(fset(iter.second.first) != fset(iter.second.second)) {
            ans += iter.first;
            un(iter.second.first, iter.second.second);
        }
    }
    cout << ans;

    return 0;
}



Measured memory_bytes: 8668
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

def main():
    N,M = map(int,input().split())
    possible = [0] * N
    possible[0] = 1
    ball_cnt = [1] * N
    for _ in range(M):
        x,y = map(int,input().split())
        x -= 1
        y -= 1
        if possible[x]:
            possible[y] = 1
            if ball_cnt[x] == 1:
                possible[x] = 0
        ball_cnt[x] -= 1
        ball_cnt[y] += 1
    ans = sum((b > 0)*p for b,p in zip(ball_cnt,possible))
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  cout << bit(31-__builtin_clz(n)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int mountain[10];
  for(int i=0;i<10;i++)cin>>mountain[i];
  sort(mountain,mountain+10);
  for(int i=9;i>=7;i--)cout<<mountain[i]<<endl;
  return 0;
}

Measured memory_bytes: 1176
#include<stdio.h>

int main(){
	int hill[10],max[3];
	int i,j,temp=0,maxj;
	for(i=0;i<10;i++){
		scanf("%d",&hill[i]);
	}
	for(i=0;i<3;i++){
		maxj=i;
		for(j=i+1;j<10;j++){
			if(hill[j]>hill[maxj])
				maxj=j;
		}
		temp = hill[maxj];
		hill[maxj] = hill[i];
		hill[i] = temp;
	}
	for(i=0;i<3;i++)
		printf("%d\n",hill[i]);
	return 0;
}

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

#define ll long long
#define an "\n";
#define pb push_back
#define pob pop_back

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	if(n>=30) {
		cout << "Yes";
	}else {
		cout << "No";
	}
}


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

int main() {
	int n; cin >> n;
	deque<int>ans;

	for (int i = 0; i < n; i++) {
		int tmp; cin >> tmp;
		if (n % 2 == 0) {
			if (i % 2 == 0)ans.push_back(tmp);
			else ans.push_front(tmp);
		}
		else {
			if (i % 2 == 0)ans.push_front(tmp);
			else ans.push_back(tmp);
		}
	}
	for (auto&& x : ans)cout << x << ' ';
	cout << endl;

	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    int sum = 0;
    int t[n];
    REP(i,n){
        cin >> t[i];
        sum += t[i];
    }
    int m;
    cin >> m;
    int p[m],x[m];
    REP(i,m){
        cin >> p[i] >> x[i];
    }
    REP(i,m){
        cout << sum - t[p[i] - 1] + x[i] << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long int
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
/*const int inf=1e9+5;
ll n,k,y,x;
const int N = 1e5+5;*/
/*bool vis[N];
ll a[N];*/
/*bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
     return (a.f>b.f);
}*/
void solve()
{   ll n,m,res=0,l,r,cnt0=0,z,sum1=0,cnt1=0,h,res1,ans=0,sum=0;
    string s;
    cin>>s;
    map<char,ll> hm;
    n=s.size();
    rep(i,0,n)
    {
        hm[s[i]]++;
    }
    if(hm.size()!=2) cout<<"No";
    else
    {
        for(auto itr=hm.begin();itr!=hm.end();itr++)
        {   ll x=itr->s;
            if(x!=2)
            {
                cout<<"No";
                exit(0);
            }
        }
        cout<<"Yes";
    }


}
int main()
{   speed_up
    ll t;
   //cin>>t;
    t=1;
    while(t--)
        solve();

}


Measured memory_bytes: 256
#coding:utf-8

r = []
for i in range(3):
    ai,bi = map(int,input().split())
    r.append((ai,bi))


f = False


for p in range(1,5):
    cr = r[:]
    for i in range(3):
        for cai,cbi in cr:
            if cai == p :
                p = cbi
                cr.remove((cai,cbi))
                break
            elif cbi == p:
                p = cai
                cr.remove((cai,cbi))
                break
    if not cr :
        f = True
        break
if f:print("YES")
else:print("NO")





Measured memory_bytes: 38384
n = int(input())
s = input()
a = [int(i) for i in s.split()]

ans = 0

for i in range(n):
    if a[i] % 2 == 0:
        while a[i] % 2 == 0:
            a[i] = a[i] // 2
            ans = ans + 1

print(ans)

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ul w, h, x, y;
  cin >> w >> h >> x >> y;
  cout << w*h/2.0 << " " << (x*2==w&&y*2==h ? 1 : 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	if(x-r>=0 && y-r>=0){
		if(x+r<=w && y+r<=h){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}else{
		printf("No\n");
	}
}


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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

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

    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    constexpr ll INF = 1e17;
    vector<vector<ll>> dp(n, vector<ll>(n, INF));
    for (int i = 0; i < n; ++i)
        dp[i][i] = 0;
    for (int len = 2; len <= n; ++len) {
        for (int i = 0; i + len <= n; ++i) {
            int j = i + len - 1;
            ll tot = 0LL;
            for (int k = i; k < j; ++k) {
                tot += a[k];
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
            }

            tot += a[j];
            // cout << "tot(" << i << ", " << j << ") = " << tot << '\n';
            dp[i][j] += tot;
        }
    }
    /*
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cout << dp[i][j] << ' ';
        }
        cout << '\n';
    }
    */

    cout << dp[0][n - 1] << '\n';
    
    return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
int main(void)
{
	int c1,c5,c10,c50,c100,c500,i,a,b,c,d,e,f;
		i=0;
		scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
		a=c1*1;
		b=c5*5;
		c=c10*10;
		d=c50*50;
		e=c100*100;
		f=c500*500;
		i=a+b+c+d+e+f;
		if(i>=1000){
			printf("1\n");
		}
		else{
			printf("0\n");
		}
	return 0;
}

Measured memory_bytes: 1012
#include <iostream>
#include <algorithm>

using namespace std;

int n;
int a[105];

int main(void)
{
	cin >> n;
	for(int i= 0; i < n; i++) cin >> a[i];
	sort(a, a+n);
	reverse(a, a+n);
	
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(i % 2) ans -= a[i];
		else ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

#define rep(i,n) for (int i=0; i < (n); ++i)
using namespace std;
using ll = long long ;
const int INF = 1001001001;

int main() {

    int n ;
    cin >> n ; 
    string s ;
    cin >> s ;
    ll cntr = 0 ;
    rep(i,n)cntr += s[i]=='R' ;
    ll ans = 0 ;
    rep(i,cntr)ans += s[i] == 'W' ;
    cout << ans << endl ; 

    return 0 ;

}

Measured memory_bytes: 3740
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<climits>
using namespace std;

int main() {
  int ans=0;
  int X = 0;
  int A = 0;

  cin >> X >> A;

  if(X >= A){
    cout << 10 << endl;
  }else{
    cout << 0 << endl;
  }

}


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

int main() {
	ll N,r=0;
	cin >> N;

	rep(i,N) {
		ll x = N/(i+1);
		r += x*(x+1)*(i+1)/2;
	}

	cout << r << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<string.h>
int main(void){
    int f = 0, i,o, j, l, z, q, k[6], s[100][6], n[6], n2[6];
    char c;
    scanf("%d",&q);
    for (z = 0; z < q; z++){
        for (i = 0; i < 6; i++){
            scanf("%d", &s[z][i]);
            n[i] = i;
        }
    }
    for (i = 0; i < q; i++){
        for (z = 0; z < q; z++){
            if (i != z){
                for (j = 1; j < 19; j++){
                    if (j % 5 == 0){
                        n2[0] = n[1]; 
                        n2[1] = n[5]; 
                        n2[3] = n[3]; 
                        n2[4] = n[0]; 
                        n2[2] = n[2]; 
                        n2[5] = n[4];
                    }
                    else {
                        n2[0] = n[3]; 
                        n2[1] = n[1]; 
                        n2[3] = n[5]; 
                        n2[4] = n[4]; 
                        n2[2] = n[0]; 
                        n2[5] = n[2];
                    }
                    for (o = 0; o < 6; o++){
                        n[o] = n2[o];
                    }
                    for (l = 0; l < 6; l++){
                        if (s[i][l] != s[z][n[l]])break;
   
                    }
                    if (l == 6){ 
                        f = 1; 
                        break;
                    }
   
                }
            }
            if (f == 1)break;
        }
        if (f == 1)break;
    }
        if (f == 1)printf("No\n");
        else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2080
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX = 100000;
static const int NIL= -1;
int n;
vector<int> G[MAX];
int color[MAX];
int ok[MAX];
void dfs(int r,int c){
    stack<int> S;
    S.push(r);
    color[r] = c;
    while(!S.empty()){
        int u = S.top();
        S.pop();
        for(int i=0;i<G[u].size();i++){
            int v = G[u][i];
            if(color[v] == NIL){
                color[v] = c;
                S.push(v);
            }
        }
    }
} 
void assignColor(){
    int id = 1;
    for(int i=0;i<n;i++) color[i] = NIL;
    for(int u=0;u<n;u++){
        if(color[u] == NIL ) dfs(u,id++);
    }
}

int main(){
    int s,t,m,q;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> s >> t;
        s = s-1;
        t = t-1;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    assignColor();
    int answer = 0;
        for(int i=1;i<n;i++){
        if(color[0] == color[i]){
            //
        } else {
            int flg = 0;
            for(int j=0;j<answer;j++){
                if(color[i]==ok[j]){
                    flg = 1;
                    break;
                }
            }
            if(flg==0){
            ok[answer] = color[i];
            answer++;
            }
        }
       }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 9180
package main

import (
	"fmt"
)

func main() {
	var (
		n int
		s string
	)
	fmt.Scan(&n, &s)
	var count int
	for i := 0; i <= len(s)-3; i++ {
		if s[i:i+3] == "ABC" {
			count++
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#pragma GCC optimize ("Ofast")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>
using namespace std;

#define ULL unsigned long long
#define LL long long
#define LLD long long double
#define REP(i, n) for(LL i = 0; i < n; i++)
#define INV_REP(i, n) for(LL i = n; 0 <= i; i--)

LL combination(LL n, LL m)
{
  LL nume = 1;
  REP(i, m) nume *= (n-i);
  LL demo = 1;
  for(int i = 1; i <= m; i++) demo *= i;
  return nume / demo;
}

template<class T>
class UnionFind
{
private:
  vector<T> par;
  vector<T> rank;
  vector<T> size;

public:
  UnionFind(T N) :
    par(N, T()), rank(N, T()), size(N, T())
  {
    REP(i, N)
    {
      par[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }

  inline T root(T x)
  {
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  inline bool same(T x, T y)
  {
    return root(x) == root(y);
  }

  inline T getSize(T x)
  {
    return size[root(x)];
  }

  void unite(T x, T y)
  {
    T r1 = root(x);
    T r2 = root(y);
    if(r1 == r2) return;

    // ランクの大きい方に併合
    if(rank[r1] < rank[r2]) swap(r1, r2);
    if(rank[r1] == rank[r2]) rank[r1]++;
    par[r2] = r1;
    size[r1] += size[r2];
  }
};

LL N, M;
vector<pair<LL, LL>> AB;

void input()
{
  cin >> N >> M;
  AB.resize(M);
  REP(i, M)
  {
    cin >> AB[i].first >> AB[i].second;
  }
}

void solve()
{
  // 橋がすべて崩落している状況から逆に考えてゆく（グラフ問題では枝の削除は難しいため）
  UnionFind<LL> tree(N);
  vector<LL> ans(M, 0);
  ans[M-1] = combination(N, 2); //すべての頂点の組み合わせ

  // 今回は崩落前の評価をしなくて良いため、2番めの橋を復元したときまで考えればいい。
  INV_REP(i, M-2)
  {
    // i+1で2番めの橋を復元したときまで
    LL indexA = AB[i+1].first-1;
    LL indexB = AB[i+1].second-1;
//    cout << indexA << ", " << indexB << endl;
    if(tree.same(indexA, indexB))
    {
      ans[i] = ans[i+1];
    }
    else
    {
      // 2 * 2
      ans[i] = ans[i+1] - tree.getSize(indexA) * tree.getSize(indexB);

      tree.unite(indexA, indexB);
    }
  }

  REP(i, M)
  {
    cout << ans[i] << "\n";
  }
}

int main()
{
  ios::sync_with_stdio(false);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 6016
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <numeric>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N, 0);
    A[0] = 0;
    for (int i = 1; i < N; ++i) {
        cin >> A[i];
    }

    vector<int> numOfTeam(N, 0);
    for (int i = 1; i < N; ++i) {
        int boss = A[i] - 1;
        numOfTeam[boss] += 1;
    }

    for (int i = 0; i < N; ++i) {
        cout << numOfTeam[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4800
#include<bits/stdc++.h>
typedef long long ll;
#define sz(x) int(x.size())
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define MOD 1000000007
using namespace std;



int main(){
    int N;
    string S;
    cin >> N >> S;
    if(N%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    else{
        for (int i = 0; i < N/2; i++)
        {
            if(S[i] != S[N/2 + i]){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

/* デカい配列はここで宣言 */

int main(int argc, char const *argv[])
{
    ll n;

    cin >> n;
    if (n == 1)
    {
        cout << 0 << endl;
        exit(0);
    }
    ll ans = 0;
    for (ll i = 1; i < n / 2; i++)
    {
        ans++;
    }
    if (n % 2 != 0)
        ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
import copy
N, K=map(int,input().split())
A=list(map(int,input().split()))
B=sorted([(a,abs(a)) for a in A],key=lambda x:x[1],reverse=True)
R=10**9+7
P=1
minus=0
last_neg=-1
last_pos=-1
for i in range(K):
    if B[i][0]>0:
        if last_pos != -1:
            P = (P * B[last_pos][1]) % R
        last_pos=i
    elif B[i][0]<0:
        if last_neg != -1:
            P = (P * B[last_neg][1]) % R
        minus+=1
        last_neg=i
    else:
        print(0)
        exit()
F=copy.copy(P)
if last_pos!=-1:
    F=(F*B[last_pos][1]) % R
if last_neg!=-1:
    F=(F*B[last_neg][1]) % R
if minus%2==1:
    if K == N:
        print(-F %R)
        exit()
    first_neg=-1
    first_pos=-1
    count=[0,0]
    for i in range(K,N):
        if count[0]==0 and B[i][0]>0:
            first_pos=i
            count[0]=1
        elif count[1]==0 and B[i][0]<0:
            first_neg=i
            count[1]=1
        elif count==[1,1]:
            break
    if first_pos==-1 and last_pos==-1:
        P = 1
        for i in range(K):
           P = (P * B[N - i - 1][0]) % R
        print(P)
        exit()
    if first_pos==-1 and first_neg==-1:
        print(0)
        exit()
    list_product=[]
    if first_neg!=-1 and last_pos!=-1:
        list_product.append(B[last_neg][1]*B[first_neg][1])
    if first_pos!=-1:
        P1=B[first_pos][1]
        if last_pos!=-1:
            P1=P1*B[last_pos][1]
        list_product.append(P1)
    print(max(list_product)*P %R)
else:
    print(F)


Measured memory_bytes: 41456
i=0
N=int(input())
while i<N:
    a,b,c=map(int,input().split())
    if a*a+b*b==c*c or a*a+c*c==b*b or b*b+c*c==a*a:
        print('YES')
    else:
        print('NO')
    i=i+1




Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
vector<int> v = {1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049};
vector<int> memo(100100, -1);
int dp(int x) {
    if (x < 0) return INF;
    if (x == 0) return 0;
    if (memo[x] != -1) return memo[x];
    int ret = INF;
    for (int y : v) {
        chmin(ret, dp(x - y));
    }
    return memo[x] = ret + 1;
}
int main() {
    int n;
    cin >> n;
    cout << dp(n) << endl;
}

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

using namespace std;

#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 DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  int n;
  cin >> n;
  vi u, v;
  if (n % 2 == 1) {
    rep1 (i, n) {
      for (int j = i + 1; j <= n; j++) {
        if (i + j == n) continue;
        u.push_back(i);
        v.push_back(j);
      }
    }
  }
  else {
    rep1 (i, n) {
      for (int j = i + 1; j <= n; j++) {
        if (i + j == n + 1) continue;
        u.push_back(i);
        v.push_back(j);
      }
    }
  }
  cout << u.size() << endl;
  rep (i, u.size()) {
    cout << u[i] << " " << v[i] << endl;
  }
}
    


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

class Node {
public:
  int value;
  Node *parent;
  Node *left;
  Node *right;
  Node (int value) {
    this->value = value;
    this->parent = NULL;
    this->left = NULL;
    this->right = NULL;
  }
};

Node *insert(Node *root, Node *toInsert) {
  Node *parent = NULL;
  Node *current = root;
  while (current != NULL) {
    parent = current;
    if (toInsert->value < current->value)
      current = current->left;
    else
      current = current->right;
  }
  toInsert->parent = parent;
  if (parent == NULL) {
    root = toInsert;
  }
  else if (toInsert->value < parent->value)
    parent->left = toInsert;
  else
    parent->right = toInsert;
  return root;
}

void printInorder(Node *current) {
  if (current != NULL) {
    printInorder(current->left);
    cout << ' ' << current->value;
    printInorder(current->right);
  }
  return;
}

void printPreorder(Node *current) {
  if (current != NULL) {
    cout << ' ' << current->value;
    printPreorder(current->left);
    printPreorder(current->right);
  }
  return;
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  Node *root = NULL;
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    string holder;
    cin >> holder;
    if (holder == "print") {
      printInorder(root);
      cout << endl;
      printPreorder(root);
      cout << endl;
    } else {
      int value;
      cin >> value;
      root = insert(root, new Node(value));
    }
  }
  return 0;
}



Measured memory_bytes: 26708
h, w = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]

from scipy.sparse.csgraph import floyd_warshall
cost=floyd_warshall(c)

total = 0
for i in range(h):
    for j in range(w):
        if a[i][j] != -1:
            start = a[i][j]
            d = cost[start][1]
            total += int(d)

print(total)


Measured memory_bytes: 14100
import sys

X, N = map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
p = input().split(" ")
a = X
b = X
for i in range(len(p)):
  for i in range(len(p)):
    if int(p[i]) == a:
      a = a + 1
    if int(p[i]) == b:
      b = b - 1
  #print(int(p[i]))
#print(a,b)
if -1*(X - a) < X - b:
  print(a)
else:
  print(b)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	vector<vector<int>> adj(n);
	for (int i = 1, u, v; i < n; ++i)
	{
		cin >> u >> v;
		--u, --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	int ans = 0;
	function<int(int, int)> dfs = [&](int u, int p)
	{
		int r = 0;
		vector<int> d;
		for (auto v : adj[u])
			if (v != p)
			{
				d.push_back(dfs(v, u)+1);
			}

		sort(d.begin(), d.end());
		reverse(d.begin(), d.end());

		if (d.size() > 0)
			r = d[0];

		ans = max(ans, r);
		if (d.size() > 1)
		{
			ans = max(ans, d[0] + d[1]);
		}

		return r;
	};

	dfs(0, -1);
	if (ans == 0)
	{
		cout << "First\n";
		return 0;
	}

	if ((ans-1)%3 == 0)
		cout << "Second\n";
	else
		cout << "First\n";

	return 0;
}


Measured memory_bytes: 29184
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

	void solve() {
		int K, N;
		cin >> K >> N;

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

		vector<int> B( N );
		B[0] = K - A[N-1] + A[0];
		int sum = B[0];

		for( int i = 1; i < N; ++i ) {
			B[i] = A[i] - A[i-1];
			sum += B[i];
		}

		int d = INT_MAX;
		for( int i = 0; i < N; ++i ) {
			d = min( d, sum - B[i] );
		}

		cout << d << endl;
	}
};

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


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

int main()
{
  int w, n, a, b;
  int num[30];
  scanf("%d %d", &w, &n);
  for(int i = 0; i < w; i++){
    num[i] = i + 1;
  }
  for(int i = 0; i < n; i++){
    scanf("%d,%d", &a, &b);
    swap(num[a - 1], num[b - 1]);
  }
  for(int i = 0; i < w; i++){
    printf("%d\n", num[i]);
  }
}

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

int main(){
  int a,b;
  string res;
  cin >> a >> b;
  if (a == b){
    res = "Draw";
  }else{
    if (a == 1 || b == 1){
      res = (a == 1) ? "Alice" : "Bob";
    }else{
      res = (a > b) ? "Alice" : "Bob";
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256