akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  int a,b,k;
  vector<int> v;
  cin >> a >> b >> k;
  for (int i=1; i <= max(a,b); i++){
    if (a%i==0 && b%i==0){
      v.push_back(i);
    }
  }
  cout << v.at(v.size()-k) << endl;
  return 0;
}
    

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;

namespace AtCoder {
    class Practice {
        static void Main() => CustomMain();

        static void Solve() {
            var a = ReadIntArray();

            WriteAnswer((a[0] - 1) * (a[1] - 1));
        }

        static void CustomMain() {
#if DEBUG
            // ファイルからテストケースを読み込む
            global::Common.ChangeStdIn();
            // 時間計測
            var stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            // 出力高速化
            var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(streamWriter);
            // 回答
            Solve();
#if DEBUG
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
#endif
            Console.Out.Flush();
        }

        static string ReadString() => Console.ReadLine().Trim();
        static int ReadInt() => int.Parse(ReadString());
        static long ReadLong() => long.Parse(ReadString());
        static float ReadFloat() => float.Parse(ReadString());
        static double ReadDouble => double.Parse(ReadString());

        static string[] ReadStringArray() => ReadString().Split(' ');
        static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
        static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
        static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
        static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

        static T TypeConversion<T>(string s) {
            if (typeof(T) == typeof(int)) {
                return (T) Convert.ChangeType(int.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(long)) {
                return (T) Convert.ChangeType(long.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(double)) {
                return (T) Convert.ChangeType(double.Parse(s), typeof(T));
            } else {
                return (T) Convert.ChangeType(s, typeof(T));
            }
        }

        static void ReadMulti<T, U>(out T a, out U b) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
        }

        static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
            c = TypeConversion<V>(str[2]);
        }

        static void WriteAnswer(object ans) => Console.WriteLine(ans);

        static bool IsOdd(long num) {
            return (num & 1) == 1;
        }

        static bool IsEven(long num) {
            return (num & 1) == 0;
        }

        static long GCD(long a, long b) {
            return b != 0 ? GCD(b, a % b) : a;
        }
    }
}

Measured memory_bytes: 11092
using System;
using System.Linq;

namespace ABC090_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var aaa = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var A = aaa[0];
            var B = aaa[1];
            var count = 0;

            for(var i=A;i<=B;i++)
            {
                var s = i % 10;
                var t = i / 10000;
                var u = i % 10000 / 1000;
                var v = i %100 / 10;

                if (s == t && u == v)
                    count++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>

typedef long long ll;

ll LCM(ll a, ll b){
   if(a<b){
      ll tmp = a;
      a = b;
      b = tmp;
   }
   ll x = a;
   ll y = b;
   ll r = a%b;
   while(r!=0){
      a = b;
      b = r;
      r = a%b;
   }
   return y/b * x;
}

int main(){
   int N;
   std::cin >> N;
   ll ans = 1;
   ll T;
   for(int i=0; i<N; ++i){
      std::cin >> T;
      ans = LCM(ans,T);
   }
   std::cout << ans << std::endl;

   return 0;
}


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

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int N = NextInt();
        int[] A = LineInt();
        double Ave = A.Average();
        double min = INF;
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            double x = Math.Abs(Ave - (A[i] + .0));
            if (min > x) { min = x;ans = i; }
        }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13524
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
  if p[i] != min(p[i-1], p[i], p[i+1]) and p[i] != max(p[i-1], p[i], p[i+1]):
    ans += 1
print(ans)

Measured memory_bytes: 9016
# include "iostream"
# include "bitset"
# include "cstdio"

using namespace std;

const int maxm=2e3+10;

int N,Sum;
int A[maxm];
bitset<maxm*maxm> LH;

