akhauriyash/Code-Regression huggingface dataset:
class UnionFind3:
    def __init__(self, size):
        self.table = [-1 for _ in xrange(size)]
 
    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]
 
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False
 
uf=UnionFind3(100001)
 
n = input()
cities = [map(int,raw_input().split(" "))+[i] for i in range(n)]
 
cities_x = sorted(cities, key=lambda a:a[0])
cities_y = sorted(cities, key=lambda a:a[1])
 
road = [[cities_x[i+1][0]-cities_x[i][0],cities_x[i][2],cities_x[i+1][2]] for i in range(n-1)]
road +=[[cities_y[i+1][1]-cities_y[i][1],cities_y[i][2],cities_y[i+1][2]] for i in range(n-1)]
 
sum = 0
for (cost,i,j) in sorted(road):
    if(uf.find(i)!=uf.find(j)):
        uf.union(i,j)
        sum += cost
 
print sum

Measured memory_bytes: 56348
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <bitset>

using namespace std;
using ll = long long;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n + 1);
    set<int> unused;
    map<int, int> cnt;
    set<pair<int, int>> xyi;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
        unused.insert(i);
    }

    for (auto p : cnt) {
        xyi.insert({ p.second, p.first });
    }

    vector<int> ans(1);
    for (int i = 1; i <= n; i++) {
        for (int x : unused) {
            xyi.erase({ cnt[a[x]], a[x] });
            cnt[a[x]]--;
            xyi.insert({ cnt[a[x]], a[x] });
            if (a[ans.back()] == x) {
                xyi.erase({ cnt[a[x]], a[x] });
                cnt[a[x]]++;
                xyi.insert({ cnt[a[x]], a[x] });
                continue;
            }
            if (xyi.rbegin()->first == n - i - 1 && unused.count(xyi.rbegin()->second) && a[x] == xyi.rbegin()->second) {
                xyi.erase({ cnt[a[x]], a[x] });
                cnt[a[x]]++;
                xyi.insert({ cnt[a[x]], a[x] });
                continue;
            }
            if (n - i == 2 && xyi.rbegin()->first == 1 && unused.count(xyi.rbegin()->second) && unused.count((++xyi.rbegin())->second) &&
               xyi.rbegin()->second != x && (++xyi.rbegin())->second != x) {
                xyi.erase({ cnt[a[x]], a[x] });
                cnt[a[x]]++;
                xyi.insert({ cnt[a[x]], a[x] });
                continue;
            }
            unused.erase(x);
            ans.push_back(x);
            break;
        }
        if (ans.size() == i) {
            cout << "-1\n";
            return 0;
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << ans[i] << " \n"[i == n];
    }
    return 0;
}

Measured memory_bytes: 15740
#include <stdio.h>
#define N 100000

typedef struct q{
  char name[10];
  int time;
}qoo;

qoo Q[N];
int head,tail,n;

void enq(qoo);
qoo deq();
int min(int,int);

int main(){
  qoo z;
  int q,i;
  int p = 0,c;

  scanf("%d %d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s %d",Q[i].name,&Q[i].time);
  }
  head=1;
  tail=n+1;

  while(head!=tail){
    z=deq();
    c=min(q,z.time);
    z.time-=c;
    p+=c;
    if(z.time>0)enq(z);
    else printf("%s %d\n",z.name,p);
  }

  return 0;
}


void enq(qoo x){
  Q[tail] = x;
  tail = (tail+1)%N; 
}
qoo deq(){
  qoo x = Q[head];
  head = (head+1)%N;
  return x;
}
int min(int a,int b)
{return a < b ? a : b;}



Measured memory_bytes: 3284
s=[];
for i in range(3):
  s.append(list(map(int,input().split())))
sum=0
for i in range(3):
  for j in range(3):sum+=s[i][j]
c1=s[0][0]+s[1][1]+s[2][2]
c2=s[0][2]+s[1][1]+s[2][0]
print('Yes'if sum==c1*3 and sum==c2*3 else 'No')

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long want[] = new long[3];
		for(int i = 0; i < 3; i ++) {
			want[i] = sc.nextLong();
		}
		long length[] = new long[num];
		for(int i = 0; i < num; i ++) {
			length[i] = sc.nextLong();
		}
		long min = Long.MAX_VALUE;
		for(int i = 0; i < Math.pow(4, num); i ++) {
			int choose[] = new int[num];
			for(int j = 0; j < num; j ++) {
				choose[j] = (i & (3 << j * 2)) >> j * 2;
			}
			int tmpL[] = new int[4];
			int add[] = new int[4];
			for(int j = 0; j < num; j ++) {
				tmpL[choose[j]] += length[j];
				add[choose[j]] ++;
			}
			if(tmpL[0] == 0 || tmpL[1] == 0 || tmpL[2] == 0) { continue; }
			long tmpMP = 0;
			for(int j = 0; j < 3; j ++) {
				tmpMP += (add[j] - 1) * 10;
				tmpMP += Math.abs(tmpL[j] - want[j]);
			}
			min = Math.min(min, tmpMP);
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 32908
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    use std::collections::HashMap;
    let mut map: HashMap<usize, usize> = HashMap::new();
    map.insert(0, 1);
    for _ in 0..N {
        let entry = map.entry(read()).or_insert(0);
        *entry += 1;
        if *entry >= 3 {
            println!("0");
            return;
        }
    }
    let mut vec: Vec<(usize, usize)> = vec![];
    for v in map {
        vec.push(v);
    }
    let mins = dfs(0, &vec, vec![]);
    println!("{}", mins.iter().max().unwrap());
}

