akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#define N 1005
using namespace std;

int n;
char ans[N][N];
string a[9][9];

void g(int p, int q, int r) {
	int i, j;
	for (i = 0; i < r; i++) {
		for (j = 0; j < r; j++) {
			ans[i + p][j + q] = a[r][i][j];
		}
	}
}

void f(int p) {
	if (p <= 7) {
		g(1, 1, p);
	} else {
		g(p - 3, p - 3, 4);
		f(p - 4);
	}
}

int main()
{
	int i, j;
	cin >> n;
	if (n == 2) {puts("-1"); return 0;}
	for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) ans[i][j] = '.';
    a[3][0] = "aa.";
    a[3][1] = "..b";
    a[3][2] = "..b";

    a[4][0] = "aabc";
    a[4][1] = "ddbc";
    a[4][2] = "efgg";
    a[4][3] = "efhh";

    a[5][0] = "ccdde";
    a[5][1] = "jaa.e";
    a[5][2] = "j..bf";
    a[5][3] = "i..bf";
    a[5][4] = "ihhgg";

    a[6][0] = "aabc..";
    a[6][1] = "ddbc..";
    a[6][2] = "..eefg";
    a[6][3] = "..hhfg";
    a[6][4] = "hi..jj";
    a[6][5] = "hi..kk";

    a[7][0] = "ccddee.";
    a[7][1] = "aa.aa.f";
    a[7][2] = "..b..bf";
    a[7][3] = "..b..bg";
    a[7][4] = "aa.aa.g";
    a[7][5] = "..b..bh";
    a[7][6] = "..b..bh";

	f(n);
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			printf("%c", ans[i][j]);
		}
		puts("");
	}
    return 0;
}

Measured memory_bytes: 2176
#!/usr/bin/node
// Generated by CoffeeScript 1.3.1 (minified manually)
(function() {
  var a=[],ma,mi,n=0,s,stdin;
  stdin=process.openStdin();
  stdin.setEncoding('utf8');

  stdin.on('data', function(input) {
    var i=0,len,ref,x=[];
    ref=input.split("\n");
    for(len=ref.length;i<len;i++){
      x.push(parseInt(ref[i]));
    }
    if(x.length>2||!isNaN(x[1]))a=x;
    else a.push(x[0]);
  });

  stdin.on('end', function(z) {
    var i,m;
    n=0;
    while(true){
      m=a[n];
      if(m==0)process.exit();
      s=0;ma=0;mi=1000;
      for(i=n+1;i<=n+m;i++){
        s=s+a[i];
        if(ma<a[i])ma=a[i];
        if(mi>a[i])mi=a[i];
      }
      console.log(Math.floor((s-ma-mi)/(m-2)));
      n=n+m+1;
    }
  });
}).call(this);

Measured memory_bytes: 7812
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define  pb push_back
#define  pob pop_back
#define mp make_pair
#define db long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define sz(x) (int)x.size()
#define endl '\n'
#define mod 1000000007
#define MAX 100005
using namespace std;

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

    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);

    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vll r(a),g(b),cl(c);
    rep(i,0,a) cin >> r[i];
    rep(i,0,b) cin >> g[i];
    rep(i,0,c) cin >> cl[i];
    vector<pair<ll,char>> ans;
    rep(i,0,c) ans.pb(mp(cl[i],'c'));
    rep(i,0,a) ans.pb(mp(r[i],'r'));
    rep(i,0,b) ans.pb(mp(g[i],'g'));
    sort(all(ans),greater<>());
    
    ll val = 0,cless = 0,red = 0,green = 0;
    rep(i,0,sz(ans)){
         if(ans[i].se == 'r'){
         	if(red == x) continue;
         	red++;
         	val += ans[i].fi;
         }
         else if(ans[i].se == 'g'){
         	if(green == y) continue;
         	green++;
         	val += ans[i].fi;
         }
         else{
         	cless++;
         	val += ans[i].fi;
         }
         if(cless+green+red == (x+y)) break;
    }
    cout << val;

    return 0;

}


Measured memory_bytes: 12908
n,m = map(int,input().split())
h = list(map(int,input().split()))
ok = [1] * n
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    if h[a] <= h[b]:
        ok[a] = 0
    if h[b] <= h[a]:
        ok[b] = 0

print(sum(ok)) 

Measured memory_bytes: 86520
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Text;
using System.Threading.Tasks;

