akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
using namespace std;
int N, W;
vector<int> w, v;
map<pair<int,int>, int> m;



int rec(int i, int j) {
	int res;
	pair<int,int> p = make_pair(i, j);
	if (m.find(p) != m.end()){
		return m[p];
	}

	if (i == N) {
		res = 0;
	}
	else if (j < w[i]) {
		res = rec(i + 1, j);
	}
	else {
		res = max(
			rec(i + 1, j),
			rec(i + 1, j - w[i]) + v[i]
			);
	}
	m[make_pair(i, j)] = res;
	return res;
}


int main(){

	cin >> N >> W;
	for (int i = 0; i < N; i++){
		int tw, tv;
		cin >>tw>> tv;
		w.push_back(tw);
		v.push_back(tv);
	}
	cout << rec(0, W) << endl;

	return 0;
}

Measured memory_bytes: 4864
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        String str1 = sc.next();
        String str2 = sc.next();
        Map<Character, Character> map = new HashMap<>();
        boolean result = true;
        
        for(int i = 0; i < str2.length(); i++){
            if(map.get(str2.charAt(i)) == null){
                if(map.containsValue(str1.charAt(i))){
                    result = false;
                    break;
                }else{
                    map.put(str2.charAt(i), str1.charAt(i));
                }
            }else{
                if(map.get(str2.charAt(i)) != str1.charAt(i)){
                    result = false;
                    break;
                }
            }
        }
        
        System.out.println(result ? "Yes" : "No");
    }
}


Measured memory_bytes: 27040
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int h,w; cin>>h>>w;
    vector<vector<string>>v(h,vector<string>(w));
    char p;
    rep(i,h)rep(j,w){rep(slsl,5){cin>>p; v[i][j].push_back(p);}}
    string snuke="snuke";
    pii ans;
    rep(i,h)rep(j,w)if(v[i][j]==snuke)ans=pii(i,j);
    char hoge[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    cout<<hoge[ans.second]<<ans.first+1<<endl;
    
}

Measured memory_bytes: 256
import queue
import scipy
n,k = map(int,input().split())

ab = [[] for j in range(n+1)]
mod = 10**9 + 7

for i in range(n-1):
    a,b = map(int,input().split())
    ab[a].append(b)
    ab[b].append(a)
    
check = [False] * (n+1)
kazu = [0] * (n+1)

check[0] = True

q = queue.Queue()
q.put(1)

ans = k
#print(ab)

while not q.empty():
    tmp = q.get()
    check[tmp] = True
    kake = 0
    for i in range(len(ab[tmp])):
        if check[ab[tmp][i]] == True:
            continue
        kazu[ab[tmp][i]] += 1
        q.put(ab[tmp][i])
        ans *= k - kake - kazu[tmp] - 1
        ans %= mod
        #print(i,k,ans,tmp,kazu[tmp])
        kake += 1
    
print(ans)

Measured memory_bytes: 35064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


class Main {
	public static void main(String[] args) throws IOException {
		ArrayList<String> ss = new ArrayList<String>();
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String i = new String(in.readLine());
			if(i.equals("0 0")){
				break;
			}
			else{
				ss.add(i);
			}
			
		}
		for(int i = 0;i < ss.size() ;i++){
			String[] sss = ss.get(i).split(" ");
			int a = Integer.parseInt(sss[0]);
			int b = Integer.parseInt(sss[1]);
			if(a > b){
				System.out.println(b + " " + a);
			}
			else{
				System.out.println(a + " " + b);
			}
			
		}
		
	}

}

