akhauriyash/Code-Regression huggingface dataset:
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

bool ispal(string &s,int i,int j)
{
    while(i<j)
    {
        if(s[i]!=s[j])
            return false;
        i++;
        j--;
    }
    return true;
}

int32_t main()
{
    IOS;
    int T=1;
    //cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        int n=s.size();
        int sz=n/2;
        if(ispal(s,0,n-1)&&ispal(s,0,n/2-1)&&ispal(s,n/2+1,n-1))
            cout<<"Yes";
        else
            cout<<"No";
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String k = "CODEFESTIVAL2016";
    int ans = 0;
    for (int i = 0; i < k.length(); i++) {
      if (S.charAt(i) != k.charAt(i)) {
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b || a==b)
    {
        for(int i=1;i<=a;i++)
            cout<<b;
        return 0;
    }
    if(a<b)
    {
        for(int i=1;i<=b;i++)
            cout<<a;
        return 0;
    }
}

Measured memory_bytes: 256
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

int n,m,l,r,d,coord[100010],visited[100010];
vvpi graph;
deque<pair<int,pi>> deq;

int main(){
    I(n); I(m);
    graph.resize(n+1);
    REP(i,m){
        I(l); I(r); I(d);
        graph[l].pb(mp(r,d));
        graph[r].pb(mp(l,-d));
    }
    REP(i,n){
        if (visited[i]) continue;
        visited[i] = 1;
        for (auto j : graph[i]) deq.pb(mp(i,j));
        while(!deq.empty()){
            pair<int,pi> dpair = deq.front();
            deq.pop_front();
            if (visited[dpair.second.first]){
                if (coord[dpair.second.first] - coord[dpair.first] != dpair.second.second){
                    cout << "No" << endl;
                    return 0;
                }
            } else {
                visited[dpair.second.first] = 1;
                coord[dpair.second.first] = coord[dpair.first] + dpair.second.second;
                for (auto j : graph[dpair.second.first]) deq.pb(mp(dpair.second.first,j));
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 12788
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> P;
int ud[2][200000];//ud[0][i]...iからスタートしたときに最も上に行ける(1は下)
P arm[100000];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		arm[i]=P(x,y);
	}
	sort(arm,arm+m);
	for(int i=0;i<n;i++)
	{
		ud[0][i]=i;
		ud[1][i]=i;
	}
	for(int i=0;i<m;i++)
	{
		ud[1][arm[i].second-1]=ud[1][arm[i].second];
		ud[0][arm[i].second]=ud[0][arm[i].second-1];
	}

	for(int i=0;i<n;i++)
	{
		cout<<ud[1][i]-ud[0][i]+1;
		if(i!=n-1)
			cout<<" ";
	}
	cout<<endl;
	return 0;
}


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

int main(){
	
	int N ;
	int a , b , p , cnt ;
	
	cin >> N ;
	while( N-- ){
		cin >> a >> b ;
		
		cnt = 0 ;
		while( a < b ){
			p = 1 ;
			while( a/p * p == a && a + p <= b ) p *= 2 ;
			a += p/2 ;
			cnt++ ;
		}
		
		cout << cnt << endl ;
	}
	
return 0 ;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
bool a[103]={0};
using namespace std;
int main() {
	int n,k,d,all=0,l;
cin>>n>>k;
for(int i=0;i<k;i++)
{
	cin>>d;
	for(int j=0;j<d;j++)
	{cin>>l;a[l]=1;}
}
for(int i=1;i<=n;i++)
if(!a[i])all++;
cout<<all;
return 0;
}

Measured memory_bytes: 3632
#競プロデッキからコピペ。
#二つの要素が同じグループに属しているかどうかを判定するためのunion-find木
class UF:
    #経路圧縮＋マージテクのunion find木
    def __init__(self,n):
        self.n = n
        self.parents = [-1] * (n+1) #1-indexedにするために１個足している
        self.rnks = [0] * (n+1)

    def find(self,n):
        if self.parents[n] < 0:
            return n
        else:
            return self.find(self.parents[n])


    def union(self,a,b):
        a_par = self.find(a)
        b_par = self.find(b)

        if a_par == b_par:
            return
        ##union by rank
        #if self.rnks[a_par] < self.rnks[b_par]: #ランクの高い方の根に低い方の根をつける　逆にしないように……！
        #    a_par,b_par = b_par,a_par
        #if self.rnks[a_par] == self.rnks[b_par]:
        #    self.rnks[a_par] += 1
        if self.size(a_par) < self.size(b_par): #parentsの値が負の数のとき、それはその木のサイズを表す。
            a_par,b_par = b_par,a_par
        self.parents[a_par] += self.parents[b_par]
        self.parents[b_par] = a_par

    def size(self,n):
        par = self.find(n)
        return abs(self.parents[par])

    def is_same(self,a,b):
        return self.find(a) == self.find(b)

#デッキコピペここまで

def main():
    n,m = map(int,input().split())
    num_lst = [0] + list(map(int,input().split()))
    uf = UF(n) #union-find木を作る
    for _ in range(m):
        x,y = map(int,input().split())
        uf.union(x,y) #union-find木内で、２つの要素を結び付けてグループにする

    counter = 0 #条件を満たす値を数える
    for i,j in enumerate(num_lst[1:]):
        if uf.is_same(i+1,j): #要素の初期位置と、その要素が示す移動先が同じグループに属するとき
            counter += 1      #swap操作により移動可能ということになる。
    print(counter)

if __name__ == '__main__':
    main()


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

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

    int n, T;
    cin >> n >> T;

    int res = 1001;
    rep(i, n){
        int c, t;
        cin >> c >> t;
        if(t <= T){
            res = min(res, c);
        }
    }

    if(res<1001) cout << res << endl;
    else cout << "TLE" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int t = 1;
		for (int i = 1; i <= t; ++i) {
			int n = in.nextInt();
			int m = in.nextInt();
			Map<Integer, List<Integer>> edge = getEdges(in, m, true);
			int r = solve(n, m, edge);
			System.out.println(r);
		}
		in.close();
	}

	private static int solve(int n, int m, Map<Integer, List<Integer>> edge) {
		int[] maxD = new int[n + 1];
		Arrays.fill(maxD, -1);
		for (int i = 1; i <= n; i++) {
			if (maxD[i] == -1) {
				dfs(i, edge, maxD);
			}
		}

		int max = 0;
		for (int i = 0; i < maxD.length; i++) {
			max = Math.max(max, maxD[i]);
		}
		return max;
	}

	static void dfs(int u, Map<Integer, List<Integer>> edge, int[] maxD) {
		maxD[u] = 0;
		List<Integer> l = edge.get(u);
		if (l != null) {
			for (int v : l) {
				if (maxD[v] < 0) {
					dfs(v, edge, maxD);
				}
				maxD[u] = Math.max(maxD[u], maxD[v] + 1);
			}
		}
	}

	static String str(int[] a) {
		String[] str = new String[a.length];
		for (int i = 0; i < a.length; i++) {
			str[i] = a[i] + "";
		}
		return String.join(" ", str);
	}

	static int[] getIntArr(Scanner in, int size) {
		int[] arr = new int[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.nextInt();
		}
		return arr;
	}

	static int[][] getIntArr(Scanner in, int row, int col) {
		int[][] arr = new int[row][];
		for (int i = 0; i < row; i++) {
			arr[i] = getIntArr(in, col);
		}
		return arr;
	}

	static char[] getCharArr(Scanner in, int size) {
		char[] arr = in.next().toCharArray();
		return arr;
	}

	static String[] getStringArr(Scanner in, int size) {
		String[] arr = new String[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.next();
		}
		return arr;
	}

	static Map<Integer, List<Integer>> getEdges(Scanner in, int size, boolean directed) {
		Map<Integer, List<Integer>> edges = new HashMap<>();
		for (int i = 0; i < size; i++) {
			int from = in.nextInt();
			int to = in.nextInt();
			if (!edges.containsKey(from)) {
				edges.put(from, new ArrayList<Integer>());
			}
			edges.get(from).add(to);
			if (!directed) {
				if (!edges.containsKey(to)) {
					edges.put(to, new ArrayList<Integer>());
				}
				edges.get(to).add(from);
			}

		}
		return edges;
	}
}


Measured memory_bytes: 109896
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
ans=[]

a=A.pop(0)
temp=0
for i in range(N-1):
    temp+=A[i]*(-1)**i

ans.append(a+temp)
for i in range(0,N-1):
    ans.append(2*A[i]-ans[-1])

a=ans.pop(-1)    
print(a,*ans)


Measured memory_bytes: 14092
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int q,x,i,k,l[N],r[N],j,n,a[N],b[N],f[N];
char c[N];
int main()
{
	scanf("%s",c+1);
	int len=strlen(c+1);
	if(c[len]=='s')
		printf("%ses",c+1);
	else
		printf("%ss",c+1);
}


Measured memory_bytes: 3820
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 100005;
bool red[MAXN];
int n,m,cnt[MAXN];
int main()
{
	scanf("%d%d",&n,&m);
	red[1]=true;
	for(int i=1;i<=n;++i)cnt[i]=1;
	for(int i=1,x,y;i<=m;++i){
		scanf("%d%d",&x,&y);
		red[y]|=red[x];
		if(!--cnt[x])red[x]=false;
		++cnt[y];
	}
	int sum=0;
	for(int i=1;i<=n;++i)sum+=red[i];
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 768
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    ans=INF
    for x in A:
        tmp=0
        while True:
            if x%2==0:
                tmp+=1
                x//=2
            else:
                break
        ans=min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()


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

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int n=sc.nextInt();
				int m=sc.nextInt();
				if(n+m==0) break;
				int[] s=new int[n];
				int[] d=new int[m];
				for(int i=0; i<n; i++) {
					s[i]=sc.nextInt();
				}
				for(int i=0; i<m; i++) {
					d[i]=sc.nextInt();
				}
				Arrays.sort(d);
//				for(int i=0; i<m; i++) {
//					System.out.print(d[i]);
//				}
//				System.out.println();
				int INF=100000000;
				int[][] dp=new int[1<<n][m+1];//dp[使用布団][日にち]
				for(int i=0; i<(1<<n); i++) {
					for(int j=0; j<=m; j++) {
						dp[i][j]=INF;
					}
				}
				dp[0][0]=0;
				
				int[] sum=new int[1<<n];//使用布団の供給合計
				for(int i=0; i<(1<<n); i++) {
					sum[i]=0;
					for(int j=0; j<n; j++) {
						if((1&(i>>j))==1)	sum[i]+=s[j];
					}
				}
				
				for(int i=0; i<m; i++) {
					for(int j=0; j<(1<<n); j++) {//i日にjの布団が使われた
						dp[j][i+1]=Math.min(dp[j][i+1], dp[j][i]+Math.abs(sum[j]-d[i]));
						for(int k=0; k<n; k++) {
							if((1&(j>>k))==1) continue;
							int nextj=j|(1<<k);
							dp[nextj][i]=Math.min(dp[nextj][i], dp[j][i]);
						}
					}
				}
				int ans=INF;
				for(int i=0; i<(1<<n); i++) {
					ans=Math.min(ans, dp[i][m]);
				}
				System.out.println(ans);

			}
		}
	}
}