namespace A_Beginner
{
    class Program
    {
        static void Main(string[] args)
        {
            string a =ReadLine();
            string[] b = a.Split(' ');
            int c = int.Parse(b[0]);
            int d = int.Parse(b[1]);
            if (c < 10)
            {
                WriteLine("{0}", 100 * (10 - c) + d);
            } else {
                WriteLine("{0}", d);
            }
            ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define stop exit(0)
#define dd double
#define po pop_back
#define pb push_back
#define ub upper_bound
#define lb lower_bound
int main(){
    vector <long long> v;
    ll a,b,c,d=0,e=0,f=0,g=0,i,j,k=1,l=1,r=1,n,m[300001],z[400001],h[600001],p[600001];
    string s,t,x[1001],y[1001];
    dd q,u,w;
    cin>>s;
    for(i=0;i<s.size();i++){
        if(s[i]=='7'){
            cout<<"Yes";
            stop;
        }
    }
    cout<<"No";
}

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

int main(){
  double l;
  cin >> l;
  printf("%.8lf\n", (l*l*l)/27);

  return 0;
}

Measured memory_bytes: 3744
fn read_usizepair() -> (usize, usize) {
    let mut input = String::new();
    let _ = std::io::stdin().read_line(&mut input);
    let v: Vec<usize> = input
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    (v[0], v[1])
}

fn main() {
    let (n, k) = read_usizepair();

    if k % 2 != 0 {
        println!("{}", ((n / k) as i64).pow(3))
    } else {
        println!("{}", ((n / k) as i64).pow(3) + (((n + k / 2) / k) as i64).pow(3));
    }
}

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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<long long> vll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

vector<pair<ll, ll>> ki(100001), gu(100001);
int main(){
    ll n;
    cin >> n;
    vll v(n);
    
    rep(i,n){
        cin >> v[i];
    }
    pair<ll, ll> karapair = make_pair(0,0);
    rep(i,n){
        if(i%2==0){
            if(gu[v[i]] != karapair){
                gu[v[i]].first++;
            }else{
                gu[v[i]] = make_pair(1, v[i]);
            }
        }else{
            if(ki[v[i]] != karapair){
                ki[v[i]].first++;
            }else{
                ki[v[i]] = make_pair(1, v[i]);
            }
        }
    }

    sort(all(gu));
    sort(all(ki));

    int flag=0;
    ll gunum, kinum;
    ll tmp;

    if(gu[100000].second!=ki[100000].second){
        tmp = n - gu[100000].first - ki[100000].first;
    }else{
        if(gu[100000].first + ki[99999].first > ki[100000].first + gu[99999].first){
            tmp = n - gu[100000].first - ki[99999].first;
        }else{
            tmp = n - ki[100000].first - gu[99999].first;
        }
    }
    cc(tmp);
}

Measured memory_bytes: 4096
from collections import defaultdict

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

for i in range(n):
    tmp = list(map(int, input().split()))
    tmp.pop(0)
    for j in tmp:
        dd[j]+=1

#print(dd)

a = [k for k in dd.values() if k == n]
#print(a)
print(len(a))

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

#define int long long

typedef long long li;
typedef long double ld;

void solve();
int32_t main() {
    #ifndef ONLINE_JUDGE
    //    freopen("input.txt", "r", stdin);
    #endif
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
const int N = 2e5;
int n;
int d[N];
void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> d[i];
	}
	sort(d + 1, d + n + 1);
	int lol1 = d[n / 2];
	int lol2 = d[(n / 2) + 1];
	cout << (lol2 - lol1) << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
	int N; 
	long long int T;
	
	cin >> N >> T;
	
	long long int ans = 0;
	
	long long int hoge;
	
	cin >> hoge;
	
	long long int pre = hoge;
	
	long long int start = pre;
	long long int final = pre + T;
	
	for(int i = 1; i < N; i++){
		long long int cur;
		cin >> cur;
		if(cur - pre < T){
			final = cur + T;
		}else{
			ans += final - start;
			start = cur;
			final = cur + T;
		}
		pre = cur;
	}
	
	ans += final - start;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {    
    
    static int MOD = (int) (Math.pow(10,9) + 7);
    
    public static void main(String[] args){

       Scanner sc = new Scanner(System.in);
       
       int N = sc.nextInt();
       int M = sc.nextInt();
       
       if(N > M + 1 || M > N + 1){
           System.out.println(0);
       }else if(N == M + 1 || M == N + 1){
           System.out.println(((Fact(M,MOD)%MOD)*(Fact(N,MOD)%MOD))%MOD);
       }else if(N == M){
           System.out.println((long)(2*(Fact(M,MOD)%MOD)*(Fact(N,MOD)%MOD)%MOD));
       }
              
    }  
    
    static long Fact(int n,int mod){
        long fact = 1;        
        for(int i = 1;i <= n;i++){
            fact *= i;
            fact %= MOD;
        }        
        return fact;
    }
    
}        
        
        
        
        

Measured memory_bytes: 24020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  int n=(int)s.size();
  long long dp[n+5][13]={}, mod=1e9+7;
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    if(s[i]=='?'){
      for(int j=0;j<=9;j++){
        for(int k=0;k<13;k++){
          dp[i+1][(k*10+j)%13] += dp[i][k];
          dp[i+1][(k*10+j)%13] %= mod;
        }
      }
    }else{
      int num=s[i]-'0';
      for(int k=0;k<13;k++){
        dp[i+1][(k*10+num)%13] += dp[i][k];
        dp[i+1][(k*10+num)%13] %= mod;
      }
    }
  }
  cout << dp[n][5] << endl;
  return 0;
}


Measured memory_bytes: 10624
var MAX = 100000;

var n = 0;
var q = 0;
var now = 0;
var queue = new Queue();
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
.map(function (value, index) {
  value = value.split(' ');
  if (index === 0) {
    n = parseInt(value[0]);
    q = parseInt(value[1]);
    return;
  } else {
    return new Process(value[0], value[1]);
  }
})
.filter(function (value) {
  return typeof value !== 'undefined';
})
.forEach(function (value) {
  queue.enqueue(value);
});


// Define
function Process(name, time) {
  this.name = name;
  this.time = parseInt(time);
  return this;
}

function Queue() {
  this.queue = [];
  this.headIndex = 0;
  this.tailIndex = 0;
  this.n = 0

  this.enqueue = function enqueue(p) {
    this.queue[this.tailIndex] = p;
    this.tailIndex = (this.tailIndex + 1) % MAX;
  };

  this.dequeue = function dequeue() {
    var p = this.queue[this.headIndex];
    this.headIndex = (this.headIndex + 1) % MAX;
    return p;
  }

  return this;
};


// Main
while (queue.headIndex !== queue.tailIndex) {
  var currentProcess = queue.dequeue();
  var c = Math.min(q, currentProcess.time);
  currentProcess.time -= c;
  now += c;
  if (currentProcess.time > 0) {
    queue.enqueue(currentProcess);
  } else {
    console.log(currentProcess.name + ' ' + now.toString());
  }
}

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

long long gcd(long x, long y)
{    if (y == 0)
        return x;
    return gcd(y, x % y);}
long long lcm(long x, long y){ return x * y / gcd(x, y);}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}