Measured memory_bytes: 25416
import java.util.*;
import java.io.*;
public class Main {
	ArrayList <Integer>output = new ArrayList<Integer>(0);
	BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
	boolean inputend = false;
	String input = null;
	ArrayList <String> run = new ArrayList<String>(0);//?????????????????°
	int datalength = 0;
	public static void main(String []args){
		Main run = new Main();
		run.Run();
	}
	public void Run(){
			try{
				input = read.readLine();
				if(datalength == 0){
					datalength = Integer.parseInt(input);
					if(datalength == 0)System.exit(0);
				}
				for(int z = 0;z < datalength;z++){
					Cut(read.readLine());
					output.add(run.size());
					run = new ArrayList<String>(0);
				}
				for(int z = 0;z < datalength;z++){
					System.out.println(output.get(z));
				}
			}catch(IOException e){
				
			}
	}
	public void Cut(String input){
		int index = 1;
		for(;index < input.length();index++){
			String output1 = input.substring(0, index);
			String output2 = input.substring(index,input.length());
			String Revoutput1 = Rev(output1);
			String Revoutput2 = Rev(output2);
			Input_Run(Revoutput1+output2);
			Input_Run(Revoutput1+Revoutput2);
			Input_Run(output1+Revoutput2);
			Input_Run(output1+output2);
			Input_Run(Revoutput2+output1);
			Input_Run(Revoutput2+Revoutput1);
			Input_Run(output2+Revoutput1);
			Input_Run(output2+output1);
		}
	}
	public String Rev(String input){
		String output = "";
		for(int z = input.length()-1;z >= 0;z--){
			output += input.substring(z,z+1);
		}
		return output;
	}public void Input_Run(String input){
		if(!run.contains(input)){
			run.add(input);
		}
	}
}

Measured memory_bytes: 87772
using System;

class Program
{
	static void Main()
	{
		while (true)
		{
			string[] D = Console.ReadLine().Split(' ');
			int a = int.Parse(D[0]), b = int.Parse(D[2]), c;
			switch (D[1])
			{
				case "+":
					c = a + b;
					break;
				case "-":
					c = a - b;
					break;
				case "*":
					c = a * b;
					break;
				case "/":
					c = a / b;
					break;
				default:
					return;
			}
			Console.WriteLine(c);
		}
	}
}

Measured memory_bytes: 5704
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader(); 
        int N = r.i();
        int[] T = r.ii();
        int M = r.i();
        int sum = 0;
        for(int t : T)
            sum += t;
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < M; i++){
            int[] a = r.ii();
            int p = a[0]-1;
            int x = a[1];
            sb.append(sum-T[p]+x);
            sb.append('\n');
        }            
        print(sb);                    
    }
    static void print(Object o){
        System.out.print(o.toString());
    }

    static void println(Object o){
        System.out.println(o.toString());
    }

    static int Int(String s){
        return Integer.parseInt(s);
    }

    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l() throws IOException{
            return Long(s());
        }

        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

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

