akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int n;
int *l=NULL;
int *r=NULL;

int cmpL(const void *a,const void *b){
  int p=*(int *)a;
  int q=*(int *)b;
  return -(l[p]-l[q]);
}

int cmpR(const void *a,const void *b){
  int p=*(int *)a;
  int q=*(int *)b;
  return r[p]-r[q];
}

int64 calc(int *a,int *b){
  int *used=(int *)calloc(n,sizeof(int));
  int now=0;
  int64 sum=0;
  int i=0,j=0;
  while(i<n || j<n){
    while(i<n && (used[a[i]] || (l[a[i]]<=now && now<=r[a[i]]))) i++;
    if(i<n){
      int x=ABS(l[a[i]]-now);
      int y=ABS(r[a[i]]-now);
      sum+=MIN(x,y);
      now=x>=y?r[a[i]]:l[a[i]];
      used[a[i]]=1;
    }
    while(j<n && (used[b[j]] || (l[b[j]]<=now && now<=r[b[j]]))) j++;
    if(j<n){
      int x=ABS(l[b[j]]-now);
      int y=ABS(r[b[j]]-now);
      sum+=MIN(x,y);
      now=x>=y?r[b[j]]:l[b[j]];
      used[b[j]]=1;
    }
  }
  free(used);
  return sum+ABS(now);
}

void run(void){
  scanf("%d",&n);
  l=(int *)malloc(sizeof(int)*n);
  r=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) scanf("%d%d",l+i,r+i);
  int *lIndex=(int *)malloc(sizeof(int)*n);
  int *rIndex=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) lIndex[i]=rIndex[i]=i;
  qsort(lIndex,n,sizeof(int),cmpL);
  qsort(rIndex,n,sizeof(int),cmpR);
  int64 x=calc(lIndex,rIndex);
  int64 y=calc(rIndex,lIndex);
  printf("%lld\n",MAX(x,y));
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 2172
#include<stdio.h>

