akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int n;
vector<string> num[1<<10];
string z[1 << 10];
bool numgreat(string a, string b) {
	if (a.length() != b.length()) {
		return a.length() < b.length();
	}
	return a < b;
}
bool great(int a, int b) {
	int now = 0;
	int s = z[a].length(), t = z[b].length();
	int ca = 0, cb = 0;
	while (true) {
		if (s == now && t == now)return true;
		else if (s == now)return true;
		else if (t == now)return false;
		if (z[a][now] != '?'&&z[b][now] != '?') {
			if (z[a][now] != z[b][now]) {
				return z[a][now] < z[b][now];
			}
		}
		else if (z[a][now] == '?'&&z[b][now] != '?') {
			return true;
		}
		else if (z[a][now] != '?'&&z[b][now] == '?') {
			return false;
		}
		else if (z[a][now] == '?'&&z[b][now] == '?') {
			if (num[a][ca] != num[b][cb]) {
				return numgreat(num[a][ca], num[b][cb]);
			}
			ca++; cb++;
		}
		now++;
	}
	return true;
}
int main() {
	cin >> n;
	rep(i, n+1) {
		string s; cin >> s;
		int le = 0;
		int len = s.length();
		rep(j, len) {
			if ('0' <= s[j]&& s[j] <= '9') {
				if(j!=le)z[i]+=s.substr(le, j - le);
				int memo = j;
				while (j + 1 < len&&'0' <= s[j + 1] && s[j + 1] <= '9') {
					j++;
				}
				num[i].push_back(s.substr(memo, j - memo + 1));
				z[i].push_back('?');
				le = j + 1;
			}
		}
			if (le != len) {
				z[i]+=s.substr(le, len - le);
			}
	}
	rep(i, n) {
		if (great(0, i + 1))cout << "+" << endl;
		else cout << "-" << endl;
	}
	//cout << num[2][0] << endl;
	//cout << z[2] << endl;
	return 0;
}



Measured memory_bytes: 3456
package main

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

func main() {
	N := 0
	sc := bufio.NewScanner(os.Stdin)
	if sc.Scan() {
		N, _ = strconv.Atoi(sc.Text())
	}
	A := make([]int, N)
	if sc.Scan() {
		for i, val := range strings.Fields(sc.Text()) {
			A[i], _ = strconv.Atoi(val)
		}
	}

	result, count := selectionSort(A, N)
	fmt.Println(String(result))
	fmt.Println(count)
}

func selectionSort(A []int, N int) ([]int, int) {
	count := 0
	for i := 0; i < N-1; i++ {
		minj := i
		for j := i; j < N; j++ {
			if A[j] < A[minj] {
				minj = j
			}
		}
		if i == minj {
			continue
		}
		A[i], A[minj] = A[minj], A[i]
		count++
	}

	return A, count
}

func String(A []int) string {
	text := ""
	for i, val := range A {
		if i > 0 {
			text += " "
		}
		text += fmt.Sprint(val)
	}
	return text
}



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


typedef long long ll;

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

    vector<pair<ll,ll>> c(N);
    for(int i=0;i<N;i++){
        cin>>c.at(i).first>>c.at(i).second;
    }
    sort(c.begin(),c.end());
    ll cnthon=0;
    ll cntkane=0;
    ll counter=0;
    while(cnthon<M){
        cnthon+=c.at(counter).second;
        cntkane+=c.at(counter).first*c.at(counter).second;
        counter++;
    }
    cntkane=cntkane-(cnthon-M)*c.at(counter-1).first;
    cout<<cntkane<<endl;
}


Measured memory_bytes: 1792
<?php
$n = trim(fgets(STDIN));
$i = 0;
while($i < $n){
$a[] = trim(fgets(STDIN));
++$i;
}
$b = array_count_values($a);
$ans = 0;
foreach($b as $val){
if($val % 2 == 1){
++$ans;
}
}
echo $ans;

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

int main ( void )
{
	int N, M, count;
	
	cin >> N >> M;

	if ( N + M < 2 ){
		cout << "ERROR!\n";
		return 0;
	}

	count = 0;

	if ( N >= 2 ) count += N * ( N - 1 ) / 2;
	if ( M >= 2 ) count += M * ( M - 1 ) / 2;

	cout << count << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>>
int main(){
	char S[101];
	char T[101];
	char temp[101];
	gets(S);
	gets(T);
	int i,j;
	int Slen=strlen(S);
	int Llen=strlen(T);
	if(Slen!=Llen){
		printf("NO\n");
	}
	else{
		int flag=0,k=Slen;
		while(k&&flag==0){
			if(strcmp(S,T)==0){
				flag=1;
			}
			else{
				temp[0]=S[Slen-1];
				j=1;
				for(i=0;i<Slen-1;i++){
					temp[j++]=S[i];
				}
				temp[j]='\0';
				strcpy(S,temp);
				k--;
			}
		}
		if(flag==0){
			printf("No\n");
		}
		else{
			printf("Yes\n");
		}
	}
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, a, b, c;
    cin >> n >> a >> b >> c;

    vector<string> ope(n);
    for (int i = 0; i < n; i++)cin >> ope[i];

    string ret;
    bool possible = true;
    for (int i = 0; i < n; i++) {
        if (ope[i] == "AB") {
            if (a == 0)ret.push_back('A'), a++, b--;
            else if (b == 0)ret.push_back('B'), b++, a--;
            else {
                if (i + 1 >= n)ret.push_back('A'), a++, b--;
                else {
                    if (ope[i + 1] == "AB")ret.push_back('A'), a++, b--;
                    if (ope[i + 1] == "AC")ret.push_back('A'), a++, b--;
                    if (ope[i + 1] == "BC")ret.push_back('B'), b++, a--;
                }
            }
        }
        if (ope[i] == "AC") {
            if (a == 0)ret.push_back('A'), a++, c--;
            else if (c == 0)ret.push_back('C'), c++, a--;
            else {
                if (i + 1 >= n)ret.push_back('A'), a++, c--;
                else {
                    if (ope[i + 1] == "AB")ret.push_back('A'), a++, c--;
                    if (ope[i + 1] == "AC")ret.push_back('A'), a++, c--;
                    if (ope[i + 1] == "BC")ret.push_back('C'), c++, a--;
                }
            }
        }
        if (ope[i] == "BC") {
            if (b == 0)ret.push_back('B'), b++, c--;
            else if (c == 0)ret.push_back('C'), c++, b--;
            else {
                if (i + 1 >= n)ret.push_back('B'), b++, c--;
                else {
                    if (ope[i + 1] == "AB")ret.push_back('B'), b++, c--;
                    if (ope[i + 1] == "AC")ret.push_back('C'), c++, b--;
                    if (ope[i + 1] == "BC")ret.push_back('B'), b++, c--;
                }
            }
        }

        if (a < 0 || b < 0 || c < 0)possible = false;
        ret.push_back('\n');
    }

    cout << (possible ? "Yes" : "No") << endl;
    if (possible)cout << ret << endl;
}

Measured memory_bytes: 6796
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int p;
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> p;
		for (int j = 2; j < int(sqrt(p) + 1); j++)
		{
			if (p % j == 0)
			{
				count++;
				break;
			}
		}
	}
	cout << n - count << endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>