int main(){
	register int i;
	scanf("%d",&N);
	LH[0]=1;
	for(i=1;i<=N;i++){
		scanf("%d",A+i);
		LH|=LH<<A[i];
		Sum+=A[i];
	}
	for(i=(Sum+1)>>1;;i++){
		if(LH[i]==1){
			printf("%d",i);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1792
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		Union union = new Union(n);
		int x, y, z;
		for (int i = 0; i < m; i++) {
			x = sc.nextInt() - 1;
			y = sc.nextInt() - 1;
			z = sc.nextInt();
			union.unite(x, y);
		}
		HashSet<Integer> hs = new HashSet<>();
		for (int i = 0; i < n; i++) {
			hs.add(union.getparent(i));
		}
		System.out.println(hs.size());
	}
}

class Union {

	private int[] rank;
	private int[] parent;

	public Union(int n) {
		rank = new int[n];
		parent = new int[n];
		for (int i = 0; i < n; i++) {
			parent[i] = i;
		}
	}

	public int root(int n) {
		if (n == parent[n]) {
			return n;
		}
		return parent[n] = root(parent[n]);
	}

	public void unite(int a, int b) {
		int aroot = root(a);
		int broot = root(b);
		if (aroot == broot) {
			return;
		}
		if (rank[aroot] > rank[broot]) {
			parent[broot] = aroot;
		} else if (rank[aroot] < rank[broot]) {
			parent[aroot] = broot;
		} else if (rank[aroot] == rank[broot]) {
			parent[broot] = aroot;
			rank[aroot]++;
		}
	}

	public int getparent(int n) {
		return parent[n] = root(parent[n]);
	}
}

Measured memory_bytes: 94920
#include<iostream>

int main(){
    int i,j,k,n;
    int out[4][3][10];
    int name,floor,No,person;

//initialize
    for(k=0;k<4;k++){
        for(j=0;j<3;j++){
            for(i=0;i<10;i++){
                out[k][j][i]=0;
            }
        }
    }
//read
    std::cin>>n;  

    for(i=0;i<n;i++){
        std::cin>>name>>floor>>No>>person;
        out[name-1][floor-1][No-1]+=person;
    }

    for(k=0;k<4;k++){
        for(j=0;j<3;j++){
            for(i=0;i<9;i++){
                std::cout<<" "<<out[k][j][i]<<std::flush;
            }
            std::cout<<" "<<out[k][j][9]<<std::endl;
        }
    if(k==3){
        break;
    }
    std::cout<<"####################"<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
  int x, a,  b ;
  cin >> x >> a >> b;
  int ax = abs(x-a);
  int bx = abs(x-b);
  if (ax > bx) {
    cout << 'B' << endl;
  } else {
    cout << 'A' << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0'){
		t=(t<<3)+(t<<1)+v-48;
		v=getchar();
	}
	return t;
}
long long a,b,c;
int main(){
	a=read();b=read();c=read();
	if(c<a+b)puts("No");
	else if((c-a-b)*(c-a-b)<=4*a*b)puts("No");
	else puts("Yes");
}



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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == 'C')
                {
                    for (int j = i + 1; j < str.Length; j++)
                    {
                        if (str[j] == 'F')
                        {
                            Console.WriteLine("Yes");
                            return ;
                        }
                    }
                }
            }
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 2648
#include<iostream>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

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

	int mx = 0;
	int num = -1;
	REP(i, 1, N + 1) {
		int cnt = 1;
		int val = i;
		while (val > 1) {
			if (val % 2 == 0) {
				cnt++;
				val /= 2;
			}
			else break;
		}
		if (cnt > mx) {
			mx = cnt;
			num = i;
		}
	}

	cout << num << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
BC = sorted(
    [list(map(int, input().split())) for _ in range(M)],
    reverse=True,
    key=lambda x: x[1]
)

BClist = []
for m in range(M):
    b, c = BC[m]
    BClist.extend([c for _ in range(b)])
    if len(BClist) > N:
        break

final_list = [None]*N
i_a = 0
i_bc = 0
for n in range(N):
    if i_bc >= len(BClist):
        final_list[n] = A[i_a]
        i_a += 1
    else:
        if A[i_a] > BClist[i_bc]:
            final_list[n] = A[i_a]
            i_a += 1
        else:
            final_list[n] = BClist[i_bc]
            i_bc += 1
print(sum(final_list))

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

#define       sf                 scanf
#define       pf                 printf
#define       pb                 push_back
#define       sz                 200005
#define       inf                0x3f3f3f3f
#define       MOD                1000000007
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);

using namespace std;

typedef       long long int      ll;

