akhauriyash/Code-Regression huggingface dataset:
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x; cin >> x;
    if (x < 1200) cout << "ABC";
    else if (x < 2800) cout << "ARC";
    else cout << "AGC";
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int D = sc.nextInt();
    int ans = 0;
    for(int i=0;i<N;i++){
      int p = sc.nextInt();
      int q = sc.nextInt();
      double dist = Math.sqrt(Math.pow(p,2)+Math.pow(q,2));
      if(dist<=D) ans++;
    }
    
    System.out.print(ans);
  }
}

Measured memory_bytes: 60476
import sys
sys.setrecursionlimit(100000000)
input=lambda : sys.stdin.readline().rstrip()

l,r=map(int,input().split())

x=l%2019
y=r%2019

if x>=y or r-l>=2019 or x==0:
    print(0)
else:
    ans=99999
    for i in range(x,y+1):
        for j in range(x+1,y+1):
            if i==j:
                break
            ans=min(ans,i*j%2019)
    print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(a) for(int i=0; i<a; i++)



int main ()
{
	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
 
	int n;
	cin >> n;
	int a,b;
	cin  >> a >> b;
	
	string ans = "NG";
	
	for(int i=a; i<=b; i++)
	{
		if(i%n==0)
		ans = "OK";
	}
	
	cout << ans;
	
	return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
    
}
signed main() {
    int a,b;cin>>a>>b;
    int n=gcd(a,b);
    map<int,int>res;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            ++res[i];
            n/=i;
        }
    }
    if(n!=1)res[n]=1;
    int count=1;
    map<int,int>::iterator ite;
    for(ite=res.begin();ite!=res.end();++ite){
        if(ite->S>0)count++;
    }
    cout<<count<<endl;
    
}

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