using namespace std;
int main(){
    int b;
    while(cin>>b){
        if(b==0)break;
        int sum=0;
        int left=1;
        for(int right=0;right<1000000000;right++){ 
            sum+=right;
            while(sum>b){
                sum-=left;
                left++;
            }
            if(sum==b){
                cout<<left<<" "<<right-left+1<<endl;
                break;
            }
        }
    }
}


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

typedef vector<char> vc;
typedef vector<int> vi;
typedef pair<int, int> pii;

int H, W;
vector<vc> S(21, vc(21));

int bfs(int sx, int sy, int gx, int gy){
  vi dx = {-1, 0, 1, 0};
  vi dy = {0, -1, 0, 1};

  vector<vi> d(21, vi(21));

  queue<pii> que;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      d[i][j] = 999999;
    }
  }

  que.push(pii(sx, sy));
  d[sx][sy] = 0;

  while(!que.empty()){
    pii cur = que.front(); que.pop();
    if(cur.first == gx && cur.second == gy) break;

    for(int i=0; i<4; i++){
      int nx = cur.first + dx[i], ny = cur.second + dy[i];
      if(0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] != '#' && d[nx][ny] == 999999){
        que.push(pii(nx, ny));
        d[nx][ny] = d[cur.first][cur.second] + 1;
      }
    }
  }

  return d[gx][gy];
}

int main(){
  cin >> H >> W;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> S[i][j];
    }
  }

  int ans = 0;
  for(int sx=0; sx<H; sx++){
    for(int sy=0; sy<W; sy++){
      for(int gx=0; gx<H; gx++){
        for(int gy=0; gy<W; gy++){
          if(S[sx][sy] != '#'){
            int tmp = bfs(sx,sy,gx,gy);
            if(tmp != 999999) ans = max(ans, tmp);
          }
        }
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;
	
const int maxn=1e5*3+20;
int b[maxn];

int main()
{
	int n,a;
	cin >> n;
	a=n;
	for(int i=0;i<n*3;i++)
		cin >> b[i];
	
	long long ans=0;
	sort(b,b+3*n);
	int x=2;
	while(n--)
	{
		ans+=b[3*a-x];
		x+=2;
	}
	cout << ans;
}

 



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int sum = 0;
  
  for(int i=1; i<=n; i++) {
    string s = to_string(i);
    int size = s.size();
    
    if(size % 2 == 1) {
      sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <deque>
using namespace std;
typedef long long int ll;

int used[100100];
vector<int> g[100100];
vector<int> ans;
deque<int> que;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	for(int i=0;i<m;i++){
		int x,y; cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int begin=0;
	used[begin]=1;
	que.push_back(0);
	int next=g[begin][0];
	while(1){
		used[begin]=1;
		if(next>=0){
			used[next]=1;
			que.push_back(next);
			//cout << "next" << next << endl;
		}
		else{
			que.push_front(begin);
			//cout << "begin" << begin << endl;
		}
		bool ok=true;
		for(int i:g[next]){
			if(used[i]==0){
				next=i;
				ok=false;
				break;
			}
		}
		for(int i:g[begin]){
			if(ok&&used[i]==0){
				ok=false;
				next=-1;
				begin=i;
				break;
			}
		}
		if(ok){
			break;
		}
	}
	cout << que.size() << endl;;
	while(que.size()){
		cout << que.front()+1 << endl;
		que.pop_front();
	}
}

Measured memory_bytes: 7168
import java.io.*;
import java.util.*;
public class Main{
   
     public static void main(String []args){
       Scanner s=new Scanner(System.in);
       int n=s.nextInt();
       HashMap<String,Integer>hm=new HashMap<>();
       String a[]=new String[n];
       for(int i=0;i<n;i++)
       {a[i]=s.next();
       if(hm.containsKey(a[i]))
       {int k=hm.get(a[i]);
       k++;
       hm.put(a[i],k);}
       else
       {hm.put(a[i],1);}}
     int max=0;
     for(Integer i:hm.values())
       {if(max<i)
       {max=i;}}
       ArrayList<String>al=new ArrayList<>();
       for (Map.Entry mapElement : hm.entrySet()) { 
            String key = (String)mapElement.getKey(); 
            if(max==(int)mapElement.getValue()) 
            al.add(key);}
            Collections.sort(al);
           for(int i=0;i<al.size();i++)
           System.out.println(al.get(i));
     }}

Measured memory_bytes: 89272
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;


public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

            int[] f = new int[N];
            int[] b = new int[N];
            int gcd = A[N - 1];
            for (int i = N - 1; i >= 0; i--) {
                gcd = gcd(gcd, A[i]);
                b[i] = gcd;
            }
            gcd = A[0];
            for (int i = 0; i < N; i++) {
                gcd = gcd(gcd, A[i]);
                f[i] = gcd;
            }

            int max = 0;
            for (int i = 0; i < N; i++) {
                int a = i - 1 >= 0 ? f[i - 1] : 0;
                int c = i + 1 < N ? b[i + 1] : 0;
                max = Math.max(max, gcd(a > 0 ? a : c, c > 0 ? c : a));
            }

            System.out.println(max);
        }
    }

    public static final int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static final ArrayList<Integer> divisor(int n) {
        ArrayList<Integer> res = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                res.add(i);
                if (n / i != i) {
                    res.add(n / i);
                }
            }
        }
        return res;
    }
}


