akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;



int main(void){
    ll n;
    cin>>n;
    vl a(n);
    ll mai = 0;
    bool zero = false;
    rep(i,n){
        cin>>a[i];
        if(a[i]<0){
            mai++;
            a[i] *= -1;
        }
        if(a[i] == 0) zero = true;
    }
    if(zero == true || mai%2 == 0){
        ll ans = 0;
        rep(i,n){
            ans += a[i];
        }
        cout<<ans<<endl;
    }
    else{
        sort(all(a));
        ll ans = 0;
        rep1(i,n) ans += a[i];
        ans -= a[0];
        cout<<ans<<endl;
    }
}

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

//#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(ba))

signed main() {
    int a[3];
    rep(i,3) cin >> a[i];
    sort(a,a+3);
    if(a[0] == 5 && a[1] == 5 && a[2] == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		try {
			System.setIn(new FileInputStream("src/aoj2103/input.txt"));
			System.setOut(new PrintStream(new FileOutputStream("src/aoj2103/result.txt")));
		} catch (FileNotFoundException e) {
		}
		new Main().run();
	}



	Scanner sc;
	void run() {
		sc = new Scanner(System.in);
		int T = sc.nextInt();
		while (T-- >0) {
			solve();
			if (T > 0)
				System.out.println();
		}
	}

	int R, C;
	char[][] table;
	boolean isin(int r, int c) {
		return 0 <= r && r < R && 0 <= c && c < C;
	}
	boolean canmove(int r, int c) {
		return isin(r,c) && table[r][c] == '.';
	}

	void solve() {
		R = sc.nextInt();
		C = sc.nextInt();
		table = new char[R][C];

		for (int r = 0; r < R; r++) {
			table[r] = sc.next().toCharArray();
		}

		int x = -1, y = -1;
		for (int r = 0; r < R; r++)
			for (int c = 0; c < C; c++)
				if (table[r][c] == '^' || table[r][c] == 'v' || table[r][c] == '<' || table[r][c] == '>') {
					x = r;
					y = c;
				}


		String dirs = ">^<v";
		int[] dr = {0, -1, 0, 1};
		int[] dc = {1, 0, -1, 0};
		int M = sc.nextInt();
		char[] cmd = sc.next().toCharArray();
		for (int i = 0; i < cmd.length; i++) {
			if (cmd[i] == 'S') {
				int d = dirs.indexOf(table[x][y]);
				int tx = x + dr[d];
				int ty = y + dc[d];
				while (isin(tx, ty)) {
					if (table[tx][ty] == '*') {
						table[tx][ty] = '.';
						break;
					}
					if (table[tx][ty] == '#')
						break;
					tx += dr[d];
					ty += dc[d];
				}
			}
			if (cmd[i] == 'U') {
				table[x][y] = '^';
				if (canmove(x - 1, y)) {
					table[x][y] = '.';
					table[x-1][y] = '^';
					x--;
				}
			}
			if (cmd[i] == 'D') {
				table[x][y] = 'v';
				if (canmove(x + 1, y)) {
					table[x][y] = '.';
					table[x+1][y] = 'v';
					x++;
				}

			}
			if (cmd[i] == 'L') {
				table[x][y] = '<';
				if (canmove(x, y-1)) {
					table[x][y] = '.';
					table[x][y-1] = '<';
					y--;
				}

			}
			if (cmd[i] == 'R') {
				table[x][y] = '>';
				if (canmove(x, y+1)) {
					table[x][y] = '.';
					table[x][y+1] = '>';
					y++;
				}
			}
		}
		for (int i = 0; i < R; i++){
			for (int j = 0; j < C; j++)
				System.out.print(table[i][j]);
			System.out.println();
		}
	}

	void tr(Object... os) {
		System.err.println(deepToString(os));
	}
}

Measured memory_bytes: 12000
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var L = parseInt(input[0][0], 10);
    var R = parseInt(input[0][1], 10);
    var d = parseInt(input[0][2], 10);
    var ans = 0;
    for (var i = L; i<= R; i++){
        if (i % d ===0) ans ++;
    }

    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 29648
#include<stdio.h>
long long n,k,L,R,M;
long long t[100000];
 
int check(long long x){
 
  long long i,id=0,count=0;
 
  for(i=0;i<n;i++){
    if(count+t[i]>x){
      count=t[i];
      id++;
    }else{
      count+=t[i];
    }
    if(id==k)return 0;
  }
  return -1;
} 
int main(){
 
  int i;
 
  scanf("%d %d",&n,&k);
 
  L=1;
  for(i=0;i<n;i++){
    scanf("%d",&t[i]);
    L=(L<t[i]?t[i]:L);
  }
   
  R=1000000000LL;
  while(L<R){
    M=(L+R)/2;
    if(check(M)==-1){
      R=M;
    }else{
      L=M+1;
    }
  }
 
  printf("%d\n",L);
 
  return 0;
}
 

