akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
    double ao,n,x[100]={},y[100]={},a,b,c,d,e;
    cin>>n;
    for(int i=0;i<n;i++) cin>>x[i];
    for(int i=0;i<n;i++) cin>>y[i];
    for(int i=0;i<n;i++){
        a+=fabs(x[i]-y[i]);
        b+=pow(fabs(x[i]-y[i]),2);
        e=sqrt(b);
        c+=pow(fabs(x[i]-y[i]),3);
        d=cbrt(c);
        ao=max(ao,fabs(x[i]-y[i]));
    }
    printf("%.6f\n%.6f\n%.6f\n%.6f",a,e,d,ao);
    return 0;
}


Measured memory_bytes: 3404
#include <stdio.h>

int main(){

	char buf[1200];
	int i = 0;

	scanf("%[^\n]", buf);
	

	while(1){
		if(buf[i]=='\0') break;
		if(buf[i]>=65 && buf[i]<=90) {			// big -> small
			buf[i] += 32;
		} else if(buf[i]>=97 && buf[i]<=122) {	// small -> big
			buf[i] -= 32;
		}

		i++;
	}

	printf("%s\n", buf);

	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(),(X).end()
#define ll long long
#define pi pair<int,int>
const int N=3e5+5,MOD=1e9+7;
 
using namespace std;
int k;
void out(vector<ll>& ans){
	sort(all(ans));
	while(k--){
			printf("%lld\n",ans.back() );
			ans.pop_back();
	}
	exit(0);
}
int main()
{
	//freopen("tst.txt","r",stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,p;
	scanf("%d %d %d %d",&n,&m,&p,&k);
	vector<ll>a(n),b(m),c(p);
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	for(int i=0;i<m;i++)scanf("%lld",&b[i]);
	for(int i=0;i<p;i++)scanf("%lld",&c[i]);
	vector<ll> acc;
	for(int i=0;i<m;i++){
		for(int j=0;j<p;j++){
			acc.pb(b[i]+c[j]);
		}
	}
	sort(all(a));
	sort(all(acc));
	std::vector<ll> ans;
	for(int j=sz(acc)-1;j>=0;j--){
	for(int i=n-1;i>=0;i--){
			ans.pb(a[i]+acc[j]);
			if(sz(ans)>=5e6){
				out(ans);
			}
		}
	}
	out(ans);
}

Measured memory_bytes: 76132
if __name__ == '__main__':
	
	#横
	B = []
	w1 = list(map(int,input().split()))
	w2 = list(map(int,input().split()))
	w3 = list(map(int,input().split()))
	n = int(input())
	A = []
	for i in range(n):
		cmd = int(input())
		A.append(cmd)
	B.append(w1)
	B.append(w2)
	B.append(w3)

	#縦
	h1 = []
	h2 = []
	h3 = []
	h1.append(w1[0])
	h1.append(w2[0])
	h1.append(w3[0])
	h2.append(w1[1])
	h2.append(w2[1])
	h2.append(w3[1])
	h3.append(w1[2])
	h3.append(w2[2])
	h3.append(w3[2])

	B.append(h1)
	B.append(h2)
	B.append(h3)

	#斜め
	s1 = []
	s2 = []
	s1.append(w1[0])
	s1.append(w2[1])
	s1.append(w3[2])
	s2.append(w1[2])
	s2.append(w2[1])
	s2.append(w3[0])

	B.append(s1)
	B.append(s2)
	
	setA = set(A)
	cnt = 0
	for k in B:
		setB = set(k)
		#intersection
		s_int = setA & setB
		if len(s_int) == 3:
			cnt = 1
			break
	if cnt == 1:
		print("Yes")
	else:
		print("No")



Measured memory_bytes: 9108
#include<iostream>
#include<cstdint>

int const MAXN = 3e5;
int64_t const MOD = 1e9+7;
int64_t A[MAXN];
int N;

template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
  //operator int64_t() const { return v_; }
};
typedef mod_int<MOD> mint;

