akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<bool> prime_p(N + 5, true);
  prime_p[0] = prime_p[1] = false;
  for (int i = 2; i * i <= N; ++i) {
    if (not prime_p[i]) { continue; }
    for (int j = i * i; j <= N; j += i) {
      prime_p[j] = false;
    }
  }

  vector<int> occs(N + 5, 0);
  for (int i = 2; i <= N; ++i) {
    for (int p = 2; p <= N; ++p) {
      if (not prime_p[p]) { continue; }
      if (i % p != 0) { continue; }
      int cnt = 0, val = i;
      while (val % p == 0) {
        ++cnt;
        val /= p;
      }
      occs[p] += cnt;
    }
  }
  ll ans = 1;
  for (int i = 2; i <= N; ++i) {
    if (not prime_p[i]) { continue; }
    if (occs[i] > 0) {
      ans = (ans * (1 + occs[i])) % MOD;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
L,R = map(int,input().split())
ans = 0

if R-L < 2018:
  nums = list(range(L,R+1))
  A = []
  for i in range(len(nums)):
    for j in range(i+1,len(nums)):
      A.append((nums[i]*nums[j])%2019)
  ans = min(A)

print(ans)

Measured memory_bytes: 81192
#include <iostream>
#include <stdio.h>       // printf,scanf
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>  //sort,binarySearch
#include <functional> 
#include <iomanip>    // setprecision
#include <utility>    // c+11 Array
#include <set>
#include <sstream>
#include <map>
#include <bits/stdc++.h>
#define MOD 1000000007
#define PI 3.141592653589793238462643383279
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define pb(x) push_back(x)
#define debug(x) cout << #x << " = " << x << endl;
#define debret(x) debug(x) ; return 0;

using namespace std;

int main(){

    int H,W;
    cin >> H >> W;

    string str;
    vector <string> vec;
    REP(i,H){
        cin >> str;
        vec.pb(str);
    }
    REP(i,H){
        cout << vec[i] << endl;
        cout << vec[i] << endl;
    }
 
    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

    static int n;
    static String[] S = new String[]{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};
    static StringBuilder sb;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        String s = "";
        sb = new StringBuilder();
        dfs(s, 1, 0);
        System.out.println(sb.toString());
        sc.close();

    }

    private static void dfs(String s, int i, int max) {
        for (int j = 0; j <  i; j++) {
            if(max < j) break;
            String a = s + S[j];
            if(i == n) System.out.println(a);
            else dfs(a, i+1, Math.max(j+1, max));
        }
    }

}


Measured memory_bytes: 40100
#!/usr/bin/env python3
x,y = map(int,input().split())
ans = 2*10**9+1
if y-x >= 0:
    ans = min(ans,y-x)
if x-y >= 0:
    ans = min(ans,x-y+2)
if y+x >= 0:
    ans = min(ans,y+x+1)
if -x-y >= 0:
    ans = min(ans,-y-x+1)
print(ans)

Measured memory_bytes: 38256
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define pb push_back
#define MP std::make_pair
#define PII std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define CL(a, b) memset(a, b, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++ i)
#define per(i, r, l) for (int i = (r); i >= (l); -- i)
#define PE(x, a) for (int x = head[a]; x;x = edge[x].next)

typedef long long ll;

int main() {

	ll a, b, c;
	scanf("%lld %lld %lld", &a, &b, &c);
	if (a + b + c >= 22) puts("bust");
	else puts("win");
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        Console.WriteLine(string.Join(" ", Read().ToList()));
    }

    private static IEnumerable<string> Read()
    {
        return Console.ReadLine().Replace(".", " ").Replace(",", " ").Split().Where(x => 6 >= x.Length && x.Length >= 3);
    }
}



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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

#define REPISE (s,e) for(int i=s,i<e;i++)
#define REPJSE (s,e) for(int j=s,j<e;j++)

typedef long long ll;

using namespace std;

int main ()
{
  int N,cnt=1;

  cin >> N;

  while (N >= pow(2,cnt))
  {
    cnt++;
  }

  cout << pow(2,cnt-1) << endl;
  return 0;
}

Measured memory_bytes: 4264
import math

a = [0] * 5
a[0] = int(input())
a[1] = int(input())
a[2] = int(input())
a[3] = int(input())
a[4] = int(input())

b = [0] * 5
c = [0] * 5

for i in range(5):
    b[i] = math.ceil(a[i] / 10) * 10

for i in range(5):
    c[i] = sum(b) - b[i] + a[i]
print(min(c))


Measured memory_bytes: 3064
// AOJ Volume 1 Problem 0118

#include <stdio.h>
#include <string.h>