int main()
{
    //READ
    optimize


    int n, t = 1000;

    cin >> n;

    cout << (((n-1)/t)+1)*t-n << endl;

    return 0;
}


Measured memory_bytes: 3648
from fractions import gcd
from functools import reduce

N,W = map(int, input().split())
v = [0]*(N+1)
wtemp = [0]*(N+1)

for i in range(1,N+1):
  v[i],wtemp[i] = map(int, input().split())

gcdw = reduce(gcd,wtemp+[W])
w = list(map(lambda x:x//gcdw, wtemp))

W2 = W//gcdw
dp = [[0]*(W2+1) for y in range(N+1)]

for i in range(1,N+1):
    dp[i][0:w[i]] = dp[i-1][0:w[i]]
    for j in range(w[i], W2+1):
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i])

print(dp[N][W2])

Measured memory_bytes: 26900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005;
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int a[N],b[N];
int main(){
	int n=read();
	ll ans=0;
	for (int i=1;i<=n;i++) a[i]=read(),b[i]=a[i]-i;
	sort(b+1,b+1+n);
	ll x=b[(n/2)+1];
	for (int i=1;i<=n;i++) ans+=abs(a[i]-(x+i));
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<vector<long long int>> vvint;
typedef vector<string> vstr;
typedef long long int llint;

llint gcd(llint x, llint y) {
	while (y != 0) {
		if (x > y) {
			llint r = x % y;
			x = y;
			y = r;
		}
		else {
			llint r = y % x;
			y = r;
		}
	}
	return x;
}

int main(void) {
	int E, Y;
	cin >> E >> Y;
	switch (E) {
	case 0:if (1868 <= Y && Y <= 1911) {
		cout << "M"<<Y - 1867 << endl;
		}
		   else if (1912 <= Y && Y <= 1925) {
		cout << "T"<<Y - 1911 << endl;
		}
		   else if (1926 <= Y && Y <= 1988) {
		cout << "S"<<Y - 1925 << endl;
		}
		   else {
		cout << "H"<<Y - 1988 << endl;
		}
		   break;
	case 1:cout << Y + 1867 << endl;
		break;
	case 2:cout << Y + 1911 << endl;
		break;
	case 3:cout << Y + 1925 << endl;
		break;
	case 4:cout << Y + 1988 << endl;
		break;
	}
	
}



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

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

const int max_n = 20;
int n, ans = 0;;
int a[max_n], x[max_n][max_n], y[max_n][max_n];

int main(){
    cin >> n;
    rep(i, n){
        cin >> a[i];
        rep(j, a[i]){
            cin >> x[i][j] >> y[i][j];
        }
    }
    for(int bit = 0; bit < (1 << n); bit++){
        bool flag = true;
        int sum = 0;
        for(int i = 0; i < n; i++){
            if((bit >> i) & 1) {
                rep(j, a[i]) {
                    if((bit >> (x[i][j]-1) & 1) != y[i][j]){
                        flag = false;
                        break;
                    }
                }
                sum++;
            }
            if(!flag) break;
        }
        if(ans < sum && flag) ans = sum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, ans = N, l[N], r[N];
string s;
int main() {
	cin >> n >> s;
	for (int i = 1; i <= n; i++) {
		l[i] = l[i - 1] + (s[i - 1] == 'W');
		r[i] = r[i - 1] + (s[i - 1] == 'E');
	}
	for (int i = 1; i <= n; i++)
		ans = min(ans, l[i - 1] + r[n] - r[i]);
	cout << ans;	
	return 0;
}

Measured memory_bytes: 2948
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
if n%2==0:
    c=a[-1]//2
else:
    c=a[-1]//2+0.5
#print(c)
b=[]
for i in range(n):
    b.append(abs(c-a[i]))
#print(b)
c=min(b)
for i in range(n):
    if b[i]==c:
        print(a[-1],a[i])
        break

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define drrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int MOD = 1'000'000'000 + 7;
const int INF = 1'000'000'000 + 5;

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

	int n; std::cin >> n;
	int ans = -1;
	rep(x, 2 * n) {
		if (x + (x * 8) / 100 == n)
			ans = x;
	}
	if (ans == -1)
		std::cout << ":(" << "\n";
	else
		std::cout << ans << "\n";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sumvec(vector<S>&a){return accumulate(all(a),S());}
template<class S>S maxvec(vector<S>&a){return *max_element(all(a));}
template<class S>S minvec(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}


int main(void){
  	cin.tie(0);
  	ios::sync_with_stdio(false);
  	
  	ll n,a;
  	vb al(1000000001,false);
  	cin>>n;
  	
  	rep(i,n){
  	    cin>>a;
  	    if(al[a]==false){
  	        al[a]=true;
  	    }else{
  	        puta("NO");
  	        return 0;
  	    }
  	}
  	
  	puta("YES");

}


Measured memory_bytes: 122368
#include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <bitset>

using namespace std;

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = int;
const ll mod = 998244353;

int main(){

    int N;
    cin >> N;

    vector<pair<int,string>> S(0);
    rep(i,0,N){
        string tmp;
        cin >> tmp;
        pair<int,string> ts(tmp.size() , tmp );
        S.push_back(ts);
    }
    sort(S.begin(),S.end() , [](pair<int,string> lhs, pair<int,string> rhs) {
    return lhs.first < rhs.first;
  });

    vector<vector<int>> tree(0);
    vector<vector<int>> end(0);
    tree.push_back(vector<int> (26,-1));
    end.push_back(vector<int> (26,0));
    
    vector<int> remain(26,0);
    long long ans = 0;
    rep(i,0,N){
        string s = S[i].second;
        s += 'a';

        rep(j,0,26) remain[j] = 0;
        for(char c : s){
            remain[c - 'a'] += 1;
        }

        int now = 0;
        
        rrep(j,s.size()-1,-1){

            char nc = s[j];
            remain[nc-'a'] -= 1;
            rep(k,0,26){
                if (remain[k] > 0){
                    ans += end[now][k];
                }
            }
            if (j == 1){
                end[now][s[0]-'a'] += 1;
            }else if (j == 0){
                break;
            }
           

            if (tree[now][s[j-1]-'a'] == -1){
                tree[now][s[j-1]-'a'] = tree.size();
                vector<int> ttt(26,-1);
                tree.push_back(ttt);
                vector<int> tt2(26,0);
                end.push_back(tt2);
            }
            now = tree[now][s[j-1]-'a'];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 269484
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
using namespace std;

int main() {
	int K;
	int A, B;

	cin >> K >> A >> B;

	for (int i = A; i <= B; i++) {
		if (i % K == 0) {
			cout << "OK"<<endl;
			return 0;
		}
	}
	cout << "NG"<<endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

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

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

void rec(pair<int, int> p[], const int &town, const int &visited, bool table[], int &ans) {
	if (visited == 4) {
		ans = 4;

		return;
	}
	
	int i;

	rep(i, 3) {
		if (table[i]) continue;

		if (p[i].X == town || p[i].Y == town) {
			table[i] = 1;

			if (p[i].X == town) rec(p, p[i].Y, visited + 1, table, ans);
			else rec(p, p[i].X, visited + 1, table, ans);

			table[i] = 0;
		}
	}
}

void solve(pair<int, int> p[]) {
	bool table[3];
	int ans = 0;

	Mem0(table);
	
	int i;

	rep(i, 3) {
		if (p[i].X == 1 || p[i].Y == 1) {
			table[i] = 1;
			
			if (p[i].X == 1) rec(p, p[i].Y, 2, table, ans);
			else rec(p, p[i].X, 2, table, ans);

			table[i] = 0;
		}
	}

	if (ans == 4) Out("YES");
	else Out("NO");
}

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    pair<int, int> p[3];

	cin >> p[0].X >> p[0].Y;
	cin >> p[1].X >> p[1].Y;
	cin >> p[2].X >> p[2].Y;

	solve(p);
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n,x=0,ans=0;
    string s;
    cin >> n >> s;
    
    rep(i,n){
        if(s[i]=='I')x+=1;
        else x-=1;
        ans=max(ans,x);
    }
    
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 3544
inf = (5000 * 10 ** 5) * 3

a, b, c, x, y = map(int, input().split())

ret = inf
for cnt_ab in range(max(x, y) * 2 + 1):
    d = cnt_ab // 2

    cnt_a = max(0, x - d)
    cnt_b = max(0, y - d)

    t = cnt_ab * c + cnt_a * a + cnt_b * b
    ret = min(ret, t)
print(ret)


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

x = input()
x = int(x)

present_min_value = x
max_profit_candidate = 1 - 10**9

for i in range(n - 1):
    a = input()
    a = int(a)
    diff = a - present_min_value
    if diff > max_profit_candidate:
        max_profit_candidate = diff
    if a < present_min_value:
        present_min_value = a

print(max_profit_candidate)

Measured memory_bytes: 7624
import sys
input = sys.stdin.readline
import math

big = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
num = A[0]
for i in range(1, N):
    num = num * A[i] // math.gcd(num, A[i])

res = 0
for a in A:
    res += num // a

print(res % big)


Measured memory_bytes: 74788
import itertools
N,K = map(int, input().split())
a = input()
l = [0]*(N-1)
for n,(i , j) in enumerate(zip(a,a[1:])):
    if i == "A" and j == "C":
        l[n] +=1
l = itertools.accumulate(l)
l = [0] + list(l)
for i in range(K):
    ta,tb = map(int, input().split())
    print(l[tb-1]-l[ta-1])


Measured memory_bytes: 55260
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	double a, b, x;
	cin >> a >> b >> x;
	double half = a*a*b/2.0;
	double ans = 0.0;
	if(x<=half) {
		ans = atan(a*b*b/2.0/x);
	} else {
		double y = (2.0*a*a*b - 2.0*x) /a/a;
		ans = atan(y/a);
	}
	std::cout<<std::fixed<<std::setprecision(10);
	cout << ans*180/M_PI << endl;

	return 0;
}

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

using namespace std;

typedef int64_t i64;

i64 calc(i64 K) {
  if (K <= 9) return K;
  deque<i64> q;
  i64 v;
  for (i64 i = 1; i <= 9; i++) {
    q.push_back(i); K--;
  }
  while (true) {
    v = q.front();
    q.pop_front();
    if (q.empty()) break;
    i64 w = v % 10;
    if (w >= 1 && K > 0) {
      q.push_back(v * 10 + (w - 1)); K--;
    }
    if (K > 0) {
      q.push_back(v * 10 + w); K--;
    }
    if (w <= 8 && K > 0) {
      q.push_back(v * 10 + (w + 1)); K--;
    }
  }
  return v;
}

int main() {
  i64 K, v;
  cin >> K;
  v = calc(K);
  cout << v << endl;
  return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

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

    int x; cin >> x;
    if (x == 7 || x == 5 || x == 3) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

//long long
using ll = long long;

// pair<int, int>
using PII = pair<int, int>;

//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;

//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

// a = max(a, b), a = min(a, b)
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; }

// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}



// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う

// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

int main(){
    int K, T;
    cin>> K >> T;
    vector<int>a(T);
    int ma = -1;
    int man = -1;
    REP(i, T) {
        cin >> a.at(i);
        if(a.at(i) > ma){
            ma = a.at(i);
            man = i;
        }
    }
    int ans = max(a.at(man) - 1 - (K - a.at(man)), 0);
    print(ans);
}

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

int main(int argc, char const *argv[]) {
    map<string, int> day;
    day["SUN"] = 7;
    day["MON"] = 6;
    day["TUE"] = 5;
    day["WED"] = 4;
    day["THU"] = 3;
    day["FRI"] = 2;
    day["SAT"] = 1;

    string s;
    cin >> s;
    cout << day[s] << endl;
    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int s;
vector<P> dat;

void init(int n_) {
	s = 1;
	while (s < n_)s *= 2;
	dat.resize(2 * s - 1);
	for (int i = s - 1; i < 2 * s - 1; i++)dat[i].second = i - s + 2;
	for (int i = s - 2; i >= 0; i--)dat[i].second = dat[2 * i + 1].second;
}

void add(int k, int x) {
	k += s - 2;
	dat[k].first = x;
	while (k > 0) {
		k = (k - 1) / 2;
		if (dat[2 * k + 1].first < dat[2 * k + 2].first)dat[k] = dat[2 * k + 2];
		else dat[k] = dat[2 * k + 1];
	}
}

P query() {
	return { dat[0].first,dat[0].second };
}

int n, a, b, c, l[10];
int ans = INF;
vector<int> vec1, vec2, vec3;

signed main() {
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++)cin >> l[i];
	for (int i = 0; i < pow(4, n); i++) {
		vec1.clear(); vec2.clear(); vec3.clear();
		int k = i;
		for (int j = 0; j < n; j++) {
			if (k % 4 == 1)vec1.push_back(l[j]);
			if (k % 4 == 2)vec2.push_back(l[j]);
			if (k % 4 == 3)vec3.push_back(l[j]);
			k /= 4;
		}
		if (!(int)vec1.size() || !(int)vec2.size() || !(int)vec3.size())continue;
		int cnt = 0;
		int cnt1 = 0, cnt2 = 0;
		for (int j = 0; j < (int)vec1.size(); j++) {
			cnt1 += vec1[j];
			cnt2++;
		}
		cnt += 10 * (cnt2 - 1) + abs(cnt1 - a);
		cnt1 = 0, cnt2 = 0;
		for (int j = 0; j < (int)vec2.size(); j++) {
			cnt1 += vec2[j];
			cnt2++;
		}
		cnt += 10 * (cnt2 - 1) + abs(cnt1 - b);
		cnt1 = 0, cnt2 = 0;
		for (int j = 0; j < (int)vec3.size(); j++) {
			cnt1 += vec3[j];
			cnt2++;
		}
		cnt += 10 * (cnt2 - 1) + abs(cnt1 - c);
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def read():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    return N, K, A

def solve(N, K, A):
    for i in range(N-K):
        if A[i] < A[i+K]:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    inputs = read()
    solve(*inputs)


Measured memory_bytes: 31724
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    long double p=3.141592;
    long double a;
    cin>>a;
    cout<<2.0*p*a<<endl;
}

Measured memory_bytes: 3808
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		var a=sc.Ia;
		long ans=a[0]+a[n-2];
		for(int i = 1;i<n-1;i++) {
			ans+=Min(a[i-1],a[i]);
		}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 13268
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b){
  return *(int*)a - *(int*)b;
}
int main(void){
  int n,i;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  qsort(a,n,sizeof(int),cmp);
  printf("%d\n",a[n/2]-a[n/2-1]);
  return 0;
}

Measured memory_bytes: 892
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Anything Goes to Zero
 */

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

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_N + 4];
int bnums[MAX_N + 1], fs[MAX_N + 1];
int bns[2], rs[2];

/* subroutines */

int powmod(int a, int n, int mod) {  // a^n % MOD
  int pm = 1;
  while (n > 0) {
    if (n & 1) pm = (ll)pm * a % mod;
    a = (ll)a * a % mod;
    n >>= 1;
  }
  return pm;
}

/* main */

int main() {
  for (int bits = 1, msb = 1; bits <= MAX_N; bits++) {
    if ((msb << 1) <= bits) msb <<= 1;
    bnums[bits] = bnums[bits ^ msb] + 1;
    fs[bits] = fs[bits % bnums[bits]] + 1;
  }

  int n;
  scanf("%d%s", &n, s);

  int bn = 0;
  for (int i = 0; i < n; i++) bn += s[i] - '0';
  bns[0] = bn - 1, bns[1] = bn + 1;

  for (int i = 0; i < n; i++)
    for (int j = 0; j < 2; j++)
      if (bns[j] > 0) rs[j] = (rs[j] * 2 + s[i] - '0') % bns[j];

  for (int i = 0; i < n; i++) {
    int j = '1' - s[i];
    int f = 0;
    if (bns[j] > 0) {
      int p = powmod(2, n - 1 - i, bns[j]);
      if (j == 0) p = (bns[j] - p) % bns[j];
      f = fs[(rs[j] + p) % bns[j]] + 1;
    }
    printf("%d\n", f);
    //printf("i=%d, j=%d, r=%d, f=%d\n", i, j, r, fs[r]);
  }
				
  return 0;
}


Measured memory_bytes: 4976
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL INF = 1e16 + 7;

int n;
vector<PII> G[140005];
LL dep[140005];
vector<PLL> dp[140005];

void gen_dep(int v)
{
	rep(i, G[v].size()) {
		int u = G[v][i].first;
		dep[u] = dep[v] + G[v][i].second;
		gen_dep(u);
	}
}

vector<PLL> merge_dp(const vector<PLL>& u, const vector<PLL>& v, LL maxs)
{
	vector<PLL> ret;
	int j = 0;
	rep(i, v.size()) {
		if(u[j].second + v[i].first <= maxs && !ret.empty()) ret.pop_back(); 
		while(j < u.size() && u[j].second + v[i].first > maxs) j ++;
		if(j == u.size()) break;
		ret.push_back(MP(u[j].first, v[i].second));
	}
	return ret;
}

void gen_dp(int v, LL maxd)
{
	if(G[v].size() == 0) {
		dp[v].clear();
		dp[v].push_back(MP(dep[v], dep[v]));
		return;
	}
	int u0 = G[v][0].first, u1 = G[v][1].first;
	gen_dp(u0, maxd);
	gen_dp(u1, maxd);
	vector<PLL> v0 = merge_dp(dp[u0], dp[u1], maxd + dep[v] * 2);
	vector<PLL> v1 = merge_dp(dp[u1], dp[u0], maxd + dep[v] * 2);
	dp[v].resize(v0.size() + v1.size());
	merge(v0.begin(), v0.end(), v1.begin(), v1.end(), dp[v].begin());
	rep(i, dp[v].size()) if(i > 0 && dp[v][i].second >= dp[v][i - 1].second)
	dp[v][i] = dp[v][i - 1];
	dp[v].resize(unique(dp[v].begin(), dp[v].end()) - dp[v].begin());
}

bool check(LL x)
{
	gen_dp(1, x);
	return !dp[1].empty();
}

int main()
{
	scanf("%d", &n);
	for(int i = 2; i <= n; i ++) {
		int x, y;
		scanf("%d%d", &x, &y);
		G[x].push_back(MP(i, y));
	}
	gen_dep(1);
	LL l = 0, r = INF;
	while(l < r) {
		LL mid = l + r >> 1;
		if(check(mid)) r = mid;
		else l = mid + 1;
	}
	printf("%lld\n", r);
	return 0;
}

Measured memory_bytes: 42228
A, B = map(int, input().split())

def F(n):
    if n % 4 == 0:
        return n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return n + 1
    else:
        return 0

print(F(A - 1) ^ F(B))


Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
//vector<int> g[200020];
vector<pair<int,int>> g[200020];
ll s[200020];
bool used[200020];
void dfs(ll x,ll sum){
	used[x]=1;
	for(auto y:g[x]){
		if(used[y.first]) continue;
		s[y.first]+=(y.second+sum);
		dfs(y.first,s[y.first]);
	}
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<ll> A(N-1),B(N-1),ans(N-1,-1);
    for(ll i=0;i<N-1;i++){
        ll a,b,c;cin>>a>>b>>c;
        a--;b--;
        
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
	ll Q,K;
	cin >> Q >>K;
	dfs(K-1,0);
	for(ll i=0; i<Q; i++){
		int aa,bb;
		cin >> aa >> bb;
		cout<<s[aa-1]+s[bb-1]<<" " << '\n';
	}
	return 0;
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    int x, y;
    cin >> x >> y;
    if ((4 * x - y) >= 0 && (4 * x - y) % 2 == 0 && (y - 2 * x) >= 0 && (y - 2 * x) % 2 == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

int main() {
	int ans = 0;
	makei(N);
	makei(K);
	vi A(N + 1);
	rep(N) {
		int a;
		cin >> a;
		++A[a];
	}
	sort(rev(A));
	if (A[K] != 0) {
		auto it = A.begin() + K;
		while (it != A.end()) {
			ans += *(it++);
		}
	}
	say(ans);
}

Measured memory_bytes: 1024
from math import gcd

N = int(input())

sum = 0
for i in range(1, N+1):
  for j in range(1, N + 1):
    x=gcd(i,j)
    for k in range(1, N + 1):
      hoge = gcd(x,k)
      sum+=hoge

print(sum)


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

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}

bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

int n, a, b, cou;
double v[60], dp[60][60];
double ave;
long long ansnum, pas[51][51];
int aa;
int main(){
    pas[1][0] = pas[1][1] = 1;
    for(int i = 2; i <=50; i++){
        pas[i][0] = pas[i][i] = 1;
        for(int j = 1; j < i; j++){
            pas[i][j] = pas[i-1][j-1] + pas[i-1][j];
        }
    }
    cin >> n >> a >> b;

    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v, v+n);

    if(v[0] == v[n-1]){
        ave = v[0];
        cou = 1;
        for(int i = a; i <= b; i++){
            ansnum += pas[n][i];
        }
    }
    else{
        cou = a;
        for(int i = 1; i <= a; i++){
            ave += v[n-i];
        }
        ave /= a;
        if(v[n-a] == v[n-a-1] || v[n-a] == v[n-a+1]){
            cou = 0;
            int cou2 = 1;
            for(int i = a+1; i <= n; i++){
                if(v[n-a] == v[n-i])    ++cou;
                else    break;
            }
            for(int i = a-1; i>= 0; i--){
                if(v[n-a] == v[n-i])    ++cou2;
                else    break;
            }
            if(v[n-1] == v[n-a]){
                for(int i = a; i <= min(b, cou+cou2); i++){
                    ansnum += pas[cou+cou2][i];
                }
            }
            else{
                ansnum += pas[cou+cou2][cou2];
            }
        }
        else{
            ansnum = 1;
        }
    }
    printf("%lf\n", ave);
    cout <<  ansnum << endl;
}


Measured memory_bytes: 256
#pragma warning(disable: 4996)
#include<stdio.h>

int a = 0, b = 0;
int S = 0, L = 0;

int main() {
	scanf("%d %d",&a ,&b );
	S = a * b;
	L = a * 2 + b * 2;
	printf("%d %d\n", S, L);

	return 0;

}


Measured memory_bytes: 2148
n = int(input())
s = [0]*n
t = [0]*n
for i in range(n):
  s[i], t[i] = map(str, input().split())
  t[i] = int(t[i])
x = input()
num = [i for i, k in enumerate(s) if x == k]
print(sum(t[num[0]+1:n]))


Measured memory_bytes: 3060
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        if(n.charAt(0)=='9'){
            System.out.print('1');
        }else{
            System.out.print('9');
        }
        if(n.charAt(1)=='9'){
            System.out.print('1');
        }else{
            System.out.print('9');
        }
        if(n.charAt(2)=='9'){
            System.out.print('1');
        }else{
            System.out.print('9');
        }
        System.out.println("");
    }
}


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

#define f(i,g,n) for(int i=g;i<=n;i++)

int main()
{
	ios::sync_with_stdio(false);

	int n;
	cin>>n;
	int A[n];
	long double sum;
	f(i,0,n-1)
		cin>>A[i];
	sort(A,A+n);
	sum = A[0];
	f(i,1,n-1)
		sum = (sum+A[i])/2;
	cout<<sum<<"\n";

	return 0;
}

Measured memory_bytes: 256
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d %d", $N, $K);
$A = explode(" ", trim(fgets(STDIN)));
$base = $A;
$mmax = max($A);

if (in_array($K, $A)) {
    echo "POSSIBLE\n";
    exit;
}
if (DEBUG) {
    rsort($A);
    var_dump($A);
}

$bool = true;

$diff = array();

while($bool) {
    $B = array();
    $bool = false;
    $cnt = count($A);
    for ($i = 0; $i < $cnt - 1; $i++) {
        $d = abs($A[$i+1] - $A[$i]);
        if (DEBUG) echo $d . PHP_EOL;
        $B[] = $d;
        if (!isset($diff[$d])) {
            $diff[$d] = 1;
            $bool = true;
        }
    }
    $B = array_unique($B);
    sort($B);
    $A = $B;
    if (DEBUG) echo "----\n";
}

if (DEBUG) {
    var_dump($diff);
    var_dump($A);
}


foreach ($diff as $key => $val) {
    if (($mmax - $K) / $key > 0 && ($mmax - $K) % $key == 0) {
        echo "POSSIBLE\n";
        exit;
    }
}
echo "IMPOSSIBLE\n";


Measured memory_bytes: 33524