int main() {
  std::cin >> N;
  for(int i = 0; i < N; ++i) std::cin >> A[i];
  mint ans;
  for(int i = 0; i < 60; ++i) {
    int64_t c = 0;
    for(int j = 0; j < N; ++j) if(((A[j]>>i)&1) > 0) ++c;
    if(c > 0) ans += mint(2).pow(i)*mint(c)*mint(N-c);
  }
  std::cout << ans.v_ << std::endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include<cmath>
using namespace std;
int main(void){

	int N, C, ans;
	int p[100];

	int cakesum = 0;
	cin >> N >> C;

	for(int i = 0; i < C; i++){
		cin >> p[i];
		cakesum += p[i];
	}

	// cout << cakesum << endl; 合計のケーキの個数

	if(cakesum % (N+1) == 0) ans = cakesum / (N+1); // 自分の人数を足さないとダメ！！！！！！！！！！！
	else ans = cakesum / (N+1)+1;

	cout << ans << endl;

}



Measured memory_bytes: 3104
#define _GLIBCXX_DEBUG
#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 m, f, r;
  char g[51];
  rep(i, 50) {
    cin >> m >> f >> r;
    if ( m==-1 && f==-1 && r==-1 ) {
      g[i] = 'Z';
      break;
    }
      
    if ( m==-1 || f==-1 ) {
      g[i] = 'F';
      continue;
    }
      
    int sum = m+f;
    if (sum>=80) g[i] = 'A';
    else if (sum >= 65) g[i] = 'B';
    else if (sum >= 50) g[i] = 'C';
    else if (sum >= 50 || (sum >= 30 && r >= 50)) g[i] = 'C';
    else if (sum >= 30) g[i] = 'D';
    else g[i] = 'F';
  }
  
  rep(i, 50) {
    if (g[i]=='Z')
      break;
    cout << g[i] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

#define MUL 1000000000000000000

int main(int argc, char* argv[]) {
  string s;
  cin >> s;
  long long K;
  cin >> K;

  int i = 0;
  while (true) {
    if (i + 1 == K) {
      cout << s[i] << endl;
      return 0;
    }
    if (s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
    ++i;
  }

  return 0;
}

Measured memory_bytes: 256
import numpy as np
def C():
    n = int(input())
    dp_gcd2d = [[0 for i in range(n+1)] for i in range(n+1)]
    dp = [[[0 for i in range(n+1)] for j in range(n+1)] for k in range(n+1)]
    def gcd(a, b):
        if b == 0:
            dp_gcd2d[a][b] = a
            return a
        elif dp_gcd2d[a][b] != 0:
            return dp_gcd2d[a][b]
        else:
            dp_gcd2d[a][b] = dp_gcd2d[b][a%b]
            return gcd(b, a%b)
    for i in range(1, n+1):
        for j in range(1, n+1):
            dp_gcd2d[i][j] = gcd(i,j)
    for i in range(1, n+1):
        for j in range(i, n+1):
            for k in range(j, n+1):
                dp[i][j][k] = dp_gcd2d[dp_gcd2d[i][j]][k]
                dp[j][i][k] = dp[i][j][k]
                dp[i][k][j] = dp[i][j][k]
                dp[k][i][j] = dp[i][j][k]
                dp[k][j][i] = dp[i][j][k]
                dp[j][k][i] = dp[i][j][k]
    print(np.sum(np.array(dp)))
    

C()

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

int n, m, l, r, a, b;

int main(){
	cin >> n >> m;
	a = 1; b = n;
	for (int i = 0; i < m; ++i){
		cin >> l >> r;
		a = max(a, l);
		b = min(b, r);
		if (a > b) break;
	}
	cout << max(b - a + 1, 0);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  int m;
  int count = 0;
  int *homework;
  int result;
  scanf("%d", &n);
  scanf("%d", &m);
  homework = (int*)malloc(sizeof(int) * m);
  
  for(int i = 0; i < m; i++){
    scanf("%d", &homework[i]);
    count = count + homework[i];
  };
  
  result = n - count;
  
  if(result < 0){
    printf("-1");
  }else{
    printf("%d", result);
  };
  
  return 0; 
}

Measured memory_bytes: 1728
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n,m,k=MI()
	mod=10**9+7

	ans=0

	cnt=0
	for i in range(1,m):
		cnt+=i*(m-i)
		cnt%=mod

	ans+=cnt*n*n
	ans%=mod

	cnt=0
	for i in range(1,n):
		cnt+=i*(n-i)
		cnt%=mod

	ans+=cnt*m*m
	ans%=mod

	f=[1]
	for i in range(1,n*m+5):
		f.append((f[-1]*i)%mod)

	finv=[]
	for i in f:
		finv.append(pow(i,mod-2,mod))
	#print(finv)

	#print(ans)

	ans*=k*(k-1)

	ans*=f[n*m-2]
	ans%=mod
	#print(ans)


	ans*=finv[n*m-2-(k-2)]
	ans%=mod
	#print(ans)


	ans*=finv[k]
	ans%=mod



	print(ans)






























if __name__ == "__main__":
	main()


Measured memory_bytes: 24928
// ~maqsat~
/*    
**    “Anyone who has never made a mistake has never tried anything new.”
**    © Albert Einstein
*/

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e10 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

#define int ll

main() {
    fre("");
    ACCELERATE;
	
	int n, k;
	cin >> n >> k;

	if((n - 1) * (n - 2) / 2 < k) return !(cout << -1);

	vector<ii> ans;
	for(int i = 2; i <= n; i++) {
		ans.pb({1, i});
	}

	k = ((n - 1) * (n - 2) / 2) - k;
	for(int i = 2; i <= n; i++) {
		bool f = 0;
		for(int j = i + 1; j <= n; j++) {
			if(!k) {
				f = 1;
				break;
			}
			ans.pb({i, j});
			k--;
		}
		if(f) break;
	}

	cout << sz(ans) << '\n';
	for(int i = 0; i < sz(ans); i++) {
		cout << ans[i].F << ' ' << ans[i].S << '\n';
	}

    return 0;
}
/*
 
*/


Measured memory_bytes: 384
import java.util.Scanner;

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

    while (in.hasNext()) {
      int a = in.nextInt();
      int b = in.nextInt();

      if (a <= b) {
        System.out.println(a);
      } else {
        System.out.println(a - 1);
      }
    }
  }
}


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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define DIGIT(c) (c >= '0' && c <= '9')
#define F first
#define S second
#define INF 1 << 30

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

int W, H;
char c[100][100];

string judge(string a, string b){
  while(a[0] == '0') a.erase(a.begin());
  while(b[0] == '0') b.erase(b.begin());
  //  cout << a << " " << b << endl;
  if(a.size() > b.size()) return a;
  if(a.size() < b.size()) return b;
  
  rep(i, a.size()){
    if(a[i] > b[i]) return a;
    if(a[i] < b[i]) return b;
  }
  return a;
}

int main(){
  while(scanf("%d%d", &W, &H) && W+H){
    rep(i, H) scanf("%s", c[i]);

    vector<vector<string> >dp(H, vector<string>(W, ""));
    if(DIGIT(c[0][0])) dp[0][0] = c[0][0];
    REP(i, 1, W) if(DIGIT(c[0][i])) dp[0][i] = dp[0][i-1] + c[0][i];
    REP(i, 1, H) if(DIGIT(c[i][0])) dp[i][0] = dp[i-1][0] + c[i][0];

    REP(i, 1, H){
      REP(j, 1, W){
	if(!DIGIT(c[i][j])) continue;
	dp[i][j] = judge((dp[i-1][j]+c[i][j]), (dp[i][j-1]+c[i][j]));
	//	cout << i << " " << j << " " << dp[i-1][j]+c[i][j] << " " << dp[i][j-1]+c[i][j] << endl;
      }
    }


    /*    rep(i, H){
      rep(j, W) cout << dp[i][j] << " ";
      puts("");
      }*/

    string res = "";
    rep(i, H) rep(j, W) res = judge(res, dp[i][j]);
    //    if(res[0] == '0') res.erase(res.begin());
    cout << res << endl;
  }
  return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

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

    s[k-1]=tolower(s[k-1]);

    cout<<s<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,l;
cin>>n>>l;
int sm=0;
for(int i=l;i<l+n;i++){
    sm+=i;
}
if(l<0){
    if(l+n-1>=0){
        cout<<sm<<endl;
        return 0;
    }
    else{
        cout<<sm-(l+n-1)<<endl;
    }
}
else{
    cout<<sm-l<<endl;
}


}


Measured memory_bytes: 256
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long s) {
    alias f = (long n) => n % 2 == 0 ? (n / 2) : (3 * n + 1);
    auto set = make!(RedBlackTree!long);

    long ans = 1;
    long a = s;

    set.insert(a);
    while (true) {
        ans++;
        a = f(a);
        if (set.removeKey(a) > 0)
            return ans;
        set.insert(a);
    }
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long s;
    s = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(s);
    else
        solve(s).writeln;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;

int main(){
  int N,K,hp;
  long long ans=0;
  cin>>N>>K;
  
  vector<int> v;
  for(int i=0;i<N;i++){
    cin>>hp;
    v.push_back(hp);
  }
  
  //昇順ソート
  sort(v.begin(),v.end());
  
  //必殺技でHPが多い順に倒していく
  for(int j=0;j<K;j++){
    v.pop_back();
    if(v.empty()){
      cout<<ans<<endl;
      return 0;
    }
  }
  
  //残りの敵のHP=攻撃回数
  ans=accumulate(v.begin(), v.end(), 0LL);
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <iostream>
using namespace std; 
typedef long long lint;

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a!=c)cout<<"1";
	else
	{
		cout<<"0";
	}
	

	return 0;
}