int main()
{
    int N,A[200010]={},f=0,s=0;

    cin>>N;

    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]>f){
            s=f;
            f=A[i];
        }else if(A[i]>s){
            s=A[i];
        }
    };

    for(int i=0;i<N;i++){
        if(A[i]==f){
            cout<<s<<endl;
        }else{
            cout<<f<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll long long int
#define endl "\n"
#define db(x) cout<<#x<<" ->"<<x<<endl
#define db2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define db4(w,x,y,z) cout<<#w <<" -> " << w << " , " << #x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++) { cout<<*it<<" "; } cout<< endl
#define IN freopen("input.txt","r",stdin)

//template<typename T>
//using ordered_set =
//tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = (int)501;
int freq[ 105 ];
int lol[ 105 ];

void fact(int x){
    for(int i = 2; i <= 100 && x > 1; i++){
        if( x % i){ continue;}
        int cnt = 0;
        while( x % i == 0){
             ++cnt;
            x/=i;
        }
        freq[ i ]+=cnt;
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
//    IN ;
    int n ;
    cin >> n;
    for(int i = 2; i <= n; i++){
        fact(i);
    }
    for(int i = 2; i <= n; i++){
        if(freq[i] >= 74){ lol[74]++;}
        if(freq[i] >= 24){ lol[24]++ ; }
        if(freq[i] >= 14){ lol[14]++ ; }
        if(freq[i] >= 4){ lol[4]++; }
        if(freq[i] >= 2){ lol[2]++ ; }
    }
    int res = 0;
    res+=lol[74];
    res+=(lol[24] * (lol[2]-1));
    res+=(lol[14] * (lol[4]-1));
    res+=( ( lol[4] * (lol[4]-1) / 2 ) * (lol[2]-2));
    cout << res << endl;
    return 0;
}


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

using namespace std;

const int MAXN = 1e6 + 100;
int a[MAXN], n, sol;

int main()
{
	scanf("%d",&n);
	if (n >=30)printf("Yes\n");else printf("No\n");
	return 0;
}

Measured memory_bytes: 3760
use std::collections::HashSet;
use std::io::stdin;

fn main() {
    let mut set = HashSet::new();
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let n: usize = s.trim().parse().unwrap();
    s.clear();

    for _ in 0..n {
        let mut s = String::new();
        stdin().read_line(&mut s).ok();
        let t = String::from(s);
        set.insert(t);
    }

    println!("{}", set.len());
}


Measured memory_bytes: 15228
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string a,b;
  cin >> a >> b;
  a += b;
  int ans = stoi(a);
  double f = sqrt(ans);
  // cout << ans << endl;
  if (((int)f)%1 +f-(int)f == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

int main(){
  int n; cin >> n;
  vector<int> a;
  for(int i=0;i<2*n;i++){
    int t; scanf("%d", &t);
    a.push_back(t);
  }
  sort(a.begin(), a.end());
  long long ans = 0;
  for(int i=0;i<n;i++){
    ans += a[2 * i];
  }
  cout << ans << "\n";
}


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

if n < 105:
    print(0)
    exit()

dp = [0] * 201
ans = 0

for i in range(1, n + 1):
    for j in range(105, n + 1):
        if j % i == 0:
            dp[j] += 1

for i in range(105, n + 1, 2):
    if dp[i] >= 8:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[3][1005];
	int n;
	cin>>n;
	for(int i=0;i<3;i++)
		for(int j=0;j<n;j++){
			cin>>a[i][j];
		}
	int cnt=0;
	for(int j=0;j<n;j++){
		if(a[0][j]==a[1][j]&&a[0][j]==a[2][j]&&a[1][j]==a[2][j])
			cnt+=0;
		else if(a[0][j]!=a[1][j]&&a[0][j]!=a[2][j]&&a[1][j]!=a[2][j])
			cnt+=2;
		else 
			cnt+=1;
	}
	cout<<cnt<<endl;
} 

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

int main(){
  string s;
  cin >> s;
  
  int count=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='o'){
      count++;
    }
  }
  cout << 700+100*count << endl;
}


Measured memory_bytes: 3604
package main
import "fmt"

func main() {

  var result uint64
  var n int
  fmt.Scan(&n)
  
  result = lucas(n)
  fmt.Print(result)
}

func lucas(n int) uint64 {
  var prev uint64 = 2
  var thiv uint64 = 1
  var result uint64 = 0
  if n == 0 {
    return 2
  } else if n == 1 {
    return 1
  }
  for  i  := 2 ; i<= n ; i++ {
    result = thiv + prev
    prev = thiv
    thiv = result
  }
  return result
}


Measured memory_bytes: 512
n = int(input())
graph = [dict() for _ in range(n)]

for i in range(n - 1):
    a, b, c = map(int, input().split())
    graph[a - 1][b - 1] = c
    graph[b - 1][a - 1] = c

q, k = map(int, input().split())
xy = []
for i in range(q):
    x, y = map(int, input().split())
    xy.append([x - 1, y - 1])
depth = [0 for _ in range(n)]
prev = [False for _ in range(n)]
depth[k - 1] = 0

import sys

sys.setrecursionlimit(10 ** 6)


def dfs(now, prev, cost, graph, depth):
    depth[now] = cost
    for k, v in graph[now].items():
        if k == prev:
            continue
        dfs(k, now, cost + v,  graph, depth)
    return depth


depth = dfs(k - 1, -1, 0, graph, depth)
for x, y in xy:
    print(depth[x] + depth[y])


Measured memory_bytes: 165340
using System;

namespace ABC123B
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int d = int.Parse(Console.ReadLine());
            int e = int.Parse(Console.ReadLine());
            
            int f, g, h, i, j;
            if (a % 10 == 0)
            {
                f = 0;
            }
            else
            {
                f = 10 - (a % 10);
            }
            if (b % 10 == 0)
            {
                g = 0;
            }
            else
            {
                g = 10 - (b % 10);
            }
            if (c % 10 == 0)
            {
                h = 0;
            }
            else
            {
                h = 10 - (c % 10);
            }
            if (d % 10 == 0)
            {
                i = 0;
            }
            else
            {
                i = 10 - (d % 10);
            }
            if (e % 10 == 0)
            {
                j = 0;
            }
            else
            {
                j = 10 - (e % 10);
            }

            if (f >= g && f >= h && f >= i && f >= j)
                Console.WriteLine(a + b + c + d + e + g + h + i + j);
            else if (g >= f && g >= h && g >= i && g >=j)
                Console.WriteLine(a + b + c + d + e + f + h + i + j);
            else if (h >= f && h >= g && h >= i && h >= j)
                Console.WriteLine(a + b + c + d + e + f + g + i + j);
            else if (i >= f && i >= g && i >= h && i >= j)
                Console.WriteLine(a + b + c + d + e + f + g + h + j);
            else if (j >= f && j >= g && j >= h && j >= i)
                Console.WriteLine(a + b + c + d + e + f + g + h + i);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    double r;
    cin >> r;
    double c;
    double d;
    d = 2.0*r*3.141592653589;
    c = r*r*3.141592653589;
    printf("%f %f\n",c,d);
}