Measured memory_bytes: 1376
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	h := nextInt()
	n := nextInt()
	var totalA int
	for i := 0; i < n; i++ {
		totalA += nextInt()
	}
	if h <= totalA {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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


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

int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    ll ans = 0LL;
    for (ll i = 1LL; i <= N; i++) {
        if (i % 3 != 0LL and i % 5 != 0LL) {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;




int main()
{
    ll n; cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++)cin >> a[i];
    vector<ll> nind;
    vector<ll> sum(n);
    sum[0] = a[0];
    for(ll i = 1; i < n; i++)sum[i] = max(sum[i - 1], a[i]);

    for(ll i = n - 1; i >= 1; i--) {
        if(sum[i] != sum[i - 1])nind.push_back(i);
    }
    nind.push_back(0);


    map<ll,ll,greater<ll>> mp;
    vector<ll> ans(n);
    ll past = n;
    ll m = nind.size();
    reverse(nind.begin(), nind.end());

    for(ll i = m - 1; i >= 0; i--) {

        for(ll j = past-1; j >= nind[i]; j--) {
            mp[a[j]]++;
        }
        


        vector<ll> del;
        for(auto j : mp) {
            if(i!=0){
            if(j.first <= a[nind[i-1]])break;}
            ans[nind[i]] += (j.first * j.second) - (i == 0 ? 0 : a[nind[i - 1]]) * j.second;
            // cerr << i << ": " << j << endl;
            del.push_back(j.first);
        }
        // prvec(del);
        if(i==0)break;
        for(auto j : del) {
            mp[a[nind[i-1]]] += mp[j];
            mp.erase(j);
        }



        past = nind[i];

    }
    for(ll i = 0; i < n; i++)cout << ans[i] << endl;
    
}

Measured memory_bytes: 12884
#include "bits/stdc++.h"
using namespace std;


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

	string ans = "No";
	if (n[0] == '7' || n[1] == '7' || n[2] == '7') {
		ans = "Yes";
	}

	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
        p[i]--;
    }

    int M = 50000;
    vector<int> a(N), b(N);
    for (int i = 0; i < N; i++) {
        a[i] = M * (i + 1);
        b[i] = M * (N - i - 1) + 1;
    }

    int min = 1;
    for (int i = 0; i < N; i++) {
        if (a[p[i]] + b[p[i]] < min) {
            b[p[i]] += min - (a[p[i]] + b[p[i]]);
        }
        min = a[p[i]] + b[p[i]] + 1;
    }

    for (int i = 0; i < N - 1; i++) {
        cout << a[i] << " ";
    }
    cout << a[N - 1] << endl;
    for (int i = 0; i < N - 1; i++) {
        cout << b[i] << " ";
    }
    cout << b[N - 1] << endl;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
int main() {
	long long int h;
	long long int n;
	long long int sum = 0;
	cin >> h >> n;
	for (int i = 0; i < n; i++) {
		long long int in;
		cin >> in;
		sum = sum + in;
	}
	if (sum >= h) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

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

#define MAX_SIZE 80

int strlen(const char* str) {
    int i;
    for(i=0; i<999+1; ++i) {
        if(!str[i]) {
            return i;
        }
    }
    return -1;
}

int main() {
    int n, i, j, num1_index, num2_index;
    char num1[999], num2[999];

    scanf("%d", &n);
    for(i=0; i<n; ++i) {
        scanf("%s %s", num1, num2);
        num1_index = strlen(num1);
        num2_index = strlen(num2);
        int sum=0, act=0, temp=0;
        char result[999] = {};
        for(j=0; j<MAX_SIZE && (num1_index > 0 || num2_index > 0); ++j) {
            if(num1_index <= 0) {
                temp = act + num2[--num2_index] - 48;
            }else if(num2_index <= 0) {
                temp = act + num1[--num1_index] - 48;
            }else {
                temp = act + num1[--num1_index] + num2[--num2_index] - 96;
            }
            result[j] = temp % 10;
            act = temp / 10;
        }
        if(j<MAX_SIZE) {
            result[j++] = act;
            act = 0;
        }
        if(j>=MAX_SIZE && (num1_index || num2_index || act)) {
            printf("overflow\n");
        }else {
            int zeros = 1;
            for(j=MAX_SIZE-1; j>=0; --j) {
                if(zeros && !result[j]) {
                    continue;
                }
                zeros = 0;
                printf("%d", result[j]);
            }
            if(zeros) {
                printf("0");
            }
            printf("\n");
        }

    }

    return 0;
}

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

int main()
{
	int n,a[101],maxn=-1,minn=1000000001;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(maxn<a[i]) maxn=a[i];
	}
	for(int i=1;i<=n;i++)
	{
		if(minn>a[i]) minn=a[i];
	}
	cout<<maxn-minn;
}

Measured memory_bytes: 256
S = int(input())
mod = 10 ** 9 + 7

DP = [0] * (S+1)

if S >= 3:
    DP[3] = 1

for i in range(4, S+1):
    DP[i] = DP[i-1] + DP[i-3]
    DP[i] %= mod

print(DP[-1])

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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

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

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

  ll ans = 0;
  for (int i = 1; i < N; i++) {
    for (int j = N - 1; j >= i; j--) {
      if (A[j-1]>A[j]) {
        swap(A[j-1], A[j]);
        ans++;
      }
    }
  }

  cout << A[0];
  for (int i = 1; i < N; i++) {
    cout << SP << A[i];
  }
  cout << BR;
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3092
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
	//	int a = sc.nextInt();
		// スペース区切りの整数の入力
	//	int b = sc.nextInt();
	//	int c = sc.nextInt();
		// 文字列の入力
		String s = sc.next();
		int len=s.length();
int sum=0;
		// 出力
		for(int i=0;i<len;i++){
		if(s.charAt(i)=='1')
		sum++;
		}
		
		System.out.println(sum);
	}
}