Measured memory_bytes: 256
module AOJ
  class Hash
    def initialize
      @size = 1000000
      #@conv = {'A' => '1', 'C' => '2', 'G' => '3', 'T' => '4'}
      @array = Array.new(@size)
    end

    def insert(value)
      key = to_key(value)
      at(key) << value
    end

    def find(value)
      key = to_key(value)
      at(key).each do |v|
        return true if v == value
      end
      false
    end

    private

    def at(key)
      @array[key] = [] unless @array[key]
      @array[key]
    end

    def to_key(raw_value)
      #digits = @conv.keys.inject(raw_value) do |str, c|
      #  str.gsub(/#{c}/, @conv[c])
      #end
      #"#{'0' * (12-digits.size)}#{digits}".to_i % @size
      (raw_value.hash % @size).abs
    end
  end
end

hash = AOJ::Hash.new

STDIN.read.split(/\n/)[1..-1].each do |line|
  ary = line.split(/\s/)
  command = ary[0]
  value = ary[1]
  if command == 'insert'
    hash.insert value
  else
    puts hash.find(value) ? "yes" : "no"
  end
end

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

int main (int argc, char **argv) {
  int N;
  cin >> N;

  long d;
  long min, pmax;

  // 1st data
  cin >> d;
  min = d;
  pmax = -1.0e9;
    
  for (int i=1; i<N; i++) {
    cin >> d;
    if (d - min > pmax) pmax = d - min;
    if (min > d) min = d;
  }

  cout << pmax << endl;
}
  