Measured memory_bytes: 83524
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>

using namespace std;

typedef long long ll;

int main() {
    int n; cin >> n;
    set<ll> s;
    for (int i = 0; i < n; i++) {
        ll a;  cin >> a;
        s.insert(a);
    }

    if (s.size() == n)
        cout << "YES" << endl;
    else 
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int a, b;
    cin >> a >> b;
    int dif = b - a;
    cout << (dif + 1) * dif / 2 - b << endl;
}


Measured memory_bytes: 256
dataCount = int(input())
while dataCount > 0:
    employeeSalesList = []
    for _ in range(dataCount):
        dataList = input().split(" ")
        employeeId, price = dataList[0], int(dataList[1]) * int(dataList[2])
        for data in employeeSalesList:
            if data[0] == employeeId:
                data[1] += price
                continue
        employeeSalesList.append([employeeId, price])

    answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
    if answerList:
        print("\n".join(map(str, answerList)))
    else:
        print("NA")

    dataCount = int(input())

Measured memory_bytes: 7812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
int n,m,c;
struct P{
    ll a,b;
    bool operator<(const P &A){
        return a<A.a;
    }
}p[N];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        ll a,b;
        cin>>a>>b;
        p[i].a=a;p[i].b=b;
    }
    sort(p+1,p+n+1);
    ll sum = 0,ans = 0;
    for(int i=1;i<=n;i++){
        if(sum+p[i].b>m){
            ll d=m-sum;
            ans+=d*p[i].a;
            break ;
        }else{
            sum+=p[i].b;
            ans+=p[i].a*p[i].b;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
N, X, Y = [int(i) for i in input().split()]
ans = [0]*(N-1)
for i in range(1, N):
    for j in range(i + 1, N + 1):
        ans[min(j - i, abs(j - Y) + abs(i - X) + 1) - 1] += 1
print(*ans)


    

Measured memory_bytes: 45020
#include<bits/stdc++.h>
  using namespace std;  
  #pragma GCC optimize("Ofast") 
  #define int long long
  #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
  #define pb push_back 
  #define eb emplace_back
  #define fn for(int i =0 ;i <n;i++)  
  #define fn1 for( int i =1;i<=n; i++)
  #define fm for(int j =0 ;j <m;j++)
  #define fm1 for(int j =1;j<=m;j++)
  #define fi first
  #define se second
  #define endl '\n'
  #define PI  3.14159265358979323846
  #define MOD 1000000007
  #define all(a) a.begin(),a.end()
  #define rall(a) a.rbegin(),a.rend()
  const int N = 2e6+5;  
  const int INF = 1e18L;
  #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
  template <typename Arg1>
  void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
  }
  template <typename Arg1, typename... Args>
  void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
  }
  int ar[N];
  int dp[N];
  signed main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    IOS;
    int T=1;
    // cin >> T;
    while(T--){
      int n , k ,m;
      cin >> n >> k >> m;
      int zero = n/m;
      int x ;
      if(n<0){
        zero=abs(zero);
        x = min(k,zero);
        n+=m*x;
        k-=x;
      }
      else{
       x =min(k,zero);
        n-=m*x;
        k-=x;
      }
      int ans;
        ans = n - (k&1 ? m :0 );
        ans = abs(ans);
        ans = min(ans,abs(n+ (k&1?m:0)));
      ans =abs(ans);
      if(k>0){
        int nn = abs(n-m);
        int k2= k;
        --k;
        if(k&1){
          nn+=m;
          ans=min(ans,nn);
          nn-=2*m;
          ans=min(ans,abs(nn));
        }
        if(k2&1){
          n+=m;
          ans=min(ans,abs(n));
          n-=2*m;
          ans=min(ans,abs(n));
        }
        ans=min(ans,abs(n));
      }
      cout <<ans<<'\n';
    
    
    }
    return 0;
  }

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

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e16;

