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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,a,d;
int m;
int x[252521],y[252521],z[252521];
int k;

int main(){
  scanf("%d%d%d%d",&n,&a,&d,&m);
  REP(i,m)scanf("%d%d%d",x+i,y+i,z+i),--y[i],--z[i];
  scanf("%d",&k),--k;
  FORR(i,0,m){
    if(x[i]!=0)continue;
    int l = y[i], r = z[i];
    if(!(l<=k && k<=r))continue;
    k -= l; r -= l;
    k = r-k;
    k += l;
  }
  int val = a + d*k;
  REP(i,m){
    if(x[i]==0){
      int l = y[i], r = z[i];
      if(!(l<=k && k<=r))continue;
      k -= l; r -= l;
      k = r-k;
      k += l;
    }else if(x[i]==1){
      if(y[i]<=k && k<=z[i])val++;
    }else{
      if(y[i]<=k && k<=z[i])val/=2;
    }
  }
  printf("%d\n",val);
  return 0;
}

Measured memory_bytes: 3352
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int,int>
using namespace std;

double INF = 1e100;
double EPS = 1e-12;

struct PT { 
  double x, y; 
  PT() {}
  PT(double x, double y) : x(x), y(y) {}
  PT(const PT &p) : x(p.x), y(p.y)    {}
  PT operator + (const PT &p)  const { return PT(x+p.x, y+p.y); }
  PT operator - (const PT &p)  const { return PT(x-p.x, y-p.y); }
  PT operator * (double c)     const { return PT(x*c,   y*c  ); }
  PT operator / (double c)     const { return PT(x/c,   y/c  ); }

  bool operator<(const PT &p) const{
  	if(fabs(x - p.x) < EPS) return y - p.y < -EPS;
  	return x - p.x < -EPS;
  }
};

double dot(PT p, PT q)     { return p.x*q.x+p.y*q.y; }
double dist2(PT p, PT q)   { return dot(p-q,p-q); }
PT RotateCCW90(PT p)   { return PT(-p.y,p.x); }

vector<PT> CircleCircleIntersection(PT a, PT b, double r, double R) {
  vector<PT> ret;
  double d = sqrt(dist2(a, b));
  if (d > r+R) return ret;
  if( d+min(r, R) < max(r, R)){
  	if(r < R) ret.pb(a);
  	else ret.pb(b);
  	return ret;
  }
  double x = (d*d-R*R+r*r)/(2*d);
  double y = sqrt(r*r-x*x);
  PT v = (b-a)/d;
  ret.push_back(a+v*x + RotateCCW90(v)*y);
  if (y > 0)
    ret.push_back(a+v*x - RotateCCW90(v)*y);
  return ret;
}

int n, k;
PT P[70];
int c[70];
double r[70];

set<PT> in;
bool f(double t){
	for(int i = 0; i < n; i++) r[i] = t/(1.0*c[i]);
	in.clear();
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			vector<PT> inter = CircleCircleIntersection(P[i], P[j], r[i], r[j]);
			for(int k = 0; k < inter.size(); k++){
				in.insert(inter[k]);
				//printf("%lf %lf\n%lf %lf\n", P[i].x, P[i].y, inter[k].x, inter[k].y);
				//printf("%lf %lf\n", r[i], sqrt(dist2(P[i], inter[k])));
			}
		}
	}
	for(auto it = in.begin(); it != in.end(); it++){
		int tot = 0;
		for(int i = 0; i < n; i++) tot += sqrt(dist2(P[i], *it)) - r[i] < EPS;
		//printf("%lf %lf\n", (*it).x, (*it).y);
		if(tot >= k) return true;
	}
	return false;
}
int main(){
	scanf("%d %d", &n, &k);
	if(k == 1){
		printf("0\n");
		return 0;
	}
	for(int i = 0; i < n; i++){
		int x, y;
		scanf("%d %d %d", &x, &y, &c[i]);
		P[i] = PT(x,y);
	}

	double lo = 0, hi = 1e7, mid;
	int iter = 0;
	while(iter++ < 100){
		mid = (lo + hi)/2.0;
		if(f(mid)) hi = mid;
		else lo = mid;
	}
	printf("%.10lf\n", lo);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K, S;
    cin >> N >> K >> S;
    ll Sub = S + 1;
    if(S == 1e9) Sub = 1;
    for(int i = 0; i < N; i++) {
        if(i != 0) cout << " ";
        if(i < K) cout << S;
        else cout << Sub;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
#! /usr/bin/ruby -w
# encoding: utf-8
#

def puts_array(a)
  sep = ''
  a.each do |e|
    print sep + e.to_s
    sep = ' '
  end
  puts
end

def insertion_sort(a, n)
  1.upto(n - 1) do |i|
    puts_array(a)
    v = a[i]
    j = i - 1
    while 0 <= j and v < a[j]
      # ?????????
      a[j + 1] = a[j]
      j -= 1
    end
    #???????????¨??????????????????
    a[j + 1] = v

  end
  puts_array(a)
end

if $0 == __FILE__
  n = gets.to_i
  a = gets.chomp.split.map(&:to_i)
  insertion_sort(a, n)
end

Measured memory_bytes: 8792
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N;
	int p[20010]={};
	
	int a[20010]={};
	int b[20010]={};

	cin >> N;
	for(int i=0;i<N;i++)
	{
		cin >> p[i];
		p[i]--;
	}
	
	a[0]=1;
	b[N-1]=1;
	for(int i=1;i<N;i++)
	{
		a[i]=a[i-1]+20000;
		b[N-1-i]=b[N-1-i +1]+20000;
	}

	for(int i=0;i<N;i++)
		a[p[i]]+=i;

	for(int i=0;i<N;i++)
	{
		cout << a[i];
		if(i==N-1)cout << endl;
		else cout << " ";
	}
	for(int i=0;i<N;i++)
	{
		cout << b[i];
		if(i==N-1)cout << endl;
		else cout << " ";
	}
	return 0;
}


Measured memory_bytes: 896
import sys
readline = sys.stdin.readline
H, W, B, A = map(int, readline().split())

S = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if not ((i < A) ^ (j < B)):
            S[i][j] = 1
print('\n'.join([''.join(map(str, a)) for a in S]))


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  if (N * A < B) {
    cout << N * A << endl;
  }
  
  if (N * A > B) {
    cout << B << endl;
  }
  
  if (N * A == B) {
    cout << B << endl;
  }
  
}

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

