akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

int result(string);
int main(){
  ll n; cin >> n;
  string ns = to_string(n);
  int keta = ns.length();

  int ans=result(ns);
  for(int i=0; i<keta; i++){
    n = (n/((ll)pow(10, i)))*((ll)pow(10, i))-1;
    ans = max(ans, result(to_string(n)));
  }

  cout << ans << endl;

  return 0;
}

int result(string s){
  int keta = s.length();
  int ans=0;
  for(int i=0; i<keta; i++){
    ans += s[i]-'0';
  }

  return ans;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
unordered_multiset<long long int>fact(long long int n){
	unordered_multiset<long long int>ret;
	long long int a=2;
	while (n!=1){
		if (n%a==0){
			n/=a;
			ret.insert(a--);
		}
		a++;
	}
	return ret;
}
int main(){
long long int n,p;
cin >>n>>p;
if (n==1){
	cout <<p;
	return 0;
}
if (n>=40 || n==16){
	cout <<"1"<<endl;
	return 0;
}
long long int ans=1;
auto l=fact(p);
long long int cnt=0;
for (long long int i=1;p>=pow(i-1,n);++i)
	cnt=i;
rep(i,cnt){
	long long int tmp=l.count(i);
	if(tmp>=n)
		ans*=pow(i,tmp/n);
}
cout <<ans<<endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

struct edge{ int to, length; };
vector<int> color;
vector<vector<edge>> graph;

void bfs(){
    queue<int> q;
    q.push(0); color[0] = 0;
    while(!q.empty()){
        int node = q.front();
        for(edge e: graph[node]){
            if(color[e.to] != -1) continue;
            color[e.to] = (e.length + color[node]) % 2;
            q.push(e.to);
        }
        q.pop();
    }
}

signed main(){
    int n; cin >> n;
    color = vector<int>(n,-1);
    graph = vector<vector<edge>>(n);
    
    rep(i,n-1){
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        graph[u].push_back({v,w});
        graph[v].push_back({u,w});
    }
    
    bfs();
    
    rep(i,n) cout << color[i] << endl;
}

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


void solve(long long N, long long M, std::vector<long long> p, std::vector<std::string> S){
    map<int, int> WA;
    int PENA = 0;
    int core = 0;
    vector<int> vec(N+1);
    for(int i = 0;i < M;i++){
        if(vec[p[i]] == 0){
            if(S[i] == "WA"){
                WA[p[i]]++;
            }else{
                vec[p[i]] = 1;
                PENA += WA[p[i]];
                core++;
            }
        }
    }
    cout<<core<<" "<<PENA<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> p(M);
    std::vector<std::string> S(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&p[i]);
        std::cin >> S[i];
    }
    solve(N, M, std::move(p), std::move(S));
    return 0;
}


Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  while (getline(cin, s), s != "0") {
    stringstream ss;
    ss << s;
    int sum = 0, one = 0, a;
    while (ss >> a) {
      if (a == 1) one++;
      else sum += min(10, a);
    }
    if (one > 21 || sum > 21 || one + sum > 21) {
      cout << 0 << endl;
    } else {
      int p = (11 * one + sum - 21 + 10 - 1) / 10;
      cout << p + (one - p) * 11 + sum << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <string>
#include <queue>

using namespace std;

void round_robin()
{
	int n, cpu, ptime;
	string name;
	queue< pair<string, int> > que;

	cin >> n >> cpu;

	for (int i = 0; i < n; ++i)
	{
		cin >> name >> ptime;
		que.push( make_pair(name, ptime) );
	}

	for (int counter = 0; !que.empty(); )
	{
		pair<string, int> tmp = que.front();
		que.pop();
		if( tmp.second <= cpu)
		{
			counter += tmp.second;
			cout << tmp.first << " " << counter << endl;
		}
		else
		{
			counter += cpu;
			que.push(make_pair( tmp.first, tmp.second - cpu ) );
		}
	}

}

int main(int argc, char const *argv[])
{
	round_robin();
	return 0;
}

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

using namespace std;

typedef long long ll;
ll x,y;
const ll INF = 1e18;
int main() {
  cin >> x >> y;
  if(x % y == 0) {
    cout << "-1" << endl;
    return 0;
  }

  ll tmp = x;
  while(true) {
    if(tmp % y == 0) {
      tmp += x;
      continue;
    }
    else {
      cout << tmp << endl;
      return 0;
    }
  }
}
  


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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 4000050;
const int maxm = 2005;
const int P = 1e9+7;

int n, k, dp[maxm][maxm], fac[maxn], infr[maxn];

ll comb(int n,int m) {return 1ll*fac[n]*infr[m]%P*infr[n-m]%P;}
int qpow(int a,int b) {int ans = 1; while(b) {if(b&1) ans = (ans*1ll*a)%P; b >>= 1; a = (a*1ll*a)%P;} return ans;}
void upd(int &x,int y) {x += y; if(x > P) x -= P;}
int main()
{
	#ifdef MPS
		fp("agc02f.in","r",stdin);
		fp("agc02f.out","w",stdout);
	#endif
	sf("%d%d",&n,&k);
	fac[0] = 1; fo(i,1,n*k) fac[i] = (fac[i-1]*1ll*i)%P;
	infr[n*k] = qpow(fac[n*k],P-2);
	fd(i,n*k-1,0) infr[i] = infr[i+1]*1ll*(i+1)%P;
	if(k == 1) return 0*pf("1\n");
	dp[0][0] = 1;
	fo(i,0,n) fo(j,0,n)
	{
		if(i < j) upd(dp[i+1][j],dp[i][j]);
		if(j < n) dp[i][j+1] = (dp[i][j+1] + (1ll * dp[i][j] * comb(j*k-j+i+k-2,k-2)) % P) % P;
	}
	pf("%lld\n",(1ll*dp[n][n]*fac[n])%P);
	return 0;
}


Measured memory_bytes: 47232
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


int taro[100],hana[100];

int main(){
	int n,m;
	while(cin>>n>>m){
		if(n==0 && m==0)break;
		
		int sumt=0;
		for(int i=0;i<n;i++){
			cin>>taro[i];
			sumt+=taro[i];
		}
		
		int sumh=0;
		for(int i=0;i<m;i++){
			cin>>hana[i];
			sumh+=hana[i];
		}
		
		int min=-1,taroc=100,hanac=100;
		
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(sumt+2*hana[j]==sumh+2*taro[i] && (min==-1 || min>hana[j]+taro[i])){
					min=hana[j]+taro[i];
					taroc=taro[i];
					hanac=hana[j];
				}
			}
		}
		
		if(min==-1)puts("-1");
		else printf("%d %d\n",taroc,hanac);
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
S = input()
ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N):
  for j in range(i+1,N):
    k = 2*j-i
    if k<N and S[i]!=S[j]!=S[k]!=S[i]:
      ans-=1

print(ans)

Measured memory_bytes: 9120
local n = tonumber(io.read())
local inp = io.read()
local T,a
for i=1,string.len(inp),1 do
  if inp:sub(i,i)==' ' then
    T = tonumber(inp:sub(1,i-1))
    a = tonumber(inp:sub(i+1,string.len(inp)))
  end
end
local hline = io.read()
h={}
string.gsub(hline,"(%S+)", function (v) table.insert(h,tonumber(v)) end)
t={}
for i=1,n,1 do
  t[i]=T-0.006*h[i]
end
res = 1
ti = t[1]
for i=1,n,1 do
  if math.abs(a-ti)>math.abs(a-t[i]) then
    res = i
    ti = t[i]
  end
end
print(res)

Measured memory_bytes: 376
from fractions import gcd
from functools import reduce
import sys


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers, maxvalue):
    first = 1
    second = 1
    for i in numbers:
        second = i
        lcm_result = lcm_base(first, second)
        if lcm_result > max_value:
            return -1
        first = lcm_result
    return lcm_result


n, m = map(int, input().split())
A = list(map(int, input().split()))

max_value = 2 * m

lcm = lcm_list(A, 2 * m)
if lcm == -1:
    print("0")
    sys.exit(0)

if any((lcm / a) % 2 != 1 for a in A):
    print("0")
    sys.exit(0)

max_product = max_value // lcm
print((max_product + 1) // 2)


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
#define MAX 2000000000
#define PI 3.1415926535897932
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  int N;cin>>N;
  ll now = 0;
  vector<pair<ll,ll>> BA;
  rep(i,N){
    ll a,b; cin>>a>>b;
    BA.push_back(make_pair(b,a));
  }
  sort(begin(BA),end(BA));
  rep(i,N){
    now+=BA.at(i).second;
    if(now>BA.at(i).first){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 6128
import java.util.Scanner;

public class Main { //???????????´???-???????????????-(ALDS1_2_B)P65

	public static void main(String[] args) {
		int i,o;  //i?????\?????¨????????°???o???????????¨????????°
		int q,minj,j,taihi;
		int count = 0;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int array[] = new int[n];
		for(i=0;i<n;i++) array[i] = Integer.parseInt(sc.next()); //??\?????????

		//????????????????????????????????¢?????´?????????
			for(q=0;q<n;q++) {
				minj = q;
				for(j=q;j<n;j++) {
					if (array[j] < array[minj]) minj =j;
				}
				if(q != minj){ //???????????????????????¨????????°???????????\????????????????????????
				taihi = array[q];
				array[q] = array[minj];
				array[minj] = taihi;
				count++;
				//System.out.println(count); //???????????????
				}
			}
		for(o=0;o<n-1;o++)
			System.out.print(array[o]+" ");//???????????????
		System.out.println(array[o]);
		System.out.println(count); //???????????????
  }
}

Measured memory_bytes: 26272
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int K;
    cin >> K;
    string S = "ACL";
    for (int i = 0; i < K; i++) cout << S;
    cout << endl;
}

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

int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main(){
    int n,h,a[100001],b[100001];
    a[0]=0;
    b[0]=0;
    //n=100;
    int pri,count;
    scanf("%d%d",&n,&h);
    for(int i=1;i<=n;i++){
        //a[i]=rand();
        scanf("%d%d",&a[i-1],&b[i-1]);
    }
    qsort(a,n,sizeof(int),desc);
    b[n]=a[0];
    qsort(b,n+1,sizeof(int),desc);
    
    if(a[0]>=b[0]){
        if(!(h%a[0])){
            count=h/a[0];
        }else{
            count=h/a[0]+1;
        }
        printf("%d",count);//
        return 0;
    }
    int maxsum=0;
    for(int i=0;i<=n;i++){
        if(a[0]==b[i]){
            pri=i;
            break;
        }
        maxsum+=b[i];
    }
    int sum=0;
    int j,ok=0;
    count=0;
    for(int i=0;-1<i;i++){
        
        sum=0;

        if(h<=maxsum){
        for(j=0;j<pri;j++){
            sum+=b[j];
            if(h<=sum){
                count+=j+1;
                ok=1;
                break;
            }
        }
        }
        if(ok)break;
        
        count++;
        h-=a[0];
        if(h<=0)break;
        
    }
    
    
    printf("%d",count);

    return 0;
}

Measured memory_bytes: 1396
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ll x, y, p, q, r, i, inp;
    vector <ll> a, b, c;

    cin >> x >> y >> p >> q >> r;

    for(i = 0; i < p; i++)
    {
        cin >> inp;
        a.push_back(inp);
    }
    for(i = 0; i < q; i++)
    {
        cin >> inp;
        b.push_back(inp);
    }
    for(i = 0; i < r; i++)
    {
        cin >> inp;
        c.push_back(inp);
    }

    sort(a.begin(), a.end(), greater <ll> ());
    sort(b.begin(), b.end(), greater <ll> ());

    for(i = 0; i < x; i++)
    {
        c.push_back(a[i]);
    }
    for(i = 0; i < y; i++)
    {
        c.push_back(b[i]);
    }

    sort(c.begin(), c.end(), greater <ll> ());

    ll sum = 0;

    for(i = 0; i < x + y; i++)
        sum += c[i];

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 8048
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

H,N = imn()
AB = [iln() for _ in range(N)]

DP = [10 ** 10 for _ in range(10**4*2)]
DP[0] = 0
for i in range(N):
    for j in range(10**4*2):
        if j - AB[i][0] >= 0:
            DP[j] = min(DP[j], DP[j-AB[i][0]] + AB[i][1])
ans = 10**10
for i in range(H, 10**4*2):
    ans = min(ans, DP[i])
print(ans)



Measured memory_bytes: 70744
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll a; cin>>a;
    vec<vec<ll>> m(a, vec<ll>(3)), dp(a, vec<ll>(3));
    for(int q=0; q<a; q++){
        for(int w=0; w<3; w++) cin>>m[q][w];
    }
    dp[0] = m[0];
    for(int q=1; q<a; q++){
        for(int w=0; w<3; w++){
            for(int e=0; e<3; e++){
                if(e==w) continue;
                dp[q][w] = max(dp[q][w], dp[q-1][e]+m[q][w]);
            }
        }
    }
    ll o = 0;
    for(int q=0; q<3; q++) o = max(o, dp[a-1][q]);
    cout<<o;
}

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

int main()
{
    long long int  a, b, c;
    cin >> a >> b >> c;
    long double left = 0, right = 0;
    left = a + b + 2 * sqrt(static_cast<long double>(a * b));
    right = c;
    if(left<right){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
//#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#define REL
//#endif
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

//#pragma GCC optimize("Ofast")
//#pragma target("sse", "sse1")

#define mp make_pair
#define pb push_back

//#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);
//mt19937_64 gen(41);

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}


int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------//
	int s, w;
	cin >> s >> w;
	if (w >= s) {
		cout << "unsafe";
	}
	else
		cout << "safe";
	//----------------------------------------------//

	return 0;
}




Measured memory_bytes: 3640
#include<stdio.h>
int main(void)
{
  int x,n,p[100],flag1=0,flag2=1,i,ans,j;
  int check1,check2;
  scanf("%d %d",&x,&n);

  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  i=1;
  while(1){
    flag1=1;
    flag2=1;
    check1=x+i;
    check2=x-i;
    for(j=0;j<n;j++){
      if(check1==p[j]){
        flag1=0;
      }if(check2==p[j]){
        flag2=0;
      }
    }
    if(flag1==1 && flag2==1){
      ans=check2;
      break;
    }else if(flag1==1){
      ans=check1;
      break;
    }else if(flag2==1){
      ans=check2;
      break;
    }
    i++;
  }
	flag1=0;
  for(i=0;i<n;i++){
    if(p[i]==x){
      flag1 =1;
    }
  }
	if(flag1!=1) ans = x;

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

  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

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

    int k = -1;
    for(int i=1;i<=N-1;i++){
        if(A[i]+A[i+1] >= L){
            k = i;
            break;
        }
    }
    if(k == -1){
        cout << "Impossible" << endl;
        return 0;
    }
    vector<int> ans;
    ans.push_back(k);
    for(int j=k+1;j<=N-1;j++){
        ans.push_back(j);
    }

    for(int j=k-1;j>=1;j--) ans.push_back(j);

    reverse(ans.begin(), ans.end());
    cout << "Possible" << endl;
    for(auto n : ans){
        cout << n << endl;
    }

    return 0;
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vr vector
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define loop(i,n) for(i=0;i<n;i++)
ll power(ll x,ll y,ll md)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = ((res%md)*(x%md))%md;

        // y must be even now
        y = y>>1; // y = y/2
        x = ((x%md)*(x%md))%md;  // Change x to x^2
    }
    return res%md;
}

  /*vr <ll> v;
  ll arr[200009];
 ll maxn=200007;
  void sieve()
 {
     arr[0]=0,arr[1]=0;
     for(ll i=2;i<=maxn;i++)
        arr[i]=1;
   for(ll i=2;i*i<=maxn;i++)
   {
       if(arr[i]==1)
       {
           for(ll j=i*i;j<=maxn;j+=i)
              arr[j]=0;
       }
   }
   for(ll i=1;i<=maxn;i++)
   {
       if(arr[i]==1)
        v.pb(i);
   }
 }*/
/*bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
       return (a.first > b.first);
}*/

int main()
{
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     //ll t; scanf("%lld",&t);
     //sieve();
     //while(t--)
     {
       ll n;
       cin>>n;
       ll p=n%1000;
       if(p==0)
        cout<<0;
       else
       cout<<(1000-p);
     }


    return 0;

}


Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define ri rd<int>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
using namespace std;
const int maxN = 103;

template<class T> T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n;
int f[maxN][maxN];

int main() {

	n = ri();
	memset(f, 0x3f, sizeof f);
	f[0][0] = 0;
	rep (i, 1, n) {
		int c = ri();
		rep (j, 1, n) {
			rep (k, 0, n) if (k != j) {
				f[i][j] = min(f[i][j], f[i-1][k] + (j != c));
			}
		}
	}
	int mn = f[n][1];
	rep (i, 1, n) mn = min(mn, f[n][i]);
	printf("%d\n", mn);

	return 0;
}


Measured memory_bytes: 256
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<pair<int, int>> oprt(N - 1);

	REP(i, N) {
		cin >> A[i];	
	}

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

	// 全要素が0以上のとき
	if (A[0] >= 0) {
		if (N == 2) {
			cout << A[1] - A[0] << endl;
			cout << A[1] << " " << A[0] << endl;
		}
		else {
			oprt[0].first = A[0];
			oprt[0].second = A[1];
			int tmp = A[0] - A[1];
			REP(i, N - 3) {
				oprt[i + 1].first = tmp;
				oprt[i + 1].second = A[i + 2];
				tmp = oprt[i + 1].first - A[i + 2];
			}
			oprt[N - 2].first = A[N - 1];
			oprt[N - 2].second = tmp;
			cout << oprt[N - 2].first - oprt[N - 2].second << endl;
			REP(i, N - 1) {
				cout << oprt[i].first << " " << oprt[i].second << endl;
			}
		}
	}
	// 全要素が負のとき
	else if (A[N - 1] < 0) {
		if (N == 2) {
			cout << A[0] - A[1] << endl;
			cout << A[0] << " " << A[1] << endl;
		}
		else {
			sort(A.begin(), A.end(), greater<int>()); //降順でソート
			oprt[0].first = A[0];
			oprt[0].second = A[1];
			int tmp = A[0] - A[1];
			REP(i, N - 2) {
				oprt[i + 1].first = tmp;
				oprt[i + 1].second = A[i + 2];
				tmp = oprt[i + 1].first - A[i + 2];
			}
			cout << oprt[N - 2].first - oprt[N - 2].second << endl;
			REP(i, N - 1) {
				cout << oprt[i].first << " " << oprt[i].second << endl;
			}
		}
	}
	else {
		if (N == 2) {
			cout << A[1] - A[0] << endl;
			cout << A[1] << " " << A[0] << endl;
		}
		else {
			int tmp_plus = A[N - 1];
			int tmp_minus = A[0];
			for (int i = 1; i < N - 1; i++) {
				if (A[i] >= 0) {
					oprt[i - 1].first = tmp_minus;
					oprt[i - 1].second = A[i];
					tmp_minus = oprt[i - 1].first - oprt[i - 1].second;
				}
				else {
					oprt[i - 1].first = tmp_plus;
					oprt[i - 1].second = A[i];
					tmp_plus = oprt[i - 1].first - oprt[i - 1].second;
				}
			}
			oprt[N - 2].first = tmp_plus;
			oprt[N - 2].second = tmp_minus;
			
			cout << oprt[N - 2].first - oprt[N - 2].second << endl;
			REP(i, N - 1) {
				cout << oprt[i].first << " " << oprt[i].second << endl;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
int P;
ll comb[3030][3030];
void combinit(ll p) {
	for (int i = 0; i <= p; i++) {
		comb[i][0] = 1LL;
		comb[i][i] = 1LL;
	}
	for (int i = 1; i <= p; i++) {
		for (int j = 1; j <= i - 1; j++) {
			comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
			comb[i][j] %= P;
		}
	}
}
 
ll modpow(ll a, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % P;
		a = a * a % P;
		n >>= 1;
	}
	return res;
}
 
vector<int> mul(int j) {
	vector<int>res(P);
	for (int i = 0; i < P; i++) {
		ll temp = modpow(j,P-1-i);
		if ((P - 1 - i) % 2) {
			temp *= -1;
			temp += P;
			temp %= P;
		}
		temp *= comb[P-1][i];
		temp %= P;
		res[i] = temp;
	}
	return res;
}
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> P;
	combinit(P);
	vector<int>ans(P);
	int cnt = 0;
	for (int i = 0; i < P; i++) {
		int a;
		cin >> a;
		if (a) {
			cnt++;
			auto v = mul(i);
			for (int j = 0; j < P; j++) {
				ans[j] += -v[j]+P;
				ans[j] %= P;
			}
		}
	}
 
	ans[0] += cnt;
	ans[0] %= P;
	for (int i = 0; i < P; i++)cout << ans[i] << " ";
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 70272
x = list(input().split())
arr = []
for i in range(len(x)):
    if x[i] == '+':
        a = arr.pop()
        b = arr.pop()
        arr.append(a+b)
    elif x[i] == '-':
        b = arr.pop()
        a = arr.pop()
        arr.append(a-b)
    elif x[i] == '*':
        a = arr.pop()
        b = arr.pop()
        arr.append(a*b)
    else:
        arr.append(int(x[i]))
print(arr[-1])

Measured memory_bytes: 7704
# Field
module Field
  def self.bomb(grid, x, y)
    return grid if grid[x][y] == 0
    grid[x][y] = 0

    search = [
      [1, 0], [0, 1], [-1, 0], [0, -1],
      [2, 0], [0, 2], [-2, 0], [0, -2],
      [3, 0], [0, 3], [-3, 0], [0, -3]
    ]

    for k in 0...search.size
      l = x + search[k][0]
      m = y + search[k][1]
      bomb(grid, l, m) if 0 <= l && l < grid.size && 0 <= m && m < grid[l].size
    end

    grid
  end

  def self.graph(grid)
    grid.each do |row|
      puts row.join
    end
  end
end

n = gets.chomp.to_i

for i in 1..n
  gets

  grid = []

  8.times do
    grid << gets.chomp.split('').map(&:to_i)
  end

  x = gets.chomp.to_i
  y = gets.chomp.to_i

  puts "Data #{i}:"
  Field.graph(Field.bomb(grid, y - 1, x - 1))
end

Measured memory_bytes: 8884
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int N,D,X,A[100],i,j,d,cnt;
inline void solve(){
  IN3(N,D,X);
  REP(i,N){
    IN(A[i]);
    for(j=0;;j++){
      d=A[i]*j+1;
      if(d<=D)cnt++;
      else break;
    }
  }
  OUT(cnt+X);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	double answer = 0;

	for (int i = 1; i <= n; i++) {
		int a = 1;
		a *= n;
		int b = i;
		while (b < k) {
			b *= 2;
			a *= 2;
		}
		answer += (double)1.0 / a;
	}
	printf("%.10lf", answer);
	//while (1);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ull unsigned long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a); i>=(b);i--)
 
const int maxn = 1e5 + 5;
const int maxm = 5000 + 5;
const int MOD = 1e9 + 7;
const int N = 1005;

int n;
int a[maxn * 2],sum[maxn * 2];
char s[maxn * 2];


int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   // #ifndef ONLINE_JUDGE 
   //freopen("input.txt", "r", stdin);
   //#endif // ONLINE_JUDGE 
   cin >> n >> (s + 1);
   a[1] = 1;
   rep(i,2,2*n){
        if(s[i] == s[i - 1]) a[i] = (a[i - 1] == 1) ? -1 : 1;
        else  a[i] = (a[i - 1] == 1) ? 1 : -1;
   } 
   rep(i,0,2*n) sum[i] = sum[i - 1] + a[i];
   if(s[1] == 'W' || s[2*n] == 'W' || sum[2*n]) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
   rep(i,1,2*n) {
      if(i <= n) ans = ans * i % MOD;
      if(a[i] == 1) continue;
      ans = ans * sum[i - 1] % MOD;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 2048
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		long A=scan.nextLong();
		long B=scan.nextLong();
		long C=scan.nextLong();
		long ans=B/C-A/C;
		System.out.println(A%C==0?ans+1:ans);
	}
}


Measured memory_bytes: 23124
def countDivBy(d,a,b):
    resB=b//d
    resA=(a-1)//d
    res = resB-resA
    return res

def gcd(c,d):
    if(d>c):
        c,d = d,c
    a,b=c,d
    r=a%b
    while (r>0):      
        a = b
        b = r 
        r = a%b
    return b
  
A = list(map(int, input().split()))
a, b, c, d = A
g = gcd(c,d)
lcm = (c*d) // g
ans = b - a + 1 - countDivBy(c,a,b) - countDivBy(d,a,b) + countDivBy(lcm,a,b)
print(ans)

Measured memory_bytes: 3064
using System;

namespace agc003_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            Console.WriteLine(0 <= str.IndexOf("N") == 0 <= str.IndexOf("S") && 0 <= str.IndexOf("W") == 0 <= str.IndexOf("E") ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 3032
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main(){
  int n,x;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  int minn = INF;
  int ans = 0;
  for(int i=0;i<n;i++){
    minn = min(minn, v[i]);
    if(v[i]==minn)
        ans++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 1024
//code by lynmisakura.wish to be accepted!
/*************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int a[100010];
int main(void) {
	int n,k,q;cin >> n >> k >> q;
	for (int i = 0; i < q; i++)
	{
		int x;cin >> x;
		a[--x]++;
	}
	for (int i = 0; i < n; i++)
	{
		if (a[i] >= q - k + 1) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <map>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long int ll;


int main() {
    ll n; cin >> n;
    vector<ll> ns(n);
    for (int i = 0; i < n; i++) {
        cin >> ns[i];
    }
    sort(ns.begin(), ns.end(), greater<ll>());
    ll used = 2;
    ll ans = ns[0];
    for (int idx = 1; idx < (int)ns.size() && used < n; idx++) {
        for (int i = 0; i < 2 && used < n; i++) {
            ans += ns[idx];
            used++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4452
#include <iostream>

using namespace std;

int main() {
  int a, b, c;
  int fivecount = 0;
  int sevencount = 0;
  for(int i = 0; i < 3; i++) {
    int x;
    cin >> x;
    if (x == 5)
      fivecount++;
    if (x == 7)
      sevencount++;
  }
  if (fivecount == 2 && sevencount == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int A,B;
  
	std::cin >> A >> B;
  
  	if(A >B){
  	std::cout << A + A - 1 << "\n";
  	}else 
	if(A < B){
    std::cout << B + B - 1 << "\n";
    }else
    {
    std::   cout << A + B << "\n";
    }
  
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

r = INT()
print(3 * r ** 2)

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

int main() {
  int a, b, c;
  int x, y;
  int an=0, bn=0, cn=0;
  int ans;

  cin >> a >> b >> c >> x >> y;

  if(a+b<=2*c) {an=x;bn=y;cn=0;}
  else if(a+b>2*c){
    if(x>=y) {
      if(2*c<=a) {cn=2*x;}
      else if(2*c>a) {an=x-y;cn=2*y;}
    }
    else if(x<y) {
      if(2*c<=b) {cn=2*y;}
      else if(2*c>b) {bn=y-x;cn=2*x;}
    }
  }

  // cout << an <<" "<< bn <<" " << cn <<" " << endl;

  ans = a*an + b*bn + c*cn;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict as dd
from collections import deque as dq
N = int(input())
e = dd(list)
for _ in range(N - 1):
  u, v, w = map(int, input().split())
  e[u].append((v, w))
  e[v].append((u, w))

res = [0] * (N + 1)
visited = [0] * (N + 1)
Q = dq([])
Q.append((1, 0))
visited[1] = 1
while len(Q):
  q = Q.pop()
  for n in e[q[0]]:
    if visited[n[0]] == 1:
      continue
    if n[1] % 2 == 0:
      res[n[0]] = res[q[0]]
    else:
      res[n[0]] = (res[q[0]] + 1) % 2
    Q.append(n)
    visited[n[0]] = 1
  #print(res, q)
for i in range(1, N + 1):
  print(res[i])

Measured memory_bytes: 46360
#include<stdio.h>
  
typedef struct{
  char m[2];
  int n;
  int o;
}Data;
  
int partition(Data *A, int p, int r){
  int i, j, a;
  Data x;
  a = A[r].n;
  i = p - 1;
  for(j = p; j < r; j++){
    if(A[j].n <= a){
      i++;
      x = A[i];
      A[i] = A[j];
      A[j] = x;
    }
  }
  x = A[i + 1];
  A[i + 1] = A[r];
  A[r] = x;
  return i + 1;
}
  
 
 
void quickSort(Data *A, int p, int r){
  int q; 
  if(p < r){
    q = partition(A, p, r);
    quickSort(A, p, q - 1);
    quickSort(A, q + 1, r);
  }
}
 int main(){
  Data A[100000];
  int n2, i, j, v = 0;
  
  scanf("%d",&n2);
  for(i = 0; i < n2; i++){
    scanf("%s %d",A[i].m, &A[i].n);
    A[i].o = i + 1;
  }
  quickSort(A, 0, n2 - 1);
  for(i = 0; i < n2; i++){
    if(A[i].o > A[i + 1].o && A[i].n == A[i + 1].n){
      v++;
      break;
    }
  }
  if(v == 0)
    printf("Stable\n");
  else
    printf("Not stable\n");
  for(i = 0; i < n2; i++)
    printf("%s %d\n",A[i].m, A[i].n);
  return 0;
}

Measured memory_bytes: 1784
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
        }
        Arrays.sort(b);
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }
        Arrays.sort(c);
        
        long count = 0;
        for (int i = 0; i < n; i++) {
            count += (long)lowerBound(a, b[i]) * (n - upperBound(c, b[i]));
        }
        
        
        System.out.println(count);
    }
    
    public static int lowerBound(int[] array, int target) {
        // 初めてのtarget以上のindexを返す
        // {1, 3, 3, 7} target: 3 -> 1
        
        int left = 0;
        int right = array.length;
        
        while (left < right) {
            int center = (left + right) / 2;
            if (array[center] < target) {
                left = center + 1;
            } else {
                right = center;
            }
        }
        
        return left;
    }

    public static int upperBound(int[] array, int target) {
        // 初めてのtarget超過のindexを返す
        // {1, 3, 3, 7} target: 3 -> 3
        
        int left = 0;
        int right = array.length;
        
        while (left < right) {
            int center = (left + right) / 2;
            if (array[center] <= target) {
                left = center + 1;
            } else {
                right = center;
            }
        }
        
        return left;
    }
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        ll a, b, x; cin >> a >> b >> x;
        double ans = atan2(2 * x, a * b * b);
        if(2 * x > a * a * b) {
            ans = atan2(a * a * a, 2 * a * a * b - 2 * x);
        }
        cout << setprecision(10) <<  90.0 - (ans / M_PI) * 180.0 << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	Int flag = 0;
	for (Int i = 1; i < 10; i++) {
		for (Int j = 1; j < 10; j++) {
			if (N == i * j) {
				flag = 1;
				break;
			}
		}
		if (flag)break;
	}

	cout << (flag ? "Yes" : "No") << "\n";

}


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

int main() {
    int N, M;
    int T[110];
    int P[110];
    int X[110];

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

    cin >> M;
    for (int i=1; i<=M; i++) {
        cin >> P[i] >> X[i];
    }

    for (int i=1; i<=M; i++) {
        int sum = 0;
        for (int j=1; j<=N; j++) {
            if (j == P[i]) sum += X[i];
            else sum += T[j];
        }
        cout << sum << endl;
    }
}

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

using namespace std;

//ABC007-Cの問題

struct mazepoint {
	int y;
	int x;
	int fukasa;
};

int main() {

	int h, w;
	cin >> h >> w;

	//int sy, sx;
	//cin >> sy >> sx;
	//sy--;
	//sx--;
	//int gy, gx;
	//cin >> gy >> gx;
	//gy--;
	//gx--;

	vector<int> mukix{ 1,0,-1,0 };
	vector<int> mukiy{ 0,1,0,-1 };

	vector<deque<mazepoint>> todo;					//行く所のスタック
	vector<vector<bool>> seen(h + 1, vector<bool>(w + 1));	//発見したらtrue

	//迷路読み込み
	vector<string> maze(h + 1);
	int counter = 0;
	for (int i = 0; i < h; i++) {
		cin >> maze[i];
		for (int j = 0; j < maze[i].size(); j++) {
			if (maze[i][j] == '#') {
				counter++;
				todo.resize(counter);
				todo[counter-1].push_back({ i,j,0 });
				seen[i][j] = true;
			}
		}
	}

	//幅優先探索処理



	//todo.push_back({ sy, sx });
	//mazepoint s = todo.front();							//今いる場所

	//seen[s.y][s.x] = true;
	//vector<vector<int>> fukasa(h + 1, vector<int>(w + 1, 0));

	int fukasa = -1;
	while (1) {				//vectorのtodoが全部空になるまで	

		fukasa++;
		for (int sh = 0; sh < counter; sh++) {

			while (todo[sh].empty()==false) { //その深さが終わるまで
				mazepoint s = todo[sh].front();						//処理番号を指定
				if (s.fukasa != fukasa) { break; }
				int tugiflg = false;					//次があったらtrueにするフラグ

				for (int i = 0; i < 4; i++) {

					int ny = s.y + mukiy[i];
					int nx = s.x + mukix[i];

					if (ny < 0 || nx < 0 || ny >= h || nx >= w) { continue; }
					if (maze[ny][nx] == '#') { continue; }
					if (seen[ny][nx]) { continue; }

					seen[ny][nx] = true;
					todo[sh].push_back({ ny,nx,fukasa+1 });
					tugiflg = true;
				}
				todo[sh].pop_front(); //次を全部探したので削除する
			}
		}

		bool brkflg = true;
		for (int sh = 0; sh < counter; sh++) {
			if (todo[sh].empty() == false) {
				brkflg = false;
			}
		}
		if (brkflg) { break; }
	}
	//	}

	cout << fukasa << endl;

	return 0;

}

Measured memory_bytes: 661648
#include <stdio.h>
#include <math.h>

int main(){
  int n,i,count=0, min, max=-1000000000;
  int Number[200000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&Number[i]);
  }
  
  min=Number[0];
  
  
  for(i=1;i<n;i++){
  	if(max<Number[i]-min){
  		max=Number[i]-min;
  }if(min>Number[i]){
  	min=Number[i];
  }
  }
  printf("%d\n", max);
  return 0;
}

Measured memory_bytes: 1376
import sys
def solve(N,A,B):
    AB = list(zip(A,B))
    AB = [(a,b) for a,b in AB if a < b] 
    AB.sort(key = lambda x: x[1]/x[0], reverse = True)
    if len(AB) == 0:
        return N
    if len(AB) == 1:
        a,b = AB[0]
        x = N//a
        return N + (b-a) * x
    if len(AB) == 2:
        (a,b),(c,d) = AB
        return max(N + (N - i * c) // a * (b-a) + i * (d-c) for i in range(a))
    dp = list(range(N+1))
    for a,b in AB:
        for n in range(a,N+1):
            y = dp[n-a] + b
            if dp[n] < y:
                dp[n] = y
    return dp[N]
    return dp[n]
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
b = list(map(int,sys.stdin.readline().split()))
ans = solve(solve(n,a,b),b,a)
print(ans)


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

int main(){
    int n;
    cin >> n;
    int t,x,y;
    int rt = 0;
    int rx = 0;
    int ry = 0;
    int p;
    for(int i=0; i!=n; i++){
        cin >> t >> x >> y;
        if(x - rx < 0){
            p = (x - rx) * -1;
        }else{
            p = x - rx;
        }
        rx = x;
        if(y - ry < 0){
            p = (y - ry) * -1 + p;
        }else{
            p = y - ry + p;
        }
        ry = y;
        t = t - rt;
        if(t < p || (t - p) % 2 != 0){
            cout << "No\n";
            return 0;
        }
        rt = rt + t;
    }
    cout << "Yes\n";
    return 0;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOf(listOf(0), listOfInt(), listOf(0)).flatMap { it }.toIntArray()
    var D = 0; for (n in 0 .. N) D += Math.abs(A[n] - A[n + 1])
    val ans = Array(N) { n ->
        D - Math.abs(A[n] - A[n + 1]) - Math.abs(A[n + 1] - A[n + 2]) + Math.abs(A[n] - A[n + 2])
    }
    println(ans.joinToString("\n"))
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { it.toInt() + d }
fun listOfLong(d: Long = 0) = listOfString().map { it.toLong() + d }


Measured memory_bytes: 55996