void trance(int A[], int N, int count){
	int i;
	for( i =0; i < N; i++ ){
		if( i > 0 ) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
	printf("%d\n",count);
}

int bubbleSort(int A[], int N, int count){
	int i,j,v,minj,sum;
	sum = count;
	for(i=0;i<N-1;i++){
		v=A[i];
		for(j=i+1;j<N;j++){
			if(v > A[j]){
				v = A[j];
				minj = j;
			}
		}
		if(A[i] != v){
			A[minj] = A[i];
			A[i] = v;
			sum++;
		}
	}
	return sum;
}

int main(void){
	int i,A[100],N,count=0;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	for(i=0;i<N;i++){
		count = bubbleSort(A,N,count);
	}
	trance(A,N,count);
	return 0;
}

Measured memory_bytes: 604
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define r_rep(i, n) for(int i = n; i >= 0; i--)
#define ll long long int
#define pb push_back

const long long INF = 1LL << 60;

int main() {
  int N;
  string s;
  int m_num = 0, cnt = 0;
  cin >> N >> s;

  rep(i, N){
    if(s[i] == 'D') cnt--;
    if(s[i] == 'I') cnt++;
    m_num = max(cnt, m_num);
  }
  print(m_num);
}


Measured memory_bytes: 256
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

def solve():
    return a[N - 1]

if __name__ == "__main__":
    print(solve())

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

#define debug(x)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sq(x) ((x) * (x))
#define PRECISION 30

using namespace std;

template<class T> int check_mod(T a, T b) { return (a % b) ? 1 : 0; }
template<class T> void maxi(T &a, T b) { a = max(a, b); return; }
template<class T> void mini(T &a, T b) { a = min(a, b); return; }

bool is_prime(int a) { if (a == 2) return true; if (!(a & 1) || a == 1) return false; for (int i = 3; i * i <= a; i += 2) if (!(a % i)) return false; return true; }
bool is_prime(ll a) { if (a == 2) return true; if (!(a & 1) || a == 1) return false; for (ll i = 3; i * i <= a; i += 2) if (!(a % i)) return false; return true; }
bool is_palindrome(string s) { int len = (int)s.length(); int mid = len >> 1; for (int i = 0; i < mid; i++) if (s[i] != s[len - i - 1]) return false; return true; }
int gcd(int a, int b) { while (b) { int mod = a % b; a = b; b = mod; } return a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int binpow(int a, int b) { int res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; }
int binpow(int a, int b, int MODULO) { int res = 1; while (b) { if (b & 1) { res *= a; res %= MODULO; } a *= a;  a %= MODULO; b >>= 1; } return res; }
ll gcd(ll a, ll b) { while (b) { ll mod = a % b; a = b; b = mod; } return a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll MODULO) { ll res = 1; while (b) { if (b & 1) { res *= a; res %= MODULO; } a *= a;  a %= MODULO; b >>= 1; } return res; }
string binary(int N) { if (!N) return "0"; string bin = ""; while (N) { bin += '0' + (N & 1); N >>= 1; } reverse(all(bin)); return bin; }
string binary(ll N) { if (!N) return "0"; string bin = ""; while (N) { bin += '0' + (N & 1); N >>= 1; } reverse(all(bin)); return bin; }
           
const int INF = 2147483547;           // Max int value - 100 so it will not overflow
const int MODULO = 1000000007;
const int _MODULO = 998244353;
const ll INF64 = 9223372036854775707; // Max long long value - 100 so it will not overflow
const ll MODULO64 = 1000000007;
const ll _MODULO64 = 998244353;
const double epsilon = 10e-6;
const double PI = acos(-1);

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	auto t1 = chrono::high_resolution_clock::now();
    #define debug(x) cerr << #x << " = " << x << "\n";                        
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k;
	cin >> n >> k;
	vector<ll> h(n);
	for (int i = 0; i < n; ++i)
		cin >> h[i];
	sort(rall(h));
	ll sum = 0;
	for (int i = k; i < n; ++i)
		sum += h[i];
	cout << sum << '\n';
#ifdef LOCAL
	auto t2 = chrono::high_resolution_clock::now();
	cerr << "Running time " << chrono::duration_cast<chrono::nanoseconds>(t2 - t1).count() << " nanoseconds" << endl;
#endif
	return 0;
}

Measured memory_bytes: 1792
use proconio::{fastout, input, source::Source, source::auto::AutoSource};

#[fastout]
fn main() {
    let s = AutoSource::new(std::io::BufReader::new(std::io::stdin()));
    println!("{}", solve(s));
}

fn solve<R : std::io::BufRead, T : Source<R>>(src: T) -> String {
    input!{
        from src,
        n : usize,
        m : usize,
        a : [i64; m],
    }
    let mut avail = n as i64;
    for (_i, v) in a.iter().enumerate() {
        avail -= v;
    }
    avail = std::cmp::max(avail, -1);

    return format!("{}", avail);
}

#[test]
fn solve_test() {
    assert_eq!(solve(AutoSource::from(
        "41 2
        5 6"
    )), "30");
}

Measured memory_bytes: 2264
#include<iostream>
using namespace std;
int main()
{
	int n,zero;
	while(1){
		cin>>n;
		if(n==0)break;
			else {
			zero=0;
			while(n>0){
				zero=zero+n/5;
				n=n/5;
			}
			cout<<zero<<endl;
		}
	}
	return 0;
}

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

const long long maxn = 1e5+10 ;
long long a[maxn] ;
long long gcd1[maxn] ;
long long gcd2[maxn] ;

int main() {

    long long n ;
    cin >> n ;
    long long mn = 0 ;
    long long sum = 0 ;
    long long m = 1e9 ;

    for(long long i = 0, tmp; i < n; i++){

        cin >> tmp ;
        sum += abs(tmp) ;
        m = min(m, abs(tmp)) ;
        if(tmp < 0)
            mn++ ;

    }
    if(mn%2 == 1){
        cout << sum - m*2 ;
    }else{
        cout << sum ;
    }

}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 2; i <= n; i++) cin >> a[i];
    vector<int> ans(n+1, 0);
    for(int i = 2; i <= n; i++) ans[a[i]]++;
    for(int i = 1; i <= n; i++) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 4844
#include<stdio.h>

int main(void)
{
  int a,b,sa,sum = 0;

  scanf("%d",&a);
  scanf("%d",&b);

  sa = b - a;

  for(int i = 0;i < sa;i++){
    sum += i;
  }

  printf("%d",sum - a);

  return 0;

}


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

using namespace std;

int main(){
	string str;
	//getline(cin, str);
	
	vector<int> alpha(122-96,0);
	
	char ch;
	while(cin >> ch){
		if(ch >= 65 && ch <= 90) ch += 32;
		else if(ch <= 96 || ch >= 123) continue;
		
		
		alpha.at(ch - 97) += 1;
		
		if(ch == EOF) break;
	}
	
	for(int i = 0; i < alpha.size(); i++){
		printf("%c : %d\n", i+97, alpha.at(i));
	}
}





Measured memory_bytes: 3196
s = input()
MOD = 2019
r = [0]*MOD
r[0] = 1
z = 0
t = 0
for i in reversed(s):
    z = int(i) * pow(10,t,MOD) + z
    z %= MOD
    r[z] += 1
    t += 1