fn dfs(depth: usize, vec: &[(usize, usize)], now_times: Vec<usize>) -> Vec<usize> {
    if depth == vec.len() {
        let mut now_times = now_times;
        now_times.sort();
        now_times.push(24);
        let min = now_times
            .windows(2)
            .fold(1000, |acc, v| std::cmp::min(acc, (v[1] - v[0]) % 24));
        return vec![min];
    }
    let v = vec[depth].0;
    let count = vec[depth].1;
    if count == 2 {
        let mut now_times = now_times;
        now_times.push(v);
        now_times.push(24 - v);
        dfs(depth + 1, vec, now_times)
    } else {
        let mut now_times_mut = now_times.clone();
        now_times_mut.push(v);
        let mins1 = dfs(depth + 1, vec, now_times_mut);
        let mut now_times_mut = now_times;
        now_times_mut.push(24 - v);
        let mins2 = dfs(depth + 1, vec, now_times_mut);
        [mins1, mins2].concat()
    }
}


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

class graph {
    struct edge {
        int to, cost;
        edge(int to, int cost) : to(to), cost(cost) {}
    };

    vector<vector<edge>> edges;
    vector<int> dist;

public:
    graph(int n) : edges(n) {}

    void connect(int from, int to, int cost) {
        edges[from].push_back(edge(to, cost));
        edges[to].push_back(edge(from, cost));
    }

    void dijkstrta(int s) {
        const int inf = 1LL << 60;
        dist.resize(edges.size(), inf);

        priority_queue<pi, vector<pi>, greater<pi>> que;
        que.push(make_pair(0, s));

        dist[s] = 0;
        while(!que.empty()) {
            int from = que.top().second;
            int cur_dist = que.top().first;
            que.pop();

            if (dist[from] < cur_dist) continue;

            for (auto edge : edges[from]) {
                int to = edge.to;
                int cost = edge.cost;
                if (dist[to] > dist[from] + cost) {
                    dist[to] = dist[from] + cost;
                    que.push(make_pair(dist[to], to));
                }
            }
        }
    }

    int distance(int i) {
        return dist[i];
    }
};

signed main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--, t--;

    graph g_yen(n), g_snuuk(n);
    rep(i, 0, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        g_yen.connect(u, v, a);
        g_snuuk.connect(u, v, b);
    }

    g_yen.dijkstrta(s);
    g_snuuk.dijkstrta(t);

    const int init_yen = 1e15;
    vector<int> ans(n);

    priority_queue<int> costs;
    for (int i = n - 1; i >= 0; i--) {
        int yen = g_yen.distance(i);
        int snuuk = g_snuuk.distance(i);

        int travel = init_yen - (yen + snuuk);
        costs.push(travel);

        ans[i] = costs.top();
    }

    for (auto i : ans) cout << i << endl;

    return 0;
}

Measured memory_bytes: 20732
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    s64 a, b, c, d;
    cin >> a >> b >> c >> d;

    s64 ans = -1e18;
    ans = max(ans, a * c);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    bool flag = true;
    int i = 0;
    while (flag)
    {
        if(a*i >= b && a*i <= c ){
            flag = false;
        }else if(a*i > c){
            break;
        }
        i++;
    }
    if(flag){
        cout << "NG" << endl;
    }else{
        cout << "OK" << endl;
    }
    
}

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

int main(){
 int a,b,c,count;
 count=0;
 cin>>a>>b>>c;
 for(int i=a;i<=b;i++){
  if(i!=0&&c%i==0){
    count++;
  }
 }
cout<<count<<'\n';
 return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i++)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  cin >> n;
  map<int,int> mapp;
  int memo;
  rep(i,0,n) {
    cin >> memo;
    mapp[memo]++;
  }
  
  int ans = 0;
  
  for (auto p : mapp) {
    auto k = p.first;
    auto v = p.second;
    if(k <= v) ans += v-k;
    else ans += v;
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
int main(){

string a,b,c;
cin>>a>>b>>c;

int m,n;

m=a.length();
m--;
n=b.length();
n--;

if(a[m]==b[0]){
if(b[n]==c[0]){
cout<<"YES"<<endl;
}
else
cout<<"NO"<<endl;

}
else
cout<<"NO"<<endl;
return 0;
}


Measured memory_bytes: 3588
from collections import deque

def solve():
    if s[0][0] == '#':
        print(-1)
        return

    stack = deque()
    stack.append([0, 0, 0])
    used = [[False for _ in range(W)] for _ in range(H)]
    costs = [[float('inf') for _ in range(W)] for _ in range(H)]
    while stack:
        i, j, cost = stack.popleft()
        costs[i][j] = cost
        for x, y in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]:
            if not 0 <= x < H or not 0 <= y < W or used[x][y] or s[x][y] == '#':
                continue
            stack.append([x, y, cost + 1])
            used[x][y] = True

    print(dot_num - 1 - costs[H - 1][W - 1] if costs[H - 1][W - 1] != float('inf') else -1)