Measured memory_bytes: 21716
#include<iostream>
using namespace std;
int main(){
  int A , B , C;
  
  cin >> A >> B >> C;
  
  if((A + B == 10 && A + C == 12) || (B + C == 10 && B + A == 12) || (C + A == 10 && B + C == 12))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
  
}

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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto X = RD;
	auto Y = RD;
	auto Z = RD;

	writeln((X-Z) / (Y+Z));
	stdout.flush();
	debug readln();
}

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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/(b))
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const LL LL_INF = LL(999999999999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;
const int RUN_SOLVE = 1;

#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    for(int do_solve_time = 0;do_solve_time < RUN_SOLVE;do_solve_time++){
        void solve();
        if(DO_BENCHMARK){
            clock_t clock_start = clock();
            solve();
            clock_t clock_end = clock();
            const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
            cout << "\n------------------------------------\n" << time << "[ms]\n";
        }
        else solve();
    }
}

/*------------------------------↓ここからコード↓----------------------------------*/
void solve(){
    LL X, K, D;
    cin >> X >> K >> D;
    LL firstmove = abs(X/D);
    if(firstmove >= K){
        cout << abs(X)-K*D << endl;
    }
    else{
        if(X > 0){
            X -= firstmove*D;
            if((K-firstmove)%2 == 1){
                X -= D;
            }
        }
        else{
            X += firstmove*D;
            if((K-firstmove)%2 == 1){
                X += D;
            }
        }
        cout << abs(X) << endl;
    }
}


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

int main(){
	int n, m, start, end;
	long long ans;
	cin >> n >> m;
	vector<int> a(m);
	vector<long long> fib(100001);

	for(int i=0; i<m; i++){
		cin >> a[i];
	}
	a.push_back(n+1);

	for(int i=0; i<m-1; i++){
		if(a[i+1] - a[i] == 1){
			cout << 0 << endl;
			return 0;
		}
	}

	fib[0] = 1;
	fib[1] = 1;
	for(int i=2; i<fib.size(); i++){
		fib[i] = (fib[i-1] + fib[i-2]) % 1000000007;
	}

	ans = 1;
	start = 0;
	for(int i=0; i<a.size(); i++){
		end = a[i];
		//ans = (ans*fib[end - start]) / 1000000007;
		ans = ans*fib[end - start-1];
		ans %= 1000000007;
		start = end+1;
	}
	cout << ans << endl;
}
/*
1 1
2 1
3 3
4 5
5 8
6 13
2 --- 0~2
*/

Measured memory_bytes: 1792
#include <stdio.h>

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[2*N-1], dneg[2*N-1];
char q[N][N];

void putQueen(int);
void printBoard(void);
void initialize(void);