int main(){
    char s[4];
    cin>>s;
    int ans=0;
    for(int i=0;i<4;i++){
        if(s[i]=='+') ans++;
        else ans--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

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

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

template <typename Container>
int SZ(const Container& S) { return S.size(); }

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg_var(x) clog << #x  << ": " << x << endl;
    #define dbg_array(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg_var(x)
    #define dbg_array(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = -1; 

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!

    int N;
    cin >> N;
    vector<int> B(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        B[i] = i-a;
    }
    for (int i = 0; i < N; i++) {
        if (B[i] < 0 or i < B[i]) {
            cout << -1 << "\n";
            return 0;
        }
    }
    for (int i = 0; i < N-1; i++) {
        if (B[i] > B[i+1]) {
            cout << -1 << "\n";
            return 0;
        }
    }
    LL res = N-1-B[N-1];
    for (int i = N-2; i >= 0; i--) {
        if (B[i] == B[i+1]) continue;
        res += i-B[i];
    }
    cout << res << "\n";
}



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

using dbl=double;
using ll=long long;
using pii=pair<int, int>;
using pll=pair<ll, ll>;

#define sz(a) ((int)a.size())
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define forse(i,s,e) for(int i=(int)s;i<(int)e;i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const dbl PI=3.141592653589793;

ll exp(ll a,ll e,int P) {
	ll res = 1; 
	while (e) { 
		if (e&1) res = (res*a)%P; 
		a = (a*a)%P; 
		e >>= 1; 
	}
	return res;
}

void solve(){
	vector<int> pre(2e5+2,1);
	forse(i,1,2e5+2){
		pre[i]=1+pre[i%__builtin_popcount(i)];
	}


	int n;cin >> n;
	string in;
	cin >> in;

	int tot=0;
	for(auto i:in) tot+=(i=='1');

	ll v1=0,v2=0;
	forn(i,n){
		if(in[n-i-1]=='1'){
			v1=(v1+exp(2,i,tot+1))%(tot+1);
			if(tot>1) v2=(v2+exp(2,i,tot-1))%(tot-1);
		}
	}
	forn(i,n){
		int cval;
		if(in[i]=='1'){
			if(tot>1){
				cval=v2;
				cval=(cval-exp(2,n-i-1,tot-1))%(tot-1);
				if(cval<0) cval+=(tot-1);
			}else cval=-1;
		}else{
			cval=v1;
			cval=(cval+exp(2,n-i-1,tot+1))%(tot+1);
			if(cval<0) cval+=(tot+1);
		}
		if(cval>=0) cout << pre[cval] << '\n';
		else cout << "0\n";
	}


}

int main() {
//	ios::sync_with_stdio(0);
//	cin.tie(0); 
	int T=1;
//	cin >> T;
	for(int c=1;c<=T;c++){
		solve();
	}
}


Measured memory_bytes: 4456
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		
		int ptrMin = 0;
		int ptrMax = n-1;
		long max1 = 0;
		boolean useMin = false;
		while(ptrMin<ptrMax-1) {
			max1 += dif(a[ptrMin],a[ptrMax]);
			ptrMin++;
			if(ptrMin==ptrMax-1) {
				useMin = true;
				break;
			}
			max1 += dif(a[ptrMin],a[ptrMax]);
			ptrMax--;
		}
		if(useMin) max1 += dif(a[0],a[ptrMin]);
		else max1 += dif(a[0],a[ptrMax]);
		
		ptrMin = 0;
		ptrMax = n-1;
		long max2 = 0;
		boolean useMax = false;
		while(ptrMin<ptrMax-1) {
			max2 += dif(a[ptrMin],a[ptrMax]);
			ptrMax--;
			if(ptrMin==ptrMax-1) {
				useMax = true;
				break;
			}
			max2 += dif(a[ptrMin],a[ptrMax]);
			ptrMin++;
		}
		if(useMax) max2 += dif(a[n-1],a[ptrMax]);
		else max2 += dif(a[n-1],a[ptrMin]);
		
		System.out.println(Math.max(max1, max2));
		in.close();

	}
	
	public static int dif(int a,int b) {
		if(a>b) return a-b;
		else return b-a;
	}

}


Measured memory_bytes: 51092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>
#include <map>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iterator>
#include <deque>
#include <bitset>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <functional>
#include <iterator>
#include <locale>
#include <memory>
#include <stdexcept>
#include <utility>
#include <fstream>
#include <ios>
#include <iosfwd>
#include <iomanip>
#include <istream>
#include <sstream>
#include <streambuf>
#include <complex>
#include <numeric>
#include <valarray>
#include <exception>
#include <limits>
#include <new>
#include <typeinfo>
#include <bitset>
#include <queue>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

int main() {
	int ans=0;
	string a;
	cin >> a;
	for (int i = 0; i < a.size()/2; i++) {
		if (a[i] != a[a.size() - 1 - i])
			ans++;
	}
	cout << ans;
}



Measured memory_bytes: 3620
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
 