if __name__ == "__main__":
    H, W = map(int, input().split())
    s = []
    dot_num = 0
    for _ in range(H):
        tmp = list(input())
        dot_num += tmp.count('.')
        s.append(tmp)
    solve()

Measured memory_bytes: 40304
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int span = sc.nextInt();
		int period = sc.nextInt();
		int cost1 = sc.nextInt();
		int cost2 = sc.nextInt();
		int total = 0;
		
		if((span - period) >= 0)
		total = period * cost1 + (span - period) * cost2;
		else 
		total = span * cost1;
		System.out.println(total);
	}
}


Measured memory_bytes: 22740
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	int w=100;
	int h;
	if(a==1 && b==1){
		h=2;
		printf("%d %d\n", h, w);
		for(int i=1; i<=w; i++){
			printf("%c", '.');
		}
		printf("\n");
		for(int i=1; i<=w; i++){
			printf("%c", '#');
		}
		printf("\n");
	}else if(a==1){
		int bq=(b+49)/50, br=b-(bq-1)*50;
		h=2*bq;
		printf("%d %d\n", h, w);
		for(int i=1; i<=bq; i++){
			if(i!=bq){
				for(int j=1; j<=w; j++){
					if(j%2!=0){
						printf("%c", '.');
					}else{
						printf("%c", '#');
					}
				}
				printf("\n");
				for(int i=1; i<=w; i++){
					printf("%c", '.');
				}
				printf("\n");
			}else{
				for(int j=1; j<=w; j++){
					if(j<=2*br && j%2==0){
						printf("%c", '#');
					}else{
						printf("%c", '.');
					}
				}
				printf("\n");
				for(int i=1; i<=w; i++){
					printf("%c", '.');
				}
				printf("\n");
			}
		}
	}else if(b==1){
		int aq=(a+49)/50, ar=a-(aq-1)*50;
		h=2*aq;
		printf("%d %d\n", h, w);
		for(int i=1; i<=aq; i++){
			if(i!=aq){
				for(int j=1; j<=w; j++){
					if(j%2!=0){
						printf("%c", '#');
					}else{
						printf("%c", '.');
					}
				}
				printf("\n");
				for(int i=1; i<=w; i++){
					printf("%c", '#');
				}
				printf("\n");
			}else{
				for(int j=1; j<=w; j++){
					if(j<=2*ar && j%2==0){
						printf("%c", '.');
					}else{
						printf("%c", '#');
					}
				}
				printf("\n");
				for(int i=1; i<=w; i++){
					printf("%c", '#');
				}
				printf("\n");
			}
		}
	}else{
		int bq=(b-1+49)/50, br=b-1-(bq-1)*50;
		int aq=(a-1+49)/50, ar=a-1-(aq-1)*50;
		h=aq*2+bq*2;
		printf("%d %d\n", h, w);
		for(int i=1; i<=bq; i++){
			if(i!=bq){
				for(int j=1; j<=w; j++){
					if(j%2!=0){
						printf("%c", '.');
					}else{
						printf("%c", '#');
					}
				}
				printf("\n");
				for(int i=1; i<=w; i++){
					printf("%c", '.');
				}
				printf("\n");
			}else{
				for(int j=1; j<=w; j++){
					if(j<=2*br && j%2==0){
						printf("%c", '#');
					}else{
						printf("%c", '.');
					}
				}
				printf("\n");
				for(int i=1; i<=w; i++){
					printf("%c", '.');
				}
				printf("\n");
			}
		}
		for(int i=1; i<=aq; i++){
			if(i!=aq){
				for(int i=1; i<=w; i++){
					printf("%c", '#');
				}
				printf("\n");
				for(int j=1; j<=w; j++){
					if(j%2!=0){
						printf("%c", '#');
					}else{
						printf("%c", '.');
					}
				}
				printf("\n");
				
			}else{
				for(int i=1; i<=w; i++){
					printf("%c", '#');
				}
				printf("\n");
				for(int j=1; j<=w; j++){
					if(j<=2*ar && j%2==0){
						printf("%c", '.');
					}else{
						printf("%c", '#');
					}
				}
				printf("\n");
				
			}
		}
	}
	return 0;
}

Measured memory_bytes: 128
list = []
words = ['AC','WA','TLE','RE']
words_count = {'AC':0,'WA':0,'TLE':0,'RE':0}
    
try:
    while True:
      val = input()
      if val:
        list.append(val)
      else:
        break
except EOFError:
    pass

for i in range(1,len(list)):
  for word in words:
    if list[i] == word:
      words_count[word] += 1

for k,v in words_count.items():
  print("{key} x {value}".format(key = k,value= v))
  	

Measured memory_bytes: 16068
// ABC048 B - Between a and b ...
#include <stdio.h>