Measured memory_bytes: 3192
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int find(int x)
{
    int ans=0;
    while(x)
    {
        ans=ans+x%10;
        x=x/10;
    }
    return ans;
}
int main()
{
    int n,s,i,j,k,t1,t2;
    s=1000000;
    scanf("%d",&n);
    for(i=1;i<n;i++)
    {
       j=i;
       k=n-j;
       t1=find(j);
       t2=find(k);
       s=min(s,t1+t2);
    }
    printf("%d\n",s);
    return 0;
}


Measured memory_bytes: 128
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n, ans = 0, c;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> c;
		ans += max(0, v[i] - c);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,a,b,c,d;
int T;
map<LL,LL>mp;
LL dfs(LL x,LL cost){
	if(x==0)return cost;
	if(x==1)return cost+d;
	LL res=2e18;
	if((1e18-cost)/x>d)res=min(res,x*d+cost);
	if(mp[x])return mp[x]+cost;
	
	for(LL i=-4;i<=4;i++){
		if((x+i)>0&&(x+i)%5==0&&(x+i)/5<x){ //cout<<x+i<<endl;
			res=min(res,dfs((x+i)/5,cost+c+abs(i)*d));
		}
	}
	for(LL i=-2;i<=2;i++){
		if((x+i)>0&&(x+i)%3==0&&(x+i)/3<x){//cout<<x+i<<endl;
			res=min(res,dfs((x+i)/3,cost+b+abs(i)*d));
		}
	}
	for(LL i=-1;i<=1;i++){
		if((x+i)>0&&(x+i)%2==0&&(x+i)/2<x){//cout<<x+i<<endl;
			res=min(res,dfs((x+i)/2,cost+a+abs(i)*d));
		}
	}
	mp[x]=res-cost;
	return res;
}
int main(){
	scanf("%d",&T);
	while(T--){
		mp.erase(mp.begin(),mp.end());
		scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
		cout<<dfs(n,0)<<endl;
	}
}

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

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

	// すべての猫のxorをとった数Xを求める
	ll x = 0;
	rep(i,n) x = x ^ a[i];

	// a[i]とXのxorを取る
	rep(i,n) {
		ll ans = x ^ a[i];
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}