Measured memory_bytes: 1164
// review

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e16;
const int MAXN = 210000;
const int MAXM = 210000;


ll l[MAXM], r[MAXM], d[MAXM];
ll x[MAXN];
vector<P> G[MAXN];
ll n, m;

bool dfs(ll s) {
  for (ll i=0;i<G[s].size();i++) {
    P p = G[s][i];
    if (x[p.first] == INF) {
      x[p.first] = x[s] + p.second;
      if (!dfs(p.first)) {
        return false;
      }
    }
    if (x[p.first] != x[s] + p.second) {
      return false;
    }
  }
  return true;
}

void solve() {
  for (ll i=0;i<m;i++) {
    G[r[i] - 1].push_back(P(l[i] - 1, d[i]));
    G[l[i] - 1].push_back(P(r[i] - 1, -d[i]));
  }
  for (ll i=0;i<n;i++) {
    x[i] = INF;
  }
  bool success = true;
  for (ll i=0;i<n;i++) {
    if (x[i] == INF) {
      x[i] = 0;
      if (!dfs(i)) {
        success = false;
        break;
      }
    }
  }
  cout << (success ? "Yes" : "No") << endl;
}

int main() {
  cin >> n >> m;
  for (ll i=0;i<m;i++) {
    cin >> l[i] >> r[i] >> d[i];
  }
  solve();
}


Measured memory_bytes: 25728
/*
	Name: Match Matching
	Author: Jerryjiang090210
	Date: 30/06/19 16:33
	Description: Jerryjiang090210's code <Match Matching>
*/
#include<bits/stdc++.h>
using namespace std;
const int maxn=(1e4+10),num[10]={0,2,5,5,4,5,6,3,7,6};
bool yes[10];
int n,m,dp[maxn],ans[maxn],sz[maxn];
int main()
{
	memset(ans,-1,sizeof(ans));
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a;
		cin>>a;
		yes[a]=true;
	}
	ans[0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=9;j>0;j--)
		{
			if(i-num[j]>=0&&yes[j]&&ans[i-num[j]]!=-1)
			{
				if(sz[i-num[j]]+1>sz[i])
		    	{
					sz[i]=sz[i-num[j]]+1;
					dp[i]=i-num[j];
					ans[i]=j;
				}
			}
		}
	}
	for(int i=n,j=sz[n];j>0;i=dp[i],j--)
		cout<<ans[i];
	return 0;
}

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