print(sum(i*(i-1)//2 for i in r))


Measured memory_bytes: 9364
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            long n = int.Parse(str[0]);
            long m = int.Parse(str[1]);

            long ans;
            if (n == 1 && m == 1)
            {
                ans = 1;
            }
            else if (n == 1 || m == 1)
            {
                ans = (n * m - 2);
            }
            else
            {
                ans = (n - 2) * (m - 2);
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <deque>

using namespace std;

#define For(i, start, end) for(ll i = (start); i < (end); i++)
#define rep(i, n) For(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ctoi(c) c - '0'
#define tos(s) to_string(s)

typedef long long ll;

int main() {
    ll n;
    cin >> n;
    ll a[n];
    rep(i,n) {
        cin >> a[i];
    }

    ll p = 1000;
    rep(i,n-1) {
        if (a[i] >= a[i+1]) {
            continue;
        }
        p += (a[i+1] - a[i]) * (p/a[i]);
    }
    cout << p << endl;
    return 0;
}

/*
ACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACAC                                                                              
                                   ******,  .,, .,, ,,,    ****.**              
                                   ** . .,,,,,,,,,,,,,,,,,,,,,. .,*             
                                   **,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.            
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                    ****      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,      
              ***************,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,    
         ********************,,,,,,,,,,,,,,@@@,,,,,,,,,,,/@@@,,,,,,,,,,,,,,,    
        ******************,,,,,,,,,,,,,,,,,,(,,.         ,,,,,,,,,,,,,,,,,,,    
       ********************,,,,,,,,,,,*,,,,,.     %&&&     .,,,,*,,,,,,,,,,,,.  
       ***,,,,,,,,,,,,,,*,,,,,,,,,,,,,,,,,,,,               ,,,,,,,,,,,,,,,,,   
       ,,,,,,,,,,,,,,,,,,,**,,,,,,,,,,.......      ##(     ........,,,,,,,,,,.  
     .,,,,,,,,,,,,,,,,,,**,,,,,,,,,,..............    ..............,,,,,,,,    
    .,,,,,,,,,,,,,,,,,,,**,,,,,,,,,.................................,,,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,***,,,,,,,....................................,,,,,,,,,  
   ,,,,,,,,,,,,,,,,,,,,**,,,,,,,,.....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,**,,,,,,,,....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,,,     
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,.,,,,,     
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,        
     ,,,,,,,,,,,,,,,,,,,,,,,,,,,,....................................,,,        
      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,          
       ..,,,,,,,,,,,,,,,,,,,,,,,,,,.................................,           
       .........**.....       ,,,,,..............................               
        .......*......                  ****,**,       ,..****                  
        .......*,....                   .......        ......                   
          .......*....                   .....          .....                   
                                         ......          .....                  
*/

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

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

    vector <pair <int, int>> gusu(100000), kisu(100000);
    rep (i, 100000) gusu[i] = kisu[i] = make_pair(0, i + 1);

    rep (i, n) {
        int v;
        cin >> v;
        (i % 2 ? gusu[v - 1] : kisu[v - 1]).first += 1;
    }

    sort(gusu.rbegin(), gusu.rend());
    sort(kisu.rbegin(), kisu.rend());

    int ans = 1000000000;
    for (auto & pvpiivpii : {make_pair(gusu, kisu), make_pair(kisu, gusu)}) {
        for (auto & pii : pvpiivpii.first) {
            auto macs = pvpiivpii.second.begin();
            if (pii.second == macs->second) macs += 1;
            ans = min(ans, n - pii.first - macs->first);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
import math
z = list(map(int,input().split()))
N = z[0]
A = z[1]
B = z[2]
C = z[3]
D = z[4]
a = math.ceil(N/A)*B
b = math.ceil(N/C)*D
if a < b:
    print(a)
else:
    print(b)



Measured memory_bytes: 5664
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (A, B) = nextIntList()
    val a = (A + 11) % 13
    val b = (B + 11) % 13
    println(if (a > b) "Alice" else if (a < b) "Bob" else "Draw")
}

Measured memory_bytes: 36068
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
#define ull unsigned long long
#define ALL(v) ((v).begin()), ((v).end())
#define INCREASING(v) sort(ALL(v))
#define DECREASING(v) INCREASING(v), reverse(ALL(v))
#define SZ(v)   ((int)((v).size()))
#define LP(c,x,n)  for(int c=x;c<n;c++)
#define LO(c,n,x)  for(int c=n;c>=x;c--)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define PI ( 2 * acos(0.0))
#define EPS 1e-8
#define INF 1.0/0.0
#define Yala_Besor3a ios_base::sync_with_stdio(0),ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ReadFile freopen("delivery.in","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
using namespace std;
const int OO = 0x3f3f3f3f,NegOO= -1*OO,N =1e5+5,mod =998244353 ;
int n,W;
int inp[105][2];
ll dp[105][N];
ll solve(int i,int curw)
{
    if(i==n||curw==0)return 0;
    ll &rf=dp[i][curw];
    if(~rf)return rf;
    if(curw-inp[i][0]>=0)rf=max(solve(i+1,curw),solve(i+1,curw-inp[i][0])+inp[i][1]);
    else rf=solve(i+1,curw);
    return rf;
}
int main()
{
    cin>>n>>W;
    LP(c,0,n)cin>>inp[c][0]>>inp[c][1];
    memset(dp,-1, sizeof(dp));
    cout<<solve(0,W)<<endl;
    return 0;
}

Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main(){
    string A, B, C;
    cin >> A; 
    cin >> B;
    cin >> C;
    transform(A.begin(), A.end(), A.begin(), ::toupper);
    transform(B.begin(), B.end(), B.begin(), ::toupper);
    transform(C.begin(), C.end(), C.begin(), ::toupper);
    cout << A[0] << B[0] << C[0] << endl;
}

Measured memory_bytes: 256
s = input()
k = int(input())
n = len(s)
rank = ["zzzzzz"]*k
for i in range(n):
  for j in range(i+1, min([i+k+1, n+1])):
    key = s[i:j]
    for r in range(k):
      if key == rank[r]:
        break
      if key < rank[r]:
        for r2 in range(r, k):
          key2 = rank[r2]
          rank[r2] = key
          key = key2
        break
print(rank[k-1])

Measured memory_bytes: 3064
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]

ans=0

for i in range(n):
    if ans<s.count(s[i])-t.count(s[i]):
        ans=s.count(s[i])-t.count(s[i])

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n, k;

		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();

		int[] a = new int[n];

		int number, index;
		for (int i = 0; i < k; i++) {
			number = sc.nextInt();
			for (int j = 0; j < number; j++) {
				index = sc.nextInt();
				a[index - 1]++;
			}
		}

		int count = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] == 0) {
				count++;
			}
		}

		sc.close();
		System.out.println(count);
		return;
	}

}