int main(void)
{
    int h, w;
    char in[102];
    int map[102][102];
    int x, y;
    int n;
    int kind;
    int flag;
    
    while (1){
        scanf("%d%d", &h, &w);
        if (h == 0 && w == 0){
            break;
        }
        
        memset(map, 0, sizeof(map));

        for (y = 1; y <= h; y++){
            scanf("%s", in);
            for (x = 1; x <= w; x++){
                switch (in[x - 1]){
                  case '@':
                    map[y][x] = -1;
                    break;

                  case '#':
                    map[y][x] = -2;
                    break;

                  case '*':
                    map[y][x] = -3;
                    break;
                }
            }
        }

        n = 1;
        
        while (1){
            for (y = 1; y <= h; y++){
                for (x = 1; x <= w; x++){
                    if (map[y][x] < 0){
                        kind = map[y][x];
                        map[y][x] = n;
                        goto label1;
                    }
                }
            }
            
            break;
label1:;
            do {
                flag = 0;
                for (y = 1; y <= h; y++){
                    for (x = 1; x <= w; x++){
                        if (map[y][x] == kind &&
                            ((map[y - 1][x    ] == n) || 
                             (map[y + 1][x    ] == n) || 
                             (map[y    ][x - 1] == n) || 
                             (map[y    ][x + 1] == n))){
                            
                            map[y][x] = n;
                            flag = 1;
                        }
                    }
                }
            } while (flag == 1);
            
            n++;
        }
        printf("%d\n", n - 1);
    }
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 200010;
const int maxM = 100010;
const int N = 5000; 
const int MOD = 1000000007;

ll a[maxN];
ll b[maxN];
ll c[maxN];
int n;
int main()
{
	scanf("%d",&n);
	int flag = 1;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		b[i] = a[i] - i;
		if(b[i] > b[i-1])
		{
			flag = 0; 
			break;
		}
	}
	if(a[1] != 0)
	{
		flag = 0;
	}
	if(flag == 0)
	{
		printf("-1");
		return 0;
	}
	int x = b[1];
	c[-x] = 1;
	for(int i=2;i<=n;i++)
	{
		if(b[i] == x)
		{
			c[-x] = i;
		}
		else
		{
			x = b[i];
			c[-x] = i;
		}
	}
	ll ans = 0;
	for(int i=1;i<=n;i++)
	{
		int y = i;
		if(c[y] == 0) continue;
		ans += ll(c[y]- i);
	}

	printf("%lld\n",ans);
	return 0;
}  

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

#define MAX_V 100

struct edge {
	edge(int a, int b) {
		cost = a;
		to = b;
	}
	int cost;
	int to;
};

int n;
vector<vector<edge>> G;
vector<int> d;

void dijkstra(int s) {
	priority_queue<pii, vector<pii>, greater<pii>> que;
	d[s] = 0;
	que.push(pii(0, s));

	while (!que.empty()) {
		pii p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(pii(d[e.to], e.to));
			}
		}
	}

}

int main() {
	int n,u,k,tmpp,tmpw;
	cin >> n;
	d = vector<int>(n, INF);
	G = vector<vector<edge>>(n);
	rep (i,n) {
		cin >> u >> k;
		rep(j, k) {
			cin >> tmpp>>tmpw;
			G[u].emplace_back(tmpw, tmpp);
		}
	}
	dijkstra(0);
	rep(i, n) {
		cout << i << " " << d[i] << endl;
	}
}



Measured memory_bytes: 7780
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
int max(int a, int b) {
	if (a < b)return b;
	return a;
}
int min(int b, int a) {
	if (a > b)return b;
	return a;
}