using namespace std;

int main()
{
    int n,max=0,j,i;
    bool done;
    cin >> n;
    int h[21];
    for(i=0;i<n;i++)
    {
        done = true;
        cin >> h[i];
        for(j=0;j<i;j++)
        {
            if(h[i]<h[j])
            {
                done = false;
                break;
            }

        }
        if(done)max++;
    }
    cout << max << endl;
    return 0;
}



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

#define int long long

signed main() {
  int r;
  cin >> r;
  if(r<1200) cout << "ABC" << endl;
  else if(r<2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
  return 0;
}



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

using namespace std;

int n;
int arr[100100], brr[100100];
multiset<int> s;
vector<int> comp, lis[100100];
bool visit[100100];

void dfs(int here) {
    int i;
    visit[here] = true;
    for (i=0;i<lis[here].size();i++) {
        int there = lis[here][i];
        if (visit[there]) continue;
        dfs(there);
    }
}

int main() {
    int i;
    scanf("%d",&n);

    for (i=0;i<n;i++) scanf("%d",&arr[i]);
    for (i=0;i<n;i++) scanf("%d",&brr[i]);
    for (i=0;i<n;i++) arr[n]^=arr[i];
    for (i=0;i<n;i++) brr[n]^=brr[i];
    n++;
    for (i=0;i<n;i++) s.insert(arr[i]);
    for (i=0;i<n;i++) {
        if (s.find(brr[i])==s.end()) {
            printf("-1\n");
            return 0;
        }
        s.erase(s.find(brr[i]));
    }
    for (i=0;i<n;i++) {
        if (arr[i]!=brr[i]) break;
    }
    if (i==n) {
        printf("0\n");
        return 0;
    }
    for (i=0;i<n;i++) {
        if (arr[i]!=brr[i]||i==n-1) {
            comp.push_back(arr[i]);
        }
    }
    sort(comp.begin(),comp.end());
    comp.erase(unique(comp.begin(),comp.end()),comp.end());
    int acnt = 0;
    for (i=0;i<n;i++) {
        if (arr[i]==brr[i]&&i!=n-1) continue;
        acnt++;
        arr[i] = lower_bound(comp.begin(),comp.end(),arr[i])-comp.begin();
        brr[i] = lower_bound(comp.begin(),comp.end(),brr[i])-comp.begin();
    }
    for (i=0;i<n;i++) {
        if (arr[i]==brr[i]&&i!=n-1) continue;
        lis[brr[i]].push_back(arr[i]);
    }
    acnt-=2;
    for (i=0;i<comp.size();i++) {
        if (!visit[i]) {
            dfs(i);
            acnt++;
        }
    }
    printf("%d\n",acnt);

    return 0;
}


Measured memory_bytes: 10152
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}

ll gcd(ll a, ll b, ll c) {
  return gcd(a,gcd(b,c)) ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k ;
  cin >> k ;
  ll ans = 0 ;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
        ans += gcd(i,j,l) ;
      }
    }
  }
  
  cout << ans <<endl ;
    
  
  
  
  return 0 ;
}




Measured memory_bytes: 3636
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def equals(self,another):

        ret = False;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            FLG = True
            for k in range(6):
                if self.number[k] != another.number[k]:
                    FLG = False
                    break
            if FLG == True:
                return True

        return ret



num_dice = int(input())
DICE = []

for i in range(num_dice):
    table = list(map(int,input().split()))
    tmp_dice = Dice()
    tmp_dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])
    DICE.append(tmp_dice)

FLG = True

for i in range(num_dice-1):
    for k in range(i+1,num_dice):
        if DICE[i].equals(DICE[k]) == True:
            FLG = False
            break


if FLG == True:
    print("Yes")
else:
    print("No")



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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const intll INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  intll k , a , b ; 
  cin >> k >> a >> b ;
  intll ans = 1 ; 
  
  if(b-a > 2){
    k -= (a-1) ;
    ans = a ; 
    ans += (b-a) * (k/2) ;
    if(k%2 == 1) ans ++ ;    
  }
  else ans +=  k ;
  
  cout << ans ; 
  
}


Measured memory_bytes: 3584
/* *********************************
Author        :Scau.ion
Created Time  :2016/09/04 19:57:42
File Name     :ion.cpp
********************************** */

#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

using namespace std;