int main(void) {
    unsigned long long a, b, x;
    unsigned long long result;
    // input
    scanf("%llu %llu %llu", &a, &b, &x);

    result = (b / x) - (a / x);
    if (a % x == 0) {
        result++;
    }

    printf("%llu\n", result);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
	int n,m,i,t,l,r;
	scanf("%d%d",&n,&m);
	if(n%2==0)n--;
	t=(n-1)/2;
	if(t==1)return 0*printf("1 2\n");
	l=t/2,r=l+2;
	for(i=1;i<=m;i++){
		printf("%d %d\n",l,r);
		l--,r++;
		if(l==0)l=(t+n+1)/2,r=l+1;
	}
	return 0;
}

Measured memory_bytes: 3232
/*
 * 2680.cc: LR
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const int INF = 1 << 30;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

string dp0[MAX_N][MAX_N], dp1[MAX_N][MAX_N], dp2[MAX_N][MAX_N];

/* subroutines */

bool lt_num(string &s0, string &s1) {
  int l0 = s0.size(), l1 = s1.size();
  if (l0 != l1) return l0 < l1;
  for (int i = 0; i < l0; i++)
    if (s0[i] != s1[i]) return (s0[i] < s1[i]);
  return false;
}

/* main */

int main() {
  string s;
  cin >> s;
  int n = s.size();

  for (int i = 0; i < n; i++) {
    if (s[i] >= '0' && s[i] <= '9') dp0[i][i] = string(1, s[i]);
    else if (s[i] == '?') dp0[i][i] = string(1, '9');
    dp1[i][i] = dp0[i][i];
  }

  for (int l = 2; l <= n; l++)
    for (int i = 0, j = l - 1; j < n; i++, j++) {
      if (((s[i] >= '0' && s[i] <= '9') || s[i] == '?') &&
	  dp0[i + 1][j].size() > 0) {
	char ch = (s[i] == '?') ? '9' : s[i];
	string sd = string(1, ch) + dp0[i + 1][j];
	if (lt_num(dp0[i][j], sd)) dp0[i][j] = sd;
	if (sd[0] != '0' && lt_num(dp1[i][j], sd)) dp1[i][j] = sd;
      }	
      if (((s[j] >= '0' && s[j] <= '9') || s[j] == '?') &&
	  dp0[i][j - 1].size() > 0) {
	char ch = (s[j] == '?') ? '9' : s[j];
	string sd = dp0[i][j - 1] + ch;
	if (lt_num(dp0[i][j], sd)) dp0[i][j] = sd;
	if (sd[0] != '0' && lt_num(dp1[i][j], sd)) dp1[i][j] = sd;
      }

      if (l >= 6 &&
	  (s[i + 1] == '(' || s[i + 1] == '?') &&
	  (s[j] == ')' || s[j] == '?')) {
	bool lok = (s[i] == 'L' || s[i] == '?');
	bool rok = (s[i] == 'R' || s[i] == '?');
	if (lok || rok)
	  for (int k = i + 3; k < j - 1; k++)
	    if (s[k] == ',' || s[k] == '?') {
	      string &dp00 = dp1[i + 2][k - 1], &dp01 = dp2[i + 2][k - 1];
	      string &dp10 = dp1[k + 1][j - 1], &dp11 = dp2[k + 1][j - 1];
	      string &dp0 = lt_num(dp00, dp01) ? dp01 : dp00;
	      string &dp1 = lt_num(dp10, dp11) ? dp11 : dp10;
	      if (dp0.size() > 0 && dp1.size() > 0) {
		if (lok && lt_num(dp2[i][j], dp0)) dp2[i][j] = dp0;
		if (rok && lt_num(dp2[i][j], dp1)) dp2[i][j] = dp1;
	      }
	    }
      }
    }

  string &d1 = dp1[0][n - 1], &d2 = dp2[0][n - 1];
  string &maxdp = lt_num(d1, d2) ? d2 : d1;
  if (maxdp.size() == 0) puts("invalid");
  else cout << maxdp << endl;
  return 0;
}

Measured memory_bytes: 1444
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

long long n;
long long a[123456];
long long d[123456];

long long imod(long long a, long long b)
{
	return ((a % b) + b) % b;
}