int main() {
  int i, j, k, r, c;

  for (i = 0; i < N; i++) {
    row[i] = FREE;
    col[i] = FREE;
  }
  for (i = 0; i < 2*N-1; i++) {
    dpos[i] = FREE;
    dneg[i] = FREE;
  }

  scanf("%d", &k);

  for (i = 0; i < k; i++) {
    scanf("%d%d", &r, &c);
    q[r][c] = NOT_FREE;
  }

  putQueen(0);
  
  return 0;
}


void putQueen(int i) {
  int j;
  
  if (i == N) {
    printBoard();
    return;
  }

  for (j = 0; j < N; j++) {
    if (col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE) continue;
    row[i] = j;
    col[j] = NOT_FREE;
    dpos[i+j] = NOT_FREE;
    dneg[i-j+N-1] = NOT_FREE;
    putQueen(i+1);
    col[j] = FREE;
    dpos[i+j] = FREE;
    dneg[i-j+N-1] = FREE;
  }
}


void printBoard(void) {
  int i, j;

  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      if (q[i][j] == NOT_FREE) {
	if (row[i] != j) return;
      }
    }
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      if (row[i] == j) printf("Q");
      else if (row[i] != j) printf(".");
    }
    printf("\n");
  }
}


void initialize(void) {
  int i, j;
  
  for (i = 0; i < N; i++) {
    row[i] = FREE;
    col[i] = FREE;
  }
  for (i = 0; i < 2*N-1; i++) {
    dpos[i] = FREE;
    dneg[i] = FREE;
  }

  for (i = 0; i < N; i++) {
    for (j = 0; j < N; j++) {
      q[i][j] = FREE;
    }
  }
}



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


int main() {
  vector<int> a(100);
  vector<int> b(100);
  for(int i = 0 ; i<100;i++){
    cin >> a.at(i);
    cin >> b.at(i);
    if( a.at(i)==0){
      break;
    }
    for(int j = 0 ; j< a.at(i) ; j++){
      if(j%2==0){
       for(int k = 0 ; k< b.at(i) ; k++){
        if(k%2==0){
          cout << "#" ;
        }
         else{
           cout << "." ;
         }
       }
      cout << endl;
      }
      
      else{
        for(int l = 0 ; l< b.at(i) ; l++){
         
           if(l%2==1){
             cout << "#" ;
         }
         else{
           cout << "." ;
         }
        }
        cout << endl;
      }
    }
    cout << endl;
  }
}
    


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> in(N, 0);
  vector<vector<int>> graph(N);
  REP(i, N+M-1){
    int u, v;
    cin >> u >> v;
    u--; v--;
    graph[u].emplace_back(v);
    in[v]++;
  }

  vector<int> ans(N, 0);

  int root = -1;
  REP(i, N) if(in[i] == 0) root = i;

  queue<int> q;
  q.push(root);

  while(!q.empty()){
    int now = q.front(); q.pop();
    for(auto to : graph[now]){
      if(--in[to] == 0){
        ans[to] = now+1;
        q.push(to);
      }
    }
  }

  REP(i, N){
    cout << ans[i] << endl;
  }


  return 0;
}

Measured memory_bytes: 7808
#include <iostream>
#include <string>
using namespace std;
int mp[3][1001][1001] = {};
string str[1001];
string joi[3];
int co=0;

void che(int a,int b){
  int f=0;
  int x,y,x2,y2;
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++)
      if(str[i+a][j+b]!=joi[i][j]){f++;x=j+b;y=i+a;x2=j;y2=i;}
  
  if(f==0){
    co++;
    for(int i=0;i<2;i++)
      for(int j=0;j<2;j++)
	for(int k=0;k<3;k++)
	  mp[k][i+a][j+b]--;
  }
  else if(f==1){
    if(joi[y2][x2]=='J') mp[0][y][x]++;
    else if(joi[y2][x2]=='O') mp[1][y][x]++;
    else if(joi[y2][x2]=='I') mp[2][y][x]++;
  }
}


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

  for(int i=0;i<m;i++) cin>>str[i];
  for(int i=0;i<2;i++) cin>>joi[i];

  for(int i=0;i<m-1;i++)
    for(int j=0;j<n-1;j++)
      che(i,j);

  int mpmax=0;
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)
      for(int k=0;k<3;k++)
	if(mpmax<mp[k][i][j]) 
	  mpmax = mp[k][i][j];

  cout <<co+mpmax<<endl;  

  return 0;
}