int main()
{
    IOS;
	LL a,b,c;
    cin>>a>>b>>c;
    if (a%2==0||b%2==0||c%2==0) cout<<"0"<<endl;
    else
    {
        if (a>b) swap(a,b);
        if (b>c) swap(b,c);
        cout<<a*b<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<map>
using namespace std;

int main()
{
   int c=0,i;
   string s;
   cin>>s;
if(s[0]=='R'&&s[1]=='S')c=1;
   else{
   for(i=0;i<3;i++)
    {
       
      if(s[i]=='R')c++;
    
    
    }
}
  cout<<c<<endl;

 }

Measured memory_bytes: 3596
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

    int n, m, k; cin>>n>>m>>k;

    char a[n][m];

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

    int ans = 0;

    for(int row_mask = 0; row_mask < (1<<n); row_mask++){
        for(int col_mask = 0; col_mask < (1 << m); col_mask++){
            unordered_set<int> ban_row, ban_col;
            for(int row = 0; row < n; row++){
                if(row_mask & (1 << row))
                    ban_row.insert(row);
            }
            for(int col = 0; col < m; col++){
                if(col_mask & (1 << col)){
                    ban_col.insert(col);
                }
            }
            int cnt = 0;
            for(int i = 0; i < n; i++){
                if(ban_row.count(i))continue;
                for(int j = 0; j < m; j++){
                    if(ban_col.count(j))continue;
                    if(a[i][j] == '#')cnt++;
                }
            }
            if(cnt == k)ans++;
        }
    }
    cout<<ans<<"\n";
    

}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1) res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    string S; cin >> S;
    sort(S.begin(), S.end());
    if (S == "abc") cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
      	if(b != 0){
      		int c [] = new int[b];
      		for(int i = 0; i < b; i++){  
      			c [i] = sc.nextInt();
      		}
      	int d = -1;
        boolean f = true;
        boolean g = true;
		boolean h = true;
		// 出力
     	while(f && h){
        	f = false;
            h = false;
            d ++;
       		 for(int i = 0; i < b; i++){
     		 	if(( c[i] - a ) == d){
         			f = true;
         		}
               if(( c[i] - a ) == -d){
         			h = true;
         		}
     		}
        }
             for(int i = 0; i < b; i++){
     		 	if( c[i] - a  ==  -d){
         			g = false;
         		}
     		}
       if(g){
    	System.out.println(a - d);   	
       }else{
       	System.out.println(a + d);
       }
	
      } 
      else{
      	System.out.println( a );
      }
	}
}


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

int main(){
  int N,K;cin>>N>>K;
  long long k1=0;
  long long k2=0;
  if(K%2==0){
    for(int i=1;i<=N;i++){
      if(i%K==0)
        k1++;
      else if(i%K==K/2)
        k2++;
    }
    //cout<<k1<<" "<<k2<<endl;
    cout<<k1*k1*k1 + k2*k2*k2;
    
  }
  else{
    for(int i=1;i<=N;i++){
      if(i%K==0)
        k1++;
    }
    //cout<<k1<<" "<<k2<<endl;
    cout<<k1*k1*k1;
  }
}

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

int main(){
 int mountain,first=0,second=0,third=0;
 for(int i=0;i<10;i++){
  cin>>mountain;
  if(mountain>first){
   third=second;
   second=first;
   first=mountain;
  }else if(mountain>second){
   third=second;
   second=mountain;
  }else if(mountain>third){
   third=mountain;
  }
 }
 cout<<first<<'\n'<<second<<'\n'<<third<<'\n';
 return 0;
}

Measured memory_bytes: 1160
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.nextInt();
        List<Integer> A = new ArrayList<>();
        Set<Integer> set = new TreeSet<>();
        HashMap<Integer, Integer> count = new HashMap<>();
        for (int n = 0; n < N; n++) {
            int i = in.nextInt();
            A.add(i);
            set.add(i);
            count.put(i, count.getOrDefault(i, 0) + 1);
        }

        boolean[] b = new boolean[1000001];
        for (int a : set) {
            if (b[a]) continue;
            for (int i = a + a; i < 1000001; i += a)
                b[i] = true;
        }

        int ans = 0;
        for (int a : A) {
            if (!b[a] && count.get(a) == 1)
                ans++;
        }
        out.println(ans);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 92548
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define DREP(i,n,N) for(int i=n;i>=N;i--)
#define print(S) cout<<S<<endl;
using namespace std;