int main()
{
    int n;
    scanf("%i",&n);
    vector<int> h(n+3,INT_MAX);
    for(int i=0;i<n;i++)
        cin >> h[i];
    vector<int> cost(n+3,INT_MAX);
    cost[0]=0;
    for(int i=0;i<n;i++)
    {
        cost[i+1]=min(cost[i+1],cost[i]+abs(h[i]-h[i+1]));
        cost[i+2]=min(cost[i+2],cost[i]+abs(h[i]-h[i+2]));
    }
    printf("%i\n",cost[n-1]);
    return 0;
}


Measured memory_bytes: 1024
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int a,b;
	cin>>a>>b;
	cout<<max({a+b,a-b,a*b})<<endl;
}










Measured memory_bytes: 256
# -*- coding:utf-8 -*-
"""解答
1 + 2 + 3 + ... + t >= X
のとき、Xを満たす和を作れるので、このときのtが答え。

なぜなら、左辺の和がXを超えた場合、
・1を引く（t=1のときジャンプしない）
・2を引く（t=2のときジャンプしない）
・3を引く（t=3のときジャンプしない）
...
という風にできるから。

左辺は、和の公式で (1+t)*t/2 で求まる。
よって、
(1+t)*t/2 >= X
t^2 + t - 2X >= 0

2次方程式の解の公式より、
t = -1±√(1+4*2X)/2

計算量はO(1)
"""
import math

def solve():
    X = int(input())

    t = (-1 + math.sqrt(1+4*2*X))/2  # tは必ず正なので+の場合のみでOK
    t = math.ceil(t)

    print(t)
        

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin>>N;
    int init[4] = {};
    for (int i=0; i<N; i++)
    {
        int a;
        cin>>a;
        init[a]++;
    }

    vector<vector<vector<double>>> T(N+1, vector<vector<double>>(N+1, vector<double>(N+1)));
    for (int c=0; c<=N; c++)
    for (int b=0; b<=N; b++)
    for (int a=0; a<=N; a++)
    if (a+b+c <= N)
    {
        int d = N - (a+b+c);
        double t = 0;
        if (a>0)
            t += T[a-1][b][c] * a/N;
        if (b>0 && a+1<=N)
            t += T[a+1][b-1][c] * b/N;
        if (c>0 && b+1<=N)
            t += T[a][b+1][c-1] * c/N;
        if (d < N)
            T[a][b][c] = (t+1) / (1-(double)d/N);
    }
    printf("%.16f\n", T[init[1]][init[2]][init[3]]);
    return 0;
}


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

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector< string > latte, malta;
  for(int i = 0; i < N; i++) {
    string s;
    cin >> s;
    string t = s;
    for(char &c : s) if(c == '?') c = 'a';
    for(char &c : t) if(c == '?') c = 'z';
    latte.push_back(s);
    malta.push_back(t);
  }

  string T;
  cin >> T;

  int ret1 = 0, ret2 = 0;

  for(int i = 0; i < N; i++) {
    if(latte[i] <= T) ++ret1;
    if(malta[i] < T) ++ret2;
  }

  for(int i = ret2; i <= ret1; i++) {
    if(i != ret2) cout << " ";
    cout << i + 1;
  }
  cout << endl;

}



Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    S = LS()
    T = LS()

    cnt = 0
    for s, t in zip(S, T):
        if s != t:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 12484