Measured memory_bytes: 46168
import sys
W,a,b = map(int,input().split())
if W < 0 or W > 100000:
    sys.exit()
if a < 0 or a > 100000:
    sys.exit()
if b < 0 or b > 100000:
    sys.exit()

move = 0
if W + a < b:
    move = b - (W + a)
if W + a > b and W + a < W + b:
    move = 0
if a > b and a < W + b:
    move = 0
if a > W + b and W + a > W + b:
    move = a - (W + b)
print(move)

Measured memory_bytes: 9196
#include <iostream>

using namespace std;
typedef long long int ll;
int main() {
	// your code goes here
	ll n,k;
	cin>>n>>k;
	ll z;
	while(n>k)
	{
	    z=n/k;
	    n=n-(k*z);
	}
	if(abs(n-k)<n)
	cout<<abs(n-k);
	else
	cout<<n;
	return 0;
}


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

int main(){
    long long int n;
    cin >> n;
    
    long long int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    /*
    long long int s[n];
    s[0] = a[0];
    for(int i=1;i<n;i++){
        s[i] *= (s[i-1]%1000000007);  
    }
    
    long long int sum=0;
    for(long long int i=0;i<=n-2;i++){
        for(long long int j=i+1;j<=n-1;j++){
            sum += ((a[i]*a[j])%1000000007);
            sum %= 1000000007;
        }
    }
    cout << sum << endl;
    */

   /*----------------------------------------------
    解説：累積和を用いて処理しよう！
    a[i]*a[i+1] + a[i]*a[i+2] + ... + a[i]*a[n]
    = a[i] * (a[i+1] + a[i+2] + ... + a[n])
    この()内で累積和を用いる
   ----------------------------------------------*/
   long long int sum[n]; //累積和 sum[0] = a[0], sum[1] = sum[0] + a[1], sum[2] = sum[1] + a[2], a[i]+...+a[j]=s[j]-s[i-1]
   sum[0] = a[0];
   for(int i=1;i<n;i++){
       sum[i] = sum[i-1] + a[i];
       sum[i] %= 1000000007;
   }

   long long int ans = 0;
    long long int mod_sum;
   for(int i=0;i<n;i++){
       //cout << i << " " << sum[n-1] - sum[i] << endl;
       mod_sum = (sum[n-1]-sum[i]) % 1000000007;
       if(mod_sum<0){//sum[n-1]-sum[i]のmod1000000007が正しくなるようにする
           mod_sum+=1000000007;
       }
       ans += (a[i]*mod_sum % 1000000007);
       ans %= 1000000007;
   }
   ans %= 1000000007;
    cout << ans << endl;
}

Measured memory_bytes: 6664
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 qvya13579
#define y1 qvyb24680
#define j0 qvja13579
#define j1 qvjb24680
#define next qvne13579xt
#define prev qvpr13579ev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS cin.tie(0);ios::sync_with_stdio(false)
#define M_P make_pair
#define P_B push_back
#define U_B upper_bound
#define L_B lower_bound
#define P_Q priority_queue
#define FIR first
#define SEC second
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZ(x) ((int)(x).size())
#define COUT(x) cout<<(x)<<endl
#define CIN(x) cin>>(x)
#define CIN2(x,y) cin>>(x)>>(y)
#define CIN3(x,y,z) cin>>(x)>>(y)>>(z)
#define CIN4(x,y,z,w) cin>>(x)>>(y)>>(z)>>(w)
#define SCAND(x) scanf("%d",&(x))
#define SCAND2(x,y) scanf("%d%d",&(x),&(y))
#define SCAND3(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define SCAND4(x,y,z,w) scanf("%d%d%d%d",&(x),&(y),&(z),&(w))
#define SCANLLD(x) scanf("%lld",&(x))
#define SCANLLD2(x,y) scanf("%lld%lld",&(x),&(y))
#define SCANLLD3(x,y,z) scanf("%lld%lld%lld",&(x),&(y),&(z))
#define SCANLLD4(x,y,z,w) scanf("%lld%lld%lld%lld",&(x),&(y),&(z),&(w))
#define PRINTD(x) printf("%d\n",(x))
#define PRINTLLD(x) printf("%lld\n",(x))
typedef long long int lli;
using namespace std;