int main() {
  int N; cin >> N;
  vector<pair<int, int>> pos, neg;
  int all_sum = 0;
  for (int i = 0; i < N; ++i) {
    string S; cin >> S;
    int sum = 0, vmin = 0;
    for (char c : S) {
      if (c == '(') ++sum;
      else          --sum;
      vmin = min(vmin, sum);
    }
    if (sum >= 0) pos.emplace_back(vmin, sum);
    else         neg.emplace_back(vmin - sum, -sum);
    all_sum += sum;
  }
  if (all_sum != 0) {
    cout << "No" << endl;
    return 0;
  }
 
  sort(pos.rbegin(), pos.rend());
  sort(neg.rbegin(), neg.rend());
 
  all_sum = 0;
  for (auto [vmin, sum] : pos) {
    if (all_sum + vmin < 0) {
      cout << "No" << endl;
      return 0;
    }
    all_sum += sum;
  }
 
  all_sum = 0;
  for (auto [vmin, sum] : neg) {
    if (all_sum + vmin < 0) {
      cout << "No" << endl;
      return 0;
    }
    all_sum += sum;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 11240
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        int n,a=0;
        n = tan.nextInt();
        a=n%10;
        if(a==2 || a==4 || a==5 || a==7 || a==9)
            System.out.println("hon");
        else if(a==0 || a==1 || a==6 || a==8)
            System.out.println("pon");
        else if(a==3)
            System.out.println("bon");
    }
}


Measured memory_bytes: 35484
(let* ((n (read))
       (ans (loop :named a
                  :for k :from 1
                  :if (= 0 (mod n k))
                    :do (loop :named b
                              :for j :from (ceiling k 2)
                              :for s := (- (expt j 5) (expt (- j k) 5))
                              :do (cond ((= s n) (return-from a (list (- j k) j)))
                                        ((> s n) (return-from b)))))))
  (format t "~A ~A" (second ans) (first ans)))

Measured memory_bytes: 24468
A, B = list(map(int, input().split()))

ab = int(abs(A-B)/2)

if (A % 2 != 0 and B % 2 == 0) or (A % 2 == 0 and B % 2 != 0):
    print("IMPOSSIBLE")