Measured memory_bytes: 50404
n, k = gets.chomp.split(' ').map(&:to_i)
r, s, p = gets.chomp.split(' ').map(&:to_i)
t = gets.chomp

cnt = 0
for idx in 0..(t.length-1)
  if idx < k
    case t[idx]
    when 'r'
      cnt += p
    when 's'
      cnt += r
    when 'p'
      cnt += s
    end
  else
    case t[idx]
    when 'r'
      if t[idx - k] == 'r'
        t[idx] = 'x'
      else
      	cnt += p
      end
    when 's'
      if t[idx - k] == 's'
        t[idx] = 'x'
      else
      	cnt += r
      end
    when 'p'
      if t[idx - k] == 'p'
        t[idx] = 'x'
      else
      	cnt += s
      end
    end
  end
end

puts cnt

Measured memory_bytes: 3964
#include<stdio.h>

int main(void){
	unsigned long long w,h,ret;
	scanf("%llu %llu",&h,&w);
	if(w==1 || h==1){
		ret=1;
	}else if(h%2){
		ret=w*(h/2);
		//printf("s%d\n",ret);
		ret+=(w+1)/2;
	}else{
		ret=w*(h/2);
	}
	printf("%llu\n",ret);
	return 0;
}


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

#define ll long long  
#define endl "\n"

const ll int MOD=1e9+7;

void solve()
{
	ll a;double b;
	cin >> a >> b;
	int c = round(b*100);
	cout << fixed;
	cout << (ll)(a*c)/100 << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	return 0;
}

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

using namespace std;