#include<bits/stdc++.h>
#include<string>
#define pii pair<int, int>
#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define S second
#define F first
using namespace std;



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

	
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	ll ans = INT_MAX;
	ll l = 1, h = INT_MAX;
	while (l <= h) {
		ll mid = (l + h) / 2;
		ll move = 0;
		for (int i = 1; i <= n; i++) {
			move = move + (a[i] - 1 ) / mid;
		}
		
		if (move <= k) {
			ans = min(ans, mid);
			h = mid - 1;
		}
		else {
			l = mid + 1;
		}

	}

	cout << ans << '\n';

}

Measured memory_bytes: 4760
#include<stdio.h>

int n,A[50];

int solve (int i, int m) {
  if( m == 0 ) return 1;
  if( i >= n ) return 0;
  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

main() {
  int q, M, i;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d",&A[i]);
  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &M);
    if( solve(0,M) ) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};
ll mod=1e9+7;

int main()
{
    int n;
    cin>>n;
    ll dp[110][4][4][4];//A0 C1 G2 T3
    m0(dp);
    for(int i = 0; i < 4; i++)
    {
        for(int j = 0; j < 4; j++)
        {
            for(int k = 0; k < 4; k++)
            {
                if((i==0&&j==2&&k==1)
                    ||(i==0&&j==1&&k==2)
                    ||(i==2&&j==0&&k==1))
                {
                    continue;
                }
                else
                {
                    dp[3][i][j][k]=1;
                }
            }
        }
    }
    for(int now = 4; now <= n; now++)
    {
        for(int i = 0; i < 4; i++)
        {
            for(int j = 0; j < 4; j++)
            {
                for(int k = 0; k < 4; k++)
                {
                    for(int l = 0; l < 4; l++)
                    {
                        if((j==0&&k==2&&l==1)
                            ||(j==0&&k==1&&l==2)
                            ||(j==2&&k==0&&l==1))
                        {
                            continue;
                        }
                        else if((i==0&&j==2&&l==1)
                            ||(i==0&&k==2&&l==1))
                        {
                            continue;
                        }
                        else
                        {
                            dp[now][j][k][l]+=dp[now-1][i][j][k];
                            dp[now][j][k][l]%=mod;
                        }
                    }
                }
            }
        }
    }
    ll ans=0;
    for(int i = 0; i < 4; i++)
    {
        for(int j = 0; j < 4; j++)
        {
            for(int k = 0; k < 4; k++)
            {
                ans+=dp[n][i][j][k];
                ans%=mod;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

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

int main() {
    while (1) {
        int a, b;
        int ret = scanf("%d%d", &a, &b);
        if (ret < 0) break;
        int g = gcd(a, b);
        printf("%d %d\n", g, a / g * b);
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

ll n, k;
ll r, s, p;
string t;


ll DP(string &st){

    ll dp[st.size()+1][3];
    for(int i = 0; i <= st.size(); i++){
        for(int j = 0; j < 3; j++){
            dp[i][j] = 0;
        }
    }

    for(int i = 1; i <= st.size(); i++){
        ll maxi = max( {dp[i-1][0], dp[i-1][1], dp[i-1][2] } );
        if(i == 1 ){
            dp[i][0] = maxi; 
            dp[i][1] = maxi;
            dp[i][2] = maxi;
            if( st[i-1] == 'r' ){
                dp[i][2] += p;
            }
            if( st[i-1] == 's' ){
                dp[i][0] += r;
            }
            if( st[i-1] == 'p' ){
                dp[i][1] += s;
            }
        }
        else{
            if( st[i-1] == 'r' ){
                dp[i][0] = max( dp[i-1][1], dp[i-1][2] );
                dp[i][1] = max( dp[i-1][0], dp[i-1][2] );
                dp[i][2] = max( dp[i-1][0], dp[i-1][1] ) + p;
            }
            if( st[i-1] == 's' ){
                dp[i][0] = max( dp[i-1][1], dp[i-1][2] ) + r;
                dp[i][1] = max( dp[i-1][0], dp[i-1][2] );
                dp[i][2] = max( dp[i-1][0], dp[i-1][1] );
            }
            if( st[i-1] == 'p' ){
                dp[i][0] = max( dp[i-1][1], dp[i-1][2] );
                dp[i][1] = max( dp[i-1][0], dp[i-1][2] ) + s;
                dp[i][2] = max( dp[i-1][0], dp[i-1][1] );
            }
        }
    }

    return max( { dp[st.size()][0], dp[st.size()][1], dp[st.size()][2] } );

}

int main(){


    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;

    vector<string> v(k);
    for(int i = 0; i < n; i++){
        v[i % k] += t[i];
    }

    ll ans = 0;
    for(int i = 0; i < k; i++){
        ans += DP( v[i] );
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
  int N, B[110], A[110];
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> B[i];
  }
  
  int start = B[0];
  int sum = 0;
  A[0] = start;
  A[1] = start;
  
  for(int i=1;i<N-1;i++){
    int amax = B[i];
    if(amax >= A[i]){
      A[i+1] = amax;
    }else if(amax <= B[i-1]){
      A[i] = amax;
      A[i+1] = amax;
    }
  }
  
  for(int i=0;i<N;i++){
    sum += A[i];
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q;
ll A[200001];
ll B[200001];
ll ans;
string S;
ll K;
map<ll, ll> m;
char ansmap[102][102];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
int main() {
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i];
	}
	rep(i, 0, N) {
		cin >> B[i];
	}
	for (ll bitIndex = 1<<28; bitIndex !=0; bitIndex >>= 1) {
		ll count = 0;
		rep(i, 0, N) {
			A[i] %= bitIndex << 1;
			B[i] %= bitIndex << 1;
		}
		sort(B, B + N);
		rep(i, 0, N) {
			count += lower_bound(B, B + N, bitIndex * 2 - A[i]) - lower_bound(B, B + N, bitIndex - A[i]);
			count += lower_bound(B, B + N, bitIndex * 4 - A[i]) - lower_bound(B, B + N, bitIndex * 3 - A[i]);
		}
		if (count % 2)ans += bitIndex;
	}
	cout << ans << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 3328
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
 
ans = -float('inf')
for s in range(N):
    S = [] 
    i = P[s] - 1
    S.append(C[i])
    while i != s:
        i = P[i] - 1
        S.append(S[-1] + C[i])
 
    if K <= len(S):
        score = max(S[:K])
    elif S[-1] <= 0:
        score = max(S)
    else:
        score1 = S[-1] * (K // len(S) - 1)
        score1 += max(S)
        score2 = S[-1] * (K // len(S))
        r = K % len(S)
        if r != 0:
            score2 += max(0, max(S[:r]))
        score = max(score1, score2)
 
    ans = max(ans, score)
 
print(ans)

Measured memory_bytes: 80840
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =2e5+10;
const int mod=1e9+7;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin>>k;
    int sum=0;
    int len=1;
    while(1)
    {
        sum=sum*10+7;
        sum%=k;
        if(sum==0)
        {
            cout<<len<<'\n';
            return 0;
        }
        if(len>k)
        {
            cout<<-1<<'\n';
            return 0;
        }
        len++;
    }


}


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

class Dijkstra {
public:
    struct edge { long long v, dist; };

    struct state {
        long long v, cost;
        bool operator>(const state s) const { return cost > s.cost; }
    };

    const long long INF = (1LL << 60);
    long long N;
    vector< vector<edge> > E;

    Dijkstra(long long n): N(n), E(n) {}

    //有効グラフの時はこっち。u→vに距離dで結ぶ
    void add_directed_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
    }

    //無向グラフの時はこっち。uとvを双方向に距離dで結ぶ
    void add_undirected_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
        E[v].push_back((edge) { u, d });
    }

    //Sを始点として、他の頂点への最短経路を探す
    vector<long long> shortest_path(long long S) {
        vector<long long> dp(E.size(), INF);
        priority_queue<state, vector<state>, greater<state> > q;
        q.push((state) { S, 0 });
        while(!q.empty()) {
            long long v = q.top().v, cost = q.top().cost;
            q.pop();
            if(dp[v] <= cost) continue;
            dp[v] = cost;
            for(int i=0;i < E[v].size() ; i++) {
            long long nv = E[v][i].v, ncost = cost + E[v][i].dist;
            if(dp[nv] > ncost) q.push((state) { nv, ncost });
            }
        }
        return dp;
    }
};


int main(){
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    s--,t--;
    Dijkstra d(n);
    long long x,y;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        x--,y--;
        d.add_undirected_edge(x,y,1);
    }
    vector<long long> vs=d.shortest_path(s);
    vector<long long> vt=d.shortest_path(t);
    long long dist=vs[t];
    map<long long,long long> cs,ct;
    for(int i=0;i<n;i++){
        cs[vs[i]]++;
        ct[vt[i]]++;
        //cerr<<"a "<<vs[i]<<" "<<vt[i]<<endl;
    }
    long long ans=0;
    for(int i=0;i<=n;i++){
        ans+=cs[i]*ct[dist-2-i];
        //cerr<<"b"<<" "<<cs[i]<<" "<<ct[dist-2-i]<<endl;
    }
    cout<<ans<<endl;

    

}


Measured memory_bytes: 27548
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

a,b,k=MI()
cnt=0
for i in range(100,0, -1):
    if a%i==0 and b%i==0:
        cnt+=1
    if cnt==k:
        print(i)
        exit()

Measured memory_bytes: 3316
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 53;
int n, m, ev[N], eu[N], par[N], mask[N];
ll dp[N][(1 << 20)];
vector <int> adj[N];

int stp = -1, endp = -1, num;

void dfs(int v, int p) {
    if (v == endp) {
        int s = v;
        while (s != stp) {
            mask[par[s]] |= (1 << num);
            s = ev[par[s]] + eu[par[s]] - s;
        }
        return;
    }
    for (auto i : adj[v]) {
        int to = ev[i] + eu[i] - v;
        if (to == p) {
            continue;
        }
        par[to] = i;
        dfs(to, v);
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n;
    for (int i = 1; i <= n - 1; i++) {
        cin >> ev[i] >> eu[i];
        adj[ev[i]].pb(i);
        adj[eu[i]].pb(i);
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        memset(& par, 0, sizeof(par));
        stp = u, endp = v;
        num = i;
        dfs(u, -1);
    }
    dp[0][0] = 1;
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < (1 << m); j++) {
            dp[i + 1][j] += dp[i][j];
        }
        for (int j = 0; j < (1 << m); j++) {
            dp[i + 1][j | mask[i + 1]] += dp[i][j];
        }
    }
    cout << dp[n - 1][(1 << m) - 1];
}


Measured memory_bytes: 403712
#define DEBUG 0
 
#include <bits/stdc++.h>
using namespace std;
 
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
 
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
 
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
 
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
 
// ---------- END OF TEMPLATE ----------
 void fopen()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
}
int dist[200][200];
int colour[200];
int main() {
    int i,j;
    int N;
    char c;
    scanf("%d",&N);
    for (i = 0; i < N; i++) {
        for (j = 0; j < N; j++) scanf(" %c",&c),dist[i][j] = (i == j) ? 0:((c == '1') ? 1:1e9);
    }
 
    int k,no = 0;
    colour[0] = 0;
    for (i = 1; i < N; i++) colour[i] = -1;
    for (i = 0; i < N; i++) {
        for (j = 0; j < N; j++) {
            for (k = 0; k < N; k++) {
                if ((dist[j][k] == 1) && (colour[j] != -1)) {
                    if (colour[k] == colour[j]) no = 1;
                    colour[k] = !colour[j];
                }
            }
        }
    }
    for (k = 0; k < N; k++) {
        for (i = 0; i < N; i++) {
            for (j = 0; j < N; j++) dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
        }
    }
    int ans = 0;
    for (i = 0; i < N; i++) {
        for (j = 0; j < N; j++) ans = max(ans,dist[i][j]);
    }
    printf("%d\n",no ? -1:ans+1);
 
    return 0;
}

Measured memory_bytes: 384
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert
#define fh(x,v) for(auto x:v)

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

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(begin(ret), end(ret));
  return (ret);
}

int solve(int n){
	int ret=0;
	vint v=divisor(n);
	rep(i,v.size()){
		v[i]--;
		if(v[i]<=1)continue;
		if(n%v[i]==n/v[i]){
			ret+=v[i];
		}
	}
	return ret;
}

main(){
	int n;
	cin>>n;
	dump(solve(n));
}





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

int main(){
  int n,t;
  cin >> n >> t;
  int a[n];
  for(int i = 0;i < n;i++) cin >> a[i];
  set<int> s;
  int benefit = 0;
  for(int i = 0;i < n-1;i++){
    s.insert(a[i]);
    auto iter = s.lower_bound(-1000000007);
    benefit = max(benefit,a[i+1]-*iter);
  }
  set<int> s2;
  int result = 0;
  for(int i = 0;i < n;i++) s2.insert(a[i]);
  for(int i = 0;i < n-1;i++){
    s2.erase(a[i]);
    auto iter = s2.lower_bound(a[i]+benefit);
    if(iter != s2.end() && *iter == a[i]+benefit){
      result++;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 9984