int main(){
int n,k;
  cin >> n >> k;
int x[n]; 
  for(int i=0;i<n;i++){
  cin >> x[i];
  }
  sort(x,x+n,greater<int>());
int sum=0;
  for(int i=0;i<k;i++){
  sum+=x[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 3508
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <functional>
#include <queue>
#include <cmath>
#include <utility>

using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rep1(i,n) for(int i=1;i<=(int)n;++i)

int N,K;
int A[100010];
const int MOD = 1e9 + 7;
const int MAX = 100010;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main()
{
	cin >> N >> K;

	if (K == 1) {
		cout << 0 << endl;
		return 0;
	}

	rep(i, N) {
		cin >> A[i+1];
	}

	sort(A + 1, A + N + 1);

	COMinit();

	int ans = 0;
	for (int i = K; i <= N; ++i) { // N - K + 1
		ans += COM(i-1, K-1) * A[i];
		ans += MOD * 1000000000ll;
		ans %= MOD;
	}

	// i-1=N-K, i-1 + a = K-1, a = K-(N-K+1)
	int cur = K;
	for (int i = N-K+1; i >= 1; --i) { // N - K + 1
		ans -= COM(cur-1, K-1) * A[i];
		ans += MOD * 1000000000ll;
		ans %= MOD;
		cur++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3328
import itertools

n = int(input())
a = list(map(int, input().split()))
s = list(itertools.accumulate(a))

total = sum(a)

# print(total)
# print(s)
temp = 10**10

for i in range(n):
    l = s[i]
    r = total - s[i]

    temp = min(temp, abs(l-r))

print(temp)



Measured memory_bytes: 100176
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = [0]*(n-k)
for i in range(k, n):
  ans[i-k] = (a[i]>a[i-k])
for i in range(0, n-k):
  print('Yes' if ans[i] else 'No')

Measured memory_bytes: 31572
N = int(input())
score_li = [int(input()) for i in range(N)]
score = sum(score_li)
if score % 10 != 0:
    print(score)
    exit()
else:
    score_li.sort()
    for i in score_li:
        if i % 10 != 0:
            print(score - i)
            exit()
print(0)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <set>
#include <queue>
#include <math.h>
#include <stdbool.h>

#define LL long long
#define inf 0x3f3f3f3f
using namespace std;
const int MAXN=1000005;

int main(){
    int w,h,x,y;
    cin>>w>>h>>x>>y;
    double m=(double)w/2*h;
    printf("%.6lf ",m);
    if(x*2==w&&y*2==h)
        puts("1");
    else puts("0");
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

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

	vector<int> h(n);
	for(int i = 0; i < n; i++)
		cin>>h[i];
	vector<int> dp(n,INT_MAX);
	dp[0] = 0;
	for(int i = 0; i < n; i++)
	{
		for(int j = i+1; j <= i+k && j < n;j++)
		{
			dp[j] = min(dp[j],dp[i] + abs(h[j] - h[i]));
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    LL n,m,k;
    Problem(LL n):n(n){};

    void solve(){
        cin >> m >> k;
        for(int i=0; i<=n; ++i){
            for(int j=0; j<=m; ++j){
                DBG(i*m+j*n-i*j)
                if(i*m+j*n-2*i*j==k){
                    cout << "Yes"<<endl;
                    return;
                }
            }
        }
        cout << "No" <<"\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	private int[] fib = new int [45];
	
	Main() {
		for(int i=0;i<45;i++) {
			if(i<=1)fib[i]=1;
			else fib[i]=fib[i-1]+fib[i-2];
		}
	}
	
	int get(int n) {
		return fib[n];
	}
	
	public static void main(String[] args) {
		System.out.println(new Main().get(new Scanner(System.in).nextInt()));
	}
}


Measured memory_bytes: 26176
import Prelude hiding (min, max, sum)

import Data.Functor ((<$>))

min (x:xs) = go x xs
  where
  go x [] = x
  go x (y:ys) = if x < y then go x ys else go y ys

max (x:xs) = go x xs
  where
  go x [] = x
  go x (y:ys) = if x > y then go x ys else go y ys

sum = foldr (\x a -> x + a) 0

main = do
  _ <- getLine
  xs <- map read . words <$> getLine
  putStrLn $ unwords $ map show [min xs, max xs, sum xs]



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

///Author:Refat(BSMRSTU)///

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const int M = 1e9 + 7;
double pi=2*acos(0.0);
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}
int main() {
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);
    int n,ans=0;char ch;
    string s;
    scanf("%d",&n);
    cin>>s;
    for(int i=0;i<n;){
        ch=s[i];
        while(ch==s[i]&&i<n){
            i++;
        }
        ans++;
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main()
{
	int a, b;
	int c, d;

	cin >> a >> b;

	c = a*b;
	d = 2 * a + 2 * b;

	cout << c << " " << d << endl;

	cin >> a;

	return 0;
	
}

Measured memory_bytes: 1164
import math

A,B,H,N = list(map(float,input().split()))

H_0 = H+N/60
N_0 = N/5
Z = H_0-N_0

if Z>6:
  angle = (12-Z)*30
else:
  angle = Z*30
  


length = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(angle)))
print(length)



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

int main() {
    int a, b;
    cin >> a >> b;
    cout <<  a*b << ' ' << 2*a+2*b  << endl;
    return 0;
}


Measured memory_bytes: 3016
#include <iostream>
#include <string>

int main() {
  std::string S;  std::cin >> S;
  if (S == "SSS")
    std::cout << "0\n";
  if (S == "RSS" or S == "SRS" or S == "SSR" or S == "RSR")
    std::cout << "1\n";
  if (S == "RRS" or S == "SRR")
    std::cout << "2\n";
  if (S == "RRR")
    std::cout << "3\n";

  return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i = 0 ; i < n-1 ; i++ ){
		cin >> a[i];
	}
	vector<int>v;
	v.push_back(a[0]);
	v.push_back(a[0]);
	for(int i = 1 ; i < n-1 ; i++){
		if(v[i]>a[i]){
			v[i]=a[i];
		}
		v.push_back(a[i]);
	}
	int sum=0;
	for(auto x : v){
		sum+=x; 
	}
	cout<<sum;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;


//const int mod=1000000007;
const int mod=998244353;



int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,d,y,l,r;
    cin >> n;
    map<ll,ll>  map;
    for(ll i=2; i*i<=n; i++){
        if(n%i==0){
            while(n%i==0){
                map[i]++;
                n/=i;
            }
        }
    }
    if(n!=1){
        map[n]++;
    }
    c=0;
    for(auto it: map){
        a=it.se;
        b=1;
        while(b*(b+1)/2<=a){
            b++;
        }
        c+=b-1;
    }
    cout << c << el;
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  double R, G;
  cin >> R >> G;

  cout << 2*G-R << endl;

  return 0;
}


Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;

int main()
{
    int d=0,t=0,i,ans=0,s=0;
    cin >> d >> t >> s;
    if(s*t>=d)
    {
        cout << "Yes" << endl;
    }
    else
    {
            cout << "No" << endl;
    }
    
  return 0;
}


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

int main(){

   
    int n,k;
    int ans=-1;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<pair<int,int> > v;
    for(int i=0;i<n;i++){
        int j=i;
        while(j<n&&s[j]==s[i]){
            j++;
        }
        v.push_back(make_pair(s[i]-'0',j-i));
        i=j-1;
    }
    if(v.front().first!=1)
    v.insert(v.begin(),make_pair(1,0));
    for(int i=0;i<v.size();i++){
        if(i==0) continue;
        v[i].second+=v[i-1].second;
    }

    // for(auto it:v){
    //     cout<<it.first<<" "<<it.second<<endl;
    // }
    if(v.front().first==1){
        int j=0;
        int i=0;
        while(k--&&j<v.size()){
            j+=2;
        }
        while(j<v.size()){
        
            if(i==0){
                ans=max(ans,v[j].second);
            }
            else{
                ans=max(ans,v[j].second-v[i-1].second);
            }
    
        i+=2;
        j+=2;
    }
    j=v.size()-1;
    if(i==0){
                ans=max(ans,v[j].second);
            }
            else{
                ans=max(ans,v[j].second-v[i-1].second);
            }
}   
cout<<ans;
    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int,int>
using namespace std;
char S[110];
int n;
bool pal(int x, int y){
	for(int i = x, j = y; i <= j; i++, j--){
		if(S[i] != S[j]) return false;
	}
	return true;
}
int main(){
	scanf("%s", S);
	n = strlen(S);
	printf("%s\n", (pal(0, n-1) && pal(0,n/2-1) && pal(n/2+1, n-1)) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>

#define N 101

using namespace std;

struct Node{
  vector<int> cons;
  vector<int> costs;
};

struct State{
  int id;
  int cost;
  int sz;
  bool vis[N];
  State():id(0),cost(0),sz(0){
    fill(vis,vis+N,false);
    vis[0]=true;
  }
  State(int id, int cst, int sz):id(id),cost(cst),sz(sz){
    fill(vis,vis+N,false);
    vis[id]=true;
  }
  bool isMST(){
    for(int i = 0; i < sz; ++i){
      if( !vis[i] ) return false;
    }
    return true;
  }
  bool operator>(const State &t)const{
    return cost < t.cost;
  }
};

const int infty = 1<<28;
struct Edge{
  int src,dst;
  Edge():src(0),dst(0){}
  Edge(int s,int d):src(s),dst(d){}
};

int Prim(const vector<Node> &G){
  int ret = 0;
  bool inMST[G.size()];
  vector< Node > MST;
  vector< Edge > MSTE;

  fill( inMST, inMST+G.size(), false );
  MST.push_back( G[0] );
  inMST[0]=true;
  while( MST.size() < G.size() ){
    int from_id = 0;
    int next_id = 0;
    int mincost = infty;

    for(int i = 0; i < MST.size(); ++i){
      for(int j = 0; j < MST[i].cons.size(); ++j){
	if( !inMST[ MST[i].cons[j] ] &&
	    mincost > MST[i].costs[j] ){
	  from_id = i;
	  next_id = MST[i].cons[j];
	  mincost = MST[i].costs[j];
	}
      }
    }
    //cout << "FROM : " << from_id << " NEXT : " << next_id << " COST : " << mincost << endl;

    inMST[ next_id ] = true;
    ret += mincost;
    MST.push_back( G[next_id] );
    MSTE.push_back( Edge(from_id, next_id) );
  }

  /*
  for(int i = 0; i < MSTE.size(); ++i){
    cout << MSTE[i].src << " -> " << MSTE[i].dst << endl;
  }
  */

  return ret;
}

int main(){
  while(true){
    int n,m;
    vector<Node> G;
    cin >> n >> m;
    if( n == 0 && m == 0 ) break;
    G.resize(n);
    for(int i = 0; i < m; ++i){
      int a,b,cost;
      cin>>a>>b>>cost;
      G[a].cons.push_back( b );
      G[a].costs.push_back( cost );
      G[b].cons.push_back( a );
      G[b].costs.push_back( cost );
    }
    cout << Prim(G) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		//（a,c）
		long ac = 0;
		ac = a * c;

		//（b,d）
		long bd = 0;
		bd = b * d;

		//（a,d）
		long ad = 0;
		ad = a * d;

		//（b,c）
		long bc = 0;
		bc = b * c;

		long values[] = {ac,bd,ad,bc};
		long max = values[0];

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


		System.out.println(max);

	}

}


Measured memory_bytes: 35736
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    string s; cin>>s;
    map<char, vector<int>> a;
    map<char, set<int>> t;
    rep(i,n) {
        a[s[i]].push_back(i);
        t[s[i]].insert(i);
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            if (s[i] == s[j]) continue;
            set<char> b;
            b.insert(s[i]); b.insert(s[j]);
            if (!b.count('R')) {
                auto itr = lower_bound(a['R'].begin(), a['R'].end(),j+1);
                ans += (a['R'].end())-itr;
                int z = j-i;
                int q = j+z;
                if (t['R'].count(q)) ans--;
            }
            else if (!b.count('G')) {
                auto itr = lower_bound(a['G'].begin(), a['G'].end(),j+1);
                ans += (a['G'].end())-itr;
                int z = j-i;
                int q = j+z;
                if (t['G'].count(q)) ans--;
            }
            else {
                auto itr = lower_bound(a['B'].begin(), a['B'].end(),j+1);
                ans += (a['B'].end())-itr;
                int z = j-i;
                int q = j+z;
                if (t['B'].count(q)) ans--;
            }
        }
    }

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

Measured memory_bytes: 3728
N = int(input())
P = [int(x) for x in input().split()]

a = [i*N + 1 for i in range(N)]
b = [i*N + 1 for i in reversed(range(N))]

for i in range(N) :
    a[P[i]-1] += i

print(*a)
print(*b)


Measured memory_bytes: 6308
object Main extends App {
  import scala.io.StdIn._
  val Array(h, w) = readLine.trim.split(' ').map(_.toInt)
  val state = new State(Array.tabulate(h){_ ⇒ readLine.trim})
  println(
    if (state.grundyNumberAt(0, w - 1, 0, h - 1) == 0) "Second"
    else "First"
  )
  class State(state: Array[String]) {
    private val memo: Array[Array[Array[Array[Option[Int]]]]] = Array.tabulate(state.head.length){_ ⇒ Array.tabulate(state.head.length){_ ⇒ Array.tabulate(state.length){_ ⇒ Array.tabulate(state.length){_ ⇒ None: Option[Int]}}}}
    private val isMarked: Array[Array[Boolean]] = state.map(str ⇒ str.map(_ == 'X').toArray)
    def grundyNumberAt(left: Int, right: Int, top: Int, bottom: Int): Int = {
      if (left > right || top > bottom) 0
      else memo(left)(right)(top)(bottom) match {
        case Some(r) ⇒ r
        case None if left == right || top == bottom ⇒
          if ((left to right).forall(x ⇒ (top to bottom).forall(y ⇒ isMarked(y)(x)))) {
            memo(left)(right)(top)(bottom) = Some(0)
            0
          }
          else {
            memo(left)(right)(top)(bottom) = Some(1)
            1
          }

        case None ⇒
          val next = (left to right).flatMap(x ⇒
            (top to bottom).withFilter(y ⇒ !isMarked(y)(x)).map(y ⇒
              grundyNumberAt(left, x - 1, top, y - 1) ^
                grundyNumberAt(x + 1, right, top, y - 1) ^
                grundyNumberAt(left, x - 1, y + 1, bottom) ^
              grundyNumberAt(x + 1, right, y + 1, bottom)
            )).distinct.toSet
          val g = (0 to 1000).find(i ⇒ !next.contains(i)).get
          memo(left)(right)(top)(bottom) = Some(g)
          g
      }
    }
  }
}


Measured memory_bytes: 268044
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n,m) for (int i = (int)(n); i < (int)(m); i++)

#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

typedef long long ll;

vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

bool isR(string s);

int main()
{
    int N,K;
    cin >> N >> K;
    string Ne,Ke;
    if(N>K)
    {
        rep(i,N)
        {
            Ke = Ke + to_string(K);
        }
        cout << Ke;
    }
    else
    {
        rep(i,K)
        {
            Ne = Ne + to_string(N);
        }
        cout << Ne;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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 = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int cnt = 0;
    for(int i = 0 ; i < n-1 ; i++){
        if(h[i]-h[i+1]>=2){cout <<"No";return 0;}
        if(h[i]-h[i+1]==1)cnt++;
        if(h[i]<h[i+1]) cnt = 0;
        if(cnt==2){cout << "No";return 0;}
    }
    cout << "Yes";
}


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

int L[2010][2010],R[2010][2010],D[2010][2010],U[2010][2010];

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;++i){
    cin >> s[i];
  }
  //int L[2010][2010],R[2010][2010],D[2010][2010],U[2010][2010];
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(s[i][j]=='#'){
        L[i][j]=0;
      }else{
        if(j==0){
          L[i][j]=1;
        }else{
          L[i][j]=L[i][j-1]+1;
        }
      }
    }
  }
  for(int i=0;i<h;++i){
    for(int j=w-1;j>=0;--j){
      if(s[i][j]=='#'){
        R[i][j]=0;
      }else{
        if(j==w-1){
          R[i][j]=1;
        }else{
          R[i][j]=R[i][j+1]+1;
        }
      }
    }
  }
  for(int i=0;i<w;++i){
    for(int j=0;j<h;++j){
      if(s[j][i]=='#'){
        D[j][i]=0;
      }else{
        if(j==0){
          D[j][i]=1;
        }else{
          D[j][i]=D[j-1][i]+1;
        }
      }
    }
  }
  for(int i=0;i<w;++i){
    for(int j=h-1;j>=0;--j){
      if(s[j][i]=='#'){
        U[j][i]=0;
      }else{
        if(j==h-1){
          U[j][i]=1;
        }else{
          U[j][i]=U[j+1][i]+1;
        }
      }
    }
  }
  int ans=0;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      ans=max(ans,L[i][j]+R[i][j]+D[i][j]+U[i][j]-3);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    while (!(H==0&&W==0)) {
        for (int i =0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <climits>

#include <cstring>
#include <queue>
using namespace std;

#define DEBUG (0)

#if DEBUG
#define DPRINTF(...) do { \
    printf("D(L%d) %s: ", __LINE__, __func__); \
    printf(__VA_ARGS__); \
  } while (false)
#else
#define DPRINTF(...)
#endif // DEBUG


const int kInvalid = -1;
const int kMaxUsers = 100 * 1000 + 1;

int g_group[kMaxUsers]; // 400 KiB

// 100 K * sizeof(vector<int>) + 100 K * sizeof(int)
// = 2.4 MiB + 100 K * sizeof(int)
vector<int> g_list[kMaxUsers];

void setRelations(int start, int end)
{
  g_list[start].push_back(end);
  g_list[end].push_back(start);
}


void doGrouptize()
{
  // debug info
  DPRINTF("size of g_group[] %lu Byte\n", sizeof(g_group));
  DPRINTF("size of g_list[]  %lu Byte\n", sizeof(g_list));

  // init
  int groupId = 0;
  //memset(g_group, kInvalid, kMaxUsers);
  for (int i = 0; i < kMaxUsers; i++)
    g_group[i] = kInvalid;

  for (int i = 0; i < kMaxUsers; i++)
  {
    if (g_group[i] != kInvalid)
      continue;

    g_group[i] = groupId;

    // grouptize connected users in BFS order
    queue<int> que;
    que.push(i);

    while (!que.empty())
    {
      const int current = que.front();
      que.pop();

      for (int j = 0; j < g_list[current].size(); j++)
      {
        const int next = g_list[current][j];

        if (g_group[next] != kInvalid)
          continue;

        g_group[next] = groupId;
        que.push(next);
      }
    }

    groupId++;
  }
}


void printAllRelations()
{
#if DEBUG
  for (int i = 0; i < kMaxUsers; i++)
  {
    for (int j = 0; j < g_list[i].size(); j++)
    {
      if (j == 0)
        DPRINTF("%d", i);

      printf(" %d", g_list[i][j]);

      if (j == g_list[i].size() - 1)
        cout << endl;
    }
  }
#endif // DEBUG
}


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

  DPRINTF("number of users %d\n", n);
  DPRINTF("number of relations %d\n", m);

  for (int i = 0; i < m; i++)
  {
    int s, t;
    cin >> s >> t; cin.ignore();

    setRelations(s, t);
  }

  printAllRelations();

  doGrouptize();

  int q;
  cin >> q; cin.ignore();

  for (int i = 0; i < q; i++)
  {
    int s, t;
    cin >> s >> t; cin.ignore();

    DPRINTF("src %d  dst %d\n", s, t);

    if (g_group[s] == g_group[t])
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }

  return 0;

}



Measured memory_bytes: 8984
N = int(input())
connect_list = [[] for i in range(N)]
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    connect_list[u].append([v,w])
    connect_list[v].append([u,w])

#print(connect_list)
d = [0]+[-1 for i in range(N-1)]
stack = []
stack.append(0)
while len(stack) != 0:
    #print("Stack=",stack)
    s = stack.pop()
    #print("s=",s)
    for x,w in connect_list[s]:
        #print("x=",x,"W=",w)
        if d[x] == -1:
            d[x] = d[s] + w
            stack.append(x)
        #print("d=",d)
for i in range(N):
    print(d[i]%2)

Measured memory_bytes: 48968
N = int(input())

iti = N % 10

if iti == 3:
  print('bon')

if iti == 0 or iti == 1 or iti == 6 or iti == 8:
  print('pon')

if iti == 2 or iti == 4 or iti == 7 or iti == 9 or iti == 5:
  print('hon')

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

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

int main(){

  int n;
  cin >> n;
  rep(i,n){
    int y,m,d,ans=0;
    cin >> y >> m >> d;
    while(y<1000){
      while(m<=10){
	while(d<=19){
	  d++; ans++;	
	}
	if(y%3==0 || m%2 == 1) ans++;
	d=1;
	m++;
      }
      m=1; 
      y++;
    }
    cout << ans << endl;
  }

}

Measured memory_bytes: 1160
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;


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

        int x =  in.nextInt();
        int y =  in.nextInt();
        int z =  in.nextInt();
        int p = x;
//        x = y;
//        y =p;
//
//        z= x;

        System.out.println(z+ " " +x + " " + y);






    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 21204
import sys

def solve():
    input = sys.stdin.readline
    A, B, C = map(int, input().split())
    count = 0
    while count < C:
        if B >= A:
            count += 1
            B -= A
        else: break
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	ll n,sum = 0,memo = 0,ans = 10000000000;
	cin >> n;
	ll a[n];
	
	rep(i,0,n){
		cin >> a[i];
		sum += a[i];
	}
	
	
	
	rep(i,0,n-1){
		memo += a[i];
		ans = min(abs((sum-memo)-memo),ans);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import math
def get_primenumber(number):
    prime_list = []
    #2からnumberまでの数字をsearch_listに入れる
    search_list = list(range(2,number+1))
    while True:
      if search_list[0] > math.sqrt(number):
        prime_list.extend(search_list)
        break
      else:
        head_num = search_list[0]
        prime_list.append(head_num)
        search_list.pop(0)
        search_list = [num for num in search_list if num % head_num != 0]
    return prime_list

#input = raw_input
a = get_primenumber(10**5+4)
n = int(input())
for val in a:
    if val >= n:
        print(val)
        break

Measured memory_bytes: 8692
#include<bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int,int>P;

#define INF INT_MAX;
#define F first
#define S second

int main(){
  double a,b,p,q,r;
  scanf("%lf %lf %lf %lf %lf",&a,&b,&p,&q,&r);

  printf("%lf\n",(p*b-q*(b-a))/(q+r)+b);

  return 0;
}



Measured memory_bytes: 3216
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun calc-parallel-case (x y)
  (cond ((< x 3) most-positive-fixnum)
        ((zerop (mod x 3)) 0)
        (t y)))

(defun main ()
  (let* ((h (read))
         (w (read))
         (area (* h w))
         (res (min (calc-parallel-case h w)
                   (calc-parallel-case w h))))
    (declare (uint32 h w)
             (uint62 res area))
    (loop for segment from 1 below h
          for area1 of-type uint62 = (* segment w)
          for area2 of-type uint62 = (* (- h segment) (floor w 2))
          for area3 of-type uint62 = (- area area1 area2)
          for tmp-min = (- (max area1 area2 area3)
                           (min area1 area2 area3))
          do (setf res (min res tmp-min)))
    (loop for segment from 1 below w
          for area1 of-type uint62 = (* segment h)
          for area2 of-type uint62 = (* (- w segment) (floor h 2))
          for area3 of-type uint62 = (- area area1 area2)
          for tmp-min = (- (max area1 area2 area3)
                           (min area1 area2 area3))
          do (setf res (min res tmp-min)))
    (println res)))

#-swank(main)


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

int main()
{
    string s;
    cin >> s;

    ll counter = 0;

    int j=0;

    for(int i=0;i<s.size();i++)
    {
        if(s.at(i)=='W')
        {
            counter += (i-j);
            j++;
        }
    }

    cout << counter << endl;

    return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-

import sys
import os
import math

T = [0] * 2001
for a in range(1001):
    for b in range(1001):
        T[a + b] += 1

for s in sys.stdin:
    n = int(s)

    sum_n_num = 0
    for a_b_sum in range(0, n+1):
        c_d_sum = n - a_b_sum
        if a_b_sum <= 2000 and c_d_sum <= 2000:
            sum_n_num += T[a_b_sum] * T[c_d_sum]

    print(sum_n_num)

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007      //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

signed main()
{
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K<=A){
        cout << K << endl;
    }else if(K <= A+B){
        cout << A << endl;
    }else{
        cout << A - (K - A - B) << endl;
    }
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
using namespace std;
int n, m;
char s[20][20];
int pp[20];
int match[20];
int ans = 0;
void check() {
	memset(match, 0, sizeof(match));
	int po = 0;
  	int i, j, k;
   	if(n&1){
   		for(i = 1; i <= n; i++) if(!pp[i]) po = i;
   	}
   	int res = 0;
   	if(m&1) res++;
   	for(i = 1; i <= m; i++){
   		if(match[i] > 0) continue;
    	for(j = i+1; j <= m; j++){
   			bool bk = true;
   			for(k = 1; k <= n; k++){
   				if(pp[k] > k){
   					if(s[k][i] != s[pp[k]][j] || s[pp[k]][i] != s[k][j]){ bk = false; break; }
    			}
   			}
   			if(n&1 && s[po][i] != s[po][j]) bk = false;
   			if(bk){ match[i] = j, match[j] = i; break; }
   		}
   		if(!match[i]){
   			if(res > 0) res--;
   			else return;
   		}
   	}
   	ans = 1;
}
void dfs(int x, int op) {
  	if(ans == 1) return;
   	if(x == n+1){ check(); return; }
   	if(pp[x] > 0){ dfs(x+1, op); return; }
   	for(int i = x+1; i <= n; i++){
   		if(!pp[i]){
   			pp[i] = x; pp[x] = i;
   			dfs(x+1, op);
   			pp[i] = pp[x] = 0;
   		}
   	}
   	if(n&1 && !op) dfs(x+1, 1);
}
int main() {
 	int i, j, k;
 	scanf("%d%d", &n, &m);
  	for(i = 1; i <= n; i++) scanf("%s", s[i]+1);
   	dfs(1, 0);
   	if(ans == 1) printf("YES\n");
   	else printf("NO\n");
   	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
 
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORL(i,a,b) for(LL i=(a);i<(b);++i)
#define REPL(i,n)  FORL(i,0,n)
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}

inline double get_time_sec(void){
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}

template<typename T>
T gcd(T a, T b) {
    if(a > b) swap(a, b);
    if(a == 0) return b;
    else return gcd(b%a, a);
}

template<typename T>
map<T, T> prime_list(T n) {
    map<T, T> ret;
    for(T i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            ret[i] = 0;
            while(n % i == 0) {
                n /= i;
                ret[i]++;
            }
        } 
    }
    if(n != 1) ret[n]++;
    return ret;
}

#define MOD 1000000007

LL mypow(LL a, LL n) {
    if(n == 1) return a % MOD;
    if(n % 2 == 1) return (a * mypow(a, n-1)) % MOD;
    LL t = mypow(a, n/2);
    return (t * t) % MOD; 
}

int main(void) {
    LL x, y;
    cin >> x >> y;
    LL ans = 0;
    while(x <= y) {
        x *= 2;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys


sys.setrecursionlimit(1000000)


MAX_N = 100001

memo = [-1] * MAX_N


def f(n):
    # 残り金額が0なら引き出す必要がないので0(再帰の終端条件)
    if n == 0:
        return 0
    # すでに探索済みならメモを参照する
    if memo[n] != -1:
        return memo[n]

    res = sys.maxsize

    pow9 = 1
    while pow9 <= N:
        if n - pow9 < 0:
            break
        # print(n)
        # print(pow9)
        res = min(res, f(n-pow9)+1)
        pow9 *= 9

    pow6 = 1
    while pow6 <= N:
        if n - pow6 < 0:
            break
        res = min(res, f(n-pow6)+1)
        pow6 *= 6

    # メモ
    memo[n] = res

    return res


if __name__ == '__main__':
    N = int(input())

    print(f(N))



Measured memory_bytes: 89668
N, K, *x = map(int, open(0).read().split())
ans = 1e9
for i in range(N - K + 1):
    l = x[i]
    r = x[i + K - 1]
    ans = min(ans, abs(l) + (r - l), abs(r) + (r - l))
    
print(ans)

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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000000000000000 // If you use it, make sure not to put in "int" type variable ;(, use long long int
const ll mod=2;

int main()
{
    int nT; nT=1;
    while(nT--)
    {
        ll n; cin>>n;
        ll a[n+2];
        ll b[n+2];
        a[0]=a[n+1]=0;
        ll neg=0;
        ll mn=1000000000000;
        for(int i=1; i<=n; i++)
            {
                cin>>a[i];
                if(a[i]<0) neg++;
                mn=min(mn,abs(a[i]));
            }
        ll tot=0;
        for(int i=1; i<=n; i++) tot+=abs(a[i]);
        if(neg%2==0) cout<<tot;
        else cout<<tot-2*mn;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <vector>

using namespace std;
int calc(int N, int A, int B, int C, int n, int a, int b, int c, int l[]){
	if (n == N){
		if(a > 0 && b > 0 && c > 0){
			return abs(A - a) + abs(B - b) + abs(C - c) - 30;
		}
		else{
			return 10000000;
		}
	}
	else{
		int res0 = calc(N, A, B, C, n+1, a, b, c, l);
		int res1 = calc(N, A, B, C, n+1, a + l[n], b, c, l) + 10;
		int res2 = calc(N, A, B, C, n+1, a, b + l[n], c, l) + 10;
		int res3 = calc(N, A, B, C, n+1, a, b, c + l[n], l) + 10;
		return min({res0, res1, res2, res3});
	}
}
int main(){
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	int l[N];
	for(int i = 0;i<N;i++){
		cin >> l[i];
	}
	cout << calc(N, A, B, C, 0, 0, 0, 0, l) << endl;
}


Measured memory_bytes: 256
def binarysearch(list,key):
    left = 0
    right = len(list)
    while left < right:
        mid = (left + right)//2
        if list[mid] == key:
            return mid + 1
        elif list[mid] > key:
            right = mid
        else:
            left = mid + 1
    return 0

N = int(input())
S = list(map(int,input().split()))
q = int(input())
T = list(map(int,input().split()))
ans = 0
for i in range(q):
    if binarysearch(S,T[i]):
        ans += 1
print(ans)



Measured memory_bytes: 16708
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int k; cin >> k;

  int sum = 0;

  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int m=1;m<=k;m++){
        int g = __gcd(i,j);
        g = __gcd(g,m);
        sum+=g;
      }
    }
  }

  cout << sum << '\n';

  

  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

int main() {
  int value;
  string opecode;
  while( 1 ) {
    string token;
    cin >> token;
    if( token == "=" ) { break; }
    if( '0' <= token[ 0 ] && token[ 0 ] <= '9' ) {
      int operand = atoi( token.c_str() );
      value = opecode == "+" ? value + operand :
              opecode == "-" ? value - operand :
              opecode == "*" ? value * operand :
              opecode == "/" ? value / operand :
              operand;

    } else {
      opecode = token;
    }
  }
  cout << value << endl;

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int n,k,i,max;
  cin>>k>>n;
  long long int a[n],b[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    if(i!=0)b[i-1]=a[i]-a[i-1];
    if(i==1)max=b[0];
    if(i>1&&b[i-1]>max)max=b[i-1];
  }
  b[n-1]=a[0]-a[n-1]+k;
  if(b[n-1]>max){
  	max=b[n-1];
  }
  cout<<k-max<<endl;
}
    

Measured memory_bytes: 3328
#include<iostream>
#define  int long long
using namespace std;
struct Node
{
    int x;
    Node *l,*r,*p;
}*root,*NIL;


void Insert(int v)
{
    Node *x=root,*y=NIL,*z=new Node();
    z->l=z->r=NIL;
    z->x=v;
    while(x!=NIL)
    {
        y=x;
        if(z->x<x->x)
            x=x->l;
        else x=x->r;
    }
    z->p=y;
    if(y==NIL)root=z;
    else if(z->x<y->x)y->l=z;
    else y->r=z;
}

bool Find(int v)
{
    Node *x=root,*y=NIL;
    while(x!=NIL)
    {
        y=x;
        if(x->x==v)
        return true;
        else if(x->x<v)x=x->r;
        else x=x->l;
    }
    return false;
}

void Inorder(Node *x)
{
    if(x==NIL)return ;
    Inorder(x->l);
    cout<<' '<<x->x;
    Inorder(x->r);
}

void Pre(Node *x)
{
    if(x==NIL)return ;
    cout<<' '<<x->x;
    Pre(x->l);
    Pre(x->r);
}
void Post(Node *x)
{
    if(x==NIL)return ;
    Post(x->l);
    Post(x->r);
    cout<<' '<<x->x;
}
void Print()
{
    Inorder(root);cout<<endl;
    Pre(root);cout<<endl;
}
signed main()
{
    int n,x;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s=="find")
        {   cin>>x;
            if(Find(x))cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
        else if(s=="insert")cin>>x,Insert(x);
        else Print();
    }
    return 0;
}



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

const int N = 200005;

int n;
int a[N];

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

  printf("%d\n", n % 1000 == 0 ? 0 : 1000 - n % 1000);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 3824