using namespace std;

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

    int N, M;
    cin >> N >> M;

    int passable[100000+1] = {};
    for (int i = 0; i < M; ++i) {
        int L, R;
        cin >> L >> R;
        ++passable[L];
        --passable[R+1];
    }
    int joker = 0;
    for (int i = 1; i <= N; ++i) {
        passable[i] += passable[i-1];
        if (passable[i] == M) {
            ++joker;
        }
    }

    cout << joker << endl;

    return 0;
}


Measured memory_bytes: 640
using System;

class B{
  static void Main(){
    int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    int N = Ar[0], ans = 0;
    double D = Math.Pow(Ar[1], 2);
    int[] Temp = new int[2];
    for (int i = 0; i < N; i++){
      Temp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
      if (Math.Pow(Temp[0], 2) + Math.Pow(Temp[1], 2) <= D) ans++;
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define sz(v) (ll)v.size()
using namespace std;

ll MOD=1e9+7;
ll g,h,l;
const ll N=100005;

ll add(ll a,ll b); ll mul(ll a,ll b); ll binpo(ll a,ll b);

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n,k,c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    bool f[n]={0},b[n]={0};
    ll job=0,rest=n+5;
    repn(i,n){
        if(s[i]=='o'){
            // cout<<i<<" "<<rest<<endl;
            if(rest>=c){
                f[i]=1;
                job++;
                rest=0;
            }
            else{
                rest++;
            }
        }
        else{
            rest++;
        }
    }
    if(job>k){
        return 0;
    }
    job=0,rest=n+5;
    bac(i,n-1,0){
        if(s[i]=='o'){
            if(rest>=c){
                b[i]=1;
                job++;
                rest=0;
            }
            else{
                rest++;
            }
        }
        else{
            rest++;
        }
    }
    if(job>k){
        return 0;
    }
    repn(i,n){
        // cout<<f[i]<<" "<<b[i]<<endl;
        if(f[i] and b[i]){
            cout<<i+1<<endl;
        }
    }
}

ll add(ll a,ll b)
{
    return (a%MOD+b%MOD)%MOD ;
}
ll mul(ll a,ll b)
{
    return (a* 1ll *b)%MOD ;
}
ll binpo(ll a,ll b)
{
    int ans = 1 ;
    while(b)
    {
        if( b % 2 != 0)
        {
            ans = mul(ans,a);
        }
        a = mul(a,a);
        b = b/2;
    }
    return ans;
}

Measured memory_bytes: 2196
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int h = sc.nextInt();
    int n = sc.nextInt();
    int[] x = new int[n];
    int[] y = new int[n];
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
      a[i] = sc.nextInt();
    }
    int[][] rect = new int[w][h];
    for (int i = 0; i < w; i++) {
      for (int j = 0; j < h; j++) {
        rect[i][j] = 0;
      }
    }
    for (int i = 0; i < n; i++) {
      int start_x = 0;
      int end_x = w;
      int start_y = 0;
      int end_y = h;
      if (a[i] == 1) {
        end_x = x[i];
      } else if (a[i] == 2) {
        start_x = x[i];
      } else if (a[i] == 3) {
        end_y = y[i];
      } else if (a[i] == 4) {
        start_y = y[i];
      }
      for (int j = start_x; j < end_x; j++) {
        for (int k = start_y; k < end_y; k++) {
          rect[j][k]++;
        }
      }
    }
    int result = 0;
    for (int i = 0; i < w; i++) {
      for (int j = 0; j < h; j++) {
        if (rect[i][j] == 0) {
          result++;
        }
      }
    }
    System.out.println(result);
  }
}