int main() {
  int X;
  cin >> X;
  int dekai = X / 500;
  int kitanai = dekai * 1000;
  int chiisai = X % 500;
  int am = chiisai / 5;
  int unko = am * 5;
  cout << kitanai + unko << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, p1, p2, x;

            var word = Console.ReadLine().Split(' ');

            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);
            p1 = (a * n);
            p2 = b;

            if ((a * n) >= (b))
            Console.WriteLine(p2); 

            else
            Console.WriteLine(p1);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

int main(void){
	int x;
	int i=0;
	while(1){
	 scanf("%d",&x);
		if(x!=0){
		printf("Case %d: %d\n",i+1,x);
		}
		if(x==0){
			break;
		}
		i++;
}

return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long N, K; cin >> N >> K;
    map<long long, long long> vals;
    rep (i, 0, N) {
        long long a, b; cin >> a >> b;
        vals[a] += b;
    }
    long long counter = 0;
    for (auto& val : vals) {
        counter += val.second;
        if (K <= counter) {
            cout << val.first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4224
listA = list(map(int,input().split()))
listB = []
listC = []
for i in range(listA[0]):
    listB.append(list(map(int,input().split())))
[listC.append(i) for i in listB if i[1] <= listA[1]]
f = lambda a, b: a if a[0] < b[0] else b
c = [1001, 1001]

for i in listC:
    c = f(i, c)
d = c[0] if c[1] < 1001 else 'TLE'
print(d)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
	ll n, k, ans = 0;
	cin >> n >> k;
	if (k == 0)cout << n * n << endl;
	else {
		for (int i = k + 1; i <= n; i++) {
			ll num = n / i;
			ans += num * (i - k);
			num = n - num * i;
			if (num >= k)ans += num - k + 1;
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;
#define Pi acos(-1)
#define _terminated return 0
#define endl "\n"
#define yes cout << "yes" << endl 
#define no cout << "no" << endl 
#define booster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<long> > v2l;

const int mod = 1e+5;
const int mx = 2e+5;
const ll inf = 1e18;

using namespace std;
#define max 101 
void solvio(){ 	
     int a,b,i; 
     cin >> a >> b; 
    if(a>b){ 
        for(i=1; i<=a; i++) cout << b;
         } else{
         for(i=1; i<=b; i++)
            cout << a; 
        } 
    cout << endl;
    
}

int main(){ 
    booster;
    solvio(); 
    _terminated;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
q main(){
    s ss;
    cin>>ss;
    for(int i=0;i<ss.size();i++){
        if(ss[i]==','){ss[i]=' ';}
    }
    cout<<ss;







return 0;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
using namespace std;
bool comp(int a, int b) 
{ 
    return (a < b); 
} 
signed main()
{
	int a, b;
	cin>>a>>b;
	if(a >=13)
		cout<<b<<endl;
	else if( a >=6 and a <=12)
		cout<<b/2<<endl;
	else
	{
		cout<<0<<endl;
	}

}

Measured memory_bytes: 256
D = int(input())
c = list(map(int, input().split()))
last = [0] * 26
S = []
for d in range(1, D+1):
    sd = list(map(int, input().split()))
    S += [sd]
score = 0
for d in range(1, D+1):
    td = int(input()) - 1

    cumsump = 0
    for i in range(26):
        if td != i:
            tmp = -c[i] * (d - last[i])
            cumsump += tmp
    last[td] = d
    score += S[d-1][td]+cumsump
    
    print(score)

Measured memory_bytes: 69836
#include<bits/stdc++.h>
using namespace std;
  int n=100005;
  

int main()
{
  
    cin>>n;
   int a,b,c,a1,b1,c1;
   a1=0,b1=0,c1=0;
   cin>>a1>>b1>>c1;
    for(int i=1;i<n;i++)
    {
        cin>>a>>b>>c;
        a+=max(b1,c1);
        b+=max(a1,c1);
        c+=max(a1,b1);
        a1=a,b1=b,c1=c;

    }
  

cout<<max(a1,max(b1,c1));

}

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

#define REP(i, x) REPI(i, 0, x)
#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;
using namespace std;

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

  int N;
  cin >> N;
  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  int ans = 2;
  int cnt = 1;
  while (N >= pow(2, cnt)) {
    ans = pow(2, cnt);
    ++cnt;
  }
  cout << ans << 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);
    long N =sc.nextLong(); 
    long A =sc.nextLong();
    long B =A+sc.nextLong();
    long m =N/B;
    long n=N%B;
    if(n<A){System.out.println(m*A+n);}
    else{System.out.println((m+1)*A);}
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

map<int,int> s;

bool divisor(int n){
    if(n==1){
        if(s[1]>1)return false;
        else return true;
    }
    bool tmp=true;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            if(s.count(i)){
                tmp=false;
                break;
            }
            if(s.count(n/i)){
                if(i==1){
                    if(s[n]>1){
                        tmp=false;
                        break;
                    }
                }
                else{
                    tmp=false;
                    break;
                }
            }
        }
    }
    return tmp;
}

int main(){
    int n;cin>>n;
    vin a(n);
    rep(i,n){
        cin>>a[i];
        s[a[i]]++;
    }
    int ans=0;
    rep(i,n)if(divisor(a[i]))ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 13552
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

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

    int n;
    cin >> n;
    // dp[i] := i 番目が 1 である場合の数 ( 便宜上 dp[0] = 1 )
    vector<modint> dp(n + 3);
    dp[0] = dp[1] = 1;
    modint ans = 0;
    for(int i = 1; i < n; ++i){
        dp[i + 2] += dp[i + 1];
        dp[i + 1] += dp[i];
        dp[i + 2] += dp[i - 1];
        ans += dp[i - 1] * n * i;
        ans += dp[i - 1] * (n - 1) * (n - i - 1);
    }
    ans += dp[n] + dp[n - 1] * (n - 1);
    cout << ans << endl;
}

Measured memory_bytes: 7120
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	sc.Split(bufio.ScanWords)

	H, W := nextInt(), nextInt()
	field := make([]string, H)

	for i := 0; i < H; i++ {
		field[i] = nextLine()
	}

	cnt := 0
	for j := 0; j < H; j++ {
		for i := 0; i < W; i++ {
			if field[j][i] == '#' {
				cnt++
			}
		}
	}
	if H+W-1 == cnt {
		fmt.Println("Possible")
	} else {
		fmt.Println("Impossible")
	}

}


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

int main()
{
    int N, M;
    cin >> N >> M;

    vector<bool> aced(N, false);
    vector<int> cnt_wa(N, 0);
    int n_ac = 0, n_wa = 0;
    for (int i = 0; i < M; i++)
    {
        int pi;
        string Si;
        cin >> pi >> Si;

        if (!aced.at(pi - 1))
        {
            if (Si == "AC")
            {
                aced.at(pi - 1) = true;
                n_ac++;
                n_wa += cnt_wa.at(pi - 1);
            }
            else
            {
                cnt_wa.at(pi - 1) += 1;
            }
        }
    }
    cout << n_ac << " " << n_wa << endl;
}

Measured memory_bytes: 640
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

a = sorted(list(map(int, input().split())))
print(a[0] + a[1])

Measured memory_bytes: 5044
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	string s; cin >> s;
	rep(i, 0, s.size()) {
		if (s[i] == s[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		else if (s[i] == s[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}

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

int main(){
    int n, ans, sum, prime, tem;
    cin >> n;
   
   ans = 0;
   for ( int i = 1; i <= n ; i+=2 ) {
       sum = 1;
       tem = i;
       
       for ( int j = 2; j*j <= i ; j++ ) {
           if ( tem % j == 0 ) {
               prime = 0;
               
               while ( tem % j == 0 ) {
                   tem /= j;
                   prime++;
               }
               
               sum *= prime + 1;
           }
       }
       
       if ( tem > 1 ) {
           sum *= 2;
       }
       
       if ( sum == 8 ) {
           ans ++;
       }
    }
    cout << ans << endl;
   
    return (0);
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}

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


 ll a,b,c,d,e;
 cin>>a>>b>>c>>d>>e;
 if(a==0)
 {
     cout<<1<<endl;
 }
 else if(b==0)
 {
     cout<<2<<endl;
 }
 else if(c==0)
 {
     cout<<3<<endl;
 }
 else if(d==0)
 {
     cout<<4<<endl;
 }
 else
 {
     cout<<5<<endl;
 }
return 0;
}



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

int main(){
  ll k,ans=-1,s=7,t=1;
  cin >> k;
  
  for(int i=1;i<=k;i++){
    s %= k;
    if(s == 0){
      ans = i;
      break;
    }
    
    s = s*10 +7;    
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int D, T, S;
 
    cin >> D >> T >> S;
 
    if (S*T>=D) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
 


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

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> data(h+2,vector<char>(w+2,'#'));
    vector<pii> path;
    rep(i,h){
        rep(j,w){
            char c;
            cin >> c;
            data.at(i+1).at(j+1) = c;
            if(c == '.') path.push_back(pii(i+1,j+1));
        }
    }
    int m = path.size();
    int ans = 0;
    rep(i,m){
        int sx = path.at(i).first;
        int sy = path.at(i).second;
        queue<pii> que;
        vvi dist(h+2,vi(w+2,-1));
        dist.at(sx).at(sy) = 0;
        que.push(pii(sx,sy));
        while(que.size()){
            pii P = que.front();
            que.pop();
            rep(l,4){
                int nx = P.first + dx[l];
                int ny = P.second + dy[l];
                if(data.at(nx).at(ny) == '#') continue;
                if(dist.at(nx).at(ny) != -1) continue;
                dist.at(nx).at(ny) = dist.at(P.first).at(P.second)+ 1;
                ans = max(dist.at(nx).at(ny),ans);
                que.push(pii(nx,ny));
            }
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int main() {
    int N;
    double ans = 0;
    cin >> N;
    for(int i = 0; i < N; ++i) {
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY")
            ans += x;
        else
            ans += x * 380000;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int t[205][2];
int mov[4][2]={{-1,0},{0,-1},{1,0},{0,1}};
int main(){
	int n;
	int a,b,c;
	int i,j,k;
	int s[2];
	while(cin>>n){
		if(!n)break;
		t[0][0]=0,t[0][1]=1;
		for(i=1;i<n;i++){
			cin>>a>>b;
			t[i][0]=t[a][0]+mov[b][0];
			t[i][1]=t[a][1]+mov[b][1];
		}
		for(i=0;i<2;i++){
			a=500,b=-500;
			for(j=0;j<n;j++){
				if(t[j][i]<a)a=t[j][i];
				if(t[j][i]>b)b=t[j][i];
			}
			s[i]=b-a+1;
		}
		cout<<s[0]<<" "<<s[1]<<endl;
	}
}



Measured memory_bytes: 2984
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] ary=new int[N];
		for(int i=0; i<N; i++) {
			ary[i]=sc.nextInt();
		}
		Arrays.sort(ary);
		int max=ary[N-1];
		int k=Integer.MAX_VALUE;
		int ati=0;
		for(int i=0; i<N; i++) {
			int tmp=ary[i];
			if(max%2==1) {
				if(k>Math.abs(ary[i]-(max+1)/2)) {
					ati=tmp;
					k=Math.abs(ary[i]-(max+1)/2);
				}
			}
			else if(max%2==0) {
				if(k>Math.min(Math.abs(ary[i]-(max/2)),Math.abs(ary[i]-(max)/2)+1)) {
					ati=tmp;
					k=Math.min(Math.abs(ary[i]-(max/2)),Math.abs(ary[i]-(max)/2)+1);
				}
			}
		}
		System.out.println(max+" "+ati);
		sc.close();
	}
}

Measured memory_bytes: 50796
import java.util.*;


public class Main {
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.next());
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      int train = n * a;
      if (train > b) {
        System.out.print(b);
      } else {
        System.out.print(train);
      }     
    }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
  ll X, Y;
  cin >> X >> Y;

  if(abs(X - Y) >= 2) {
    cout << "Alice" << endl;
    return 0;
  }else {
    cout << "Brown" << endl;
    return 0;
  }

}


Measured memory_bytes: 256
def p_d():
    hb, wb = map(int, input().split())
    t = [input() for _ in range(hb)]
    lb = [[0] * (wb + 2) for _ in range(hb + 2)]
    rb = [[0] * (wb + 2) for _ in range(hb + 2)]
    ub = [[0] * (wb + 2) for _ in range(hb + 2)]
    db = [[0] * (wb + 2) for _ in range(hb + 2)]
    for h in range(1, hb + 1):
        for w in range(1, wb + 1):
            if t[h - 1][w - 1] != "#":
                lb[h][w] = lb[h][w - 1] + 1
                ub[h][w] = ub[h - 1][w] + 1
            if t[hb - h][wb - w] != "#":
                rb[hb - h + 1][wb - w + 1] = rb[hb - h + 1][wb - w + 2] + 1
                db[hb - h + 1][wb - w + 1] = db[hb - h + 2][wb - w + 1] + 1
    ans = 0
    for h in range(1, hb + 1):
        for w in range(1, wb + 1):
            tmp = lb[h][w] + rb[h][w] + ub[h][w] + db[h][w]
            ans = max(ans, tmp - 3)
    print(ans)
    
p_d()

Measured memory_bytes: 178692
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int n =  sc.nextInt();
	int[] x = new int[n];
	int sum = 0;
	int ans = Integer.MAX_VALUE;

	for(int i=0;i<n;i++) {
		x[i] = sc.nextInt();
	}

	for(int i=1;i<=100;i++) {
		for(int j=0;j<n;j++) {
			sum += (x[j]-i)*(x[j]-i);
		}
	ans = Math.min(sum, ans);
	sum = 0;
	}
	System.out.println(ans);
  }
}

Measured memory_bytes: 21972
n,m=list(map(int, input().split()))
h=list(map(int, input().split()))
p=[]
remain = set(range(1, n+1))
for i in range(m):
    p.append(list(map(int, input().split())))
temp = []
for a,b in p:
    temp.append([b,a])
p = p + temp
delset = set()
for a,b in p:
    if h[a-1]<=h[b-1]:
        #remain = remain - set([a])
        delset.add(a)
remain = remain - delset
print(len(remain))

Measured memory_bytes: 120140
#include<stdio.h>
int main(){
  int n,m,k,i,anum=0;
  scanf("%d%d%d",&n,&m,&k);
  int a[n+1],check=0,max=0;
  int b[m+1];
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
    if(k-a[i]>=0 && check==0){
      anum=i;
      k-=a[i];
    }
    else
      check=1;
  }
  max=anum;
  for(i=1;i<=m;i++)
    scanf("%d",&b[i]);
  for(i=1;i<=m;i++){
    while(k<b[i]){
      k+=a[anum];
      anum--;
      if(anum<1)
        break;
    }
    if(anum<0)
      break;
    k-=b[i];
    if(i+anum>max)
      max=i+anum;
  }
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 3296
from collections import defaultdict

N, K = map(int, input().split())
d = defaultdict(int)
for i in range(N):
    a, b = map(int, input().split())
    d[a] += b
for k in sorted(d.keys()):
    K -= d[k]
    if K <= 0:
        print(k)
        exit()


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

int N;
vector<vector<P>> xy;

bool judge(int bit) {
	rep(i, N) {
		if(!(bit & (1 << i))) continue;

		for(P p : xy[i]) {
			int x = p.first;
			int y = p.second;

			if(y == 0 && (bit & (1 << x))) return false;
			if(y == 1 && !(bit & (1 << x))) return false;
		}
	}
	return true;
}

int main() {
	cin >> N;
	xy.resize(N);
	rep(i, N) {
		int A;
		cin >> A;
		xy[i].resize(A);
		rep(j, A) {
			cin >> xy[i][j].first >> xy[i][j].second;
			--xy[i][j].first;
		}
	}

	int ans = 0;
	rep(bit, 1 << N) {
		if(judge(bit)) {
			int cnt = 0;
			rep(i, N) {
				if(bit & (1 << i)) ++cnt;
			}
			ans = max(ans, cnt);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
//aoj 0005
using namespace std;
int x,y;
int gcd(int a,int b)
{
	if(b==0)
	{
		return a;
	}else{
		return gcd(b,a%b);
	}
}
int lcm(int a,int b)
{
	return (long long)a*b/gcd(a,b);
}
int main()
{
	while(scanf("%d%d",&x,&y)!=EOF)
	{
		printf("%d %d\n",gcd(x,y),lcm(x,y));
	}
	return 0;
}










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

int	intcmp(const void *n1, const void *n2)
{
	return (*(int *)n2 - *(int *)n1);
}

int	main()
{
	int	N;
	int	i;
	int	dif;
	int	*cards;

	i = 0;
	dif = 0;
	scanf("%d\n", &N);
	cards = (int *)malloc(sizeof(int) * (N + 1));
	while (i < N)
	{
		scanf("%d ", &cards[i]);
		i++;
	}
	qsort(cards, i, sizeof(int), intcmp);
	i = 0;
	while (i < N)
	{
		dif += cards[i] - cards[i + 1];
		i += 2;
	}
	printf("%d\n", dif);
	return (0);
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    long long dp[n][n], a[n], pfx[n + 1];
    pfx[0] = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        pfx[i + 1] = pfx[i] + a[i];
    }
    for (int len = 1; len <= n; len++) {
        for (int i = 0; i < n - len + 1; i++) {
            int r = i + len - 1;
            if (len == 1) {
                dp[i][r] = a[i];
                continue;
            }
            dp[i][r] = 1000000001ll * 1000000001;
            for (int mid = i; mid < r; mid++) dp[i][r] = min(dp[i][r], dp[i][mid] + dp[mid + 1][r] + pfx[r + 1] - pfx[i]);
        }
    }
    cout << dp[0][n - 1] - pfx[n];
    return 0;
}


Measured memory_bytes: 1664
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| min!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(z) = it.next() {
            Some(it.fold(z, |x, y| max!(x, y)))
        } else {
            None
        }
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut xs: Vec<usize> = (0..n).map(|_| sc.cin()).collect();
    xs.sort();
    put!(xs[n/2] - xs[n/2 - 1]);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 11508
from fractions import gcd

k = int(input())
s = 0
mem = {}
for a in range(1, k + 1):
    for b in range(1, k + 1):
        if mem.get((a, b)) is None:
            g = gcd(a, b)
            mem[(a, b)] = g
            mem[(b, a)] = g
        else:
            g = mem[(a,b)]            
        for c in range(1, k + 1):
            if mem.get((g, c)) is None:
                h = gcd(g, c)
                mem[(g, c)] = h
                mem[(c, g)] = h
                s += h
            else:
                s += mem[(g, c)]
print(s)


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

int main() {
  int *A, H, id, k, pk, lk, rk;

  scanf( "%d" , &H );
  A = malloc((H+1) * sizeof(int));
  for ( id=1; id<=H; id++ ) scanf( "%d" , &A[id] );

  for ( id=1; id<=H; id++ ) {
    printf( "node %d: key = %d, " , id , A[id] );
    if ( id/2 >= 1 ) printf( "parent key = %d, " , A[id/2] );
    if ( id*2 <= H ) printf( "left key = %d, " , A[id*2] );
    if ( id*2+1 <= H ) printf( "right key = %d, " , A[id*2+1] );
    printf( "\n" );
  }
  
  return 0;
}



Measured memory_bytes: 2048
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] dp = new int[N+1];
        for(int n=0; n<=N; n++) dp[n] = n;
        for(int n=1; n<=N; n++){
            int m = 1;
            while(m<=N){
                if(n>=m) dp[n] = Math.min(dp[n], 1+dp[n-m]);
                m *= 6;
            }
            m = 1;
            while(m<=N){
                if(n>=m) dp[n] = Math.min(dp[n], 1+dp[n-m]);
                m *= 9;
            }
        }
        System.out.println(dp[N]);
    }
}


Measured memory_bytes: 36064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7
#define eb emplace_back


int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    int ans = 0;
    if (k > n) ans = 0;
    else if (k == 1) {
        ans = 0;
    } else {
        n -= k;
        ans = n;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
S = list(input())
ans = []
for i in range(len(S)):
    if S[i]=="A":
        ans.append(i)
        break
T = S[::-1]
for i in range(len(T)):
    if T[i]=="Z":
        ans.append(i)
        break
print((len(S)-ans[0])-ans[1])

Measured memory_bytes: 6308
let id x = x

let (>>=) l f = List.flatten (List.map f l)

type tree = False
          | True
          | Var of int
          | Neg of tree
          | Xor of tree * tree
          | And of tree * tree

let parse str =
  let rec loop i = match String.get str i with
      '0' -> (False, i + 1)
    | '1' -> (True, i + 1)
    | 'a' .. 'd' as c -> (Var (Char.code c - Char.code 'a'), i + 1)
    | '-' -> let (t, i) = loop (i + 1) in
             (Neg t, i)
    | '(' -> let (t1, j) = loop (i + 1) in
             let (t2, k) = loop (j + 1) in
             if String.get str j = '^' then
               (Xor (t1, t2), k + 1)
             else
               (And (t1, t2), k + 1)
    | _ -> raise (Failure "") in
  let (t, _) = loop 0 in
  t

let rec truth_table t =
  match t with
  | False -> 0
  | True -> 0xffff
  | Var 0 -> 0x5555
  | Var 1 -> 0x3333
  | Var 2 -> 0x0f0f
  | Var 3 -> 0x00ff
  | Neg t -> lnot (truth_table t) land 0xffff
  | Xor (t1, t2) -> truth_table t1 lxor truth_table t2
  | And (t1, t2) -> truth_table t1 land truth_table t2
  | _ -> raise (Failure "")

let all_patterns =
  let gen l t = (truth_table t, l) in
  let gen' (p1, l1) (p2, l2) =
    [(p1 land p2, l1 + l2 + 3); (p1 lxor p2, l1 + l2 + 3);
     (lnot (p1 land p2) land 0xffff, l1 + l2 + 4); (lnot (p1 lxor p2) land 0xffff, l1 + l2 + 4)] in
  let ps11 = List.map (gen 1) [False; True] in
  let ps12 = List.map (gen 1) [Var 0; Var 1; Var 2; Var 3] @
               List.map (gen 2) (List.map (fun t -> Neg t) [Var 0; Var 1; Var 2; Var 3]) in
  let ps2 = ps12 >>= (fun p1 ->
              ps12 >>= (fun p2 ->
                gen' p1 p2)) in
  let ps3 = ps12 >>= (fun p1 ->
              ps2 >>= (fun p2 ->
                gen' p1 p2)) in
  let ps41 = ps2 >>= (fun p1 ->
               ps2 >>= (fun p2 ->
                 gen' p1 p2)) in
  let ps42 = ps12 >>= (fun p1 ->
               ps3 >>= (fun p2 ->
                 gen' p1 p2)) in
  List.fold_left (fun l l' -> List.rev_append l' l) ps42 [ps41; ps3; ps2; ps12; ps11]

let rec loop () =
  let str = Scanf.scanf "%s\n" id in
  if str <> "." then
    let tt = truth_table (parse str) in
    let res = all_patterns
              |> List.filter (fun (p, _) -> p = tt)
              |> List.map snd
              |> List.fold_left min 100 in
    Printf.printf "%d\n" res;
    flush stdout;
    loop ()

let () = loop ()


Measured memory_bytes: 57652
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;

    //vector<int> A; 

    int num = 0;
    int temp;
    int temp_num = 0;

    cin >> N;
    int A[N];

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

//    sort(A.begin(), A.end());
    sort(A, A + N);

    temp = A[0];
    temp_num = 1;

    for(int i=1; i<N; i++){
        if(temp == A[i]){
            temp_num++;
        }
        else{
            temp = A[i];
            num += (temp_num % 2);
            temp_num = 1;
        }
    }

    num += (temp_num % 2);

    cout << num << endl;
    
}


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

int main(){
  int x;
  cin >> x;
  int ans = 1;
  for(int i = 1; ; i++){
    if(i * 360 % x == 0){
      cout << (i * 360) / x << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		long long b=n/i;
		long long a=i;
		long long l=a+i*(b-1);
		ans+=b*(a+l)/2;
	}
	cout<<ans;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPP(i,m,n) for(ll i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    ll E = C,F = D;
    ll cnt = 0;
    vector<ll> V;
    if(C < D) swap(C,D);
    ll r = C % D;
    ll x = C*D;
    while(r!=0){
        C = D;
        D = r;
        r = C % D;
    }
    ll gcd = x/D;
  //cout << gcd << endl;
      ll ans = B/E - A/E;
    ans += B/F - A/F;
    ans -= B/gcd - A/gcd;
  if(A % gcd != 0 && A % E != 0 && A% F != 0){
    //if(B % gcd != 0 && B% E != 0 && B% F != 0){
     // cout <<(B-A)-ans+2 << endl;
      //return 0;
   // }
    cout <<(B-A)-ans+1 << endl;
    return 0;
  }
    cout << (B-A)-ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
string S;
int a[3];
int main(){
    cin>>S;
    for(auto c:S){
        switch (c){
        case 'a':a[0]++;break;
        case 'b':a[1]++;break;
        case 'c':a[2]++;break;
        default:break;
        }
    }
    sort(a,a+3);
    cout<<((S.size()/3==a[0]&&(S.size()+1)/3==a[1]&&(S.size()+2)/3==a[2])?"YES":"NO")<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(void){
  string str;
  cin >> str;
  int i;
  for(i=0; i<3; i++)
    if(str[i] == '1')
      cout << "9" ;
    else if(str[i] == '9')
      cout << "1" ;
    else{
      if(i == 0)
	cout << "???" << endl << "error!" << endl;
      else if(i == 1)
        cout << "??" << endl << "error!" << endl;
      else
        cout << "?" << endl << "error!" << endl;
      exit(1);
    }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int n, q;
int a[1000005];
priority_queue<pair<int,int>> pque;

int main()
{
	cin >> n >> q;
	REP(i, n) a[i] = 0;
	REP(i, q)
	{
		int x, y;
		cin >> x >> y;
		a[x] += y;
		pque.push(make_pair(a[x], -x));
		int ansf, ansp;
		while (1)
		{
			ansf = pque.top().first;
			ansp = pque.top().second;

			if (ansf == a[-ansp])
 			{
				cout << -ansp << " " << ansf << endl;
				break;
			}
			pque.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 6008
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
mod = 10**9+7

# 素数列挙
primes = []
is_prime = [True]*(N+1)
for i in range(2,N+1):
    if is_prime[i]:
        primes.append(i)
        j = 2
        while i*j < N+1:
            is_prime[i*j] = False
            j += 1

# 約数の集計用
from collections import defaultdict
div = defaultdict(int)

ans = 1
# N = 2 から全探索
for i in range(2,N+1):
    for p in primes:
        if p > i:
            break
        cnt = 0
        while i%p==0:
            i //= p
            cnt += 1
        div[p] += cnt

for d in div.values():
    ans *= d+1
    ans %= mod

print(ans)

Measured memory_bytes: 3316
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<iostream>
using namespace std;
int n,ans=1,m[100066];
int main(){
	cin>>n;
	bool jia=false,jian=false,flag=false;
	for(int i=1;i<=n;i++)cin>>m[i];
	for(int i=1;i<=n;i++){
		if(jia==false&&jian==false&&m[i]!=m[i+1]){
			if(m[i+1]>m[i])jia=true;
			else if(m[i+1]<m[i])jian=true;
		}
		if(i!=1) {
			if(m[i]==m[i-1])continue;
			else if(m[i]>m[i-1]){
				if(jia==false&&jian==true){
					ans++;jian=false;
				}
			}
			else if(m[i]<m[i-1]){
				if(jian==false&&jia==true){
					ans++;jia=false;
				}
			}
		}
		if(jia==false&&jian==false&&m[i]!=m[i+1]){
			if(m[i+1]>m[i])jia=true;
			else if(m[i+1]<m[i])jian=true;
		}
	}
	cout<<ans;
	return 0;
}

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

struct data{
    int l=0,r=0;
    char letter;

    explicit data(char c){
        letter = c;
    }
};

int main() {
    int N;
    cin >> N;
    string S(N,'\0');
    cin >> S;
    vector<data> chars;
    int i=0;
    for (auto &c:S) {
        static bool is_first;
        is_first = true;
        for (auto &c_list:chars) {
            if(c_list.letter==c){
                c_list.r=i;
                is_first = false;
            }
        }
        if(is_first){
            chars.emplace_back(c);
            chars.back().l=i;
            chars.back().r=i;
        }
        i++;
    }
    int max=0;
    for (int j = 0; j < N; j++) {
        static int temp;
        temp=0;
        for(auto &d:chars){
            temp += (d.l<=j&&j<d.r);
        }
        max = (temp>max)?temp:max;
    }
    cout << max;
    return 0;
}

Measured memory_bytes: 256
#! /usr/bin/env ruby

input = STDIN.read.split("\n").map{|l| l.split(" ").map{|i| i.to_i}}
d = input[1]

# even, odd のそれぞれの要素ごとの個数を数える

evens = {}
odds = {}

def countup(dic, v)
  if dic.has_key?(v) then
    dic[v] = dic[v] + 1
  else
    dic[v] = 1
  end
end

d.each_with_index do |v, i|
  if i % 2 == 1 then
    odds_cnt = odds_cnt
    countup(odds, v)
  else
    countup(evens, v)
  end
end

# それぞれの最大個数を持つ要素を取り出す
odds_max = odds.max{|x,y| x[1] <=> y[1]}
evens_max = evens.max{|x,y| x[1] <=> y[1]}

odds_max_v = odds_max[0]
odds_max_cnt = odds_max[1]
evens_max_v = evens_max[0]
evens_max_cnt = evens_max[1]

# もし、最大個数の要素が一致していたら、2番めに多い個数の要素を取り出す
if odds_max_v == evens_max_v then
  evens.delete(evens_max_v)
  odds.delete(odds_max_v)

  if evens.length == 0 then
    evens_second_max = [0,0]
  else
    evens_second_max = evens.max{|x,y| x[1] <=> y[1]}
  end

  if odds.length == 0 then
    odds_second_max = [0,0]
  else
    odds_second_max = odds.max{|x,y| x[1] <=> y[1]}
  end

  if evens_second_max[1] > odds_second_max[1] then
    evens_max_cnt = evens_second_max[1]
  else
    odds_max_cnt = odds_second_max[1]
  end
end

p d.length - evens_max_cnt - odds_max_cnt


Measured memory_bytes: 17788
n = int(input())
a_list = list(map(int, input().split()))

swap_count = 0
for i in range(0, n):
    mini = i
    for j in range(i, n):
        if a_list[j] < a_list[mini]:
            mini = j
    if i != mini:
        temp = a_list[i]
        a_list[i] = a_list[mini]
        a_list[mini] = temp
        swap_count = swap_count + 1

print(' '.join(map(str, a_list)))
print(swap_count)


Measured memory_bytes: 5596