Measured memory_bytes: 13992
def main():
    n, k = [int(x) for x in input().split()]
    dice = [int(x) for x in input().split()]

    expected_accum = []
    for i, p in enumerate(dice):
        ex = (1 + p) / 2
        if i == 0:
            expected_accum.append(ex)
        else:
            expected_accum.append(expected_accum[-1] + ex)

    def gen():
        for start in range(n - k + 1):
            if start == 0:
                yield expected_accum[k - 1]
            else:
                yield expected_accum[start + k - 1] - expected_accum[start - 1]

    print(max(gen()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 24836
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;

int main() {
	int a;
	string b; 
	cin >> a;
	cin >> b;
	size_t c = b.length();
	if (a >= c) {
		cout << b;
	}
	else {
		std::string c = b.substr(0, a);
		cout << c << "...";
	}
	return 0;
}

Measured memory_bytes: 3564
x,n  = gets.chomp.split(" ").map(&:to_i)
nums = gets.chomp.split(" ").map(&:to_i)

i = 0
while i <= x do
  unless nums.include?(x - i)
    puts x - i
    break
  end
  unless nums.include?(x + i)
    puts x + i
    break
  end
i += 1
end

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

using namespace std;

typedef long long ll;
ll n;
ll d[2001];
ll mod = 1e9 + 7;

ll go(int x){
    if(x == n){
        return 1;
    }
    ll &ret = d[x];
    if(ret != -1)return ret;
    ret = 0;
    for(int i = 3; i <= 2000; i++){
        if(x + i <= n){
            ret += go(x + i); ret %= mod;
        }
    }
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;

    memset(d,-1, sizeof(d));

    cout << go(0) << '\n';

}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1(x,n) for(int x = 1; x <= n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

ll dp[1001][1001];

ll noWays(std::vector<std::vector<char> >& v,int i,int j)
{
	
	if(dp[i][j]!=-1){
		return dp[i][j];
	}
	if(i==0&&j==0){
		dp[i][j]=1;
		return dp[i][j];
	}
	else if(i==0)
	{
		if(dp[i][j-1]==-1)
			dp[i][j-1]=noWays(v,i,j-1);
		dp[i][j] = (v[i][j]=='.')?dp[i][j-1]%mod:0;
		return dp[i][j];
	}
	else if(j==0)
	{
		if(dp[i-1][j]==-1)
			dp[i-1][j]=noWays(v,i-1,j);
		dp[i][j]=(v[i][j]=='.')?dp[i-1][j]%mod:0;
		return dp[i][j];
	}

	if(dp[i-1][j]==-1)
		dp[i-1][j]=noWays(v,i-1,j);
	if(dp[i][j-1]==-1)
		dp[i][j-1]=noWays(v,i,j-1);
	dp[i][j] = (v[i][j]=='.')?(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod:0;
	return dp[i][j];
}
int main(){
	IOS

	int h,w;
	cin>>h>>w;
	vector<std::vector<char> >v;
	v.resize(h);

	forn(i,h)
		forn(j,w){
			char temp;
			cin>>temp;
			v[i].pb(temp);	
		}

	memset(dp,-1,sizeof(dp));

	cout<<noWays(v,h-1,w-1)%mod;
 	
	return 0;	
}

Measured memory_bytes: 9344
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
void recurse(int len, char nxtchr, string str) {
	if (len == 0) {
		printf("%s\n", str.c_str());
		return;
	}
	for (char c = 'a'; c < nxtchr; ++c) recurse(len - 1, nxtchr, str + c);
	recurse(len - 1, nxtchr + 1, str + nxtchr);
}
int main() {
	int N;
	scanf("%d", &N);
	recurse(N, 'a', "");
	return 0;
}

Measured memory_bytes: 1536
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut g = vec![vec![]; n];
    let mut es = vec![];
    for _ in 1..n {
        let a = sc.cin::<usize>() - 1;
        let b = sc.cin::<usize>() - 1;
        g[a].push(b);
        g[b].push(a);
        es.push((a, b));
    }
    let mut edge_color = std::collections::HashMap::new();
    let deg = (0..n).map(|i| g[i].len()).max().unwrap();
    let mut col = vec![deg - 1; n];
    let mut used = vec![false; n];
    {
        let mut stack = vec![0];
        while let Some(u) = stack.pop() {
            if used[u] { continue}
            used[u] = true;
            let mut c = col[u];
            for &v in g[u].iter() {
                if used[v] { continue }
                c = (c + 1) % deg;
                col[v] = c;
                stack.push(v);
                edge_color.insert((u, v), c);
            }
        }
    }
    put!(deg);
    for &(u, v) in es.iter() {
        put!(1 + edge_color.get(&(u, v)).unwrap());
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 22440
program lucky_7
  implicit none
  character(3) :: n
  read(*,*) n
  if (n(1:1) == "7" .or. n(2:2) == "7" .or. n(3:3) == "7") then
    write(*,'(a)') "Yes"
  else
    write(*,'(a)') "No"
  end if
end program lucky_7

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

typedef long long ll;

int main() {
	int n; cin>>n;
	vector<ll> a(n);
	for (int i=0; i<n; i++) cin>>a[i];
	vector<ll> ret(2);
	for (int c=0; c<2; ++c){
		int sgn=c?1:-1;
		for (ll s=0, t=0; t<n; t++, sgn*=-1) {
			s+=a[t];
			if(sgn*s<=0) ret[c]+=abs(s)+1, s=sgn;
		}
	}
	cout<<min(ret[0],ret[1])<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int n;
    cin>>n;

    vector<int> dp(n+1);
    dp[0] = 1;
    dp[1] = 1;
    dp[2] = 1;

    int cursum = 0;
    int curweight = 0;

    for (int i = 3; i<=n; i++)
    {
        cursum = add(cursum, dp[i-3]);
        curweight = add(curweight, mul(i-3, dp[i-3]));
        dp[i] = add(1, sub(mul(cursum, i-2), curweight));
    }

    /*for (int i = 0; i<=n; i++) cout<<dp[i]<<' ';
    cout<<endl;*/

    ll total = n;
    for (int i = 0; i<=n-2; i++)
    {
        total = add(total, mul(n-1, dp[i]));
        total = add(total, mul(n-1, add(mul(n-2, dp[i]), dp[i+1])));
    }

    cout<<total;

}

Measured memory_bytes: 4224
#include <stdio.h>

int main(void){
	int i,o,a[100]={0},p=0,min,temp,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);

	for(i=0;i<=n-1;i++){
		min=i;
		for(o=i+1;o<=n-1;o++){
			if(a[o]<a[min])
				min=o;
		}
		if(i != min)
			p++;
		temp=a[i];
		a[i]=a[min];
		a[min]=temp;
	}
	for(i=0;i<n;i++){
		printf("%d",a[i]);
		if(i != n-1)
			printf(" ");
	}
	printf("\n%d\n",p);
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	vector<int> c(n - 1);
	vector<int> s(n - 1);
	vector<int> f(n - 1);
	for(int i = 0; i < n - 1; i++)
	{
		cin >> c[i] >> s[i] >> f[i];
	}
	
	vector<int> ans(n);
	for(int i = 0; i < n; i++)
	{
		if(i == n - 1)
		{
			ans[i] = 0;
			break;
		}
		
		int sans = 0;
		sans += s[i];
		sans += c[i];
		for(int j = i + 1; j < n - 1; j++)
		{
			int tmp = s[j];
			while(sans > tmp)
			{
				tmp += f[j];
			}
			sans += (tmp - sans);
			sans += c[j];
		}
		
		ans[i] = sans;
	}
	
	for(auto itr = ans.begin(); itr != ans.end(); itr++)
	{
		cout << *itr << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
using namespace std;

string s;
long long n;
long long dp[100005][2] = {0};

long long solve();

int main() {
  cin >> s;
  n = s.size();
  cout << solve() << endl;
  return 0;
}

long long solve() {
  dp[0][0] = 1;
  for(int i = 0; i < n; ++i) {
    if(s[i] == '1') {
      // not use
      dp[i + 1][1] += (dp[i][1] + dp[i][0]) % N;
      // use
      dp[i + 1][0] += dp[i][0] * 2 % N;
      dp[i + 1][1] += dp[i][1] * 2 % N;
      dp[i + 1][1] %= N;
      dp[i + 1][0] %= N;
    }
    else {
      dp[i + 1][0] += dp[i][0];
      dp[i + 1][1] += dp[i][1] * 3 % N;
    }
  }
  return (dp[n][0] + dp[n][1]) % N;
}

Measured memory_bytes: 2048
s=str(input())
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])

if a+b+c+d==7:print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d==7:print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c+d==7:print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b-c-d==7:print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b+c+d==7:print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d==7:print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d==7:print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b-c-d==7:print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')


Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
    N,D = MI()
    sqrD = D**2
    ans = 0
    for i in range(N):
        X,Y = MI()
        if(X**2+Y**2<=sqrD):
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9216
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  int n,q;
  string s;
  
  cin>>n>>q;
  cin>>s;
  int a[n];
  for(int i = 0; i < n; i++){
    a[i]=0;
  }
  int tmp = 0;
  if(s[0]=='A') tmp = 1;
  for(int i = 1; i < n; i++){
    if(tmp==1&&s[i]=='C'){
      a[i]=a[i-1]+1;
      tmp=0;
    }
    else if(s[i]=='A'){
      tmp=1;
      a[i]=a[i-1];
    }
    else{
      tmp=0;
      a[i]=a[i-1];
    }
  }
  
  int b[q];
  for(int i = 0; i < q; i++){
    int l,r;
    cin>>l>>r;
    b[i]=a[r-1]-a[l-1];
  }
  for(int i = 0; i < q; i++){
    cout<<b[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s == "SAT")    cout << "1\n";
    else if(s == "FRI")    cout << "2\n";
    else if(s == "THU")    cout << "3\n";
    else if(s == "WED")    cout << "4\n";
    else if(s == "TUE")    cout << "5\n";
    else if(s == "MON")    cout << "6\n";
    else    cout << "7\n";
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
data = []

N.times do
  data << gets.split.map(&:to_i)
end

data.sort_by! do |d|
  d[1]
end

sum = 0

data.each do |d|
  sum += d[0]
  if sum > d[1]
    puts 'No'
    exit
  end
end

puts 'Yes'

Measured memory_bytes: 22520
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int a, b, x;
	cin >> a >> b >> x;
	
	auto calc = [&](double c) {
		if (c > a) {
			double d = c - a;
			double y = (b - d) * a * a / 2.;
			y += d * a * a;
			return y < x;
		}
		else {
			double y = b * c * a / 2.;
			return y < x;
		}
	};
	
	double lb = 0, ub = a + b;
	for (int i=0; i<100; ++i) {
		double med = (lb + ub) / 2.;
		if (calc(med)) lb = med;
		else ub = med;
	}
	
	double A = (ub > a ? a : ub);
	double B = b - (ub > a ? ub - a : 0);
	printf("%.9f\n", 90. - 180. / PI * atan(A / B));
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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


int main()
{
	int A, B;

	cin >> A >> B;

	int ans;

	ans = A - (B * 2);
	if (ans < 0) ans = 0;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define INF 1e9
using ll = std::int64_t;

template <class T>
bool chmax(T &a, const T &b);
template <class T>
bool chmin(T &a, const T &b);
//最大公約数
std::int64_t gcd(std::int64_t a, std::int64_t b);
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb);
//ラングレス圧縮
std::vector<std::pair<char, std::int64_t>> rle(std::string str);
//素数判定
bool is_prime(std::int64_t n);
// 約数の列挙
std::vector<std::int64_t> divisor(std::int64_t n);
// 素因数分解
std::map<std::int64_t, std::int64_t> prime_factor(std::int64_t n);

//10^9 + 7
#define yojo 1000000007
#define MAX_NUM 200001

void Main()
{
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = a; i <= a + a * b; i += a)
  {
    if (i % b == c)
    {
      std::cout << "YES" << std::endl;
      return;
    } 
  }
  
  std::cout << "NO" << std::endl;

  return;
}

int main()
{
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return true;
  }
  return false;
}

//最大公約数
std::int64_t gcd(std::int64_t a, std::int64_t b)
{
  // a >= b && b != 0
  std::int64_t c;
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}

//最大公約数安全版
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb)
{
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0)
  {
    return -1;
  }
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}

//ラングレス圧縮
std::vector<std::pair<char, std::int64_t>> rle(std::string str)
{
  std::vector<std::pair<char, std::int64_t>> data;
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++)
  {
    if (i == str.size())
    {
      data.push_back(make_pair(str[i - 1], count));
      break;
    }
    else if (now != str[i])
    {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return data;
}

//素数判定
bool is_prime(std::int64_t n)
{
  for (std::int64_t i = 0; i * i <= n; i++)
  {
    if (n % i == 0)
    {
      return false;
    }
  }

  return n != 1;
}

//約数の列挙
std::vector<std::int64_t> divisor(std::int64_t n)
{
  std::vector<std::int64_t> res;
  for (int i = 0; i < n; i++)
  {
    if (n % i == 0)
    {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  return res;
}

// 素因数分解
std::map<std::int64_t, std::int64_t> prime_factor(std::int64_t n)
{
  std::map<std::int64_t, std::int64_t> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      ++res[i];
      n /= i;
    }
  }

  if (n != 1)
  {
    res[n] = 1;
  }

  return res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LIM 1+2+4+8+16+32+64+128
#define int long long 
using namespace std;
typedef struct{
  int per;
  int ko;
  int kyoda;
  int konoko;
}TRE;
int ace(int a,int b){
  int ss=0;
  for(int i=b;i<=a;i++){
    ss+=i;
  }
  return(ss);
}
typedef pair<int,int>P;
signed  main(){
  int n;
  while(1){
    cin>>n;
    if(n==0){
      break;
    }
    int mxn=0,sm=0,l[n];
    for(int i=0;i<n;i++){
      cin>>l[i];
      if(l[i]!=0){
	sm++;
      }
      if(l[mxn]<l[i]){
	mxn=i;
      }
    }
    if(l[mxn]<=1){
      cout<<"NA"<<endl;
    }else{
      if(sm==1){
	cout<<2<<endl;
      }else{
	cout<<sm+1<<endl;
      }
    }
  }
  return(0);
}



Measured memory_bytes: 3164
#include <stdio.h>
#include <algorithm>
#define MAX_N (7368792)

using namespace std;

bool b[MAX_N];

int main(void){
	int n, m, count;

	while(1){
		scanf("%d%d", &m, &n);
		if(!n && !m) break;

		fill(b,b+MAX_N,false);
		count = 0;
		for(int i=m; ; i++){
			if(b[i] == false){

				if(count == n){
					printf("%d\n", i);
					break;
				}
				for(int j = i; j<=MAX_N; j += i){
					b[j] = true;
				}
				count++;
			}
		}

	}//endwhile

	return 0;
}


Measured memory_bytes: 9852
N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(N)]

AB = sorted(AB)

result = 0
c = 0
for a, b in AB:
    d = min(M - c, b)
    c += d
    result += d * a
    if c == M:
        break

print(result)



Measured memory_bytes: 22380
#include<cstdio>
typedef long long LL;
const int N = 1e5+5;
struct Element{
	int l, r;
	LL v;
};
LL a[N];
Element b[N];
int p[N];
int l[N][2], r[N][2];

void deleteNode(int p){
	int L = b[p].l, R = b[p].r;
	if(L!=-1) b[L].r = R;
	if(R!=-1) b[R].l = L;
}

void pre(int n){
	for(int i = 1; i <= n; i++){
		b[i].v = a[i];
		if(i==1) b[i].l = -1;
		else b[i].l = i-1;
		if(i==n) b[i].r = -1;
		else b[i].r = i+1;
	}
	//u既是a中位置, 也是b中位置
	for(int i = 1; i <= n; i++){
		int u = p[i];
		l[u][0] = b[u].l, l[u][1] = -1;
		if(l[u][0]!=-1) l[u][1] = b[l[u][0]].l;
		r[u][0] = b[u].r, r[u][1] = -1;
		if(r[u][0]!=-1) r[u][1] = b[r[u][0]].r;
		deleteNode(u);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){ 
		scanf("%lld",&a[i]);
		p[a[i]] = i;
	}
	pre(n);
	LL ans = 0;
	for(int i = 1; i <= n; i++){
		//printf("i = %d: %d %d %d %d\n",i,l[i][1],l[i][0],r[i][0],r[i][1]);
		if(l[i][0]!=-1){
			LL len = 0;
			if(l[i][1]!=-1) len = l[i][0]-l[i][1];
			else len = l[i][0];
			LL other = 0;
			if(r[i][0]!=-1) other = r[i][0]-i;
			else other = n-i+1;
			ans += other*len*(a[i]);
			//printf("left: %d %d\n",len,other);
		}
		if(r[i][0]!=-1){
			LL x0 = 0;
			if(r[i][1]!=-1) x0 = r[i][1]-r[i][0];
			else x0 = n-r[i][0]+1;
			LL x1 = 0;
			if(l[i][0]!=-1) x1 = i-l[i][0];
			else x1 = i;
			ans += x0*x1*a[i];
			//printf("right: %d %d\n",x0,x1);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4480
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>

using namespace std;

typedef long long ll;

int main(){
 ll N,M; cin >> N >> M;
 vector<ll> P(M,0); vector<ll> Y(M,0);
  vector<vector<ll>> to(N + 1);
  
  for(ll i = 0; i < M; i++){
  cin >> P[i] >> Y[i];}
  
  for(ll i = 0; i < M; i++){
    to[P[i]].push_back(Y[i]);}
  
  for(ll j = 1; j <= N; j++){
    sort(to[j].begin(),to[j].end());}
  
  for(ll i = 0; i < M; i++){
    ll iter = lower_bound(to[P[i]].begin(),to[P[i]].end(),Y[i]) - to[P[i]].begin();
    cout << setw(6) << setfill('0') << P[i];
    cout << setw(6) << setfill('0') << iter + 1<< endl;}
  
  return 0;}
      
                          
  
  

Measured memory_bytes: 8576