int ctoi(char c)
{
  if( c >= '0' and c <= '9' )
    {
      return (int)(c-'0');
    }

  return -1;
}

int alphabet_pos(char c) 
{
  if( c >= 'a' and c <= 'z' )
    {
      return (int)(c-'a');
    }

  return -1;
}


int alphabet_pos_capital(char c)
{
  if( c >= 'A' and c <= 'Z' )
    {
      return (int)(c-'A');
    }

  return -1;
}


vector<string> split(string str, char ch)
{
  int first = 0;
  int last = str.find_first_of(ch);
  
  if(last == string::npos)
    {
      last = SIZ(str);
    }

  vector<string> result;

  while( first < SIZ(str) )
    {
      string Ssubstr(str, first, last - first);
      result.push_back(Ssubstr);
      first = last + 1;
      last = str.find_first_of(ch, first);

      if(last == string::npos)
	{
	  last = SIZ(str);
	}
    }
  
  return result;
}

/*--------------- the end of the template --------------------*/









int main()
{
  //IOS; /* making cin faster */
  int N,K;
  SCAND2(N,K);

  if( N % K == 0 )
    {
      PRINTD(0);
      
    }
  else
    {
      PRINTD(1);
      
    }

  

}


Measured memory_bytes: 256
import bisect

A, B, Q = map(int, input().split())
s = [int(input()) for i in range(A)]
t = [int(input()) for i in range(B)]
x = [int(input()) for i in range(Q)]


for i in x: # N
  idx_i = bisect.bisect(s, i) # log A
  z = float('inf')
  for j in s[max(0, idx_i - 1): idx_i + 1]: # 2
    idx_j = bisect.bisect(t, j) # log B

    for k in t[max(0, idx_j - 1): idx_j + 1]: # 2
      _z = min(abs(i - j) + abs(j - k), abs(i - k) + abs(k - j))
      z = min(z, _z)
  print(z)


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n;
    cin >> n;
    vector<int> x(n),y(n),u(n),v(n);
    for (int i = 0;i < n;++i) cin >> x[i] >> y[i];
    for (int i = 0;i < n;++i) u[i] = x[i]+y[i];
    for (int i = 0;i < n;++i) v[i] = x[i]-y[i];
    int ans = max(*max_element(u.begin(),u.end())-*min_element(u.begin(),u.end()),*max_element(v.begin(),v.end())-*min_element(v.begin(),v.end()));
    cout << ans << newl;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122

/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK: 20000000005")
*/

using namespace std;

const int N = 2e5 + 5;

int n;
int a[N], b[N], c[N];

int ans;