else:
    print(min(abs(A), abs(B))+ab)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
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;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<ll> A(N+1);
    vector<ll> B(N);
    ll out=0;
    for(int i=0;i<=N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        cin >> B[i];
    }
    for(int i=0;i<N;i++){
        if(A[i]<=B[i]){
            out += A[i];
            ll tmp=B[i]-A[i];
            if(A[i+1]<=tmp){
                out += A[i+1];
                A[i+1]=0;
            }else{
                out += tmp;
                A[i+1] -= tmp;
            }
        }else{
            out += B[i];
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val X = listOfInt().sorted()
    if (N >= M) { println(0); return }
    val L = (0 until M - 1).map { X[it + 1] - X[it] }.sortedDescending()
    val lSum = L.subList(0, N - 1).sum()
    val ans = (X.last() - X.first()) - lSum
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

Measured memory_bytes: 52028
import sys

def main():

	N = int(input())
	A = list(map(int, input().split()))
	H = 0
	max = A[0]
	for i in range(N-1):
		if max>A[i+1]:
			H = H + max - A[i+1]
		if max < A[i+1]:
			max = A[i+1]
	print(H)

if __name__ == "__main__":
    main()

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//

void solve(long long N, std::vector<long long> a) {
  vector<pair<ll,ll>> b(N);
  rep(i,N) b[i] = mp(a[i], (ll)i);
  sort(all(b));
  ll state = 1;
  ll pos = -1;
  ll nchain = 0;
  rep(i,N){
    if(b[i].first == state && pos<b[i].second ){ state++; pos = b[i].second; nchain++; }
  }
  if(nchain == 0) cout << -1 << endl;
  else cout << N - nchain << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 7992
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

using namespace std;

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

int main(){
    int N,L;
    cin>>N>>L;
    long long sum=0;
    
    rep(i,1,N+1){
        sum+=(L+i-1);
    }

    if(L>0){
        cout<<sum-L;
    }
    else if(N+L-1>=0){
        cout<<sum;
    }
    else{
        cout<<sum-(N+L-1);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);



int main(){

	ll n,k;
	cin>>n>>k;
	ll a[n];
	fo(i,n) cin>>a[i];
	ll cnt=1;
	ll still=k;
	while(still<n){
		still+=(k-1);
		cnt++;

	}
	cout<<cnt<<endl;

    
}

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

int f_func(int x){
    int ans=0;
    while(x>0){
        ans+=x%10;
        x/=10;
    }
    return ans;
}

int main(){
    int n;
    cin>>n;
    
    if(n%f_func(n)==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3532
#include <iostream>
#include <cstring>
#define INF INT_MAX / 2
#define rep(i, s, n) for(int i = s; i < (int)n; ++i)

using namespace std;

int N, R;

int main() {
        cin >> N >> R;
        if (N >= 10) {
                cout << R;
        } else {
                cout << R + 100 * (10 - N);
        }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp

int n;
int A[100005];

int bubble() {
    int cnt = 0;
    bool flag = true;
    for (int i = 0; flag; i++) {
        flag = false;
        for (int j = n-1; j >= i+1; j--) {
            if (A[j] < A[j-1]) {
                swap(A[j], A[j-1]);
                cnt++;
                flag = true;
            }
        }
    }
    return cnt;
}

int main() {
    cin >> n;
    REP(i, n) cin >> A[i];
    int c = bubble();
    arrdump(n, A);
    cout << c << "\n";
    return 0;
}



Measured memory_bytes: 3124
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long A, long long B){
  cout << max(2*A-1,max(2*B-1,A+B)) << endl;
}

int main(){
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (ll)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e4+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll d[MAXn],c[MAXn];
vector<ll> tmp;
int main(){
    IOS();
    ll x,y,z,k;
    cin >> x >> y >> z >> k;
    REP (i,x) cin >> d[i];
    REP (i,y) {
        ll t;
        cin >> t;
        REP (j,x) tmp.eb(t+d[j]);
    }
    REP (i,z) cin >> c[i];
    sort(ALL(tmp),greater<ll>());
    sort(c,c+z,greater<ll>());
    priority_queue<ll> pq;
    REP (i,min(k,SZ(tmp))) REP (j,min(k,z)) pq.emplace(tmp[i] + c[j]);
    REP (i,k) {
        cout << pq.top() << endl;
        pq.pop();
    }
}


Measured memory_bytes: 43364
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll a,b; cin >> a >> b;
    cout << (a<=b ? a : a-1) << endl;
}

Measured memory_bytes: 256
# ABC047D - 高橋君と見えざる手 / An Invisible Hand (ARC063D)
def main():
    N, T = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    cur, cand = A[0], []
    for i in A:
        if i < cur:
            cur = i
        else:
            cand += [i - cur]
    x = max(cand)
    ans = sum(i == x for i in cand)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14356
#include<bits/stdc++.h>
//#define int long long
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)
using namespace std;
const int N = 100010, mod = 2147483647;
inline int read()
{
    register char cc = getchar(); register int cn(0), flus(1);
    while(cc < '0' || cc > '9') {if(cc == '-') flus = - flus; cc = getchar();}
    while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - '0'; cc = getchar();}
    return cn * flus;
}
const double PI=3.1415926;

signed main()
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	double n;

	n = read();

	printf("%.2lf",2 * n * PI);
	return 0;

}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Unionfind{
    vector<int> parent;
    void init(int forestSize){
        parent.resize(forestSize);
        for(int i=0;i<forestSize;i++){parent.at(i)=i;}
    }
    int root(int v){
        if(parent.at(v)==v){return v;}
        else{return parent.at(v)=root(parent.at(v));}
    }
    bool belong(int x,int y){
        if(root(x)==root(y)){return true;}
        else{return false;}
    }
    void unite(int x,int y){
        if(parent.at(x)!=parent.at(y)){parent.at(root(y))=root(x);}
    }
};
int main(){
  int N,M,ans=1;
  cin>>N>>M;
  Unionfind<int> rock;
  vector<int> S(N,0);
  rock.init(N);
  for(int i=0;i<M;i++){
    int A,B;
    cin>>A>>B;
    rock.unite(A-1,B-1);
  }
  for(int i=0;i<N;i++){
    S.at(rock.root(i))++;
  }
  for(int i=0;i<N;i++){
    ans=max(ans,S.at(i));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5032
#include<iostream>
using namespace std;
int main(void)
{
	int i,n,x,l[200],now=0,b=1;
	cin>>n>>x;
	for(i=1;i<=n;i++) cin>>l[i];
	for(i=1;i<=n;i++){
		now=now+l[i];
		if(now<=x) b++;
		else break;
	}
	cout<<b;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;

int main() {
	fastio;
	ll n;
	cin>>n;
	vector<ll> a(n);
	ll sum = 0;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		a[i] -= i+1;
		
	}
	sort(a.begin(),a.end());
	if(n%2){
		for(ll i=0;i<n;i++){
			sum += abs(a[i]-a[n/2]); 
		}
		cout<<sum<<"\n";
	}
	else{
		ll s1 = 0,s2 = 0;
		for(ll i=0;i<n;i++){
			s1 += abs(a[i]-a[n/2]); 
		}
		for(ll i=0;i<n;i++){
			s2 += abs(a[i]-a[n/2-1]); 
		}
		cout<<min(s1,s2)<<"\n";
	}
	
	
	
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ull            unsigned long long int
#define ll             long long int
#define pb(x)          push_back(x)
#define mp(a,b)        make_pair(a,b)
#define li(ini)        for(ull i=ini;;i++)
#define lfi(i,ini,r)   for(ull i=ini;i<r;i++)
#define lfd(i,ini,r)   for(ull i=ini;i>=r;i--)
#define lit(it,v)      for(auto it=v.begin();it!=v.end();it++)
#define l(v)           for(ull b:v)
#define sorta(v)       sort(v.begin(),v.end())
#define sortd(v)       sort(v.begin(),v.end(),greater<>())
#define vf(i)          v[i].first
#define vs(i)          v[i].second
#define fast_io        ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define en             "\n"
#define sr(s)          reverse(s.begin(),s.end())


using namespace std;

vector<ll>v;
vector<ll>s;

int main()
{
    //fast_io

    ll x=0,res=0,t1=0,i=0,j=0,m=0,n=0,a=0,b=0,c=0,d=0,sum=0,flag=0,flag1=1,cont=0,k=0;

    string s,t,r;
    cin>>s>>t;
    r.assign(t.begin(),t.end()-1);

    (r==s)?cout<<"Yes\n":cout<<"No\n";


    return 0;
}





Measured memory_bytes: 3628
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

double dp[305][305][305];
int num[4];
int N;

double dfs(int i, int j, int k) {
    if (i < 0 || j < 0 || k < 0) return 0;
    if (dp[i][j][k] > 0) return dp[i][j][k];

    if (i + j + k == 0) return 0;

    double res = 0;
    res += dfs(i - 1, j, k) * i;
    res += dfs(i + 1, j - 1, k) * j;
    res += dfs(i, j + 1, k - 1) * k;
    res += N;
    res /= (i + j + k);

    return dp[i][j][k] = res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> N;

    vector<int> a(N);
    REP(i, N) cin >> a[i];

    REP(i, N) {
        num[a[i]]++;
    }

    REP(i, num[1] + 1) REP(j, num[2] + 1) REP(k, num[3] + 1) dp[i][j][k] = -1;

    fcout << dfs(num[1], num[2], num[3]) << endl;

    return 0;
}


Measured memory_bytes: 219392
function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0].split(" ")[0]);
  var m = parseInt(input[0].split(" ")[1]);
  x= new Array(Math.pow(10,5)*2).fill(0);
  var ans = "IMPOSSIBLE";
  for(i=0;i<m;i++){
    tmp=input[i+1].split(" ");
    if(tmp[0]==1){
      if(x[tmp[1]]==1){
        ans="POSSIBLE";
        break;
      }else{
      x[tmp[1]]++;
      }
    }
    if(tmp[1]==n){
      if(x[tmp[0]]==1){
        ans="POSSIBLE";
        break;
      }else{
        x[tmp[0]]++;
      }
    }
  }


  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37204
using System;

namespace ABC066A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, min;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            min = a + b;
            if (a + c < min) min = a + c;
            if (b + c < min) min = b + c;

            Console.WriteLine(min);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
	int n;
	string s;
	cin >> n;
	cin >> s;
	int i;
	int r=0, b=0;
	for (i = 0; i < n; i++) {
		if (s[i] == 'R') {
			r++;
		}
		else {
			b++;
		}
	}
	if (r > b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

#define MX 105
#define INF 1e9

typedef long long ll;
int mat[MX][MX],sum[MX];

int main()
{
    #ifdef shibli
       //freopen("input.txt","r",stdin);
    #endif // shibli

    int n,x;
    cin>>n;

    int cur_sum,cur_max,f_max;
    cur_max = -INF;

    for(int i = 0; i < n; i++ )
    {
        for(int j = 0; j < n; j++ )
        {
           scanf("%d",&mat[i][j]);
           //cin>>mat[i][j];
           cur_max = max(cur_max, mat[i][j]);
        }
    }

    for(int i = 0; i < n; i++ )
    {
        memset(sum,0,sizeof(sum));

        for(int j = i; j < n; j++ )
        {
            cur_sum = 0;
            //cur_max = -INF;

            for(int k = 0; k < n; k++ )
            {
                sum[k] += mat[k][j];
                cur_sum = max( 0, cur_sum+sum[k]);
                if(cur_sum > 0) cur_max = max(cur_max, cur_sum);
                //cur_max = max(cur_sum,cur_max);
            }
           // f_max = max(f_max,cur_max);
        }
    }
        cout<<cur_max<<endl;
}

/* Most men die at 25 , We just don't bury them until they are 70 - Benjamin Franklin */

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll x, k, d, ans;
    cin >> x >> k >> d;
    x = abs(x);
    ll count = x / d;
    ll res = k - count;
    if (res<0){
        ans = x - k*d;
        cout << ans << endl;
        return 0;
    }
    x -= d * count;
    if (res%2 == 0) ans = x;
    else ans = abs(x-d);
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 3608
#include<stdio.h>
int main() {
	int a, b, c,d,x;
	scanf("%d",&a);
	b = 0;
	x = 0;
	while (a > b) {
		scanf("%d%d",&c,&d);
		x = x + 1 + (d - c);
		b++;
	}
	printf("%d",x);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  string s,t;
  cin>>s>>t;
  int cum_s[100001]={},cum_t[100001]={};

  cum_s[0]=(s[0]=='A'?1:2);
  cum_t[0]=(t[0]=='A'?1:2);
  for(int i=1;i<s.size();i++){
    cum_s[i]=cum_s[i-1]+(s[i]=='A'?1:2);
  }
  for(int i=1;i<t.size();i++){
    cum_t[i]=cum_t[i-1]+(t[i]=='A'?1:2);
  }

  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;b--;c--;d--;

    int sv=(a-1>=0?(cum_s[b]-cum_s[a-1]):cum_s[b]);
    int st=(c-1>=0?(cum_t[d]-cum_t[c-1]):cum_t[d]);
    cout<<((sv%3==st%3)?"YES":"NO")<<endl;
  }

  return 0;
}


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

bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0) return false;
	}
	return n != 1;  // 1の場合は例外
}

int main(void) {
	int N; cin >> N;
	int cnt=0;
	for (int i = 2; i <= 55555; i++) {
		if (is_prime(i)) {
			if (i % 10 == 1) {
				cout << i <<" ";
				cnt++;
			}
		}
		if(cnt==N) break;
	}
	cout << endl;
}

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

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

    ll x[n];
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }

    ll ans = -1;
    int i = 0;
    ll dis = 0;
    while(1){
        if(i + k - 1 >= n){
            break;
        }
        if(x[i + k - 1] <= 0){
            dis = - x[i];
        }else if(x[i] < 0 && x[i + k - 1] > 0){
            ll m = - x[i];
            ll p = x[i + k - 1];
            if(m < p){
                dis = 2 * m;
                dis += p;
            }else{
                dis = 2 * p;
                dis += m;
            }
        }else if(x[i] >= 0){
            dis = x[i + k - 1];
        }

        if(ans == -1){
            ans = dis;
        }else{
            if(ans > dis){
                ans = dis;
            }
        }
        i++;
    }

    cout << ans << endl;
}

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

