akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
   	int n, i = 0;
  	cin >> n;
  	while(true){
      	i++;
    	if(i*i > n){
        	cout << (i-1)*(i-1) << endl;
          	return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
def calc_start(mid):
    cnt = -1
    i = 1
    while 10 ** i < mid:
        cnt += i * (10 ** i - 10 ** (i - 1))
        fif = (10 ** i - 1) // 15 - (10 ** (i - 1) - 1) // 15
        three = (10 ** i - 1) // 3 - (10 ** (i - 1) - 1) // 3
        five = (10 ** i - 1) // 5 - (10 ** (i - 1) - 1) // 5
        cnt += (three + five) * 4 - (three + five - fif) * i
        i += 1
    cnt += i * (mid - 10 ** (i - 1))
    fif = (mid - 1) // 15 - (10 ** (i - 1) - 1) // 15
    three = (mid - 1) // 3 - (10 ** (i - 1) - 1) // 3
    five = (mid - 1) // 5 - (10 ** (i - 1) - 1) // 5
    cnt += (three + five) * 4 - (three + five - fif) * i
    return cnt + 1


N = int(input()) - 1
left, right = 1, 10 ** 18
while left + 1 < right:
    mid = (left + right) // 2
    start = calc_start(mid)
    if start <= N:
        left = mid
    else:
        right = mid
ans = ''
for i in range(left, left + 30):
    tmp = ''
    if i % 3 == 0:
        tmp += "Fizz"
    if i % 5 == 0:
        tmp += "Buzz"
    if not tmp:
        tmp = str(i)
    ans += tmp
start = calc_start(left)
print(ans[N - start:N - start + 20])

Measured memory_bytes: 7804
#include<bits/stdc++.h>
using namespace std;
long long int dp[100007];

long long int RFrog1(vector<long long int >& v, long long int i, long long int k){
	long long int  n=v.size()-1, temp=INT_MAX;
	if(i>=n) return 0;
	else if(dp[i]!=-1) return dp[i];
	if(i+k-1==n) k--;
	for(int j=1;j<=k;j++){
		temp = min(temp, abs(v[i+j]-v[i])+RFrog1(v, i+j, k));
	}
	dp[i] = temp;

	return dp[i];
}

int main(){
	long long int n, k;
	cin>>n>>k;
	k = min(n, k);
	memset(dp, -1, sizeof(dp));
	vector<long long int > v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	cout<<RFrog1(v, 0, k);
}



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

int main(void){
  int i, k=1;
  int n, m;
  int *a;
  int *pat;
  int ans;

  scanf("%d %d", &n, &m);
  a=(int *)malloc((m+1)*sizeof(int));
  //何段目が壊れているかとインデックスを合わせる
  if(a == (int *)NULL){
    //エラーメッセージ
    printf("メモリ領域の確保に失敗しました。\n");
    exit(1);
  }
  a[0]=0;
  for(i=1; i<=m; i++){
    scanf("%d", &a[i]);
  }

  pat=(int *)malloc((n+1)*sizeof(int));
  //インデックスを合わせる
  if(pat== (int *)NULL){
    //エラーメッセージ
    printf("メモリ領域の確保に失敗しました。\n");
    exit(1);
  }
  pat[0]=1;

  for(i=1; i<=n; i++){
    if(k<=m-1){
      if(a[k+1]-a[k]==1){
        ans=0;
        break;
      }
    }
    if(a[k]==i){
      pat[i]=0;
      k++;
    }else{
      if(i==1){
        pat[1]=1;
      }else if(i==2){
        pat[2]=pat[1]+1;
      }else{
        pat[i]=(pat[i-1]+pat[i-2])%1000000007;
      }
      if(i==n) ans=pat[n];
    }
  }

  printf("%d\n", ans);
  free(a);
  free(pat);
  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;
class UnionFind
{
public:
	vector<ll> par; // 各元の親を表す配列
	vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
	{
		for (ll i = 0; i < sz_; ++i)
			par[i] = i; // 初期では親は自分自身
	}
	void init(ll sz_)
	{
		par.resize(sz_);
		siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i)
			par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x)
	{ // 根の検索
		while (par[x] != x)
		{
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y)
	{
		x = root(x);
		y = root(y);
		if (x == y)
			return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y])
			swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y)
	{ // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x)
	{ // 素集合のサイズ
		return siz[root(x)];
	}
};
int main()
{
	int n, m;
	cin >> n >> m;
	UnionFind uf(m);
	vector<vector<int>> L(n);
	vector<bool> used(m, false);
	deque<int> vertex;
	
	rep(i, n)
	{
		int k;
		cin >> k;
		int parent;
		rep(j, k)
		{
			int l;
			cin >> l;
			l--;
			if (j == 0)
			{
				parent = l;
			}
			uf.merge(l, parent);
			if (!used[l])
			{
				used[l] = true;
				vertex.push_front(l);
			}
		}
	}

	bool ok = true;
	int fir = vertex.front();
	ok=uf.size(fir)==vertex.size();
	/*rep(i, m)
	{
		if (used[i])
		{
			if (uf.issame(fir, i))
			{

			}
			else
			{
			//	cout << i << endl;
				ok = false;
			}
		}
	}*/
//	cout << uf.size(6) << endl;

	if (ok)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 4224
#define ll long long
#define pb push_back
#define make_pair mp
#define first f
#define second s
#define upper_bound ub
#define lower_bound lb

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;


#define ordered_set tree<pair<ll,ll> , null_type,less<pair<ll,ll> >, rb_tree_tag,tree_order_statistics_node_update>

void solve(){
    ll n,x,m;
    cin>>n>>x>>m;
    if(n==1){
        cout<<x;return;
    }
    ll ps[100005];
    memset(ps,0,sizeof(ps));
    ps[1]=x;
    map<ll,ll> ma;
    ma[x]=1;
    ll ans=x;
    ll ci=2,pe=x;
    for(;ci<=n;ci++){
        ll ce = (pe*pe)%m;
        if(ma.count(ce)>0){
            break;
        }
        else if(ce==0){
            cout<<ans;return;
        }
        else{
            ma[ce]=ci;ans+=ce;
        }
        ps[ci]=ps[ci-1]+ce;
        pe=ce;
    }
    cout<<endl;
    if(ci<n){
        ci--;
        ll ce = (pe*pe)%m;
        ll len = ci - ma[ce] + 1;
        ans += (ps[ci]-ps[ci-len])*((n-ci)/(len));
        ll rem_len=(n-ci)%len;
        ans += (ps[ci-len+rem_len]-ps[ci-len]);
    }
    cout<<ans;
}

int main ()
{
  ios_base::sync_with_stdio (false);
  cin.tie (NULL);
  ll t;
  //cin>>t;
  t = 1;
  while (t)
    {
      solve();t--;
      //cout<<"end of test case"<<endl;
    }
  return 0;
}


Measured memory_bytes: 7448
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
  std.range, std.container, std.bigint, std.ascii, std.typecons, std.format;

// }}}
// nep.scanner {{{
class Scanner {
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0) {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }

  void scan()() {
  }

  void scan(T, S...)(ref T x, ref S args) {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
    str ~= s.to!(char[]).strip.split;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  string s = cin.next!string;

  if (s == "AAA" || s == "BBB") {
    writeln("No");
  } else {
    writeln("Yes");
  }
}


Measured memory_bytes: 256
N,K=map(int,input().split())
d=[]
x=[0]*N
for i in range(K):
  d.append(int(input()))
  a=list(map(int,input().split()))
  for j in range(d[i]):
    #print(j)
    x[a[j]-1]=1
print(N-sum(x))

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

using namespace std;

#define MAX 100000

vector<int> G[MAX];
bool visited[MAX];

void init()
{
    for (int i = 0; i < MAX; i++) {
        G[i].clear();
        visited[i] = 0;
    }
}

void dfs(int v)
{
    for (int i = 0; i < (int)G[v].size(); i++) {
        int to = G[v][i];
        if (!visited[to]) {
            visited[to] = 1;
            dfs(to);
        }
    }
}

bool check(int N)
{
    for (int i = 0; i < N; i++) {
        if (G[i].size() >= 3) return 0;
        if (!visited[i] && G[i].size() <= 1) {
            visited[i] = 1;
            dfs(i);
        }        
    }
    return (count(visited, visited + N, 0) == 0);
}

int main()
{
    int N, M;
    while (cin >> N >> M, N) {
        int a, b;
        init();
        for (int i = 0; i < M; i++) {
            cin >> a >> b;
            a--; b--;
            G[a].push_back(b);
            G[b].push_back(a);
        }
        cout << (check(N) ? "yes" : "no") << endl;
    }
    return 0;
}

Measured memory_bytes: 8920
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
	int t;
	int n, k;
	vector<int> x(100000);
	cin >> t;
	while(t--)
	{
		cin >> n >> k;
		for(int i = 0; i < n; i++)
		{
			cin >> x[i];
		}
		int len;
		if(k >= n)
		{
			len = 0;
		}
		else
		{
			len = x[n-1] - x[0];
			vector<int> a(100000);
			for(int j = 0; j < n-1; j++)
			{
				a[j] = x[j+1] - x[j];
			}
			sort(a.begin(),a.end());
			reverse(a.begin(),a.end());
			for(int i = 0; i < k - 1; i++)
			{
				len -= a[i];
			}
		}
		cout << len << endl;
	}
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std ;
int main()
{
	int a=0 , b=0 , c=0 , d=0 ;
	cin >> a >> b ;
	1<=a,b<=100 ;
	c=a*b ;
	d=2*a+2*b ;
	cout << c << " " << d << endl ;
}



Measured memory_bytes: 3068
def c_time3_or_div2():
    N = int(input())
    A = [int(i) for i in input().split()]
    # a を 2 進数として下位ビットから見たとき，最初に 1 が現れるまでの 0 の個数
    return sum((a & -a).bit_length() - 1 for a in A)

print(c_time3_or_div2())

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  int A[N], odd = 0, even = 0;
  rep(i, N) cin >> A[i], (A[i]%2 ? odd : even)++;
  if(odd%2) cout << "NO" << endl;
  else cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

if A > 0:
    print(E * (B - A))
if A == 0:
    print(D + E * B)
if A < 0:
    print(C * abs(A) + D + E * B)



Measured memory_bytes: 5592
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;

#define ll long long

int main(){
    int N;
    double sum = 0;
    cin >> N;
    vector<double> x(N);
    vector<string> u(N);
    for(int i = 0; i < N; i++){
        cin >> x[i] >> u[i];
        if(u[i] == "BTC"){
            sum += x[i] * 380000;
        }else{
            sum += x[i];
        }
    } 
    cout << sum << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

int main()
{
	int a, b; cin >> a >> b;
	int d = b - a;
	int h = 0;
	for (int i = 0; i < d; i++) {
		h += i;
	}
	cout << h - a << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
using namespace std;
#define INF 1000000005
int gcd(int a, int b) {
    if (b == 0)
        return a;

    return gcd(b, a % b);
}



int main()
{
int n,x;
std::cin >> n >> x;
std::vector<int> mapp;
for(int i = 0; i < n; i++){
    int temp;
    std::cin >> temp;
    temp -= x;
    mapp.push_back(temp);
}
int d = mapp[0];
for(int j = 1; j < n; j++){
    d = gcd(d,mapp[j]);
}
std::cout << abs(d) << std::endl;

return 0;
}

Measured memory_bytes: 892
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(nil, 1000000000000)

	n := nextInt()
	as := make([]int, n)
	asum := make([]int, n)

	mod := int(1e9 + 7)

	for i := 0; i < n; i++ {
		as[i] = nextInt() % mod
	}

	asum[n-1] = as[n-1]
	for i := 1; i < n-1; i++ {
		asum[n-1-i] = asum[n-i] + as[n-1-i]
	}

	ans := 0
	for i := 0; i < n-1; i++ {
		ans += as[i] * (asum[i+1] % mod)
		ans = ans % mod
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7556
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=10000;

int main(){
	int X,Y;
	cin>>X>>Y;
	cout<<X+(Y/2);
}

Measured memory_bytes: 256
N, Y = map(int, input().split())
flag = 1
for i in range(0, N+1):
    for j in range (0,N+1):
        if flag == 1 and (i + j)<=N and (10000*i + 5000*j + 1000*(N-i-j)) == Y:
            flag = 0
            print(i, j, N-i-j)
            break

if flag == 1:
    print("-1 -1 -1")

        

Measured memory_bytes: 9132
using System;
using System.Diagnostics;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;


    int H, W;

    void calc()
    {
        int N = cin.nextInt();
        int T = cin.nextInt();
        Tuple<int, int>[] tp = new Tuple<int, int>[N];
        for (int i = 0; i < N; i++)
        {
            tp[i] = Tuple.Create(cin.nextInt(), cin.nextInt());
        }
        Array.Sort(tp);

        long ans = 0;
        long[] dp = new long[T + 1];
        for (int i = 0; i < N; i++)
        {
            int a = tp[i].Item1;
            int b = tp[i].Item2;
            for (int j = T - 1; j >= 0; j--)
            {
                long next = dp[j] + b;
                ans = Math.Max(ans, next);
                if (j + a <= T)
                {
                    dp[j + a] = Math.Max(dp[j + a], next);
                }
            }
        }
        Console.WriteLine(ans);
    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}




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


a=0
b=0
c=0
d=0

for i in range(N):
    s = input()
    if s=="AC":
        a+=1
    elif s=="WA":
        b+=1
    elif s=="TLE":
        c+=1
    elif s=="RE":
        d+=1 
    
print("AC x "+str(a))
print("WA x "+str(b))
print("TLE x "+str(c))
print("RE x "+str(d))

Measured memory_bytes: 9116
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

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

  int ans = 0;
  int vec[a];

  for(int i = 0; i < a; i++) {
      vec[i] = a - i;
  }

  for(int i = 0;i < a; i++){
      if(vec[i] % 2 != 0){
          ans++;
      }
  }
  cout << fixed;
  cout << setprecision(10) << double(ans) / double(a) << endl;

  return 0;
}


Measured memory_bytes: 256
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
void fo (){fflush(stdout);}
using namespace std;
ll fact (int x ){return (x <= 1 ? 1 : 1LL * x * fact (x-1));}
int n ;
int main ()
{
  cin >> n ;
  cout << n * 800 -  (n / 15) * 200 ;
  cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Measured memory_bytes: 256
//                _                                      
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __  
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \ 
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/ 
//                  |___/                         |_|  
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    if(n>=30) {
        cout<<"Yes";
    }
    else {
        cout<<"No";
    }
	return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int bar[3] = { 2, 1, 0 };

int mul[3][3] = {
	{ 0, 0, 0 },
	{ 0, 1, 1 },
	{ 0, 1, 2 }
};

int add[3][3] = {
	{ 0, 1, 2 },
	{ 1, 1, 2 },
	{ 2, 2, 2 }
};

string str;
int var[3];

int parse(int l, int r) {
	int arc = 0, nl = -1;
	stack< char > op;
	stack< int > val;
	
	for_(i,l,r) {
		if (arc == 0 && str[i] == '(') {
			++arc;
			nl = i + 1;
		} else if (arc > 0) {
			if (str[i] == ')') {
				--arc;
				if (arc == 0) val.push(parse(nl, i));
			} else if (str[i] == '(') {
				++arc;
			}
		} else if (arc == 0) {
			if (isdigit(str[i])) val.push(str[i] - '0');
			else if (str[i] == 'P') val.push(var[0]);
			else if (str[i] == 'Q') val.push(var[1]);
			else if (str[i] == 'R') val.push(var[2]);
			else op.push(str[i]);
		}
	}
	
	if (val.size() == 1) {
		int res = val.top(); val.pop();
		
		while (!op.empty() && op.top() == '-') {
			op.pop();
			res = bar[res];
		}
		
		return res;
	}
	
	int x2 = val.top(); val.pop();
	while (op.top() == '-') {
		op.pop();
		x2 = bar[x2];
	}
	
	char opp = op.top(); op.pop();
	
	int x1 = val.top(); val.pop();
	while (!op.empty() && op.top() == '-') {
		op.pop();
		x1 = bar[x1];
	}
	
	return (opp == '*' ? mul[x1][x2] : add[x1][x2]);
}

int main() {
	while (cin >> str) {
		if (str == ".") break;
		
		int ans = 0;
		
		for_(p,0,3) for_(q,0,3) for_(r,0,3) {
			var[0] = p; var[1] = q; var[2] = r;
			if (parse(0, (int)str.size()) == 2) ++ans;
		}
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string S;
    cin >> S;

    int len = (int)S.size();
    vector<int> cnt(len);

    int l = 1;
    repd(i, 1, len) {
        if (S[i - 1] == 'L') l++;
        else l = 1;
        if (S[i] == 'L') cnt[i] = l;
    }

    int r = 1;
    for (int i = len - 2; i >= 0; i--) {
        if (S[i + 1] == 'R') r++;
        else r = 1;
        if (S[i] == 'R') cnt[i] = r;
    }

    vector<int> ans(len);

    rep(i, len) {
        if (cnt[i] % 2) {
            if (S[i] == 'R') {
                ans[i + cnt[i] - 1]++;
            }
            else {
                ans[i - cnt[i] + 1]++;
            }
        }
        else {
            if (S[i] == 'R') {
                ans[i + cnt[i]]++;
            }
            else {
                ans[i - cnt[i]]++;
            }
        }
    }

    rep(i, len) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 4316
use text_io::*;
use std::collections::*;
use std::process::exit;
use std::cmp::max;

fn main() {
    let mut n:usize = read!();
    let mut x:usize = read!();
    for i in 1..n {
        let mut a:usize = read!();
        if x-1 > a{
            println!("No");
            exit(0);
        }
        if x-1==a {
            a+=1;
        }
        x=a;
    }
    println!("Yes");
}

Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

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

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

int main()
{
    string s;
    cin >> s;
    for (int i = (int)s.size() - 3; i >= 1; i -= 2) {
        for (int j = 0; j <= i/2; j++) {
            if (s[j] != s[j + (i + 1)/2]) {
                goto loopend;
            }
        }
        cout << i + 1 << endl;
        return 0;
    loopend:;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  char c;
  cin>>c;
  if(c=='A') cout << 'T' << endl;
  else if(c=='T') cout << 'A' << endl;
  else if(c=='C') cout << 'G' << endl;
  else if(c=='G') cout << 'C' << endl;

  return 0;

}


Measured memory_bytes: 256
gets.to_i.times{
  n=gets.to_i
  count = 0
  array = []
  
  while true
    break if n/10 == 0
    if array.index(n) != nil
      count = -1
      break
    end

    ns = n.to_s.split("")
    products=[]
    ns.length.times{|t|
      products.push ns[0..t].join.to_i * ns[t+1..ns.length-1].join.to_i
    }
    n = products.max

    count += 1
  end

  p count
}

Measured memory_bytes: 6200
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int s;
    cin >> s;
    int count = s;
    for(int i = 1; ; i++){
        if(count == 1 || count == 2 || count == 4){
            cout << i+3 << endl;
            return 0;
        }
        if(count % 2 == 0){
            count = count / 2;
        }else{
            count = count * 3 + 1;
        }
    }
    return 0;
}



Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
x,y=map(int,input().split())
tate,yoko=[],[]
kaisi=0
tmp=0
flag=1
for i in range(len(s)):
    if s[i]=="F":
        tmp+=1
    elif s[i]=="T":
        if kaisi==0:
            kaisi=1
            x-=tmp
        elif flag==0:
            flag=1
            yoko.append(tmp)
        else:
            flag=0
            tate.append(tmp)
        tmp=0


if kaisi==0:
    kaisi=1
    x-=tmp
elif flag==0:
    flag=1
    yoko.append(tmp)
else:
    flag=0
    tate.append(tmp)

if sum(yoko)==0 and sum(tate)==0:
    if x==0 and y==0:
        print("Yes")
    else:
        print("No")
    quit()
# print(yoko,tate)

if abs(x)>sum(yoko) or abs(y)>sum(tate):
    print("No")
    quit()
yokolst=[[0]*(sum(yoko)*2+1) for i in range(len(yoko)+1)]
tatelst=[[0]*(sum(tate)*2+1) for i in range(len(tate)+1)]
yokolst[0][sum(yoko)]=1
tatelst[0][sum(tate)]=1
# print(yokolst)
# print(tatelst)
for i in range(len(tate)):
    for j in range(len(tatelst[0])):
        if tatelst[i][j]==1:
            tatelst[i+1][j+tate[i]]=1
            tatelst[i+1][j-tate[i]]=1


for i in range(len(yoko)):
    for j in range(len(yokolst[0])):
        if yokolst[i][j]==1:
            yokolst[i+1][j+yoko[i]]=1
            yokolst[i+1][j-yoko[i]]=1


# print(yokolst)
# print(tatelst)

if tatelst[-1][sum(tate)+y]==1 and yokolst[-1][sum(yoko)+x]==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 167260
s = input()
t = list(filter(lambda x: x in ['R','U','D'],s[0::2]))
u = list(filter(lambda x: x in ['L','U','D'],s[1::2]))
print('Yes' if len(s[0::2]) == len(t) and len(s[1::2]) == len(u) else 'No')

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back

typedef long long ll;
typedef pair<int,int> P;

//-----------------------------------------------------------------------

int sqsum(int a,int b){ return a*a+b*b;}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int h,w;
    while(cin>>h>>w,h+w){
        int h1=1000,w1=1000;

        for(int j=2;j<=150;j++) for(int i=1;i<j;i++){
            if(sqsum(h,w)<sqsum(i,j) ||
                sqsum(h,w)==sqsum(i,j) && h<i){

                if(sqsum(i,j)<sqsum(h1,w1)||
                    sqsum(i,j)==sqsum(h1,w1) && i<h1){
                    h1=i; w1=j;
                }
            }
        }
        cout<<h1<<" "<<w1<<endl;
    }
}


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

#define MAX_N 110

#define INF 999999999

int x[MAX_N][MAX_N];
int d[MAX_N];

queue<int>Q;

int bfs(int s, int t){
	for(int i=0;i<MAX_N;i++){
		d[i]=INF;
	}
	d[s]=0;
	Q.push(s);
	while(!Q.empty()){
		int z=Q.front();
		for(int i=0;i<MAX_N;i++){
			if(x[z][i]<INF){
				if(d[i]==INF){
					d[i]=d[z]+1;
					Q.push(i);
				}
			}
		}
		Q.pop();
	}
	return d[t];
}

int main(){
	int n,m,a,b,c;
	for(int i=0;i<MAX_N;i++){
		for(int j=0;j<MAX_N;j++){
			x[i][j]=INF;
		}
	}
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		for(int j=0;j<b;j++){
			cin>>c;
			x[a][c]=1;
		}
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>a>>b>>c;
		int y=bfs(a,b);
		if(y>=c){cout<<"NA"<<endl;}
		else{cout<<y+1<<endl;}
	}
	return 0;
}

Measured memory_bytes: 1264
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define from1(obj) obj.begin() + 1, obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbp(p) cerr << #p << ":(" << p.first << ", " << p.second << ") "
#define dbpl(p) cerr << #p << ":(" << p.first << ", " << p.second << ")\n"
#define dbt3(t3) cerr << #t3 << ":(" << get<0>(t3) << ", " << get<1>(t3) << ", " << get<2>(t3) << ") "
#define dbt3l(t3) cerr << #t3 << ":(" << get<0>(t3) << ", " << get<1>(t3) << ", " << get<2>(t3) << ")\n"
#define dbt4(t4) cerr << #t4 << ":(" << get<0>(t4) << ", " << get<1>(t4) << ", " << get<2>(t4) << ", " << get<3>(t4) << ") "
#define dbt4l(t4) cerr << #t4 << ":(" << get<0>(t4) << ", " << get<1>(t4) << ", " << get<2>(t4) << ", " << get<3>(t4) << ")\n"
#define dbv(vec) cerr << #vec << ":{ "; for (auto e : vec) cerr << e << ", "; cerr << "}\n"
#define dbvv(vv) cerr << #vv << ":{\n"; for (auto vec : vv) { cerr << "{ "; for (auto e : vec) cerr << e << ", "; cerr << "}\n"; } cerr << "}\n"
#define dbm(map) cerr << #map << ":{ "; for (auto p : map) cerr << "(" << p.first << ", " << p.second << "), "; cerr << "}\n"
#define YN(f) cout << (f ? "YES" : "NO") << "\n"
#define Yn(f) cout << (f ? "Yes" : "No") << "\n"
#define yn(f) cout << (f ? "yes" : "no") << "\n"
using ll = long long;
using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vb = vector<bool>;
using vvi = vector<vi>; using vvl = vector<vl>; using vvb = vector<vb>;
using pii = pair<int, int>; using pil = pair<int, ll> ; using pll = pair<ll, ll>; using pli = pair<ll, int>;
using vpii = vector<pii>; using vpll = vector<pll>;
using ti3 = tuple<int, int, int>; using tl3 = tuple<ll, ll, ll>;
using ti4 = tuple<int, int, int, int>; using tl4 = tuple<ll, ll, ll, ll>;
using mii = map<int, int>; using mil = map<int, ll>; using mll = map<ll, ll>; using mli = map<ll, int>;

int N, K, C;
vb w;

int main() {
	// 日数は1-ind
	cin >> N >> K >> C;
	string S; cin >> S;
	w.assign(N + 2, false);
	rep(i, N) if(S[i] == 'o') w[i + 1] = true;

	vi L(N + 2); // 1~i日目で何日働けるか
	int x = 1, d = 0;// current
	while (x <= N) {
		if (w[x]) {
			L[x] = ++d;
			rep(j, C) {
				if (x > N) break;
				L[++x] = d;
			}
		} else {
			L[x] = d;
		}
		x++;
	}
	vi R(N + 2); // N~i日目で何日働けるか
	x = N; d = 0; // current
	while (x >= 1) {
		if (w[x]) {
			R[x] = ++d;
			rep(j, C) {
				if (x < 1) break;
				R[--x] = d;
			}
		} else {
			R[x] = d;
		}
		x--;
	}

	dbv(w); dbv(L); dbv(R);
	rep2(i, 1, N + 1) {
		if (L[i - 1] + R[i + 1] < K) cout << i << endl;
	}	
}

Measured memory_bytes: 3332
#include <cstdio>
#include <algorithm>

const int S = 2e5 * 30, inf = 2e9;

int ls[S], rs[S], mx[S], sz;

int build(int l, int r) {
  int o = sz++;
  ls[o] = rs[o] = 0;
  if (l + 1 == r) {
    scanf("%d", &mx[o]);
    return o;
  }
  int m = (l + r) >> 1;
  ls[o] = build(l, m);
  rs[o] = build(m, r);
  mx[o] = std::min(mx[ls[o]], mx[rs[o]]);
  return o;
}

int ins(int o, int l, int r, int x, int v) {
  int p = sz++;
  ls[p] = ls[o];
  rs[p] = rs[o];
  if (l + 1 == r) {
    mx[p] = v;
    return p;
  }
  int m = (l + r) >> 1;
  if (x < m) ls[p] = ins(ls[o], l, m, x, v);
  else rs[p] = ins(rs[o], m, r, x, v);
  mx[p] = std::min(mx[ls[p]], mx[rs[p]]);
  return p;
}

int ask(int o, int l, int r, int L, int R) {
  if (L <= l && R >= r) return mx[o];
  int ret = inf, m = (l + r) >> 1;
  if (L < m) ret = std::min(ret, ask(ls[o], l, m, L, R));
  if (R > m) ret = std::min(ret, ask(rs[o], m, r, L, R));
  return ret;
}

int main() {
  ls[0] = rs[0] = 0;
  mx[0] = inf;
  sz = 1;
  int n;
  scanf("%d", &n);
  int ra = build(0, n);
  int rb = build(0, n);
  int q;
  scanf("%d", &q);
  while (q--) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    if (x == 1) ra = ins(ra, 0, n, y - 1, z);
    if (x == 2) rb = ins(rb, 0, n, y - 1, z);
    if (x == 3) printf("%d\n", ask(ra, 0, n, y - 1, z));
    if (x == 4) printf("%d\n", ask(rb, 0, n, y - 1, z));
    if (x == 5) ra = rb;
    if (x == 6) rb = ra;
  }
  return 0;
}

Measured memory_bytes: 31756
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

  

    ll n; ld k;
    cin >> n >> k;

    ld x,y; ll ans=0;
    while(n--)
    {
        cin >> x >> y;
        ld d = sqrt(x*x + y*y);
      //  cout << d << endl;
        if(d<=k) ans++;
    }

    cout << ans << endl;
   
}






Measured memory_bytes: 3772
using System;
using System.Collections.Generic;
using System.Linq;
namespace AOJ
{
    internal class Program
    {
        public static void Main(string[] args) { new Program().solve(); }
        void solve() {
            var D = new DiceClass();
            var inputs = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
            var order = Console.ReadLine();
            Action<char> f = (c) => {
                if (c == 'N') D.RollN();
                if (c == 'S') D.RollS();
                if (c == 'W') D.RollW();
                if (c == 'E') D.RollE();
            };

            D.SetDice(inputs);
            foreach (var c in order.ToCharArray()) {
                f(c);
            }
            Console.WriteLine(D.Above);
        }
    }
    class DiceClass
    {
        //above figure is |0|
        //front figure is |1|
        //     N
        //    |0|
        //W |3|1|2|4| E
        //    |5|
        //     S
        public int[] Dice = new int[6];
        public int Above { get { return Dice[0]; } }
        public void SetDice(int[] a) {
            for (int i = 0; i < 6; ++i)
                Dice[i] = a[i];
        }
        public void SetBasicDice() {
            SetDice(Enumerable.Range(1, 6).ToArray());
        }
        public void RollN() {
            SetDice(new int[] { Dice[1], Dice[5], Dice[2], Dice[3], Dice[0], Dice[4] });
        }
        public void RollW() {
            SetDice(new int[] { Dice[2], Dice[1], Dice[5], Dice[0], Dice[4], Dice[3] });
        }
        public void RollE() {
            SetDice(new int[] { Dice[3], Dice[1], Dice[0], Dice[5], Dice[4], Dice[2] });
        }
        public void RollS() {
            SetDice(new int[] { Dice[4], Dice[0], Dice[2], Dice[3], Dice[5], Dice[1] });
        }
        public void Show() {
            //     N
            //    |0|
            //W |3|1|2|4| E
            //    |5|       
            //     S
            Console.WriteLine("     N");
            Console.WriteLine("    |" + Dice[0] + "|");
            Console.WriteLine("W |" + Dice[3] + "|" + Dice[1] + "|" + Dice[2] + "|" + Dice[4] + "| E");
            Console.WriteLine("    |" + Dice[5] + "|");
            Console.WriteLine("     S");

        }




    }
}


Measured memory_bytes: 9580
#include<stdio.h>

int main(int argc, char* argv[]){

	int A[100];
	int key;
	int i,j,k;

	scanf("%d",&k);
		
	for(j =	0;j < k;j++)
	 scanf("%d",&A[j]);

	for(i = 0;i < k ;i++){
		key = A[i];
		j =	i - 1;
			
		while(j >= 0 &&	A[j] > key){
			A[j + 1] = A[j];
			j--;	
		}	
			A[j + 1] = key;
	for(j =	0;j < k - 1;j++)
		printf("%d ",A[j]);	
        printf("%d\n",A[j]);
	}	
	
	return 0;
}	

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

int main() {
	int a,b,c,d,total = 0,x = 0,y = 0;
	cin >> a >> b >> c >> d;
	total = a + b + c + d;
	x = total / 60;
	y = total % 60;
	cout << x << endl;
	cout << y << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int e[n],w[n],minv=300000005;
    string a;
    for(int i=0;i<n;i++){
    	e[i]=0;
    	w[i]=0;
	}
	cin>>a;
	if(a[0]=='E')
	    e[0]=1;
	else
	    w[0]=1;
	for(int i=1;i<n;i++)
	 {
	 	if(a[i]=='E') 
		   {e[i]=e[i-1]+1;
	 	    w[i]=w[i-1];}
	 	else 
		   {w[i]=w[i-1]+1;
		    e[i]=e[i-1];}
	 }
	for(int i=0;i<n;i++){
		int sum=0;
		if(i==0)
		    sum=e[n-1]-e[i];
		else if(i==n-1) 
		    sum=w[n-2];
		else
		    sum=w[i-1]+(e[n-1]-e[i]);
		minv=min(minv,sum);
	}
	cout<<minv;
}


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

//最大公約数を求める関数
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    int n, x;
    cin >> n >> x;
    int a[100010];
    int ans;
    for(int i=0; i<n; i++){
        cin >> a[i];
        a[i] = abs(x-a[i]);
    }
    ans = a[0];
    for(int i=1; i<n; i++){
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define INF 1000000000000000000
#define N 100100
#define pb push_back
#define fn(i,n) for(int i=0;i<n;i+=1)

int dp[100100]={0};
int vis[N]={0};
vector <int> adj[N];
void dfs(int i)
{
    vis[i]=1;
    for(auto it:adj[i])
    {
        if(!vis[it])
        {
            dfs(it);      
        }
         dp[i]=max(dp[it]+1,dp[i]);
    }
}
signed main() {
    int n,m;cin>>n>>m;
    fn(i,m)
    {
        int u,v;cin>>u>>v;
        adj[u].pb(v);
    }
    for(int i=1;i<=n;i+=1)
    {
        if(!vis[i])
        dfs(i);
    }
    cout<<*max_element(dp,dp+n+1)<<endl;



    return 0;
}



Measured memory_bytes: 9344
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define DEBUG(x) std::cout << '>' << #x << ':' << x << '\n';
#define PRINTVEC(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i] << ' '; std::cout << '\n';
#define PRINTPAIR(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i].first << ' ' << x[i].second << '\n'; std::cout << '\n';
#define PRINTSET(x) for (auto it = x.begin(); it != x.end(); it++) { std::cout << *it << ' '; } std::cout << '\n';
#define io std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);   
const int INF = 1<<29;
typedef long long ll;
using namespace std;


int main()
{
	io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);  
    #endif

    int n;
    cin >> n;
    int res = n / 1000;
    if (n % 1000 != 0) res++;
    cout << res * 1000 - n;

    #ifndef ONLINE_JUDGE   
    std::cout << '\n' << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;

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

	vector <string> a(N);

	for (int i = 0; i < N; i++) {
		cin >> a.at(i);
	}

	int b= 1;

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

	for (int i = 0; i < N-1; i++) {
		if (a.at(i) != a.at(i + 1)) b++;
	}

	cout << b << endl;
	

}

Measured memory_bytes: 9504
l, r = map(int, input().split())
if r - l > 2030: print(0)
else:
    ans = 2018
    for i in range(l, r):
        for j in range(i+1, r+1):
            ans_ = i*j%2019
            if ans_ < ans:
                ans = ans_
    print(ans)

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int k, a, b;
  cin >> k >> a >> b;
  if (a % k) a += k - a % k;
  if (a <= b) {
    cout << "OK";
  } else {
    cout << "NG";
  }
  return 0;
}

Measured memory_bytes: 3640
import sys
N, Y = input().split()
N, Y = int(N), int(Y)

#一万円札
for m in range(N + 1):
    #五円札
    for f in range(N + 1 - m):
        money = m*10000 + f*5000
        diff = Y - money
        
        if diff%1000 == 0 and m+f+int(diff/1000) == N:
            print(m, f, int(diff/1000))
            sys.exit()
            
print(-1, -1, -1)

Measured memory_bytes: 3060
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val a = sc.nextInt()
    val b = sc.nextInt()
    val h = sc.nextInt()
    val m = sc.nextInt()
    val t1 = 2 * Math.PI / 12.0 * h + 2 * Math.PI / 720.0 * m
    val t2 = 2 * Math.PI / 60.0 * m
    val t = (t1 - t2)
    println(Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(t)))
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 34608
N, M = map(int, input().split())
H = list(map(int, input().split()))

H_list = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    H_list[a-1].append(H[b-1])
    H_list[b-1].append(H[a-1])

ans = 0
for i in range(N):
    if len(H_list[i]) == 0:
        ans += 1
        continue
    if H[i] > max(H_list[i]):
        ans += 1
print(ans)

Measured memory_bytes: 92836
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define MOD 1000000007
#define ll long long

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

void swap(int *a, int *b);

int main(int argc, char **argv){
    int n,m,i;
    scanf("%d %d",&n,&m);
    if(n-m>=2 || m-n>=2){
        printf("0\n");
        return 0;
    }
    if(m==n){
        //2*(n!)^2
        ll x=1;
        for(i=1;i<=n;i++){
            x=x*i%MOD;
        }
        x=x*x%MOD;
        x=x*2%MOD;
        printf("%lld\n",x);
    } else {
        if(m<n) swap(&m,&n);
        //m-n=1
        //m!*n!
        ll x=1;
        for(i=1;i<=n;i++){
            x=x*i%MOD;
        }
        for(i=1;i<=m;i++){
            x=x*i%MOD;
        }
        printf("%lld\n",x);
    }

    return 0;
}

void swap(int *a, int *b){
    int tmp=*a;
    *a = *b;
    *b = tmp;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;


int main(){
    ll h,a; cin>>h>>a;
    ll ans = 0;
    ans = h/a;
    
    if(ans*a<h)ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

int n, len;
string str;
int as[MAX_N], bs[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n;
    if (n == 0) break;

    cin >> str;
    len = str.length();

    for (int i = 0; i < n; i++) {
      cin >> as[i] >> bs[i];
      as[i]--, bs[i]--;
    }

    for (int i = n - 1; i >= 0; i--) {
      int ai = as[i], bi = bs[i];
      int dab = (ai > bi) ? ai - bi : bi - ai;

      char ca = (str[ai] - 'a' + dab) % 26 + 'a';
      char cb = (str[bi] - 'a' + dab) % 26 + 'a';
      str[ai] = cb;
      str[bi] = ca;
    }

    cout << str << endl;
  }

  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define fi first
#define se second
 
const ll MOD = 1000000007;
const string RGB = "RGB"; 

int main() {
   int r; scanf("%d", &r);
   printf("%d", 3 * r * r);
   return 0;
}

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

long long H, W, C = 1;

int main() {
	cin >> H >> W;
	if (H == 1 && W == 1) {
		cout << "1" << endl;
	}
	else if (H == 1) {
		cout << W - 2 << endl;
	}
	else if (W == 1) {
		cout << H - 2 << endl;
	}
	else {
		cout << H * W - (H + W - 2) * 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i, n, money;
	
	scanf("%d", &n);
	
	money = 100000;
	for (i = 0; i < n; i++){
		money += (money * 0.05);
		money += 999;
		money = (money / 1000) * 1000;
	}
	
	printf("%d\n", money);
	
	return (0);
}

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

using namespace std;

const long long M = 1e9+7;
int a[10003], cnt[1000003];

long long ppow(long long a, long long n)
{
    if (n == 0) return 1;
    if (n % 2) return a * ppow(a, n-1) % M;
    long long x = ppow(a, n/2);
    return x * x % M;
}

void f(int x)
{
    for (int i = 2; i*i <= x; ++i) if (x % i == 0) {
        int c = 0;
        while (x % i == 0) {
            c++;
            x /= i;
        }
        cnt[i] = max(cnt[i], c);
    }
    if (x > 1) {
        cnt[x] = max(cnt[x], 1);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        f(a[i]);
    }

    long long all = 1;
    for (int i = 2; i < 1000003; ++i) {
        all *= ppow(i, cnt[i]);
        all %= M;
    }

    long long an = 0;
    for (int i = 0; i < n; ++i) {
        an += all * ppow(a[i], M-2);
        an %= M;
    }
    cout << an << endl;

    return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i,n) for(int i=n-1;i>=0;i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;

int ans; 

signed main(){
	
	int n,a[111111];
	cin>>n;
	rep(i,n*2)cin>>a[i];
	sort(a,a+n*2);
	rep(i,n*2){
		if(i%2==0)ans+=a[i];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256