main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> b[i];
    for (int i = 1; i < n; i++)
        cin >> c[i];
    for (int i = 1; i <= n; i++)
        ans += b[i];
    for (int i = 1; i < n; i++)
        if (a[i + 1] == a[i] + 1)
            ans += c[a[i]];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long C(int N,int K)
{
	long x=1,y=1;
	for(long i=1;i<=K;i++)
	{
		x=x*(N-i+1)%mod;
		y=y*i%mod;
	}
	return x*power(y,mod-2)%mod;
}
main()
{
	int r1,c1,r2,c2;
	cin>>r1>>c1>>r2>>c2;
	r2++,c2++;
	long ans=C(r2+c2,r2)-C(r1+c2,r1)-C(r2+c1,c1)+C(r1+c1,r1);
	cout<<(ans%mod+mod)%mod<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int data[2][51][51],sy,sx,gy,gx;
int sw[51][51],h,w,num;
string s[51],t;
int dy[]={0,0,-1,1};
int dx[]={-1,1,0,0};
bool used[51][51][1<<10][2];
struct dat{
    int y,x,sw,flo,cost;
    dat(int a,int b,int c,int d,int e){
        y=a;x=b;sw=c;flo=d;cost=e;
    }
};
signed main(){
    memset(data,-1,sizeof(data));
    cin>>w>>h;
    r(i,h)cin>>s[i];
    r(i,h)r(j,w){
        if(s[i][j]=='%')data[0][i][j]=100,sy=i,sx=j;
        if(s[i][j]=='&')data[0][i][j]=100,gy=i,gx=j;
        if(s[i][j]=='_')data[0][i][j]=100;
        if(s[i][j]=='^')data[1][i][j]=100;
        if(s[i][j]=='|')data[0][i][j]=data[1][i][j]=101;
        if(isalpha(s[i][j])){
            if(islower(s[i][j]))data[0][i][j]=(s[i][j]-'a');
            if(isupper(s[i][j]))data[1][i][j]=(s[i][j]-'A');
        }
    }
    cin>>num;
    r(i,num)r(j,h){
        cin>>t;
        r(k,w)if(t[k]=='*')sw[j][k]|=(1<<i);
    }
    queue<dat>q;
    q.push(dat(sy,sx,0,0,0));
    used[sy][sx][0][0]=1;
    while(!q.empty()){
        dat a=q.front();q.pop();
        if(a.y==gy&&a.x==gx){
            cout<<a.cost<<endl;
            return 0;
        }
        int y=a.y;
        int x=a.x;

        // 階段
        if(data[a.flo][y][x]==101){
            if(!used[y][x][a.sw][a.flo^1]){
                used[y][x][a.sw][a.flo^1]=1;
                q.push(dat(y,x,a.sw,a.flo^1,a.cost+1));
            }
        }

        // 移動
        r(i,4){
            int ny=y+dy[i];
            int nx=x+dx[i];
            int A=a.sw;
            int B=sw[ny][nx];
            int C=A&B;
            int D=__builtin_popcount(C)+a.flo;D%=2;
            if(data[D][ny][nx]!=-1){
                //cout<<ny<<' '<<nx<<endl;
                if(!used[ny][nx][a.sw][a.flo]){
                    used[ny][nx][a.sw][a.flo]=1;
                    q.push(dat(ny,nx,a.sw,a.flo,a.cost+1));
                }
            }
        }

        // スイッチ
        if(isalpha(s[y][x])){
            int A=a.sw;
            int B=sw[y][x];
            int C=A&B;
            int D=__builtin_popcount(C)+a.flo;D%=2;
            int E=data[D][y][x];
            int F=0;
            if(islower(s[y][x]))F|=(1<<(s[y][x]-'a'));
            if(isupper(s[y][x]))F|=(1<<(s[y][x]-'A'));
            if(F&B){
                if(!used[y][x][a.sw^F][a.flo^1]){
                    used[y][x][a.sw^F][a.flo^1]=1;
                    q.push(dat(y,x,a.sw^F,a.flo^1,a.cost+1));
                }
            }
            else{
                if(!used[y][x][a.sw^F][a.flo]){
                    used[y][x][a.sw^F][a.flo]=1;
                    q.push(dat(y,x,a.sw^F,a.flo,a.cost+1));
                }
            }
        }
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 8560
<?php
$hextable = array(
    "A" => 10,
    "B" => 11,
    "c" => 12,
    "D" => 13,
    "E" => 14,
    "F" => 15 
);

fscanf(STDIN,"%s %s",$x,$y);
if($hextable[$x] < $hextable[$y]) echo "<";
elseif($x == $y) echo "=";
else echo ">";


?>

Measured memory_bytes: 3828
#include <stdio.h>
int main()
{
    int a[10],i,j,p,q,m,n;
    char b[5],c[5];
    scanf("%d",&m);
    for(n=0;n<4;n++)
    {
        a[4-n-1]=m%10;
        m/=10;
    }
    int sum=a[0],flag=0;
    for(b[1]=0;b[1]<2;b[1]++)
    {
        for(b[2]=0;b[2]<2;b[2]++)
        {
            for(b[3]=0;b[3]<2;b[3]++)
            {
                for(q=1;q<=3;q++)
                {
                    if(b[q]==0)sum=sum+a[q];
                    if(b[q]==1)sum=sum-a[q];
                }
                if(sum==7){c[1]=b[1];c[2]=b[2];c[3]=b[3];flag=1;}
                sum=a[0];
                if(flag==1)break;
            }if(flag==1)break;
        }if(flag==1)break;
    }
   printf("%d",a[0]);
   for(i=1;i<=3;i++)
   {
       if(c[i]==0)printf("+");
       else printf("-");
       printf("%d",a[i]);
   }
   printf("=7");
   return 0;
}

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

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

    int total = 0;
    for (size_t i = 0; i < N.size(); i++)
    {
        total += N[i] - '0';
    }

    string ans;
    ans = (total % 9 == 0) ? "Yes" : "No";
    cout << ans << endl;
}


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

using namespace std;

bool compstr ( string& s1, string& s2, int pos )
{
  if ( pos + s2.size() > s1.size() ) return false;

  for ( int i = 0; i < s2.size(); ++i ) {
    if ( s1[pos+i] != '?' && s1[pos+i] != s2[i] ) return false;
  }

  return true;
}



string findstr ( string &s1, string& s2 )
{
  string ans = string(s1.size(),'z');
  bool flag = false;

  for ( int i = 0; i < s1.size(); ++i ) {
    if ( compstr(s1, s2, i ) ) {
      string tmp = s1;
      for ( int j = 0; j < s2.size(); ++j ) tmp[i+j] = s2[j];
      for ( int j = 0; j < tmp.size(); ++j ) if ( tmp[j] == '?' ) tmp[j] = 'a';
      if ( ans > tmp ) ans = tmp;
      flag = true;
      //cout << s1 << "\n";
      //cout << tmp << "\n";
    }
  }
  if ( !flag ) ans = "UNRESTORABLE";

  return ans;
}


int main()
{
  string s1, s2;

  cin >> s1;
  cin >> s2;


  cout << findstr(s1,s2) << "\n";
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

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

    void solve(InputReader in, PrintWriter out) {
        int N = in.nextInt();
        int M = in.nextInt();

        int[] as = new int[N];
        for (int i = 0; i < N; i++) {
            as[i] = in.nextInt();
        }

        HashMap<Integer, Integer> map = new HashMap<>();
        HashSet<Integer> index = new HashSet<>();
        for (int i = 0; i < M; i++) {
            int B = in.nextInt();
            int C = in.nextInt();

            map.compute(C, (key, old) -> (old == null) ? B : B + old);
            index.add(C);
        }

        ArrayList<Integer> inxdexList = new ArrayList<>(index);
        inxdexList.sort(Collections.reverseOrder());
        Arrays.sort(as);
        int aaa = 0;
        int value = inxdexList.get(aaa);
        Integer count = map.get(value);
        for (int i = 0; i < N; i++) {
            if (count == 0) {
                aaa++;
                if (aaa == inxdexList.size()) {
                    break;
                }
                value = inxdexList.get(aaa);
                count = map.get(value);
            }

            if (as[i] < value) {
                as[i] = value;
                count--;
            }
        }

        long ans = 0;
        for (int i = 0; i < N; i++) {
            ans += as[i];
        }

        out.println(ans);
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

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

    long nextLong() {
        return Long.parseLong(this.sc.next());
    }

    double nextDouble() {
        return Double.parseDouble(this.sc.next());
    }

    @Override
    public void close() {
        this.sc.close();
    }
}


Measured memory_bytes: 73668
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

ll gcd(ll x, ll y) {
  if(x > y)
    return gcd(y, x);
  else if(x == 0)
    return y;
  else
    return gcd(y % x, x);
}
ll lcm(ll x, ll y) {
  ll g = gcd(x, y);
  return g * (x / g) * (y / g);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll X;
  cin >> X;
  ll L = lcm(X, 360);
  cout << L / X << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

struct coor {
	int x, y, h;
	coor() {}
	const bool operator<(coor l) const { return h > l.h; } // 先頭にh!=0が来るように
};

int main() {

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

	int N;
	cin >> N;

	vector<coor> data(N);
	for (int i = 0; i < N; i++) cin >> data[i].x >> data[i].y >> data[i].h;
	sort(data.begin(), data.end());

	vector<coor> tmp;
	for (int X = 0; X <= 100; X++) {
		for (int Y = 0; Y <= 100; Y++) {

			int H = data[0].h + abs(data[0].x - X) + abs(data[0].y - Y);
			bool flag = true;
			for (int i = 0; i < N; i++) {

				if (max(H - abs(data[i].x - X) - abs(data[i].y - Y), 0) != data[i].h) {
					flag = false;
					break;
				}

			}

			if (flag) {
				cout << X << " " << Y << " " << H << "\n";
				return 0;
			}

		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (ll i=(a); i >= b; i--)

#define MN 505
int n;

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

    cin >> n;
    F0R(i, n-1){
        FOR(j, i+1, n-1){
            int ree = i ^ j;
            cout << __builtin_ctz(ree)+1 << " ";
        }
        cout << "\n";
    }

    return 0;
}


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

using namespace std;

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  int xa=a-x,xb=b-x;
  if(xa<0)
    xa = xa*-1;
  if(xb<0)
    xb = xb*-1;
  if(xa<xb)
    cout << 'A' << "\n";
  else
    cout << 'B' << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
    std::cout << std::fixed << std::setprecision(10);
ll w,h,x,y;
cin>>w>>h>>x>>y;
double ans=(double)(w*h)/2;
cout<<ans<<endl;
if((double)x==(double)w/2&&(double)y==(double)h/2){
    cout<<"1"<<" ";
}else{
    cout<<"0"<<endl;
}
}










Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a, ans,moku, b, tyokin;
	while (1) {
		cin >> moku;
		if (moku == 0) {
			goto a;
		}
		tyokin = 0;
		ans = 0;
		for (int i = 1; i <= 12; i++) {
			cin >> a >> b;
			tyokin += a - b;
			if (moku <= tyokin) {
				ans = i;
				tyokin = -99999999;
			}
		}
		if (ans == 0) {
			cout << "NA" << endl;
		}
		else {
			cout << ans << endl;
		}
	}
a:;
}


Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

// #define DEBUG

int main()
{
#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif
    queue<pair<string, int>> a;
    vector<pair<string, int>> result;
    pair<string, int> exec;
    int n, q, t, used_time, total_time;
    string name;
    cin >> n >> q;
    used_time = 0, total_time = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> name >> t;
        a.push(make_pair(name, t));
    }

    while (!a.empty())
    {
        exec = a.front();
        a.pop();
        name = exec.first;
        t = exec.second;

        used_time = min(t, q);
        t -= used_time;
        total_time += used_time;
        if (t == 0)
        {
            result.push_back(make_pair(name, total_time));
        }
        else
        {
            a.push(make_pair(name, t));
        }
    }
    for (int i = 0; i < distance(result.begin(), result.end()); i++)
    {
        cout << result[i].first << " " << result[i].second << endl;
    }

    return 0;
}


Measured memory_bytes: 7020
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;

int main() {
	int n,a1,a2,a3;
	cin>>n;
	a1=n%10;
	n/=10;
	a2=n%10;
	a3=n/10;
//	cout<<a1<<' '<<a2<<' '<<a3<<endl;
	if( a1==1 )
		a1=9;
	else if( a1==9 )
		a1=1;
	if( a2==1 )
		a2=9;
	else if( a2==9 )
		a2=1;
	if( a3==1 )
		a3=9;
	else if( a3==9 )
		a3=1;
	cout<<(a1+a2*10+a3*100)<<endl;
	return 0;
	}


Measured memory_bytes: 256
function Main(input) {
	input = input.split("\n");
  	var tmp = input[0].split(" ");
  	var N = tmp[0];
  	var D = tmp[1];
  
  	var count = 0;
  
  	for(var i = 1; i <= N; i++){	
		var tmp = input[i].split(" ");
      	var x = tmp[0];
      	var y = tmp[1];
      	var distance = Math.sqrt((x*x) + (y*y));
      	if(distance <= D){
        	count++;
        }
    }
  	console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 62712
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	private static Node[] V;
	private static ArrayList<Integer> sort = new ArrayList<>();
	
	public static void main(String[] args) {
		int Vn = sc.nextInt();
		int En = sc.nextInt();
		
		V = new Node[Vn];
		for(int i=0; i<Vn; i++) {
			V[i] = new Node();
			V[i].id = i;
		}
		
		for(int i=0; i<En; i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			V[s].nbr.add(t);
		}
		
		for(int i=0; i<Vn; i++) {
			if(V[i].visited == 0) {
				V[i].visit();
			}
		}
		
		for(int i=sort.size()-1; i>=0; i--) {
			System.out.println(sort.get(i));
		}
	}
	
	static class Node {
		int id;
		HashSet<Integer> nbr = new HashSet<>();
		int visited = 0;
		
		void visit() {
			if(visited == 1) {
				System.out.println(1);
				System.exit(0);
			} else if(visited == 0) {
				visited = 1;
				for(int x : nbr) {
					V[x].visit();
				}
				
				visited = 2;
				sort.add(id);
			} 
		}
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 46216
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, a[100009];
vector<pair<int, int> > vec;
stack<int> stk[2];

int fun(bool LP)
{
	int L, R;
	if (stk[0].size() == 1 && stk[1].size() == 1) {
		L = stk[0].top();
		R = stk[1].top();
		if (!LP) swap(L, R);
	}
	else if (stk[0].size() > 1) {
		if (LP) {
			L = stk[0].top();
			stk[0].pop();
			R = fun(!LP);
		}
		else {
			R = stk[0].top();
			stk[0].pop();
			L = fun(LP);
		}
	}
	else if (stk[1].size() > 1) {
		if (!LP) {
			L = stk[1].top();
			stk[1].pop();
			R = fun(!LP);
		}
		else {
			R = stk[1].top();
			stk[1].pop();
			L = fun(LP);
		}
	}
	vec.pb(make_pair(L, R));
	return (L - R);
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	stk[0].push(a[0]);
	int cur = 1;
	while (1) {
		if (cur >= n - 1) break;
		if (a[cur] < 0) break;
		stk[0].push(a[cur++]);
	}
	for (int i = n - 1; i >= cur; i--)
		stk[1].push(a[i]);
	cout << fun(true) << E;
	for (int i = 0; i < (int)vec.size(); i++) {
		cout << vec[i].fi << " " << vec[i].se << E;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 8132
k, toayen, fromayen = map(int, input().split())
if fromayen <= toayen + 2 or k <= toayen:
    print(k + 1)
    exit()
k -= (toayen - 1)
bs = toayen
bs += (fromayen - toayen) * (k//2)
k %= 2
print(bs + 1 if k else bs)

Measured memory_bytes: 38384
while True:
    a,op,b=input().split()
    if op == "?":
        break
    a,b=int(a),int(b)
    if op == "+":
        print(str(a+b))
    elif op == "-":
        print(str(a-b))
    elif op == "*":
        print(str(a*b))
    else:
        print(str(a//b))

Measured memory_bytes: 7612
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

string translate(ll x){
	if (x == 0) return "0";
	string s = "";
	while (x != 0){
		int r = x % -2;
		x /= -2;
		if (r == -1) r = 1, x++;
		s += to_string(r);
	}
	reverse(full(s));
	return s;
}
int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	ll n;
	cin >> n;
	cout << translate(n) << endl;
	return 0;
}

Measured memory_bytes: 256