Measured memory_bytes: 21716
//in progress
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define forn(i,n) for(int i =0; i < (int)(n); i++)
#define rfr(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define PI 3.14159265
ll n;
ll a[100005][3],rec[100005][3];
ll recur(ll ind,ll pos)
{
  if(ind>=n)
  return 0;
  for(int i=0;i<3;i++)
  if(rec[ind+1][i]==-1)rec[ind+1][i]=recur(ind+1,i);

  if(pos==-1)
  return max(a[ind][0]+rec[ind+1][0],max(a[ind][1]+rec[ind+1][1],a[ind][2]+rec[ind+1][2]));
  else if(pos==0)
  return max(a[ind][1]+rec[ind+1][1],a[ind][2]+rec[ind+1][2]);
  else if(pos==1)
  return max(a[ind][0]+rec[ind+1][0],a[ind][2]+rec[ind+1][2]);
  else if(pos==2)
  return max(a[ind][0]+rec[ind+1][0],a[ind][1]+rec[ind+1][1]);
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //freopen("a.in", "r", stdin);
  //freopen("a.out", "w", stdout);
  cin>>n;
  memset(rec,-1,sizeof(rec));
  for(int i=0;i<n;i++)
  cin>>a[i][0]>>a[i][1]>>a[i][2];
  cout<<recur(0,-1)<<"\n";
  return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    ll N, i, judge=1, sum=0;

    cin >> N;

    vector<pair<ll,ll>> p(N);

    for(i=0; i<N; i++){
        cin >> p[i].second >> p[i].first;
    }

    sort(p.begin(), p.end());

    for(i=0; i<N; i++){
        sum += p[i].second;

        if(sum > p[i].first) judge = 0;
    }

    if(judge==1) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    double a, b;
    const double tubo = 3.305785;

    cout << setprecision(6) << setiosflags(ios::fixed);
    while (cin >> a >> b) {
        cout << a * b / tubo << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

lint segdata[(1<<19)-1];

lint neutral(){
    return LINF;
}
lint calc(lint a,lint b){
    return min(a,b);
}
void seginit(){
    rep(i,(1<<19)-1) segdata[i]=neutral();
}
void update(lint i,lint x){ // i番目の値をxに更新
    i+=(1<<18)-1;
    segdata[i]=x;
    while(i>0){
        i=(i-1)/2;
        segdata[i]=calc(segdata[i*2+1],segdata[i*2+2]);
    }
}
lint seg(lint a,lint b,lint k,lint l,lint r){
    if(r<=a || b<=l) return neutral();
    if(a<=l && r<=b) return segdata[k];
    else{
        lint left=seg(a,b,k*2+1,l,(l+r)/2);
        lint right=seg(a,b,k*2+2,(l+r)/2,r);
        return calc(left,right);
    }
}
lint query(lint a,lint b){
    return seg(a,b+1,0,0,1<<18);
}

int main(void){
    seginit();
    int N;
    cin >> N;
    rep(i,N){
        int P;
        cin >> P;
        update(i,P);
    }
    int ans=0;
    rep(i,N) if(query(0,i)>=query(i,i)) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
  int n,k,i,j;
  cin>>n>>k;
  int a[n+1];
  for(i=1;i<=n;i++)
   cin>>a[i];
  vector<int> v;
  int x,b=a[1];v.push_back(b);map<int,int> m;
  m[b]=v.size()-1;
  while(1)
  {
    b=a[b];
    if(m.count(b)){
      j=m[b];break;}
    v.push_back(b);
    m[b]=v.size()-1;
  }
 if(k<=j)
  cout<<v[k-1];
 else
 {
   k=k-j-1;
   x=v.size()-j;
   k=k%x;
   cout<<v[k+j];
 }
}

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

int main()
{
  long N;
  cin >> N;
  int SN = 0;
  long tmp = N;
  while (tmp > 0){
    SN += tmp % 10;
    tmp /= 10;
  }
  if (N % SN == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

struct RLUQ{
  struct query{
    int type;//0=empty, 1=set
    int value;
    query(int a=0,int b=0):type(a),value(b) {}
  };
  query s[(1<<18)];
  int t[(1<<18)];
  RLUQ(){
    fill(t,t+(1<<18),INT_MAX);
  }
  void compute(int k,int l,int r){
    query q=s[k];
    s[k].type=0;
    if(q.type==0||r-l==1)return;
    s[k*2+1]=s[k*2+2]=q;  
    t[k*2+1]=t[k*2+2]=q.value;
  }
  void Set(int a,int b,int x,int k=0,int l=0,int r=(1<<17)){
    if(b<=l || r<=a)return;
    compute(k,l,r);
    if(a<=l && r<=b){
      s[k]=query(1,x);
      t[k]=x;
    }else{
      int m=(l+r)/2;
      Set(a,b,x,k*2+1,l,m);
      Set(a,b,x,k*2+2,m,r);
      t[k]=min(t[k*2+1],t[k*2+2]);
    }
  }
  int Get(int a,int b,int k=0,int l=0,int r=(1<<17)){
    if(b<=l || r<=a)return INT_MAX;
    compute(k,l,r);
    if(a<=l && r<=b){
      return t[k];
    }else{
      int m=(l+r)/2;
      int lv=Get(a,b,k*2+1,l,m);
      int rv=Get(a,b,k*2+2,m,r);
      return min(lv,rv);
    }
  }
};

int main(){
  RLUQ a;
  int n,q;
  cin>>n>>q;
  int c,s,t,x;
  for(int i=0;i<q;i++){
    cin>>c;
    if(c){
      cin>>s>>t;
      cout<<a.Get(s,t+1)<<endl;
    }
    else{
      cin>>s>>t>>x;
      a.Set(s,t+1,x);
    }
  }
}


Measured memory_bytes: 6184
from collections import OrderedDict

A, B, K = map(int, input().split())
L = []
res = []

if K > B-A:
    for i in range(A, B+1):
        print(i)
    exit()
else:
    for i in range(A, A+K):
        res.append(i)
    for i in range(B-K+1, B+1):
        res.append(i)

res_unique = list(set(res))
res_unique.sort()

for i in res_unique:
    print(i)

Measured memory_bytes: 9460
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll a,b,x;
    cin >> a>>b>>x;
    if (x-a==0) cout << "YES" <<endl;
    else if (x-a>0 && x-a-b<=0) cout << "YES" <<endl;
    else cout <<"NO"  << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,x;cin>>n>>m>>x;
    //5 - 0 1 2 3 4 5 -6 nos so n+2 is correct
    vector<int >a(n+1,0) ;
    for (int i=0,d;i<m;i++) {
        cin>>d;
        a[d]=1;
    }
    int min1=0,min2=0;
    for(int i=0;i<=x;i++)min1+=a[i];
    for(int i=x;i<=n;i++)min2+=a[i];
    cout<<min(min1,min2);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
  int n;
  cin>>n;
  int t[n];
  for(int i(0);i<n;i++){
    cin>>t[i];
  }
  int m;
  cin>>m;
  int p[m],x[m];
  for(int i(0);i<m;i++){
    cin>>p[i]>>x[i];
  }
  int sum(0);
  for(int i(0);i<n;i++){
    sum+=t[i];
  }
  for(int i(0);i<m;i++){
    cout<<sum-t[p[i]-1]+x[i]<<endl;
  }
  return 0;
}

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

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int n;
vector<int> g[200000];
int color[200000];
int ans[200000];
int used[200001];

void dfs(int u, int b, int d) {
    color[u] = d;
    for (auto v : g[u]) {
        if (v == b)
            continue;
        dfs(v, u, !d);
    }
}

int main() {
    int a, b;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0, 0, 0);

    int e = count(color, color + n, 0);
    int o = count(color, color + n, 1);
    if (min(e, o) <= n / 3) {
        int k = (e < o ? 0 : 1);
        for (int i = 0, c = 3; i < n; ++i) {
            if (color[i] == k) {
                ans[i] = c;
                used[c] = 1;
                c += 3;
            }
        }
        for (int i = 0, c = 1; i < n; ++i) {
            if (ans[i] == 0) {
                while (used[c])
                    c++;
                ans[i] = c;
                used[c] = 1;
            }
        }
    }
    else {
        for (int i = 0, c1 = 1, c2 = 2; i < n; ++i) {
            if (color[i] == 0 && c1 <= n) {
                ans[i] = c1;
                used[c1] = 1;
                c1 += 3;
            }
            else if (color[i] == 1 && c2 <= n) {
                ans[i] = c2;
                used[c2] = 1;
                c2 += 3;
            }
        }
        for (int i = 0, c = 3; i < n; ++i) {
            if (ans[i] == 0) {
                while (used[c])
                    c += 3;
                ans[i] = c;
                used[c] = 1;
            }
        }
    }

    cout << ans[0];
    for (int i = 1; i < n; ++i) {
        cout << " " << ans[i];
    }
    cout << endl;

    return 0;
}

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

using namespace std;

#define N 100000
#define M 100000

int a[N + 1];
int b[N + 1];
vector<int> v[M + 1];
priority_queue<int, vector<int>, greater<int>> pq;

int main(){
	int ans, n, m, i;

	scanf("%d%d", &n, &m);

	for (i = 1; i <= n; i++){
		scanf("%d%d", a + i, b + i);

		if (a[i] <= m){
			v[m - a[i] + 1].push_back(b[i]);
		}
	}

	for (i = 1; i <= m; i++){
		sort(v[i].begin(), v[i].end());

		while (!v[i].empty() and pq.size() < i){
			pq.push(v[i].back());
			v[i].pop_back();
		}

		while (!v[i].empty()){
			if (v[i].back() <= pq.top()){
				break;
			}

			pq.pop();
			pq.push(v[i].back());
			v[i].pop_back();
		}
	}

	ans = 0;

	while (!pq.empty()){
		ans += pq.top();
		pq.pop();
	}

	printf("%d\n", ans);

	return 0;
}

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

int main(){
  int a[13],b[13],c[13];

  scanf("%s %s %s", a, b, c);

  printf("%c%c%c\n", a[0] - 'a' + 'A', b[0] - 'a' + 'A', c[0] - 'a' + 'A');
  
  return 0;
}


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


int main(int argc, char const *argv[])
{
    int n; cin >> n;
    long long int lst[100010];
    int l = 0;
    for (int i = 0; i < n; i++)
    {
        long long int a; cin >> a;
        
        bool dn = false;
        if (l == 0) {
          lst[0] = a;
          l ++;
          continue;
        }
        if (a <= lst[l-1]) {
            lst[l] = a;
            l ++;
            continue;
        }
        if (a > lst[0])
        {
            lst[0] = a;
            continue;
        }

        int f = 0, r = l-1;

        while (r-f>1)
        {
            int m = (f+r)/2;
            if (a > lst[m]) {
                r = m;
            }
            else {
                f = m;
            }
        }
        lst[r] = a;


    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9 + 5;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
using namespace std;

int n,m,u,v;
int memo[110000];
bool fl[110000];
vector<int> eg[110000];


int dp(int v){
    if(fl[v]){
        return memo[v];
    }
    int ans = 0;
    for(int to: eg[v]){
        ans = max(ans, dp(to) + 1);
    }
    fl[v] = true;
    memo[v] = ans;
    return ans;
}
using namespace std;
int main(){
   

    cin >> n >> m;
    REP(i,m){
        cin >> u >> v;
        eg[u].push_back(v);
    }
    int ans = 0;
    FOR(i,1,n+1){
        ans = max(ans,dp(i));
    }

    cout << ans <<endl;

}





Measured memory_bytes: 11756
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    int a, b, c;
    scan(a, b, c);
    auto ans = min(b / a, c);
    writeln(ans);
}










int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {writeln(b ? "Yes" : "No");}
void YES(bool b) {writeln(b ? "YES" : "NO");}
T[] readArr(T)() {return readln.split.to!(T[]);}
T[] readArrByLines(T)(int n) {return iota(n).map!(i => readln.chomp.to!T).array;}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main(){
  int i = 0, j = 0, k = 0;
  int flag = 1, n = 0, key = 0;
  int A[N];

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  while(flag >= 1){
    flag = 0;
    for(i = n-1; i >= 1; i--){
      if(A[i] < A[i-1]){
	key = A[i-1];
	A[i-1] = A[i];
	A[i] = key;
	flag = 1;
	k++;
      }
    }
  }

  for(i = 0; i < n; i++){
    printf("%d",A[i]);
    if(i == n-1)printf("\n");
    else printf(" ");
  }
  printf("%d\n",k);
  
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
vector<long long>a;
vector<vector<long long>>dp;
long long sa(long long b,long long e)
{
  if(dp[b][e]!=1000000000)return dp[b][e];
  if(b==e)return a[b];
  if(e-b==1)
  {
    return abs(a[e]-a[b]);
  }
  long long tmp1,tmp2;
  tmp1=min(a[b]-a[b+1]+sa(b+2,e),a[b]-a[e]+sa(b+1,e-1));
  tmp2=min(a[e]-a[b]+sa(b+1,e-1),a[e]-a[e-1]+sa(b,e-2));
  dp[b][e]=max(tmp1,tmp2);
  return dp[b][e];
}
int main()
{
  ios::sync_with_stdio(false);
  long long n;
  cin>>n;
  a=vector<long long>(n);
  dp=vector<vector<long long>>(n,vector<long long>(n,1000000000));
  for(long long i=0;i<n;i++)
  {
    cin>>a[i];
  }
  cout<<sa(0,n-1)<<endl;
  return 0;

}


Measured memory_bytes: 70912
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		long n = in.nextLong();
		long k = in.nextLong();
		long r = n % k;
		r = Math.min(r, Math.abs(k - r));
		System.out.println(r);
		in.close();
	}
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	int ans = 0, outlet = 1;
	while (outlet < b) {
		outlet--;
		outlet += a;
		ans++;
	}
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 256
import sys
import math

n = int(raw_input())

for data in sys.stdin:
  x1, y1, x2, y2, x3, y3 = map(float, data.split())
  a1 = x2 - x1
  b1 = y2 - y1
  a2 = x3 - x1
  b2 = y3 - y1
  px = (b2 * (a1 * a1 + b1 * b1) - b1 * (a2 * a2 + b2 * b2)) / (2 * (a1 * b2 - a2 * b1))
  py = (a1 * (a2 * a2 + b2 * b2) - a2 * (a1 * a1 + b1 * b1)) / (2 * (a1 * b2 - a2 * b1))
  r = math.sqrt(px * px + py * py)
  px += x1
  py += y1
  print "{0:.3f} {1:.3f} {2:.3f}".format(px, py, r)

Measured memory_bytes: 4392
k, s = list(map(int, input().split()))
count = int(0)

for x in range(k+1)[::-1]:
    yz = s - x
    if yz > k*2:
        break
    for y in range(k+1)[::-1]:
        z = yz - y
        if x >= y >= z >= 0:
            if len({x, y, z}) == 1:
                count += 1
            elif len({x, y, z}) == 2:
                count += 3
            else:
                count += 6

print(count)


Measured memory_bytes: 3188
#include<stdio.h>

int main(){
  int n,m;
  int q = 1;
  int p = 1;
  int i,j;

  scanf("%d %d", &n, &m);

  if(n == 1 && m == 1) printf("0\n");

  else if(n == 1 && m != 1){
    for(i = 1;i <= 2;i++) p = p*(m - i + 1)/i;
    printf("%d\n", q);
  }

  else if(n != 1 && m == 1){
    for(i = 1;i <= 2;i++) p = p*(n - i + 1)/i;
    printf("%d\n", q);
  }

  else{
    for(i = 1;i <= 2;i++) p = p*(m - i + 1)/i;
    for(j = 1;j <= 2;j++) q = q*(n - j + 1)/j;
    printf("%d\n", p + q);
  }

  return 0;
}


Measured memory_bytes: 128
#include <iostream>	
#include <stdio.h>	
#include <bits/stdc++.h>	
#include <queue>	
using namespace std;	
#define N 1000	
	
int main(){
    int n;
    cin>>n;
    vector<long> num;
    vector<long> data;
    for (int i=0; i<n; i++){
        long a;
        cin>>a;
        num.push_back(a);
        data.push_back(a);
    }
    sort(num.begin(), num.end());
    reverse(num.begin(), num.end());
    long p; //存在しない最小数
    for (int i=1; i<=n+1; i++){
        long count=0;
        while(true){
            if (num.back()==i){ 
                num.pop_back();
                count+=1;
            }
            else break; 
        }
        if (count==0){
            p=i-1;
            break;
        }
    }
    
    if (p==0) cout<<"-1"<<endl;
    else{
        long num_count=1;
        for (int i=0; i<n; i++){
            if (data[i]==num_count) num_count+=1;
        }
        cout<<n-num_count+1<<endl;
    }
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//1e12って、せいぜい2^100くらい？
//公約数列挙して互いに素か全探索してもいけるかな
//100^2/2とかなら全然。いけそう。
//公約数の列挙はしゃくとり法みたいなかんじかな
int main(){
  ll A,B; cin>>A>>B;
  vector<ll> a(0,0), b(0,0), c(0,0);
  for(int i=1; i<=A/i; i++){
    if(A%i==0){
      a.emplace_back(i);
      if(i!=A/i)
        a.emplace_back(A/i);
    }
  }
  for(int i=1; i<=B/i; i++){
    if(B%i==0){
      b.emplace_back(i);
      if(i!=B/i)
        b.emplace_back(B/i);
    }
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ll asz=a.size(), bsz=b.size();
  //a{1,3,4,7,8,11,15}
  //b{1,5,6,7,9,10,11,12,13,14}naikedo
  for(int i=0,j=0; i<asz&&j<bsz; i++){
//    cout<<"i:"<<i<<" j:"<<j<<endl;
    while(a[i]>b[j] && j<bsz)
      j++;
    if(j>=bsz) break;
    if(a[i]==b[j]){
      c.emplace_back(a[i]);
      j++;
      continue;
    }
  }
  //{1,2,3,4,7,12,28,42,84}
  //1,2,3,7
  //素因数分解した個数かな
  //公約数で得られる最大の数字を素因数分解か
  ll ans=1, csz=c.size(), c_max=c[csz-1];
  //めちゃでかい素数だったらやばいな
  for(int i=1; i<csz; i++){
    if(c_max<c[i]) break;
    if(c_max%c[i]==0) ans++;
    while(c_max%c[i]==0)
      c_max/=c[i];
  }  
  cout<<ans<<endl;
}

Measured memory_bytes: 512
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    print(((N - 1) // 1000 + 1) * 1000 - N)

if __name__ == '__main__':
    resolve()


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

typedef long long ll;
const int maxn = 5e3 + 5;

int C[maxn];
ll dp[maxn][maxn], A, B;
int n, where[maxn], a[maxn];

int main(int argc, char const *argv[])
{
	// freopen("in", "r", stdin);
	cin >> n >> A >> B;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		where[a[i]] = i;
	}
	for(int i = 1; i <= n; i++) {
		int c = 0;
		for(int j = 1; j < i; j++) {
			if(where[j] < where[i])
				c++;
		}
		C[i] = c + 1;
	}
	for(int i = 0; i <= n; i++) dp[i][0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= i; j++) {
			if(C[i] > j) {
				dp[i][j] = dp[i - 1][j];
			} else {
				dp[i][j] = min(dp[i - 1][j - 1] + A, dp[i - 1][C[i] - 1] + (j - C[i]) * B);
			}
		}
	}
	cout << dp[n][n] << endl;
	return 0;
}

Measured memory_bytes: 194048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,K;
  cin >> A >> B >> K;
  
  // 100から順に公約数を探す
  
  int cnt = 0; // 今まで見つかった数
  int i;
  for(i = 100; i >= 1; i--){
    
    if(A % i == 0 && B % i == 0){
      cnt++; // 公約数が見つかったらcnt("何番目"のカウント)を1増やす
      if(cnt == K){
        cout << i << endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int32_t main()
{
	//freopen("input.txt", "r", stdin);
	IOS;
	
	int n; cin >> n;
	int x; cin >> x;
	int m; cin >> m;

	unordered_set<int> cache;
	vector<int> path;

	int ans = x, curr = x;
	cache.insert(x);
	path.push_back(x);

	for(int i = 1 ; i < n ; i++)
	{
		int t = (curr*curr)%m;
		if(cache.find(t) != cache.end())
		{
			curr = t;
			// cout << curr << '\n';
			break;
		}
		curr = t;
		ans += t;
		cache.insert(curr);
		path.push_back(curr);
	}

	int sum = 0, index = -1;
	for(int i = 0 ; i < path.size() ; i++)
	{
		if(path[i] == curr)
		{
			index = i;
			// cout << index << '\n';
			break;
		}
	}

	if(index == -1)
	{
		cout << ans << '\n';
		return 0;
	}

	for(int i = index ; i < path.size() ; i++)
	{
		sum += path[i];
	}
	int nums = path.size() - index;
	int done = n - path.size();
	int factor = done/nums;
	int rem = done%nums;

	ans += (factor*sum);
	while(rem--)
	{
		ans += path[index];
		++index;
	}

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 5532
/*
    Author :DurJoy
*/
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a(N), l(N + 1), r(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  l[0] = 0;
  int temp = 0, tot = 0;
  for (int i = 1; i <= N; i++) {
    l[i] = __gcd(l[i - 1], a[i - 1]);
  }
  r[0] = 0;
  for (int i = 1; i <= N; i++) {
    r[i] = __gcd(r[i - 1], a[N - i]);
  }
  int ans = 1;
  for (int i = 1; i <= N; i++) {
    ans = max(ans, __gcd(l[i - 1], r[N - i]));
  }
  cout << ans <<endl;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int stack[100];
int top = 0;
void push(int);
int pop(void);

int main()
{
int x,a,b;
char s[100];

while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
    a=pop();
    b=pop();
    push(a+b);
    } 
    else if ( s[0] == '-' ){
    a=pop();
    b=pop();
    push(b-a);
    } 
    else if ( s[0] == '*' ){
    a=pop();
    b=pop();
    push(a*b);
    } 
    else {
      push(atoi(s));
}
  }
  printf("%d\n",pop());
  return 0;
}

void push(int num)
{
if(top == 100){
    printf("Stack overflow\n");
    exit(2);
}
stack[top] = num;
top++;
}

int pop(void)
{
if(top == 0)
{
    printf("Stack is empty\n");
    exit(3);
}
top--;
return stack[top];
}


Measured memory_bytes: 2108
gets
a = gets.split.map(&:to_i)

sum = 0
70.times do |i|
  n0 = a.count{|x| x[i] == 0}
  #n1 = a.count{|x| x[i] == 1}
  n1 = a.size - n0
  #p [i, n0, n1]

  sum += n0*n1*2**i
end

p sum % (10**9 + 7)


Measured memory_bytes: 36892
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n,a,b = map(int, input().split())

    # k = n // (a+b): 完璧にループがおわったぶん
    # ここにあるBlueはa*k
    # n -( k*(a+b)) : 端数
    # ここにあるBlueはmin(n-(k*(a+b)), a)
    k = n // (a+b)
    eprint(k)
    eprint(min(n-(k*(a+b)), a))
    print(a*k + min(n-(k*(a+b)), a))
    return 

if __name__ == '__main__':
    main()

Measured memory_bytes: 65772
#include <stdio.h>
#define S 1000000000
int N[500000], L[250001], R[250001], count=0;
  
int main(){
  int i, n;

  scanf("%d",&n);
  for(i = 0; i < n; i++)
    scanf("%d",&N[i]);
  
  mergesort(0,n);
  
  for(i = 0; i < n; i++){
    if(i > 0) printf(" ");
    printf("%d",N[i]);
  }
  printf("\n%d\n",count);
  return 0;
}
 
void merge(left, mid, right){
  int n1, n2, i, j, k;

  n1 = mid - left;
  n2 = right - mid;

  for(i = 0; i < n1; i++)
    L[i] = N[left + i];
  for(i = 0; i < n2; i++)
    R[i] = N[mid + i];

  L[n1] = S;
  R[n2] = S;

  i = 0;
  j = 0;

  for(k = left; k < right; k++){
    if(L[i] <= R[j]){
      N[k] = L[i];
      i = i + 1;
      count++;
    }
    else{
      N[k] = R[j];
      j = j + 1;
      count++;
    }  
  }
}
  
void mergesort(left, right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergesort(left, mid);
    mergesort(mid, right);
    merge(left, mid, right);
  }
  return 0;
}

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

using namespace std;

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

    int Sum = 0;

    while(n--)
    {
        int x;  scanf("%d", &x);

        Sum += x;
    }

    puts(Sum >= m ? "Yes" : "No");
}


Measured memory_bytes: 256