int main(void)
{
        vector<long long> a;
        vector<long long> b;
        vector<long long> c;
        int n;

        cin >> n;
        long long x;
        for(int i = 0; i < n; i++){
                cin >> x;
                a.push_back(x);
        }
        for(int i = 0; i < n; i++){
                cin >> x;
                b.push_back(x);
        }
        for(int i = 0; i < n; i++){
                cin >> x;
                c.push_back(x);
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        sort(c.begin(), c.end());

        long long cntb[100010] = {0};
        long long idxa = 0;
        for(int i = 0; i < n; i++){
                for(; idxa < n && b[i] > a[idxa]; idxa++);
                cntb[i] = idxa;
        }

        long long sumb[100010] = {0};
        sumb[0] = cntb[0];
        for(int i = 1; i < n; i++){
                sumb[i] = sumb[i-1] + cntb[i];
        }

        long long cnt = 0;
        long long idxb = 0;
        for(int i = 0; i < n; i++){
                for(; idxb < n && c[i] > b[idxb]; idxb++);
                if(idxb>0) cnt += sumb[idxb-1];
        }

        cout << cnt << endl;

        return 0;
}

Measured memory_bytes: 4340
n, a, b = map(int, input().split())
if b < a or (a != b and n == 1):
    print(0)
    exit()
if a == b:
    print(1)
    exit()
_min = a*(n-1)+b
_max = a+b*(n-1)
ans = _max - _min + 1
print(ans)


Measured memory_bytes: 9104
import sys
import itertools
import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
a = 0
b = 0
for _ in range(N):
    L = readline().decode('utf8').split()
    if L[0] == L[1]:
        a += 1
        b += 1
    elif L[0] > L[1]:
        a += 3
    else:
        b += 3

print(a, b)



Measured memory_bytes: 5664
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF 1e8
using namespace std;
int dx[]={0,1,1,0,-1,-1};
int dy[]={1,1,0,-1,-1,0};
bool table[150][150];
int d[150][150];
int turn;
void bfs(int x,int y){
    d[x][y] = 0;
    queue<pair<int,int> > que;
    que.push(pair<int,int>(x,y));
    while(!que.empty()){
		pair<int,int> p = que.front();
        que.pop();
        int x = p.first,y = p.second;
        if(d[x][y] == turn) break;
        rep(i,6){
            int nx = x+dx[i];
            int ny = y+dy[i];
            if(table[nx][ny] || d[nx][ny] != INF) continue;
            d[nx][ny] = d[x][y] + 1;
            que.push(pair<int,int>(nx,ny));
        }
    }
}
int main(){
    int block;
    while(cin >> turn >> block){
        if(turn == 0 && block == 0) break;
        rep(i,150){
            rep(j,150) {
                d[i][j] = INF;
                table[i][j] = 0;
            }
        }
        int x,y;
        rep(i,block){
            cin >> x >> y;
            table[x+70][y+70] = 1;
        }
        int sx,sy;
        cin >> sx >> sy;
        sx += 70; sy += 70;
        bfs(sx,sy);
        int ans = 0;
        rep(i,150){
            rep(j,150){
                if(d[i][j] != INF) ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3204
// 10:40

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>

using namespace std;

#define FOR(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define REP(i,n) FOR((i),0,(n))
#define FORCLS(i,a,b) for(int (i) = (a); i <= (b); (i)++)
#define REPCLS(i,n) FORCLS((i),1,(n))

#if defined(DEBUG) && true
#define DOUT(x) {cout << #x << ":" << x << endl;}
#define DOUTA(ary,n) {cout << #ary << ": "; for(int i = 0; i < (n); i++) { cout << (ary)[i] << ", ";} cout << endl; }
#else
#define DOUT(x)
#define DOUTA(ary,n)
#endif

using Int = long;

const Int N_MAX = 100003;
Int n,m;
Int a0,a1;
Int bs[N_MAX * 2];
Int cs[N_MAX * 2];

void solve() {
    Int sum = 0;
    cin >> n >> m;
    REP(i, 2*m) { bs[i] = 0; }
    cin >> a1;
    REP(i, n-1) {
        a0 = a1; cin >> a1;
        Int s = a0;
        Int t = a1;
        t = (s < t) ? t : t + m;
        bs[s + 2] += 1;
        bs[t + 1] -= 1;
        cs[t + 1] -= t - s - 1;
        sum += t - s;
    }
    REP(i, 2*m-1) {
        bs[i + 1] += bs[i];
    }
    REP(i, 2*m-1){
        bs[i + 1] += bs[i] + cs[i+1];
    }
    REP(i, m) {
        bs[i] += bs[i + m];
    }
    cout << sum - *max_element(bs, bs + m) << endl;
}

#ifdef DEBUG
#define MAIN hoge
#else
#define MAIN main
#endif

int MAIN() {
    solve();
    
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<string> v;
	vector<pair<int, string>> v2;
	vector<string> v3;
	string s;
	rep(i, n){
		cin>>s;
		v.push_back(s);
	}
	int a=1, b=0;
	sort(v.begin(), v.end());
	for(int i=1; i<n; i++){
		if(v[i]==v[i-1]){
			a++;
		}
		else{
			if(b<=a){
				b=a;
				v2.push_back(make_pair(b, v[i-1]));
			}
			a=1;
		}
	}
	if(b<=a){
		b=a;
		v2.push_back(make_pair(b, v[n-1]));
	}
	sort(v2.begin(), v2.end(), greater<>());
	for(int i=1; i<v2.size()+1; i++){
		v3.push_back(v2[i-1].second);
		if(v2[i].first!=v2[i-1].first)
			break;
	}
	sort(v3.begin(), v3.end());
	rep(i, v3.size()){
		cout<<v3[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 21740
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int X  = keyboard.nextInt();
		
		int[]L = new int[N];
		
		for(int i = 0; i < N; i++) {
				L[i] = keyboard.nextInt();	
		}
		
		int sum = 0;
		int count = 0;
		
		for(int i = 0; i < N; i++) {
			sum += L[i];
			if(sum < X + 1){
				if(count == N-1) {
					System.out.println(i + 2);
				}else{
					count++;
				}
			}else {
				System.out.println(i + 1);
				break;
			}
		}
		
		keyboard.close();	
	}
}

Measured memory_bytes: 23892
#include<cstdio>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=18,mod=998244353;
int n,lim,cur,inv2,g[1<<N],f[1<<N],h[1<<N]; //f*g=h
inline int quick_pow(int x,int p=mod-2,int mul=1)
{
	for (;p;p>>=1,x=1LL*x*x%mod) if (p&1) mul=1LL*mul*x%mod; return mul;
}
inline int sum(CI x,CI y)
{
	int t=x+y; return t>=mod?t-mod:t;
}
inline int sub(CI x,CI y)
{
	int t=x-y; return t<0?t+mod:t;
}
inline void FWT(int* f,CI opt)
{
	for (RI i=1,j,k,x,y;i<lim;i<<=1) for (j=0;j<lim;j+=(i<<1)) for (k=0;k<i;++k) 
	x=f[j+k],y=f[i+j+k],f[j+k]=sum(x,y),f[i+j+k]=sub(x,y),
	!~opt&&(f[j+k]=1LL*f[j+k]*inv2%mod,f[i+j+k]=1LL*f[i+j+k]*inv2%mod);
}
int main()
{
	RI i; for (scanf("%d",&n),lim=1<<n,i=0;i<lim;++i)
	scanf("%d",&g[i]),cur=sum(cur,g[i]);
	for (cur=quick_pow(cur),i=0;i<lim;++i) g[i]=1LL*g[i]*cur%mod;
	for (inv2=quick_pow(2),g[0]=sub(g[0],1),i=1;i<lim;++i) h[i]=mod-1;
	for (h[0]=lim-1,FWT(g,1),FWT(h,1),i=0;i<lim;++i)
	f[i]=1LL*h[i]*quick_pow(g[i])%mod; for (FWT(f,-1),i=0;i<lim;++i)
	printf("%d\n",sub(f[i],f[0])); return 0;
}

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

typedef pair<int,int> pii;

int main(){
    int n, t;
    cin >> n >> t;
    vector<pii> v;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        v.push_back({a,b});
    }
    sort(v.begin(), v.end());
    vector<int> dp(6005, 0);
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(ans, v[i].second+dp[t-1]);
        for(int j = t-1; j-v[i].first >= 0; j--){
            dp[j] = max(dp[j], dp[j-v[i].first]+v[i].second);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int n; cin>>n;
	string s; cin>>s;
	int a[n]={},b[n]={};
	for(int i=1;i<n;i++){
		if(s[i-1]=='W'){
			a[i]=a[i-1]+1;
		}else{
			a[i]=a[i-1];
		}
	}
	for(int i=n-2;i>=0;i--){
		if(s[i+1]=='E'){
			b[i]=b[i+1]+1;
		}else{
			b[i]=b[i+1];
		}
	}
	int ans=a[0]+b[0];
	rep(i,n){
		if(ans>a[i]+b[i]) ans=a[i]+b[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3076
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      ab: [(Usize1, Usize1); n-1]
   }
   let mut to = vec![vec![]; n];
   for &(a, b) in ab.iter() {
      to[a].push(b);
      to[b].push(a);
   }
   let mut d1 = vec![0; n];
   let mut d2 = vec![0; n];
   dfs(0, 0, &mut d1, &to);
   dfs(n - 1, n - 1, &mut d2, &to);
   let mut ans = vec![0; n];
   for i in 0..n {
      if d1[i] > d2[i] {
         ans[i] = 1;
      }
   }
   let mut f = 0;
   let mut s = 0;
   for i in 0..n {
      match ans[i] {
         0 => f += 1,
         _ => s += 1,
      }
   }
   if f > s {
      println!("Fennec");
   } else {
      println!("Snuke");
   }
}

fn dfs(v: usize, p: usize, d: &mut Vec<usize>, to: &Vec<Vec<usize>>) {
   for &u in to[v].iter() {
      if u == p {
         continue;
      }
      d[u] = d[v] + 1;
      dfs(u, v, d, to);
   }
}


Measured memory_bytes: 18400
#include<stdio.h>
int main(){
    char s[5];
    scanf("%s",s);
    int i,c[27]={0};
    for(i=0;i<4;i++) c[s[i]-'A']++;
    for(i=0;i<27;i++){
        if(c[i]==2||c[i]==0);
        else{
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 128
def p_d():
    from sys import stdin
    input = stdin.readline
    import sys
    sys.setrecursionlimit(10 ** 6)
    n = int(input())
    route = [[] for _ in range(n)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        w = 0 if w & 1 == 0 else 1
        route[u - 1].append((v - 1, w))
        route[v - 1].append((u - 1, w))

    ans = [-1] * n

    def dfs(p, d):
        ans[p] = d
        for i, j in route[p]:
            if ans[i] < 0:
                dfs(i, d ^ j)

    dfs(0, 0)
    print("\n".join(map(str, ans)))
    
p_d()

Measured memory_bytes: 85748
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong x, y;

int main() {
    cin >> x >> y;

    if (llabs(x - y) > 1) {
        cout << "Alice" << endl;
    }
    else {
        cout << "Brown" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
x = int(input())
point = 0
while x != 0:
    if x >= 500:
        result = x // 500
        summ = (500 * result)*2
        point = point + summ
        remainder = x % 500
        x = remainder
    if x >= 5:
        result = x // 5
        summ = 5 * result
        point = point + summ
        break;
print(point)

Measured memory_bytes: 3060
N = int(input())
X = []
L = []
for i in range(N) :
    p, q = map(int,input().split())
    X.append(p)
    L.append(q)

Arm = []
for i in range(N) :
    Arm.append([X[i]-L[i], X[i]+L[i]])

Arm.sort(key=lambda x:x[1])
ans = 0
mxa = -10**10
for a in Arm :
    if a[0] >= mxa :
        mxa = a[1]
        ans += 1

print(ans)


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int h,a;
	cin >> h >> a;
	if(h < a) cout << 1 << endl;
	else{
		double x = (double)h/a;
		cout << ceil(x) << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using PLL = pair<ll, ll>;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
#define ALL(V) (V).begin(), (V).end()
#define endl '\n'
    
V<PLL> dir = {
    PLL(0, 1),
    PLL(-1, 0),
    PLL(0, -1),
    PLL(1, 0),
};

V<ll> primes;

PLL advance(ll h, ll w, ll idx) {
    ll dh, dw;
    tie(dh, dw) = dir[idx];
    ll nh = h + dh, nw = w + dw;
    return make_pair(nh, nw);
}

void decide_dir(ll h, ll w, ll &idx, const VV<ll> &holes) {
    ll next_d = (idx + 1) % 4;
    ll nh, nw;
    tie(nh, nw) = advance(h, w, next_d);
    if(holes[nh][nw] == -1) idx = next_d;
}

bool is_prime(ll p) {
    auto ite = lower_bound(ALL(primes), p);
    return (ite != primes.end() && (*ite) == p);
}

ll H = 2e3 + 10, W = 2e3 + 10;

PLL dfs(ll h, ll w, const VV<ll> &holes, VV<PLL> &memo) {
    if(holes[h][w] == -1) return PLL(0, 0);
    if(memo[h][w] != PLL(-1, -1)) return memo[h][w];
    PLL ret(0, 0);
    V<PLL> recs;
    for(ll i = -1; i <= 1; i++) {
        ll nh = h + 1;
        ll nw = w + i;
        if(!(0 <= nh && nh < H &&
             0 <= nw && nw < W)) continue;
        recs.push_back(dfs(nh, nw, holes, memo));
    }
    sort(ALL(recs), 
         [](PLL a, PLL b) {
             ll ca, pa, cb, pb;
             tie(ca, pa) = a;
             tie(cb, pb) = b;
             if(ca != cb) return ca < cb;
             else return pa < pb;
         });
    if(recs.size()) {
        auto tmp = recs.back();
        ret.first += tmp.first;
        ret.second = tmp.second;
    }
    ll p = holes[h][w];
    if(is_prime(p)) {
        if(ret.second == 0) ret.second = p;
        ret.first++;
    }
    return memo[h][w] = ret;
}

bool solve() {
    ll M, N;
    cin >> M >> N;
    if(!(N + M)) return false;
    VV<ll> holes(H, V<ll>(W, -1));
    VV<PLL> memo(H, V<PLL>(W, PLL(-1, -1)));
    ll didx = 3;
    ll h = holes.size() / 2, w = holes.size() / 2;
    ll init_h, init_w;
    for(ll i = 1; i <= M; i++) {
        holes[h][w] = i;
        if(i == N) tie(init_h, init_w) = PLL(h, w);
        decide_dir(h, w, didx, holes);
        tie(h, w) = advance(h, w, didx);
    }
    auto ans = dfs(init_h, init_w, holes, memo);
    cout << ans.first << ' ' << ans.second << endl;
    return true;
}

int main() {
    V<bool> used(1e6 + 10, false);
    for(ll i = 2; i < used.size(); i++) {
        if(used[i]) continue;
        primes.push_back(i);
        for(ll j = 1; i * j < used.size(); j++) used[i * j] = true;
    }
    while(solve());
    return 0;
}



Measured memory_bytes: 98672
#include<stdio.h>
int a[2500];
int main ()
{
	int n=0,m=0,j=1;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m*2;i++,j++)
	{
		scanf("%d",&j);
		a[j]++;
	}
	for(int i=1;i<=n;i++)
	printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] atgs) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        // 配列内の最小値とその番号を調べる
        int min = a[0];
        int minIndex = 0;
        for (int i = 1; i < n; i++) {
            if (min > a[i]) {
                min = a[i];
                minIndex = i;
            }
        }

        int cnt = 0;
        int tmp = 0;
        for (int l = minIndex-1; l >= 0; l--) {
            if (a[minIndex] == a[l])
                continue;
            else {
                cnt++;
                l -= k-2;
                if (l-1 < 0)
                    tmp = Math.abs(l);
            }
        }

        for (int r = minIndex+1+tmp; r < n; r++) {
            if (a[minIndex] == a[r])
                continue;
            else {
                cnt++;
                r += k-2;
            }
        }

        System.out.println(cnt);
    }
}

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

void solve() 
{
    ll n;cin>>n;
    map<ll,ll>m;
    REP(i,n){
        ll a;cin>>a;
        m[a]++;
    }
    ll sum=0;
    for(auto it:m)sum+=it.first*it.second;
    ll q;cin>>q;
    REP(i,q){
        ll b,c;cin>>b>>c;
        sum+=(c-b)*m[b];
        m[c]+=m[b];
        m[b]=0;
        cout<<sum<<endl;
    }

}

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

Measured memory_bytes: 9508
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>

using namespace std;
using ll=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)
#define REPT(i, t, n)  for(int i = t; i <= (int)n; ++i)
#define REPll1(i, n)  for(ll i = 1; i*i < (int)n; ++i)

int cnt(ll n) {
    int c = 0;
    while (true) {
        if (n < 1)break;
        n = n / 10;
        c++;
    }
    return c;
}

string zeroPadding(ll n) {
    string s = to_string(n);
    while (s.length() < 6) {
        s = "0" + s;
    }
    return s;
}

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll mod = 1e9 + 7;

int main() {
    int N = 0, M, K, O, a = 0, b = 0;
    ll x, y, sum, pos = 0, c = 0;
    string k, v;
    bool flag = true;
    ll D, G;
    cin >> D >> G;

    vector<ll> A(D);
    vector<ll> B(D);

    REP(i, D)cin >> A[i] >> B[i];
    ll ans = 1e9;

    for (int bit = 0; bit < (1 << D); ++bit) {
        //   cout << bitset<10>(bit) << endl;
        ll s = 0;
        sum = G;
        for (int i = D; i >= 0; i--) {
            if (bit & (1 << i)) {
                x = A[i];
                y = B[i];

                int tmp = sum - (100 * (i + 1)) * x;
                if (tmp <= 0) {
                    s += sum / (100 * (i + 1));
                    sum = tmp;
                    break;
                } else sum = tmp - y;

                if (sum <= 0) {
                    s += x;
                    break;
                } else s += x;
            }
        }
        if (s == 0 || sum > 0)continue;
        ans = min(s, ans);
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K; cin>>N>>K;
    vi a(N);
    rep(i,N) cin>>a[i];
    int l=0, r=(int)1e9;
    while(r-l>1){
        int c = (l+r)/2;
        ll sum=0;
        rep(i,N){
            int k = (a[i]+c-1)/c;
            sum+=k-1;
        }
        (sum<=K)?r=c:l=c;
    }
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 3940
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        ab_vec: [(usize, usize); n],
    }

    let mut bmap: BTreeMap<usize, usize> = BTreeMap::new();
    
    for (a, b) in ab_vec.iter() {
        *bmap.entry(*a).or_insert(0) += b;
    }

    let mut cnt = 0;
    let mut ans = 0;
    
    for (key, v) in bmap.iter() {
        cnt += *v;
        if cnt >= k {
            ans = *key;
            break;
        }
    }

    dbg!(&ans);

    println!("{}", ans);
}


Measured memory_bytes: 6572
#include <iostream>
using namespace std;
 
int main (){
	int N,sum = 0,ans = 0,diff = 9999;
  		cin >> N;
  	int W[N];
  		for(int i = 0;i < N;i++){
        	cin >> W[i];
          	sum += W[i];
          	//cout << W[i] << endl;
        }
  		//cout << sum;
		for(int i = 0;i < N;i++){
        	ans = sum - W[i];
          	//cout << ans << endl;
          	if(diff > abs(ans - W[i])){
            	diff = abs(ans - W[i]);
              	//cout << diff << endl;
            }
          	W[i+1] += W[i];
          	//cout << W[i] << endl;
        }
  		cout << diff;
  
}		

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n;
int a[20005];
int res;
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n-2;i++)
        for(int j=i+1;j<n-1;j++)
        {
            int l=lower_bound(a+j+1,a+n,a[j]-a[i]+1)-a;
            if(l>=n || a[l]>=a[j]+a[i]) continue;
            int r=upper_bound(a+j+1,a+n,a[j]+a[i]-1)-a;
            r-=1;
            res+=r-l+1;
        }
    cout<<res;
    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string s;
    cin >> s;
    vector<int> v(26, -inf);

    REP(i, size(s)){
        char c = s[i];
        if(i - v[c - 'a'] < 3){
            cout << max(1, i-1) << " " << min(size(s), i+1) << endl;
            return 0;
        }
        v[c - 'a'] = i;
    }

    cout << -1 << " " << -1 << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

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

  int n = s.size();
  char c[26];
  for(int i = 0; i < 26; i++){
    c[i] = 'A';
  }
  bool flag = true;
  for(int i = 0; i < n; i++){
    if(c[s[i]-'a'] == 'A') c[s[i]-'a'] = t[i];
    if(c[s[i]-'a'] != t[i]) flag = false;
  }
  for(int i = 0; i < 26; i++){
    c[i] = 'A';
  }

  for(int i = 0; i < n; i++){
    if(c[t[i]-'a'] == 'A') c[t[i]-'a'] = s[i];
    if(c[t[i]-'a'] != s[i]) flag = false;
  }


  cout <<(flag ?"Yes":"No") << endl;

  return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll l,r,d,x=0;
    string s;
    cin>>l;
    for(int i=1;i<=l;i++) {
        cin>>r;
        if(i%2==1&&r%2==1)
        x++;
    }
    cout<<x;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  map<string,int64_t> m;


  rep(i,N){
    string t;
    cin >> t;
    sort(t.begin(),t.end());
    s.at(i) = t;
    m[t] ++;
  }

  int64_t ans=0;

  for(auto val: m){
    int64_t x = val.second;
    ans += (x-1)*x / 2;
  }

  cout << ans << endl;


}


Measured memory_bytes: 16640
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,k = gets.chomp.split.map(&:to_i)

ans = 0

1.upto(n) do |a|
  if (2 * a) % k == 0
    b = (n + a) / k - a / k
    ans += b ** 2
  end
end

puts ans







Measured memory_bytes: 14644
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
const ll MOD = 1e9 + 7;

string L;
// 0: 未確定, 1: 確定
ll dp[100002][2];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> L;

  dp[0][0] = 1;
  dp[0][1] = 0;
  for (ll i = 0; i < L.size(); i++) {
    if (L[i] == '0') {
      dp[i + 1][0] = dp[i][0];
      dp[i + 1][1] = dp[i][1] * 3 % MOD;
    } else {
      dp[i + 1][0] = dp[i][0] * 2 % MOD;
      dp[i + 1][1] = (dp[i][0] + dp[i][1] * 3) % MOD;
    }
  }

  cout << (dp[L.size()][0] + dp[L.size()][1]) % MOD << endl;
  return 0;
}

Measured memory_bytes: 2000
#include <iostream>
#include <complex>
#include <cmath>
#include <stdio.h>

using namespace std;

typedef complex<double> P;

const double PI = acos(-1.0);

int main(){
	int N, D;
	while(cin >> N >> D, N){
		P p = P(0,0); double dir = PI/2;
		for(int i=0;i<N;i++){
			int L, R, T; cin >> L >> R >> T;
			if(L==R){
				p = p + T*L/180.0*PI*P(cos(dir), sin(dir));
			}
			else {
				double r = ((double)L+R)/(L-R)*D;
				P c = p + P(cos(dir), sin(dir))*P(0,-1)*r;
				double agl = (r > 0 ? -L/abs(r+D) : R/abs(r-D))*T*PI/180.0;
				dir += agl;
				p = (p-c)*P(cos(agl), sin(agl))+c;
			}
		}
		printf("%.8lf\n%.8lf\n", real(p), imag(p));
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
#include <iomanip>
using namespace std;

#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define maxn 20

char mp1[maxn][maxn];
int mp[maxn][maxn];
int dx[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
int t[5] ;
int hash[256];
char str[10] = "DRUL";
int n,m;
int sx , sy;
int sdir;
int st[1000005];
int num ;
int ans ;
void init()
{
  memset(hash,-1,sizeof(hash));
  hash['U'] = 2;
  hash['D'] = 0;
  hash['R'] = 1;
  hash['L'] = 3;
  t[0] = 2;
  t[1] = 3;
  t[2] = 0;
  t[3] = 1;
}
int check(int x ,int y ,int dir )
{
  int res;
  res = 0 ;
  x += dx[dir][0];
  y += dx[dir][1];
  res ++ ;
  while(mp[x][y] == 0 && x <= n && y <= m && x > 0 && y > 0  )
  {
    res ++ ;
    x += dx[dir][0];
    y += dx[dir][1];
  }
  //printf("%d\n",res);
  if(mp[x][y] == 0 ) return -1;
  else return res;
}
bool flag;
int sd;
void print(int nn )
{
  sd = sdir;
  int cnt = sd;
  for(int i = 0 ; i < nn ; i ++ )
  {
    if(st[i] == 0 && sd == 3 ) cnt = (cnt + 1 )% 4 ;
    else if(st[i] == 3 && sd == 0 )  cnt = (cnt - 1 + 4 ) % 4;
    else if(st[i] > sd ) cnt = (cnt + 1 ) % 4;
    else if(st[i] < sd  ) cnt = (cnt - 1 + 4) % 4 ;
    sd = st[i];
    printf("%c",str[cnt]);
  }
  printf("\n");
}
void dfs(int x ,int y ,int dir, int dep )
{
  //printf("dfs: %d %d\n",x,y);
  if(flag ) return ;
  if(num == 1)
  {
    print(dep);
    flag = true ;
    return ;
  }
  int kk , xx , yy , ndir ;
  ndir = t[dir];
  for(int k = 0; k < 4; k ++ )
    if(flag == false && k != ndir  )
    {
      kk = check(x,y,k);
      if(kk == -1 ) continue;
      xx = x + kk * dx[k][0];
      yy = y + kk * dx[k][1];
      num = num - 1 ;
      mp[x][y] = 0 ;
      st[dep] = k ;
      dfs(xx , yy , k , dep + 1 );
      num = num + 1 ;
      mp[x][y] = 1;
    }
}
int main()
{
  init();
  while(scanf("%d%d",&n,&m)!=EOF)
  {
    memset(mp,0,sizeof(mp));
    num = 0 ;
    sx = -1;
    sy = -1;
    for(int i = 1 ; i <= n ; i++ )
    {
      scanf("%s",mp1[i]);
      // printf("%s|\n",mp1[i]);
      for(int j = 0 ; j < m ; j ++ )
      {
        // printf("%c",mp1[i][j]);
        if(mp1[i][j] == 'o')
        {
          num ++ ;
          mp[i][j + 1 ] = 1 ;
        }
        else if(mp1[i][j] == '.' )
        {
          mp[i][j+1] = 0 ;
        }
        else// if(mp1[i][j] == 'U' ||mp1[i][j] == 'D' ||mp1[i][j] == 'L'||mp1[i][j] =='R' )
        {
          // printf("aasdmaklsd");
          num ++ ;
          mp[i][j+1] = 1;
          sx = i;
          sy = j + 1 ;
         // printf("sx sy %d %d\n",sx,sy);
          sdir = hash[mp1[i][j]];
        }
      }
    }
   // printf("%d %d\n",sx,sy);
    int tmp ;
    tmp = num;
    flag = false;
    dfs(sx,sy,sdir,0);
  }
  return 0;
}


/*

URRULULDDLUURDLLLURRDLDDDRRDR
URRULULDDLUURDLLLURRDLDDDRRDR


*/

Measured memory_bytes: 1172
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, x float64
	fmt.Scan(&a, &b, &x)

	tan := 2 * (b/a - x/(a*a*a))
	if a*tan <= b {
		theta := math.Atan(tan)
		fmt.Println(theta * 180 / math.Pi)
	} else {
		theta := math.Atan(a * b * b / (2 * x))
		fmt.Println(theta * 180 / math.Pi)
	}
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int S_1[20000],S_2[20000],S_3[20000];
int cnt=0,cnt2=0,cnt3=0;
void push1(int x);
void push2(int x);
void push3(int x);
int pop1();
int pop2();
int pop3();

int main(void){
	char s[20000];
	int i=0 ,j=0,k=0,sum=0;
	scanf("%s",s);
	while(s[i]=='\\'||s[i]=='_'||s[i]=='/'){
		if(s[i]=='\\'){
			push1(i);
		}
		else if(s[i] == '/' && cnt != 0){
			j=pop1();
			k=i-j;
			sum+=k;
			while(cnt2!=0&&j<S_2[cnt2]){
				pop2();
				k+=pop3();
			}
			push2(j);
			push3(k);
		}
		i++;
	}
	printf("%d\n",sum);
	printf("%d",cnt3);
	
	for(i=1;cnt3!=0;i++){
		pop3();
		printf(" %d",S_3[i]);
	}
	printf("\n");
	return 0;
}

void push1(int x){
	cnt++;
	S_1[cnt] = x;
}
void push2(int x){
	cnt2++;
	S_2[cnt2] = x;
}
void push3(int x){
	cnt3++;
	S_3[cnt3] = x;
}
int pop1(){
	cnt--;
	return S_1[cnt+1];
}
int pop2(){
	cnt2--;
	return S_2[cnt2+1];
}
int pop3(){
	cnt3--;
	return S_3[cnt3+1];
}



Measured memory_bytes: 2108
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;


public class Main {


    static void solve() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int v = 1000;
        while(n > v) {
            v+=1000;
        }
        int res = v-n;
        System.out.println(res);

//        long t = scan.nextLong();

//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
//            int res = n%1000;
//            System.out.println(res);
////            scase(n);
//        }
    }


    static void solveCase(int t, int x, String s) {

    }

    static void scase(long n) {

    }


    public static void main(String[] args) {
        solve();
        //        Main m = new Main();
        //        Scanner scan = new Scanner(System.in);

        //        long n = scan.nextLong();
        //        long r = scan.nextLong();
        //        List<Long> list = new ArrayList<>();
        ////        int[] arr = new int[n];
        //        for (long i=0;i<n;i++){
        //            list.add(scan.nextLong());
        //        }
//            System.out.println(ch);
        //        solve(n, arr);
        //        scan.close();
    }


//
//    class Counter extends HashMap<Integer, Integer> {
//        public int get(int k) {
//            return containsKey(k) ? super.get(k) : 0;
//        }
//
//        public void add(int k, int v) {
//            put(k, get(k) + v);
//        }
//    }


//    static class TreeNode {
//        int val;
//        TreeNode left;
//        TreeNode right;
//
//        TreeNode(int x) {
//            val = x;
//        }
//    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

}

Measured memory_bytes: 26972
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	int w, a, b;
	cin >> w >> a >> b;

	if (a < b){
		if (a + w >= b) cout << 0 << endl;
		else {
			cout << b - (a + w) << endl;
		}
	}
	else if (b < a){
		if (b + w >= a) cout << 0 << endl;
		else {
			cout << a - (b + w) << endl;
		}
	}
	else cout << 0 << endl;

}


Measured memory_bytes: 256