using namespace std;

int H, W, N, T, I, x, y, dx, dy;
string field[20];

void show() {
  // cout << "---------" << endl;
  // cout << x << ' ' << y << endl;
  for (int i = 0; i < H; i++)
    cout << field[i] << endl;
  if (I != T-1) cout << endl;
}

void solve() {
  cin >> H >> W;
  for (int i = 0; i < H; i++)
    cin >> field[i];
  for (int j = 0; j < H; j++)
    for (int i = 0; i < W; i++)
      if (field[j][i] == '^' || field[j][i] == 'v' ||
          field[j][i] == '<' || field[j][i] == '>') {
        x = i; y = j;
        goto escape;
      }
escape:
  cin >> N;
  for (int i = 0; i < N; i++) {
    char c;
    cin >> c;
    switch (c) {
    case 'S':
      switch (field[y][x]) {
      case '^':
        dx = 0; dy = -1; break;
      case 'v':
        dx = 0; dy = 1; break;
      case '<':
        dx = -1; dy = 0; break;
      case '>':
        dx = 1; dy = 0; break;
      default:
        break;
      }
      break;
    case 'U':
      dx = 0; dy = -1; field[y][x] = '^'; break;
    case 'D':
      dx = 0; dy = 1; field[y][x] = 'v'; break;
    case 'L':
      dx = -1; dy = 0; field[y][x] = '<'; break;
    case 'R':
      dx = 1; dy = 0; field[y][x] = '>'; break;
    default:
      break;
    }
    if (c == 'S') {
      int p = x, q = y;
      for (;;) {
        p += dx; q += dy;
        if (p < 0 || p >= W || q < 0 || q >= H) break;
        if (field[q][p] == '*') {
          field[q][p] = '.';
          break;
        }
        if (field[q][p] == '#') break;
      }
    } else {
      int p = x + dx, q = y + dy;
      if (0 <= p && p < W && 0 <= q && q < H && field[q][p] == '.') {
        field[q][p] = field[y][x];
        field[y][x] = '.';
        x = p; y = q;
      }
    }
    // show();
  }
  show();
}

int main() {
  cin >> T;
  for (I = 0; I < T; I++)
    solve();
  return 0;
}

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



int main(){
	int n, x, y, i, j, sqsize;
	while(true){
		cin>>n; if(n==0)break;
		vector< vector<int> > sq(n, vector<int>(n, 0));
		sqsize = sq.size() * sq.size();
		x = n/2.0 + 0.5 - 1.0;
		y = n/2.0 + 0.5 - 1.0;
		y = y+1;
		for(i=1;i<=sqsize;i++){
			sq[y][x]=i;
			(x+1<n)? x++: x=0;
			(y+1<n)? y++: y=0;
			if(sq[y][x]!=0){
				(x-1>=0)? x--: x=n-1;
				(y+1<n)? y++: y=0;
			}
		}
		for(i=0;i<n;i++){
			cout<<setw(4)<<sq[i][0];
			for(j=1;j<n;j++){
				cout<<setw(4)<<sq[i][j];
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228