int main(void)
{
	cin >> n;
	long long normsum = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		normsum += a[i];
	}
	if (normsum % (n * (n + 1) / 2) != 0)
	{
		cout << "NO" << endl;
		return 0;
	}
	long long time = normsum / (n * (n + 1) / 2);
	a[n] = a[0];
	long long difsum = 0;
	for (int i = 0; i < n; ++i)
	{
		long long dif = a[i + 1] - a[i];
		d[i] = dif;
		difsum += dif;
		if (imod(dif, n) != imod(time, n))
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	if (difsum != 0)
	{
		cout << "NO" << endl;
		return 0;
	}
	long long mcount = 0;
	for (int i = 0; i < n; ++i)
	{
		long long tim = (time - d[i]) / n;
		if (tim < 0)
		{
			cout << "NO" << endl;
			return 0;
		}
		mcount += tim;
	}
	if (mcount != time)
	{
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 1920
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){

  int a,b,n;
  scanf("%d%d%d",&n,&a,&b);
  if(n*a<b){
    printf("%d",n*a);
  }
  else
  printf("%d",b);


}


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

Measured memory_bytes: 2664
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
int main() {
    int n;
    cin >> n;
    vector<int> ans(n+1);
    for(int x = 1;x <= 100;x++){
        for(int y = 1;y <= 100;y++){
            for(int z = 1;z <= 100;z++){
                int s = x * x + y * y + z * z;
                s += x * y + y * z + z * x;
                if(s > n){
                    continue;
                }
                ans[s]++;
            }
        }
    }

    for(int i = 1;i <= n;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3512
#include<stdio.h>
#include <unistd.h>
#include <stdlib.h>
int totonoe(int *,int);
int n;
int main(){
  int i,a[500001];
  scanf("%d",&n);
  for(i=1;i<n+1;i++){
    scanf("%d",&a[i]);

  }
  for(i=n/2;i>0;i--){
    totonoe(a,i);
  }
  

  for(i=1;i<n+1;i++){
    printf(" %d",a[i]);

  }
  printf("\n");

}
int totonoe(int *a,int root){
  int tmp,b=1;
  if(n>=root*2)
    if(a[root*2]>a[root])
      b*=2;
  if(n>=root*2+1)
    if(a[root*2+1]>a[root])
      b*=3;
  if (b%2 == 0 && b%3 ==0){
    if(a[root*2]>a[root*2+1]){
      tmp=a[root*2];
      a[root*2] = a[root];
      a[root] = tmp;
      totonoe(a,root*2);
    }else{
      tmp=a[root*2+1];
      a[root*2+1] = a[root];
      a[root] = tmp;
      totonoe(a,root*2+1);
    }
    
  }else if(b%2 == 0){
      tmp=a[root*2];
      a[root*2] = a[root];
      a[root] = tmp;
      totonoe(a,root*2);


  }else if(b%3 ==0){
      tmp=a[root*2+1];
      a[root*2+1] = a[root];
      a[root] = tmp;
      totonoe(a,root*2+1);


  }
  return 0;
}



Measured memory_bytes: 3672
import sys
sys.setrecursionlimit(10**7)

def dfs(v, color):
    colors[v] = color
    for to in g[v]:
        if colors[to] == color: return False
        if colors[to] == 0 and not dfs(to, -color):
            return False
    return True

n, m = map(int, input().split())

g = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

colors = [0]*n

ans = -m
if dfs(0,1):
  b = (sum(colors)+n)//2
  w = n-b
  ans += b*w
else:
  ans += n*(n-1)//2
print(ans)

Measured memory_bytes: 31060
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int jp[n+1],h[n+1],minimum[k];
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	h[0] = 10001;
	jp[2] = abs(h[2]-h[1]);
	jp[1] = 0;
	for(int i=3;i<=n;i++){
	    
	    int j=i-1;
	    while(j>=max(1,(i-k))){
	      minimum[j] = (abs(h[i]-h[j]) + jp[j]);
	      j--;
	    }
	    int res = minimum[j+1];
		for(int m =j+2;m<=i-1;m++){
		    res = min(res,minimum[m]);
		}
		jp[i] = res;
	}
	cout<<jp[n];
}

Measured memory_bytes: 1024
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    A += A
    A.sort()
    A.pop()
    ans = 0
    for _ in range(n - 1):
        ans += A.pop()
    print(ans)
resolve()

Measured memory_bytes: 105016
N, M = map(int, input().split())
H = [int(i) for i in input().split()]
AB = []
for m in range(M):
  AB.append([int(i) for i in input().split()])
  
s = [1] * N
for m in range(M):
  a = AB[m][0]
  b = AB[m][1]
  if H[a-1] < H[b-1]:
    s[a-1] = 0
  elif H[b-1] < H[a-1]:
    s[b-1] = 0
  elif H[a-1] == H[b-1]:
    s[a-1] = 0
    s[b-1] = 0
    
print(sum(s))

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

int main(){
    string a;
    cin >> a;

    if(a[0] == '7' || a[1]=='7' || a[2]=='7'){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  for (int& x : a) {
    cin >> x;
  }
  int idx = -1;
  for (int i = 0; i < a.size() - 1; i++) {
    if (a[i] + a[i+1] >= m) {
      idx = i;
    }
  }
  if (idx == -1) {
    cout << "Impossible\n";
  } else {
    cout << "Possible\n";
    for (int i = 0; i < idx; i++) {
      cout << (i + 1) << "\n";
    }
    for (int i = a.size() - 2; i >= idx; i--) {
      cout << (i + 1) << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 1152
from collections import deque
from math import ceil

# n个怪物，d杀伤半径，a杀伤值
n, d, a = map(int,input().split())

ms = [map(int, input().split()) for i in range(n)]
ms = sorted([(pos, ceil(hp / a)) for pos, hp in ms])
 
bombs = deque()
 
ans = 0
valid_bomb = 0
for pos, hp in ms:
  # 查看队列里的bomb是否对当前怪物有效
  while bombs and bombs[0][0] < pos:
    bomb_border, bomb_cnt = bombs.popleft()
    valid_bomb -= bomb_cnt
  
  # 还需新加多少bomb才能灭掉当前怪物
  bomb_cnt = max(0, hp - valid_bomb)
  valid_bomb += bomb_cnt
  ans += bomb_cnt
  
  # 新加的bomb放入队列
  if bomb_cnt > 0:
    bombs.append([pos + d * 2, bomb_cnt])
 
print(ans)  


Measured memory_bytes: 100384
import java.util.Scanner;

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

        int n = scanner.nextInt();
        int r = scanner.nextInt();

        int result;
        if (n >= 10) {
            result = r;
        } else {
            result = 100 * (10 - n) + r;
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <string.h>

int main() {
    char w[100+1];
    scanf("%s", w);

    int len = strlen(w);
    if (len % 2 == 1) {
        puts("No");
        return 0;
    }

    int az[26] = {}; // ぜ～んぶゼロへ初期化
    for (int i = 0; i < len; i++) {
        az[ w[i]-'a' ] += 1;
    }

    for (int i = 0; i < 26; i++) {
        if (az[i] % 2 == 1) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");

    return 0;
}

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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
#define N 100010
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;
ll T,n;

int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >> s;
    ll n = s.size();
    ll i=0,j=n-1;
    ll f=0;
    if(n%2==0)
        f=1;
    while(i<j){
        if(s[i] == s[j]){
            i++;
            j--;
        }
        else{
            f=1;
            break;
        }
    }
    i=0;
    j=n/2-1;
    while(i<j){
        if(s[i] == s[j]){
            i++;
            j--;
        }
        else{
            f=1;
            break;
        }
    }
    i=n/2+1;
    j=n-1;
    while(i<j){
        if(s[i] == s[j]){
            i++;
            j--;
        }
        else{
            f=1;
            break;
        }
    }
    if(f)
        cout << "No\n";
    else
        cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int k,s,i,j,buf,count = 0;

    scanf("%d %d",&k,&s);
    for (i = 0; i <= k; i++)
    {
        for (j = 0; j <= k; j++)
        {
            buf = s - i - j;
            if (0 <= buf && buf <= k)
            {
                count ++;
            }
        }        
    }
    printf("%d",count);
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a>2*b)cout << a-2*b << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,ans=0;
	cin>>n;
	vector<int>p(n);
	rep(i,n)cin>>p[i];
	sort(all(p));
	rep(i,n)ans+=p[i];
	cout<<ans-p.back()/2<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int n, i, count = 1;
	char s[100000];
	scanf("%d", &n);
	scanf("%s", s);
	for (i = 0; i < n - 1; i++) {
		if (s[i] != s[i + 1])
			count++;
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 256
/*---------------------------*\
____________Mari000____________         
________Mostafa  Shehab________    
\*---------------------------*/

#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
typedef long long ll;
typedef long double ld;
//template <class Type>

ll power(ll x,ll y,ll p);
int Bit(ll x);
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}

const int N=2e5 + 5;
int arr[N];
map<int,int> mp;
int n;
int cnt,m;


vector<int> vec;
int a,b,c,d;

int main(){
	int n=D(),k=D();
	for(int i=0;i<n;++i)
		++arr[D()];
	for(int i=0;i<N;++i)
		if(arr[i])
			vec.push_back(arr[i]);
			
	sort(vec.rbegin(),vec.rend());

	for(int i=0;i<k && i<vec.size();++i)
		cnt+=vec[i];
	
	printf("%d",n-cnt);
			
	
	

}










ll power(ll x,ll y,ll p){ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
    while (y > 0){ 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;
    }
    return res; 
}


int Bit(ll x){
	if(!x)
		return 0;
	return 1+Bit(x>>1);
}


















Measured memory_bytes: 2168
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

minus_index = -1
happy = 0

for i in range(n):
    index = a[i] - 1
    happy += b[index]
    if(a[i] == minus_index + 1):
        happy += c[minus_index-1]
    minus_index = a[i]

print(happy)

Measured memory_bytes: 9064
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
    char a, b, c, d;
    cin >> a >> b >> c >> d;

    a -= '0'; b -= '0'; c -= '0'; d -= '0';
    for (int i = 0; i < 0b1000; i++) {
        int sum = a;
        if (0b100 & i) sum -= b; else sum += b;
        if (0b010 & i) sum -= c; else sum += c;
        if (0b001 & i) sum -= d; else sum += d;
        if (sum == 7) {
            cout << (int)a << ((0b100 & i)?"-":"+")
                 << (int)b << ((0b010 & i)?"-":"+")
                 << (int)c << ((0b001 & i)?"-":"+")
                 << (int)d << "=7\n";
            break;
        }
    }
    return 0;
}

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

int main() {
 int x,a,b,c; cin>>x;
  a=x/100; b=x/10-10*a; c=x%10;
  if(a==1)a=9;
  else if(a==9)a=1;
   if(b==1)b=9;
  else if(b==9)b=1;
   if(c==1)c=9;
  else if(c==9)c=1;
  
    cout<<a<<b<<c<<endl;



}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf(x) (ll)(1e##x)
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int N = 201000;
int u[N],v[N],d[N],tag[N],n,X,Y;
class graph{
public:
	vector<int> e[N];
	int dep[N],fa[20][N];
	void add(int x,int y){e[x].push_back(y);}
	void dfs(int x,int dad){
		dep[x]=dep[dad]+1;fa[0][x]=dad;
		for(int v:e[x]) if(v!=dad) dfs(v,x);
	}
	void build(){
		for(int i=1;i<=18;i++)
			for(int j=1;j<=n;j++)
				fa[i][j]=fa[i-1][fa[i-1][j]];
	}
	int lca(int x,int y){
		if(dep[x]<dep[y]) swap(x,y);
		for(int k=dep[x]-dep[y],i=0;k;k>>=1,i++)
			if(k&1) x=fa[i][x];
		if(x==y) return x;
		for(int i=18;~i;i--)
			if(fa[i][x]!=fa[i][y]) x=fa[i][x],y=fa[i][y];
		return fa[0][x];
	}
	int dis(int u,int v){return dep[u]+dep[v]-2*dep[lca(u,v)];}
}g1,g2;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int ,int> > > q;
int main(){
	read(n);read(X);read(Y);
	for(int i=1;i<n;i++){
		int x,y;read(x);read(y);
		g1.add(x,y);g1.add(y,x);
		u[i]=x;v[i]=y;
	}
	for(int i=1;i<n;i++){
		int x,y;read(x);read(y);
		g2.add(x,y);g2.add(y,x);
	}
	g2.dfs(Y,0);g2.build();
	for(int i=1;i<n;i++)
		if(g2.dis(u[i],v[i])>2) tag[u[i]]=tag[v[i]]=1;
	memset(d,63,sizeof(d));d[X]=0;
	q.push(make_pair(0,X));
	while(!q.empty()){
		int u=q.top().second,dis=q.top().first;q.pop();
		if(dis>d[u]) continue;
		if(d[u]+1>=g2.dep[u]) continue;
		for(int v:g1.e[u]) if(d[v]>d[u]+1){
			d[v]=d[u]+1;
			q.push(make_pair(d[v],v));
		}
	}
	for(int i=1;i<=n;i++)
		if(tag[i]&&d[i]+1<g2.dep[i]){cout<<-1<<'\n';return 0;}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(d[i]+1<=g2.dep[i]) ans=max(ans,g2.dep[i]*2-2);
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 49660
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
// https://ykmaku.hatenablog.com/entry/2018/09/03/153250
int main() {
    int a, b;
    cin >> a >> b;
    //しろがA個の連結成分 less than 500
    //くろがB個の連結成分 less than 500
    string s[100];
    for(int i = 0; i < 100; i++) {
        for(int j = 0; j < 100; j++) {
            if(i < 50)
                s[i].push_back('.');
            else
                s[i].push_back('#');
        }
    }
    int cnt = 0;
    for(int i = 0; i < 50; i += 2) {
        for(int j = 0; j < 100; j += 2) {
            if(cnt == b - 1) {
                break;
            }
            s[i][j] = '#';
            cnt++;
        }
    }
    cnt = 0;
    for(int i = 51; i < 100; i += 2) {
        for(int j = 0; j < 100; j += 2) {
            if(cnt == a - 1) {
                break;
            }
            s[i][j] = '.';
            cnt++;
        }
    }
    cout << 100 << " " << 100 << endl;
    for(int i = 0; i < 100; i++) {
        cout << s[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n,m,k;
char s[2000][2000];
int c[2000][2000][3];
int main(){
    scanf("%d%d%d",&m,&n,&k);
    REP(i,m)
        scanf("%s",s + i);

    REP(i,m)
        REP(j,n){
            if(s[i][j] == 'J')
                s[i][j] = 0;
            else if(s[i][j] == 'O')
                s[i][j] = 1;
            else
                s[i][j] = 2;
        }

    REP(i,m)
        REP(j,n)
        REP(k,3)
        c[i][j][k] = 0;

    c[0][0][s[0][0]] ++;
    FOR(i,1,n){
        REP(j,3)
            c[0][i][j] = c[0][i - 1][j];
        c[0][i][s[0][i]]++;
    }
    FOR(i,1,m){
        REP(j,3)
            c[i][0][j] = c[i - 1][0][j];
        c[i][0][s[i][0]]++;
    }

    FOR(i,1,m){
        FOR(j,1,n){
            REP(k,3){
                c[i][j][k] += c[i - 1][j][k] + c[i][j - 1][k] - c[i - 1][j - 1][k];
            }
            c[i][j][s[i][j]]++;
        }
    }

    REP(i,k){
        int x,y,w,z;
        scanf("%d%d%d%d",&x,&y,&w,&z);
        x--;y--;w--;z--;
        REP(j,3){
            int ans = c[w][z][j];
            if(x > 0 && y > 0)
                ans += c[x - 1][y - 1][j];
            if(x > 0)
                ans -= c[x - 1][z][j];
            if(y > 0)
                ans -= c[w][y - 1][j];
            printf("%d",ans);
            if(j < 2)
                printf(" ");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 20692
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CCountOrder {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> P(N), Q(N);
        REP(i, N) cin >> P[i];
        REP(i, N) cin >> Q[i];

        vector<int> v;
        REP(i, N) v.push_back(i + 1);

        int a = 0;
        int b = 0;
        int cnt = 0;
        do {
            bool ok = true;
            REP(i, N) {
                if (v[i] != P[i]) ok = false;
            }
            if (ok) {
                a = cnt;
            }
            ok = true;
            REP(i, N) {
                if (v[i] != Q[i]) ok = false;
            }
            if (ok) {
                b = cnt;
            }
            cnt++;
        } while (next_permutation(v.begin(), v.end()));

        cout << abs(a - b) << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CCountOrder solver;
    solver.solve(in, out);
    return 0;
}


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    int r, D;
    ll  x;

    cin >> r >> D;
    cin >> x;

    for (int i = 1; i <= 10; i++) {
        x = r * x - D;

        cout << x << endl;
    }

    return 0;
}


Measured memory_bytes: 256
require 'prime'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times {|i|yield(i)}                    end
def repl(st,en,n=1);       n*= -1 if st>en;st.step(en,n){|i|yield(i)} end


w,h,n = gi

m = darray(w,h,0)

rep n do
	x,y,a = gi

	case a
	when 1
		rep x do |j|
			rep h do |l|
				m[j][l] = 1
			end
		end
	when 2
		x.upto w-1 do |j|
			rep h do |l|
				m[j][l] = 1
			end
		end
	when 3
		rep y do |j|
			rep w do |l|
				m[l][j] = 1
			end
		end
	when 4
		 y.upto h-1 do |j|
			rep w do |l|
				m[l][j] = 1
			end
		end
	end
end

ans =  0
m.each do |mm|
	ans += mm.count(0)
end
puts ans


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  int cal;
  for (int i = 1; i <= n; ++i) {
    cal = (double)i * 1.08;
    if (cal == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(\n";
}


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

using namespace std;

string s;
int k;

int main()
{
  cin >> s >> k;
  set<string>$;
  for (int i = 1; i <= min((int)s.size(), k); i++) {
    for (int j = 0; j <= s.size() - i; j++)
      $.insert(s.substr(j, i));
  }
  set<string>::iterator it;
  it = $.begin();
  for (int i = 1; i < k; i++)
    it++;
  cout << *it;
  return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>

int min(int p0,int p1){
  return(p0<p1?p0:p1);
}

int pow(int p0,int p1){
  int i,n=1;
  for(i=0;i<p1;i++){
    n*=p0;
  }
  return(n);
}

int main(){
  int n,i,j,k,l,m=0,a[200][46],b[200],c[200][200],p[46]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199};
  scanf("%d",&n);
  for(i=0;i<n;i++){
    k=i+1;
    for(j=0;j<46;j++){
      a[i][j]=0;
      while((k%p[j])==0){
        k/=p[j];
        a[i][j]++;
      }
    }
    b[i]=0;
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      l=1;
      for(k=0;k<46;k++){
        l*=pow(p[k],min(a[i][k],a[j][k]));
      }
      b[l-1]++;
      c[i][j]=l;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      m+=c[i][j]*b[i];
    }
  }
  printf("%d",m);
  return(0);
}

Measured memory_bytes: 1900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
int gcf(int a, int b) {return (b == 0) ?  a : gcf(b, a%b);}
ll gcf(ll a, ll b) {return (b == 0) ? a : gcf(b, a%b);} 
int lcm(int a, int b) {return (a*b)/gcf(a, b);}
ll lcm(ll a, ll b) {return (a*b)/gcf(a, b);}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}

int gcf3(int a, int b, int c) {
    return gcf(gcf(a, b), c);
}

void solve() {
    int k; sc(k);
    ll ans = 0;
    fo1(a, k) {
        fo1(b, k) {
            fo1(c, k) {
                ans += (ll) gcf3(a, b, c);
            }
        }
    }
    printf("%I64d", ans);
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vs vector<string>
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main()
{
    int n, m;
    cin>>n>>m;
    string a(n, m+'0');
    string b(m, n+'0');
    cout<<(a<b?a:b)<<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 k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		boolean bl = false;
		for(int i = a; i <= b; i++) {
			if(i % k == 0)
				bl = true;
		}
		if(bl)
			System.out.println("OK");
		else
			System.out.println("NG");
	}
}


Measured memory_bytes: 35804
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>

using namespace std;

int main(void)
{
	int a, b;

	cin >> a >> b;
	if (a == b)
	{
		cout << "Draw" << endl;
	}
	else if (a == 1)
	{
		cout << "Alice" << endl;
	}
	else if (b == 1)
	{
		cout << "Bob" << endl;
	}
	else
	{
		if (a > b)
		{
			cout << "Alice" << endl;
		}
		else
		{
			cout << "Bob" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int H,W,X,Y;

	scanf("%d %d %d %d",&H,&W,&X,&Y);

	if((H*W)%2 == 1 && (X+Y)%2 == 1){

		printf("No\n");

	}else{

		printf("Yes\n");
	}

	return 0;
}



Measured memory_bytes: 3140
using System;

class Program
{
    static void Main()
    {
        string w = Console.ReadLine();
        int cnt = 0;
        while (true)
        {
            string t = Console.ReadLine();
            if (t == "END_OF_TEXT")
                break;
            t = t.ToLower();
            string[] word = t.Split(' ');
            for(int i = 0;i < word.Length; i++)
            {
                if (word[i] == w)
                    cnt++;
            }
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 9008