int main() {
	int n,k;
	cin >> n >> k;
	map<int, int> S;
	rep(i, 0, k) {
		int z;
		cin >> z;
		S[z] = 1;
	}
	for (int i = n;; i++) {
		string z = to_string(i);
		bool s = true;
		rep(j, 0, z.size()) {
			if (S[z[j] - '0'])s = false;
		}
		if (s) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
    if(ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[1]){
    long long sum = 0, p = 1, i;
    for(i=0; i<strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1 + (key % (M-1));}

int find(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i=0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i=0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for(i=0; i<M; i++) H[i][0] = '\0';
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%s %s", com, str);
        
        if(com[0] == 'i'){
            insert(str);
        } else {
            if(find(str)){
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 17468
import java.util.Scanner;

public class Main{
	
	

	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int N,K;
	N=sc.nextInt();
	K=sc.nextInt();
	String S=sc.next();
	if(S.substring(K-1,K).equals("A")) {
		String str1=S.substring(0,K-1);
		String str2=S.substring(K);
		S=str1+"a"+str2;
		
	}else if(S.substring(K-1,K).equals("B")) {
		String str1=S.substring(0,K-1);
		String str2=S.substring(K);
		S=str1+"b"+str2;
		
	}else if(S.substring(K-1,K).equals("C")) {
		String str1=S.substring(0,K-1);
		String str2=S.substring(K);
		S=str1+"c"+str2;
		
	}
	
	System.out.println(S);
	
		
	}
	

	
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define anuj ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define ll long long int
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%I64d",&x)
#define ss(s)	scanf("%s",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl '\n'
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;
const int N = 2e5;
const int LG = 20;
ll a[N],dp[N];

int main(){
	anuj;

	int n;
	cin >> n;

	Fo(i,1,n+1) cin >> a[i];
	dp[1]=0;dp[2]=abs(a[2]-a[1]);

	Fo(i,3,n+1) dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));

	cout << dp[n];



}


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

int main() {

  int N;
  cin >> N;

  string c;
  bool P = false;
  bool W = false;
  bool G = false;
  bool Y = false;
  int num = 0;

  for (int i; i < N; i ++){
    cin >> c;
    if (c == "P"){
      P = true;
    }
    if (c == "W"){
      W = true;
    }
    if (c == "G"){
      G = true;
    }  
    if (c == "Y"){
      Y = true;
    }
  }

  if (P == true){
    num ++;
  }
  if (W == true){
    num ++;
  }
  if (G == true){
    num ++;
  }
  if (Y == true){
   num ++;
  }

  if (num == 3){
    cout << "Three" <<endl;
  }


  if (num == 4){
    cout << "Four" <<endl;
}
  
}

Measured memory_bytes: 256
#[allow(dead_code)]

pub struct Scanner {
    idx: usize, 
    buf: Vec<String>,
}

impl Scanner {
    pub fn new<T: std::io::Read>(inf: &mut T) -> Scanner {
        Self {
            idx:0,
            buf: {
                let mut s = String::new();
                inf.read_to_string(&mut s).expect("I/O error");
                s.split_whitespace().map(|x| x.to_owned()).collect()
            },
        }
    }

    pub fn read<T: std::str::FromStr> (&mut self) -> T 
    where
        <T as std::str::FromStr>::Err: std::fmt::Debug,
    {
        if self.empty() {
            panic!("reached the end of input")
        }
        let ret = self.buf[self.idx].parse::<T>().expect("parse error");
        self.idx += 1;
        return ret;
    }

    pub fn empty(&self) -> bool {
        return self.idx >= self.buf.len();
    }
}

fn main() {
    let mut sc = Scanner::new(&mut std::io::stdin());
    let n: usize = sc.read();
    let m: usize = sc.read();
    let a: Vec<Vec<char>> = (0..n).map(|_| sc.read::<String>().chars().collect()).collect();
    let b: Vec<Vec<char>> = (0..m).map(|_| sc.read::<String>().chars().collect()).collect();

    let mut ans = false;

    for i in 0..n {
        for j in 0..n {
            let mut cnt = 0;
            for ii in 0..m {
                for jj in 0..m {
                    if i + ii >= n || j + jj >= n {
                        continue;
                    }
                    if a[i + ii][j + jj] == b[ii][jj] {
                        cnt += 1;
                    }
                }
            }
            if cnt >= m * m {
                ans = true;
            }
        }
    }


    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 2116
import java.util.Scanner;

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

		if(a<=8 && b<=8) {
			System.out.println("Yay!");
		}
		else {
			System.out.println(":(");
		}
	}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"

using namespace std;

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

using ll = long long;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int main() {

  int cnt0z = 0;
  int cntHz = 0;
  int n, k; cin >> n >> k;
  for(int i = 1; i <= n; i++){

    if(i%k == 0)cnt0z++;
    if(i%k == k/2 && k%2==0)cntHz++;

  }


  cout << cnt0z * 1ll * cnt0z * 1ll * cnt0z + cntHz * 1ll * cntHz * 1ll * cntHz << '\n';




  return 0;
}


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

int a[5];
int main(void){
    rep(i, 5) cin >> a[i];
    sort(a, a+5, greater<int>());
    rep(i, 4) cout << a[i] << " ";
    cout << a[4] << endl;
}

Measured memory_bytes: 1176
#include <iostream>

using namespace std;
const int MAXN = 100010;

int n;
int p[MAXN];

void solve() {
  int cnt = 0;
  for (int i=0;i<n;i++) {
    if (i == p[i] - 1) {
      swap(p[i], p[i+1]);
      cnt++;
    }
  }
  cout << cnt << endl;
}

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


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

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  if (x % y == 0) {
    return y;
  } else {
    return gcd(y, x % y);
  }
}

vector<int> divisor(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    reverse(ret.begin(), ret.end());
    return ret;
}

int main()
{
  int a, b, k;
  cin >> a >> b >> k;

  int n = gcd(a, b);

  cout << divisor(n)[k-1] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}

vec<ll> g[100100];
ll depth[100100];
ll par[100100][20];

void dfs(ll v,ll p,ll d){
    par[v][0]=p;
    depth[v]=d;
    rep(i,g[v].size()){
        if(g[v][i]!=p) dfs(g[v][i],v,d+1);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    if(n%2!=0){
        cout<<0<<endl;
        return 0;
    }
    ll sum=0;
    ll b=10;
    while(b<=n){
        sum+=(n/b);
        b*=5;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 2688
import collections
N=int(input())
a=[-1]*(N+1)
checker = collections.defaultdict(int)
for i in range(1,N+1):
  a[i]=int(input())
pos = 1
checker[1] = 1
for _ in range(N):
  if pos == 2:
    print(len(checker.values()) - 1)
    exit(0)
  pos = a[pos]
  if pos not in checker:
    checker[pos] = 1
  else:
    break
  

print(- 1)


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

int main() {
    int N, K, X, Y;
    int sum;

    cin >> N >> K >> X >> Y;

    for (int i = 0; i < N; i++){
        if(i < K){
            sum += X;
        } else {
            sum += Y;
        }
    }

    cout << sum << endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 10010
using namespace std;
char s[maxn][20];
int len[maxn], id[4][maxn], cnt[4];
int main()
{
	int n, res = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%s", s[i] + 1);
		len[i] = strlen(s[i] + 1);
		if (s[i][1] == 'B' && s[i][len[i]] == 'A') id[2][++cnt[2]] = i;
		else if (s[i][1] == 'B') id[1][++cnt[1]] = i;
		else if (s[i][len[i]] == 'A') id[0][++cnt[0]] = i;
		else id[3][++cnt[3]] = i;
		for (int j = 1; j <= len[i] - 1; j++)
			if (s[i][j] == 'A' && s[i][j + 1] == 'B') res++;
	}
	if (cnt[0] == 0 && cnt[2]) {cnt[0] = 1; cnt[2]--;}
	res += cnt[2] + min(cnt[1], 1 + cnt[0] - 1);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

const int kMaxN = 100000;

int n;
int a[kMaxN];
int ans = 0;

int main() {
  cin >> n;
  REP(i, n) { cin >> a[i]; }

  sort(a, a+n);
  int i = 0;
  while (i < n) {
    int ai = a[i];
    int ai_cnt = 0;
    for (int j = 0; a[i+j] == ai && i+j < n; ++j) { ++ai_cnt; }
    if (ai_cnt < ai) {
      ans += ai_cnt;
    } else if (ai_cnt == ai) {
      ;
    } else {
      ans += ai_cnt - ai;
    }
    i += ai_cnt;
  }

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
int gcd(int x,int y){
    int a=x,b=y,c=x%y;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}
vector<char>s;
vector<char>t;
string a,b;
bool ans=true;
signed main(){
    cin>>a>>b;
    int l=a.size();
    int m=b.size();
    rep(i,l)s.push_back(a[i]);
    rep(i,m)t.push_back(b[i]);
    sort(s);
    sort(t);
    reverse(t);
    int x=min(l,m);
    rep(i,x){
        if(s[i]>t[i])ans=false;
        else if(s[i]<t[i])break;
        if(i==x-1){
            if(l>=m)ans=false;
        }
    }
    if(ans==true)puts("Yes");
    else puts("No");
    return 0;
}   

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
   int n,m;
   cin >> n >> m;
   vector<int>p(m);
   vector<int>y(m);
   vector<vector<int>>v(n);
   for(int i=0;i<m;i++){
       cin >> p[i] >> y[i];
       p[i]--;
   }
   for(int i=0;i<m;i++){
       v[p[i]].push_back(y[i]);
   }
   for(int i=0;i<n;i++){
       sort(v[i].begin(),v[i].end());
   }
   for(int i=0;i<m;i++){
       printf("%06d",p[i]+1);
       int id=lower_bound(v[p[i]].begin(),v[p[i]].end(),y[i])-v[p[i]].begin();
       printf("%06d\n",id+1);
   }
}

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


Measured memory_bytes: 7808
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [usize1; n]
    }
    let mut q = vec![0; n];
    for i in 0..n {
        q[v[i]] = i;
    }
    for i in 0..n - 1 {
        print!("{} ", n * (i + 1) + q[i]);
    }
    println!("{}", n * n + q[n - 1]);
    for i in (1..n).rev() {
        print!("{} ", n * (i + 1));
    }
    println!("{}", n);
}


Measured memory_bytes: 4732
/**
 *    author:  tourist
 *    created: 29.12.2019 22:19:18       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  int k = 1;
  int s = 0;
  while (true) {
    s += k++;
    if (s >= x && s % 1 == x % 1) break;
  }
  cout << k - 1 << '\n';
  return 0;
}


Measured memory_bytes: 256
n, W = gets.chomp.split.map(&:to_i)
 
dp = Array.new(W+1,0)
 
n.times do |i|
  w, v = gets.chomp.split.map(&:to_i)
  W.downto(0).each do |weight|
    if w <= weight
      dp[weight] = dp[weight-w] + v if dp[weight] < dp[weight-w] + v
    end
  end
end
 
# dp.each{|line| p line}
# p dp
puts dp[W]

Measured memory_bytes: 15032
import numpy as np
A,B = map(int,input().split())
w = "."
b = "#"
if A<B:
    w,b = b,w
    A,B = B,A
Q1 = np.array([[b,b,b,b],[b,b,b,b],[b,b,b,b],[b,b,b,b]],dtype=np.unicode)
Q2 = np.array([[w,w,w,b],[w,w,w,b],[w,w,w,b],[b,b,b,b]],dtype=np.unicode)
Q3 = np.array([[w,w,w,b],[w,b,w,b],[w,w,w,b],[b,b,b,b]],dtype=np.unicode)
Grid = [[Q1]*25 for _ in range(20)]
B -= 1
for i in range(20):
    for j in range(25):
        if A:
            Grid[i][j] = Q2
            A -= 1
            if B:
                Grid[i][j] = Q3
                B -= 1
for i in range(20):
    if i == 0:
        AC = Grid[0][0]
    else:
        AC_ = Grid[i][0]
    for j in range(1,25):
        if i == 0:
            AC = np.hstack([AC,Grid[0][j]])
            continue
        AC_ = np.hstack([AC_,Grid[i][j]])
    if i != 0:
        AC = np.vstack([AC,AC_])
print(80,100)
for i in range(80):
    print(*AC[i],sep="")


Measured memory_bytes: 13820
/*
操作： 1≤i≤N−1 を満たす整数 i を選ぶ。Ai と Ai+1 に −1 を乗算する。

操作終了後の整数列を B1,B2,...,BN とします。
B1+B2+...+BN
 の最大値を求めてください。
*/
#include <iostream>
#include <vector>
using namespace std;

int main(){
    long n,minus_cnt=0,min,min_num,sum=0;
    vector<long> x;
    cin>>n;
    for(int i=0;i<n;i++){
        long buf;
        cin>>buf;
        if(buf<0) minus_cnt++;
        if(i==0||min>abs(buf)){
            min=abs(buf);
            min_num=i;
        }
        x.push_back(buf);
    }
    //cout<<min<<":"<<min_num<<endl;
    if(minus_cnt%2==0){
        for(int i=0;i<n;i++){
            sum+=abs(x.at(i));
        }
    }else{
        for(int i=0;i<n;i++){
            if(min_num==i){
                sum-=abs(x.at(i));
            }else{
                sum+=abs(x.at(i));
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1400
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using PLL = pair<LL,LL>;
using VPI = vector<PII>;
using VPL = vector<PLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i,m,n) for(LL i=(m);i<(n);i++)
	//i=m -> n-1(昇順)
#define RREP(i,m,n) for(int i=(m);i>=(n);i--)
	//i=m -> n(降順)

int main(){
  const LL up_to = 300010;
  LL n,x,m;
  cin >> n >> x >> m;
  VLL checked(m,0),a(min(n+1,up_to),-1);
  a[1] = x;
  checked[x]++;
  bool start = false;
  LL span = 0, sum_span=0, sum=x, mark;
  
  REP(i,2,n+1){
    a[i] = (a[i-1]*a[i-1]) % m;
    checked[a[i]]++;
    sum += a[i];
    if(checked[a[i]] == 2){
      start = true;
    }
    if(checked[a[i]] == 3){
      mark = i-1;
      sum -= a[i];
      break;
    }
    if(start){
      span++;
      sum_span += a[i];
    }
  }
  
  if(a[a.size()-1] >= 0){
    cout << sum << endl;
    return 0;
  }
  
  sum += ((n-mark)/span)*sum_span;
  LL rest = (n-mark) % span;
  LL cnt = mark - (2*span) + 1;
  REP(i,0,rest){
    sum += a[cnt+i];
  }
  cout << sum << endl;

  
  return 0;
}


Measured memory_bytes: 6344
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1e18;

int main(){
  int N;
  cin >> N;
  vector<long long> A(N+1);
  A[0] = 0;
  for(int i = 0; i < N; ++i) cin >> A[i+1];
  for(int i = 0; i < N; ++i) A[i+1] += A[i];
  vector< vector<long long> > dp(N+1,vector<long long>(N+1,INF));
  for(int i = 0; i <= N; ++i) dp[i][i] = 0;
  for(int i = 1; i <= N; ++i){
    for(int j = 0; j < N-i; ++j){
      for(int k = j; k < j+i; ++k){
        if(dp[j][k] == INF or dp[k+1][j+i] == INF) continue;
        dp[j][j+i] = min(dp[j][j+i],dp[j][k]+dp[k+1][j+i]+A[j+i+1]-A[j]);
      }
    }
  }
  cout << dp[0][N-1] << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF(pow(10,10));

int main(){
	int N,K;
	cin >> N >> K;
	vector<ll> h(N);
	for(int i(0);i<N;++i) cin >> h[i];
	sort(h.begin(),h.end());
	int min(INF),diff;
	for(int i(0);i<N-K+1;++i){
		diff = h[i+K-1] - h[i];
		if(diff < min) min = diff;
	}
	cout << min << endl;
	return 0;
}

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

int main(){
    string a,b;
    cin >> a >> b;
    if(a.size() > b.size()) cout << "GREATER" << endl;
    else if(a.size() < b.size()) cout << "LESS" << endl;
    else{
        bool eq = true;
        rep(i,a.size()){
            char x = a.at(i), y = b.at(i);
            if(x > y){
                cout << "GREATER" << endl;
                eq = false;
                break;
            }else if(x < y){
                cout << "LESS" << endl;
                eq = false;
                break;
            }
        }
        if(eq) cout << "EQUAL" << endl;
    }
}   

Measured memory_bytes: 256
use std::cmp;

const L: usize = 16;
const MAX_A: u64 = 1 << 32;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let mut a: Vec<usize> = sc.vec(n);

    let dp1 = solve(&a);
    a.reverse();
    let dp2 = solve(&a);

    let mut cost = 1 << 50;
    for prefix in 0..(n + 1) {
        let prefix_cost = if prefix > 0 {
            dp1[prefix - 1][0] * 2 + prefix
        } else {
            0
        };
        let suffix_cost = if prefix < n {
            dp2[n - 1 - prefix][0] * 2
        } else {
            0
        };
        cost = cmp::min(prefix_cost + suffix_cost, cost);
    }

    println!("{}", cost);
}

fn solve(a: &Vec<usize>) -> Vec<Vec<usize>> {
    let n = a.len();
    let mut dp = vec![vec![0; L]; n];
    for i in 0..L {
        dp[0][i] = i;
    }
    for i in 1..n {
        let mut cur = 1;
        let mut prev_l = 0;
        let mut prev_a = a[i - 1];
        for l in 0..L {
            let cur_a = cur * a[i];
            while prev_a < cur_a {
                prev_a *= 4;
                prev_l += 1;
            }
            if prev_l >= L {
                dp[i][l] = dp[i - 1][L - 1] + i * (prev_l - (L - 1)) + l;
            } else {
                dp[i][l] = dp[i - 1][prev_l] + l;
            }
            cur *= 4;
        }
    }
    dp
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 67836
<?php
fscanf(STDIN, "%d",$N);
$aArray = explode(" ", trim(fgets(STDIN)));
$sum = array_sum($aArray);
$min = 10**18;
$b = 0;
array_pop($aArray);
foreach($aArray as $a){
    $b = $b + $a;
    $min = min($min, abs($sum - $b*2));
}
echo $min;


Measured memory_bytes: 20980
N, M = map(int, input().split())
d = dict()
A = list(map(int, input().split()))
for i in range(N):
	d[A[i]] = d.get(A[i], 0) + 1
for i in range(M):
	B, C = map(int, input().split())
	d[C] = d.get(C, 0) + B

ans = 0
keys = sorted(list(d.keys()), reverse = True)
for k in keys:
	kosuu = min(N, d.get(k))
	ans += k * kosuu
	N -= kosuu
	if N == 0:
		break
print(ans)

Measured memory_bytes: 108660
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n, m;
	cin >> n;
	set<string> ss;
	REP(i,n){
		string s;
		cin >> s;
		ss.insert(s);
	}
	cin >> m;
	bool open = false;
	REP(i, m){
		string s;
		cin >> s;
		if (ss.find(s) == ss.end()){
			cout << "Unknown " << s << endl;
		}
		else{
			if (open){
				cout << "Closed by " << s << endl;
			}
			else{
				cout << "Opened by " << s << endl;
			}
			open ^= true;
		}
	}
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef bitset<35> sta;
int n,a[200005],Next[200005],t[200005];
ll k,p;
bool v[200005];
int getNext(int now){
	p++;
	if (Next[now]<=now){
		p+=Next[now]+n-now;
	}else p+=Next[now]-now;
	now=Next[now];
	if (now==n) now=1;
	else now=now+1;
	return now;
}
int main(){
	cin>>n>>k;
	for (int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	for (int i=n;i>=1;--i){
		if (t[a[i]]) Next[i]=t[a[i]];
		t[a[i]]=i;
	}
	memset(t,0,sizeof t);
	for (int i=1;i<=n;++i){
		if (t[a[i]]==0) t[a[i]]=i;
		if (Next[i]==0){
			Next[i]=t[a[i]];
		}
	}
	int now=1;
	while (1){
		if (v[now]){
			k=((k)%p)*(n%p)%p;
			if (k==0) return 0;
			k--; p=0;
			while (1){
				int tt=getNext(now);
				if (p>=k){
					break;
				}
				now=tt;
			}
			break;
		}
		v[now]=1;
		int tt=getNext(now);
		now=tt;
	}
	memset(t,0,sizeof t);
	deque <int> q;
	for (int i=now;i<=n;++i){
		if (t[a[i]]!=0){
			int z;
			do{
				z=q.back(); q.pop_back();
				t[z]=0;
			}while (z!=a[i]);
		}else q.push_back(a[i]),t[a[i]]=1;
	}
	while (!q.empty()){
		cout<<q.front()<<" "; q.pop_front();
	}
	return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

const int N = 20005;

struct djs {
  vector<int> a;
  djs(int n) {
    a.resize(n + 1);
    for (int i = 1; i <= n; i++) {
      a[i] = i;
    }
  }
  int root(int i) {
    if (i == a[i]) return i;
    else return a[i] = root(a[i]);
  }
  void join(int u, int v) {
    a[root(u)] = root(v);
  }
};

void solve() {
  int n, k, l;
  cin >> n >> k >> l;
  djs rd(n), rw(n);
  for (int i = 1; i <= k; i++) {
    int u, v;
    cin >> u >> v;
    rd.join(u, v);
  }
  for (int i = 1; i <= l; i++) {
    int u, v;
    cin >> u >> v;
    rw.join(u, v);
  }
  map<int, map<int, int>> cnt;
  for (int i = 1; i <= n; i++) {
    cnt[rd.root(i)][rw.root(i)]++;
  }
  for (int i = 1; i <= n; i++) {
    cout << cnt[rd.root(i)][rw.root(i)] << ' ';
  }
  cout << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 34800
#include <iostream>
#include <utility>
#include <cmath>

using namespace std;

int main(void){
	int N;
	cin >> N;

	for(int i=0;i<N;i++){
		pair<double,double> p[2];
		double d,r[2];

		for(int j=0;j<2;j++){
			float x,y;
			cin >> x >> y >> r[j];
			p[j]=make_pair(x,y);
		}
		d=sqrt(pow(p[0].first-p[1].first,2)+pow(p[0].second-p[1].second,2));

		cout << (d<=r[0]+r[1]?d+r[1]>=r[0]?d+r[0]>=r[1]?1:-2:2:0) << endl;
	}

	return 0;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 1e9 + 1
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

#define MAX_N 100
#define MAX_M 100

int main(){
    int s, w;
    cin >> s >> w;
    if(s <= w) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

	int ans;

	if (n % 2 != 0) {
		ans = (n / 2) * ((n / 2) + 1);
	}
	else {
		ans = (n / 2) * (n / 2);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define FOR(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

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

	int n;
	cin >> n;

	vi L(n * 2);

	REP(i, n * 2) cin >> L[i];
	SORT(L);

	int cnt = 0;
	REP(i, n * 2) {
		if (L[i] == L[i + 1]) {
			cnt += L[i];
		} else {
			cnt += L[i + 1] - abs(L[i + 1] - L[i]);
		}
		i++;
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
#define db double
const int N = 1e2+10;
int a[N];
signed main(){
    int n;
    cin>>n;
    int res=0;
    for(int i=1;i<=n;i++){cin>>a[i];if(i%2!=0&&a[i]%2!=0)res++;}
    cout<<res;
    return 0;
}

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

int main() {
    
    int A,B,C;
    cin >> A >> B >> C;
    
    if (A == B && A == C && B == C) {
        cout << "No" << endl;
    }
        
    else if (A != B && A != C && B != C) {
        cout << "No" << endl;
    }
    
    else {
        cout << "Yes" << endl;
    }
    
}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())

mod = 10**9 + 7


def main():

    H, W = in_nn()
    grid = in_map2(H)

    dp = [[0 for _ in range(W)] for _ in range(H)]
    dp[0][0] = 1

    for y in range(H):
        for x in range(W):
            if x + 1 < W and grid[y][x + 1]:
                dp[y][x + 1] += dp[y][x]
                dp[y][x + 1] %= mod
            if y + 1 < H and grid[y + 1][x]:
                dp[y + 1][x] += dp[y][x]
                dp[y + 1][x] %= mod

    print(dp[H - 1][W - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 85816
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 200005
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;

vector<int>v[N];
int vis[N];
int d;
void dfs(int s)
{
    vis[s] = 1;
    d++;
    for(int i=0; i<v[s].size();i++){
        if(!vis[v[s][i]])dfs(v[s][i]);
    }
}
int main()
{


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

   int n, m, x, y;
   cin>>n>>m;
   for(int i=0; i<m; i++){
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
   }
   int ans = 0;
   for(int i=1; i<=n; i++){
    if(!vis[i]){
        d=0;
        dfs(i);
        ans = max(ans,d);
    }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 21600
graph = [[1,2],[0],[0,3,4],[2,4,5],[2,3,6],[3],[4]]

sakigake = []
nakagake = []
atogake = []




def main():
    n = int(input())
    tree = [[] for i in range(n)]
    check = [False]*n
    for i in range(n):
        a,b,c = list(map(int,input().split()))
        if b != -1:tree[a].append(b)
        else:tree[a].append(-1)
        if c != -1:tree[a].append(c)
        else:tree[a].append(-1)
        check[b] = True;check[c] = True
    indes = 0
    for i in range(n):
        if check[i] == False:
            indes = i
            break
    dfs(indes,tree)
    print("Preorder",end = "\n")
    for i in sakigake:
        print("",i,end = "")
    print("\nInorder",end = "\n")
    for i in nakagake:
        print("",i,end = "")
    print("\nPostorder",end = "\n")
    for i in atogake:
        print("",i,end = "")
    print()
def dfs(v,tree):
    #print(tree)
    sakigake.append(v)
    if tree[v][0] != -1:dfs(tree[v][0],tree)
    nakagake.append(v)
    if tree[v][1] != -1:dfs(tree[v][1],tree)
    atogake.append(v)

if __name__ == "__main__":
    main()


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

using namespace std;

struct Cake {
	int w;
	int d;
	int s;
	void menseki( void ) { s = w * d; }
};

bool operator<( const Cake &a, const Cake &b )
{
	return ((a.s) < (b.s));
}

int main( void )
{
	int n, w, d;
	Cake cakes[101];
	while(cin >> n >> w >> d, n | w | d)
	{
		cakes[0].w = w;	cakes[0].d = d; cakes[0].menseki();
		for(int i=0; i < n; ++i) {
			Cake cut1, cut2;
			int p, s;
			cin >> p >> s;
			--p;
			s = s % (cakes[p].w + cakes[p].d);
			if(s > cakes[p].w) {
				cut1.w = cut2.w = cakes[p].w;
				cut1.d = s - cakes[p].w;
				cut2.d = cakes[p].d - cut1.d;
			}
			else {
				cut1.d = cut2.d = cakes[p].d;
				cut1.w = s;
				cut2.w = cakes[p].w - cut1.w;
			}
			for(int j=p; j < i; ++j)
				cakes[j] = cakes[j+1];
			cut1.menseki(); cut2.menseki();
			if(cut1 < cut2) {
				cakes[i] = cut1;
				cakes[i+1] = cut2;
			}
			else {
				cakes[i] = cut2;
				cakes[i+1] = cut1;
			}
		}
		sort(cakes, cakes+n+1);
		for(int i=0; i <= n; ++i) {
			cout << cakes[i].w * cakes[i].d;
			if(i != n) cout << ' ';
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(1000001)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
g = []
for i in range(n+1): g.append([])

for i in range(n-1):
    a, b, c = na()
    g[a].append((b,c))
    g[b].append((a,c))

q,k = na()

def dfs(cur, pre, g, par, dw, w):
    dw[cur] = w
    par[cur] = pre
    for e in g[cur]:
        if e[0] != pre:
            dfs(e[0], cur, g, par, dw, w + e[1])

par = [-1] * (n+2)
dw = [-1] * (n+2)
dfs(k, -1, g, par, dw, 0)

for z in range(q):
    x, y = na()
    print(dw[x] + dw[y])



Measured memory_bytes: 142156