int main() {
	long long int x,a,A;
	cin>>x;
	a=x/11;
	A=x%11;
	if(A==0){
		print(a*2);
	}else if(0<A&&A<7){
		print(a*2+1);
	}else{
		print(a*2+2);
	}
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Prelude hiding (putStrLn, getLine, getContents)
import Data.List as L
import Data.Text as T
import Data.Text.IO

main :: IO ()
main = putStrLn . f =<< getLine
  where f x = if (sort $ splitOn " " x) == ["5", "5", "7"] then "YES" else "NO"

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

bool solve(int pos, vi v) {
    int res = 5;
    while(res>0) {
        res -= v[pos++];
        if(res<0) return false;
    }
    res = 7;
    while(res>0) {
        res -= v[pos++];
        if(res<0) return false;
    }
    res = 5;
    while(res>0) {
        res -= v[pos++];
        if(res<0) return false;
    }
    res = 7;
    while(res>0) {
        res -= v[pos++];
        if(res<0) return false;
    }
    res = 7;
    while(res>0) {
        res -= v[pos++];
        if(res<0) return false;
    }
    return true;
}

int main()
{
    int n;
    while(cin>>n, n) {
        vi v;
        rep(i,n) {
            string s;
            cin >> s;
            v.push_back(s.size());
        }
        rep(i,n) {
            if(solve(i,v)) {
                P(i+1);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3116
N=int(input())
xyh=[list(map(int,input().split()))for _ in range(N)]
hxy=[[h,x,y]for x,y,h in xyh]
hxy.sort()
for X in range(101):
    for Y in range(101):
        h,x,y=hxy[-1]
        H=h+abs(X-x)+abs(Y-y)
        if all(h==max(H-abs(X-x)-abs(Y-y),0)for h,x,y in hxy):
            print(X,Y,H)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;


int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    REP(i,s.size()){
        if(s[i] =='?'){
            s[i] = 'D';
            cout << s[i];
        }
        else cout << s[i];
    }
}
 

Measured memory_bytes: 3784
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll k;
    cin >> k;
    vll a(n,0);
    ll sum = 0;
    REP(i,n){
        cin >> a[i];
        sum+=a[i];
    }
    ll ans = 1;
    for(ll i=1;i*i<=sum;i++){
        if(sum%i!=0){
            continue;
        }
        {
            ll now = i;
            ll tmp = 0;
            vll rem(n,0);
            REP(j,n){
                ll aj = a[j];
                aj %= now;
                rem[j]=aj;
            }
            sort(ALL(rem));
            ll last = n-1;
            REP(j,n){
                if(j>=last){
                    break;
                }
                ll x = rem[j];
                tmp+=x;
                rem[j]=0;
                while(x>0){
                    ll y = min(x,now-rem[last]);
                    x-=y;
                    rem[last]+=y;
                    if(rem[last]==now){
                        last--;
                    }
                }
            }
            if(tmp<=k){
                ans = max(ans,now);
            }
        }
        ////////////////////////////////
        {
            ll now = sum/i;
            //cout << now <<" ";
            ll tmp = 0;
            vll rem(n,0);
            REP(j,n){
                ll aj = a[j];
                aj %= now;
                rem[j]=aj;
            }
            sort(ALL(rem));
            ll last = n-1;
            REP(j,n){
                if(j>=last){
                    break;
                }
                ll x = rem[j];
                tmp+=x;
                rem[j]=0;
                while(x>0){
                    ll y = min(x,now-rem[last]);
                    x-=y;
                    rem[last]+=y;
                    if(rem[last]==now){
                        last--;
                    }
                }
            }
            //cout << tmp << endl;
            if(tmp<=k){
                ans = max(ans,now);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;


int main(){

char x, y;
cin >> x >> y;
char ans;
if(x > y) ans = '>';
else if(x == y) ans = '=';
else ans = '<';
cout << ans << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <vector>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))

using namespace std;

typedef long long ll;

int group(int n){
    if(n==2)
        return 2;
    else if(n==4 || n==6 || n==9 || n==11)
        return 1;
    else
        return 0;

}

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int x,a,b;
    cin >> x >> a >> b;
    cout <<(abs(a-x)<abs(b-x)? "A":"B") << endl;
    return 0;
}


Measured memory_bytes: 256
def goodinteger(inputstr):
  a=inputstr[0]
  b=inputstr[1]
  c=inputstr[2]
  d=inputstr[3]
  return (b==c and (a==b or c==d))
  

def test1(inputstr):
  if goodinteger(inputstr):
    return 'Yes'
  else:
    return 'No'
      
 
if __name__ == '__main__':
  inputstr = input()
  print(test1(inputstr), flush=True)

Measured memory_bytes: 3060
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
def judge(k, M):
    while M%k==0:
        M //= k
    return M%k == 1

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

l = make_divisors(N)+make_divisors(N-1)
ans = 0
for x in l:
    if x == 1:
        continue
    if judge(x, N):
        ans += 1
print(ans)


Measured memory_bytes: 5328
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int a, b, c, d, p;
    cin >> a >> b >> c >> d >> p;
    cout << min(a*p, b+d*max(p-c, 0)) << "\n";
    return 0;
}



Measured memory_bytes: 3092
#include <stdio.h>

using namespace std;

struct Node{
	Node(){
		left_child = right_child = parent = -1;
	}
	int left_child,right_child,parent;
};

class Heap{
public:
	Heap(int H){
		index = 0;
		array = new long long[H];
		struct_array = new Node[H];
	}
	~Heap(){
		delete[] array;
	}
	void push(long long data){
		array[index] = data;
		if(index != 0){
			if(index%2 == 0){
				struct_array[(index-1)/2].right_child = index;
				struct_array[index].parent = (index-1)/2;
			}else{
				struct_array[index/2].left_child = index;
				struct_array[index].parent = index/2;
			}
		}
		index++;
	}

	void print(){
		for(int i = 0; i < index; i++){
			printf("node %d: key = %d, ",i+1,array[i]);
			if(struct_array[i].parent != -1) printf("parent key = %lld, ",array[struct_array[i].parent]);
			if(struct_array[i].left_child != -1) printf("left key = %lld, ",array[struct_array[i].left_child]);
			if(struct_array[i].right_child != -1) printf("right key = %lld, ",array[struct_array[i].right_child]);
			printf("\n");
		}
	}

private:
	long long* array;
	Node* struct_array;
	int index;
};

int main(){
	int H;
	long long tmp;
	scanf("%d",&H);
	Heap heap(H);

	for(int i = 0; i < H; i++){
		scanf("%lld",&tmp);
		heap.push(tmp);
	}
	heap.print();
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define each(i, mp) for (auto &i : mp)
#define size(x) int(x.size())

int main()
{
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k <= a)
  {
    cout << k << endl;
    return 0;
  }
  if (k <= a + b)
  {
    cout << a << endl;
    return 0;
  }
  cout << a - (k - (a + b)) << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<cmath>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<utility>
#include<list>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
struct XY
{
	int x;
	int y;
};


/*
(char)'1' - (int)48 = (int)1;


*/
int main()
{
	int h, w;
	cin >> w>> h;
	while (w != 0 || h != 0)
	{
		queue<XY> m;
		XY fis;
		int a[200][200] = {};
		for (int i = 0; i < h; i++)
		{
			for (int l = 0; l < w; l++)
			{
				char r;
				cin >> r;
				if (r == '.')
					a[i + 1][l + 1] = 1;
				else if (r == '@')
				{
					fis.x = l + 1;
					fis.y = i + 1;
				}

			}
		}


		int ans = 1;
		m.push(fis);
		while (!m.empty())
		{
			XY gg;
			int x, y;
			x = m.front().x;
			y = m.front().y;
			m.pop();

			for (int i = 0; i < 4; i++)
			{
				if (a[y + dy[i]][x + dx[i]] == 1)
				{
					ans++;
					a[y + dy[i]][x + dx[i]] = 0;
					gg.x = x + dx[i];
					gg.y = y + dy[i];
					m.push(gg);
				}
			}

		}

		cout << ans << endl;
		cin >> w >> h;
	}
}

Measured memory_bytes: 1376
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f;
int n,m;
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i;
	cin>>n>>m;
	if(m&1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	m=m/2;
	if(m>=n&&m<=n*2)
		cout<<"Yes"<<endl;
	else 
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3588
s = input()

cnt = 0

if( s == "SUN" ):
  cnt = 7
elif( s == "MON" ):
  cnt = 6
elif( s == "TUE" ):
  cnt = 5
elif( s == "WED" ):
  cnt = 4
elif( s == "THU" ):
  cnt = 3
elif( s == "FRI" ):
  cnt = 2
elif( s == "SAT" ):
  cnt = 1
  
print(cnt)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

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


Measured memory_bytes: 2748