akhauriyash/Code-Regression huggingface dataset:
// problem: longest distance from 0 to V-1, checking for positive cycle only on this path
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1 << 30;

struct Tadj {
	int id, w;
};
vector<vector<Tadj>> adjList;
int V;

vector<ll> ld;

vector<bool> visited;
void dfs(int u) {
   if (visited[u]) return;
   visited[u] = 1;
   for (Tadj v : adjList[u])
      dfs(v.id);
}

/* O(V*E) - retorna true se há um ciclo positivo entre 0 e V-1 */
bool belmman_ford(int s) {
   ld.assign(V, -INF); ld[s] = 0;

   ll first0, first1;
   for (int i = 0; i < V; i++) {
      // para cada aresta u --v.w--> v.id
      for (int u = 0; u < V; u++)
         for (Tadj v : adjList[u]) {
            if (ld[u] + v.w > ld[v.id] && ld[u] > -INF) {
               ld[v.id] = ld[u] + v.w;

               // se ainda conseguiu relaxar depois das V-1 vezes anteriores
               if (i == V-1) {
                  visited.assign(V, 0);
                  dfs(v.id);
                  if (visited[0] || visited[V-1]) return true;
               }
            }
         }
   }

   return false;
}

int main() {
   int E, P; cin >> V >> E >> P;
   adjList.assign(V, vector<Tadj>());
   while (E--) {
      int u, v, w; cin >> u >> v >> w; u--; v--; w -= P;
      adjList[u].push_back({v, w});
   }

   cout << (belmman_ford(0)? -1 : max(ld[V-1], 0ll)) << endl;
}

Measured memory_bytes: 3868
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
bool a[5001][5001];
int main(){
  int i,j;
  int v,w,x[3000],y[3000],n;
  int mx;
  while(cin>>n&&n){
    memset(a,0,sizeof(a));
    for(i=0;i<n;i++){
      cin>>x[i]>>y[i];
      a[x[i]][y[i]]=1;
    }
    mx=0;
    for(i=0;i<n-1;i++){
      for(j=i+1;j<n;j++){
	v=x[i]-x[j];
	w=y[i]-y[j];
	if((x[i]-w>=0&&y[i]+v>=0&&x[j]-w>=0&&y[j]+v>=0&&x[i]-w<=5000&&y[i]+v<=5000&&x[j]-w<=5000&&y[j]+v<=5000&&a[x[i]-w][y[i]+v]&&a[x[j]-w][y[j]+v])||
	   (x[i]+w>=0&&y[i]-v>=0&&x[j]+w>=0&&y[j]-v>=0&&x[i]+w<=5000&&y[i]-v<=5000&&x[j]+w<=5000&&y[j]-v<=5000&&a[x[i]+w][y[i]-v]&&a[x[j]+w][y[j]-v]))
	  if(mx<v*v+w*w)
	    mx=v*v+w*w;
      }
    }
    cout<<mx<<endl;
  }
  return 0;
}

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

using namespace std;

using ll = long long;

struct UnionFind {
    std::vector<int> data;

    UnionFind() {}
    UnionFind(int size) : data(size, -1) {}

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) std::swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -data[root(x)]; }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
};

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

    int n, k, l;
    cin >> n >> k >> l;

    vector<pair<int, int>> pq(k), rs(l);
    for (auto &&x: pq) {
        cin >> x.first >> x.second;
        --x.first; --x.second;
    }
    for (auto &&x: rs) {
        cin >> x.first >> x.second;
        --x.first; --x.second;
    }

    UnionFind uf1(n), uf2(n);
    for (const auto &it : pq) uf1.unite(it.first, it.second);
    for (const auto &it : rs) uf2.unite(it.first, it.second);

    map<pair<int, int>, int> cnt;
    for (int v = 0; v < n; ++v)
        ++cnt[make_pair(uf1.root(v), uf2.root(v))];

    for (int v = 0; v < n; ++v)
        cout << cnt[make_pair(uf1.root(v), uf2.root(v))] << " \n"[v == n - 1];

    return 0;
}


Measured memory_bytes: 15104
MOD = 1000000007
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
T = [0 for _ in range(N + 1)]

for a in A:
    T[a] = -1

T[0] = 1
for i in range(0, N):
    if i + 1 <= N and T[i + 1] != -1 and T[i] != -1:
        T[i + 1] = (T[i + 1] + T[i]) % MOD
    if i + 2 <= N and T[i + 2] != -1 and T[i] != -1:
        T[i + 2] = (T[i + 2] + T[i]) % MOD

print(T[N])


Measured memory_bytes: 7856
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int cnt = 0;
		for(int i = a; i <= b; i++) {
			int v1 = i % 10;//一の位
			int v2 = i / 10 % 10;//十の位
			int v3 = i / 1000 % 10;//千くらい
			int v4 = i / 10000 % 10;//万の位
			if(v1 == v4 && v2 == v3) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

typedef long long int ll;
const ll MOD=1000000007;

int main(){
	ll n,k;
	ll dp[1001][1001]={};
	scanf("%lld %lld",&n,&k);
	if(n<k) printf("0\n");
	else{
		dp[0][0]=1;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=k;j++){
				dp[i][j]+=dp[i-1][j]*j;
				dp[i][j]+=dp[i-1][j-1]*j;
				dp[i][j]%=MOD;
			}
		}
		printf("%lld\n",dp[n][k]);
	}
}


Measured memory_bytes: 11056
def main():
    _len = int(input())
    _str = input()

    if _len < 0 or _len > 100 or _len % 2 : 
        print("No")
        return
    idx = int(_len/2)
    a, b = _str[:idx], _str[idx:]

    print("Yes" if a == b else "No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""

import numpy as np
import sys
""""
import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect
"""

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

"""
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))


def main():
    P = [0]*N
    for n in range(N):
        P[n] = V[n]-C[n]
    P.sort(reverse = True)
    res=0
    for n in range(N):
        if P[n] <= 0:
            break
        else:
            res+=P[n]
            
    print(res)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 21576
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	string s, t;
	cin >> n >> s >> t;
	
	string ret;
	for(int i = 0; i < n; i++) ret += string(1, s[i]) + string(1, t[i]);
	
	cout << ret << endl;

	return 0;
}

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

using namespace std;
int ar[1000000],cc[100050];
vector<pair<int,int> > gg[100050];
map<int,int> o;
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>ar[i];
cc[ar[i]]++;
}
sort(ar,ar+n);
long long h=0,l=0;
for(int i=0;i<100050;i++){
        int x;
        if(cc[i]!=0){
if(cc[i]%2==0)
h++;
else
l++;


        }
}

if(h%2==0)
cout<<l+h;
else
    cout<<l+h-1;






    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S.size() 配列名.Length()
using namespace std;
typedef unsigned long long ll;

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

	vector<bool> broken(n + 1);
	rep(i, m){
		int a;
		cin >> a;
		broken[a] = true;
	}

  vector<int> dp(n + 2);
	dp[n] = 1;
	for(int i = n - 1; i >= 0; --i){
		if(broken[i]) dp[i] = 0;
		else dp[i] = (dp[i + 1] + dp[i + 2]) % MOD;
	}

	cout << dp[0] << endl;
	return 0;
}


Measured memory_bytes: 640
import java.io.*
import java.lang.*


fun solve() {
    val N = rd.readInt()
    val C = IntArray(N)
    for (i in 0 until N) {
        C[i] = rd.readInt()
    }

    val dp = LongArray(N+5){0L}
    val dpSum= LongArray(C.max()!!+5){0L}

    dp[0] = 1L
    dpSum[C[0]] = dp[0]

    for (i in 1 .. N) {
        if (i < N && C[i] == C[i-1]) {
            dp[i] = dp[i-1]
            continue
        }

        dp[i] = dpSum[C[i-1]]

        if (i < N) {
            dpSum[C[i]] = (dpSum[C[i]] + dp[i]) % MOD
        }
    }

    val ans = dp[N]
    println(ans)
}


//val rd = debug.Reader("agc", "031", "b", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 57772
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n; 
  vl num(n);
  
  rep(i,n) cin >> num[i];
  
  ll cnt = 0;
  
  for(ll i=0; i < n; i++){
    for(ll j=i+1; j < n; j++){
      for(ll k=j+1; k < n; k++){
        
        if(num[i]+num[j] > num[k] and num[j]+num[k] > num[i] and
           num[k]+num[i] > num[j] and
           num[i]!=num[j] and num[j]!=num[k] and num[k]!=num[i]) 
          cnt++;
      }
    }
  }
  
  cout << cnt << endl;
  
  
}

Measured memory_bytes: 3628
#include "stdio.h"

#define MDU 998244353

typedef struct SegTree SegTree;
long long tpwm[200010];
long long ones[200010];

struct SegTree{
    int l;
    int r;
    long long val;
    long long tag;
} tree[200010 * 4];

int build(int i, int l, int r) {
    tree[i].l = l;
    tree[i].r = r;
    tree[i].val = ones[r - l + 1];
    if (tree[i].l == tree[i].r) return 0;
    int mid = (tree[i].l + tree[i].r) >> 1;
    build(2 * i, l, mid);
    build(2 * i + 1, mid + 1, r);
    return 0;
}

int push_down (int i) {
    if (tree[i].tag == 0) return 0;
    if (tree[i].l == tree[i].r) {
        tree[i].val = tree[i].tag;
        tree[i].tag = 0;
        return 0;
    }
    else {
        tree[2 * i].tag = tree[i].tag;
        tree[2 * i].val = ones[tree[2 * i].r - tree[2 * i].l + 1] * tree[i].tag % MDU;
        tree[2 * i + 1].tag = tree[i].tag;
        tree[2 * i + 1].val = ones[tree[2 * i + 1].r - tree[2 * i + 1].l + 1] * tree[i].tag % MDU;
        tree[i].tag = 0;
        return 0;
    }
}

int insert(int i, int l, int r, int val) {
    if (tree[i].l >= l && tree[i].r <= r) {
        tree[i].val = ones[tree[i].r - tree[i].l + 1] * val % MDU;
        tree[i].tag = val;
    }
    else {
        push_down(i);
        int mid = (tree[i].l + tree[i].r) >> 1;
        if (mid >= l) insert(2 * i, l, r, val);
        if (mid < r) insert(2 * i + 1, l, r, val);
        tree[i].val = (tree[2 * i].val * tpwm[tree[2 * i + 1].r - tree[2 * i + 1].l + 1] % MDU + tree[2 * i + 1].val) % MDU;
        return 0; 
    }
}

int search(int i, int l, int r) {
    long long res = 0;
    if (tree[i].l >= l && tree[i].r <= r) {
        res += tree[i].val * tpwm[tree[i].l - l] % MDU;
        return res;
    }
    else {
        int mid = (tree[i].l + tree[i].r) >> 1;
        if (mid >= l) res += search(2 * i, l, r);
        if (mid < r) res += search(2 * i + 1, l, r);
        return res % MDU;
    }
    return 0;
}

int main() {
    int N, Q;
    scanf("%d%d", &N, &Q);
    tpwm[0] = 1;
    ones[0] = 0;
    for (int i = 1; i <= N; i++) {
        tpwm[i] = (tpwm[i - 1] * 10) % MDU;
        ones[i] = ((ones[i - 1] * 10) % MDU + 1) % MDU;
    }
    build(1, 1, N);
    for (int i = 0; i < Q; i++) {
        int L, R, D;
        scanf("%d%d%d", &L, &R, &D);
        insert(1, L, R, D);
        printf("%d\n", search(1, 1, N));
    }
    return 0;
    
}

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

int main(){
    long N,K,tmpa,tmpb;
    cin >> N >> K;
    long list[100001] = {0};

    for (long i=0; i<N; i++){
        cin >> tmpa >> tmpb;
        list[tmpa] = list[tmpa] + tmpb; 
    }
    
    long cnt = 0;
    for(long i=0; i<100001; i++){
        cnt += list[i];
        if(cnt >= K){
            cout << i << endl;
            break;
        }
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k;
main(){
	int c = 1;
	cin >>k >> n >> m;
	if(k <= n or m-n <= 2){
		c += k;
	}else{
		k-=(n-1);
		c = n;
		int rol =(k)/2;
		c += (m-n)*rol;
		c += (k%2);
	}
	cout<<c<<endl;

}



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

int main()
{
    int H, W;

    while (cin >> H >> W && H && W) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++)
                cout << (((i + j) % 2)? '.' : '#');
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<int,int> > section;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    section.push_back(make_pair(b-2,a-1));
  }
  sort(all(section));
  int ans = 0;
  int now = -1;
  for(p:section){
    int start = p.second;
    int goal  = p.first;
    if(start<=now) continue;
    ans++;
    now = goal;
  }
  cout << ans << endl;
}



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

bool prime(ll n){
  for(ll i=2;i*i<=n;i++){
    if(n%i==0) return false;
  }
  return true;
}
 
int main(){
  ll n;
  cin>>n;
  while(true){
    if(prime(n)){
      cout<<n<<endl;
      return 0;
    }
    n++;
  }
}


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

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  int64_t result = N - 1;
  for (int64_t i = 2; i * i <= N; ++i) {
    if (N % i != 0) continue;
    int64_t tmp = (i - 1) + ((N / i) - 1);
    if (tmp < result) {
      result = tmp;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;

int power10_memo[11];

int fact_memo[11];
int nchoosek(int n, int k){
    return fact_memo[n]/(fact_memo[n-k]*fact_memo[k]);
}
long long formulas(string in){
    vector<int> digit_nums;
    
    fact_memo[0] = 1;
    power10_memo[0] = 1;
    for(int i = 1; i < 11; i++){
        fact_memo[i] = fact_memo[i-1]*i;
        power10_memo[i] = power10_memo[i-1]*10;
    }
    int combs = 0;
    int n = in.length()-1;
    for(int k = 0; k <= in.length()-1; k++)
        combs += nchoosek(n, k);
    digit_nums.insert(digit_nums.begin(), combs);
    long long sum = 0;
    for(int i = in.length()-1; i >= 0; i--){
        
        for(int j = digit_nums.size()-1; j >= 0; j--){
            int num_times = digit_nums[j];
            sum += num_times*(long long)power10_memo[digit_nums.size()-1-j]*(in[i]-48);
        }
        digit_nums[0] /= 2;
        digit_nums.insert(digit_nums.begin(), digit_nums[0]);
        
    }
    return sum;
}

int main()
{
    string input;
    cin >> input;
    
    cout << formulas(input) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int t[7],n[7],i,x;
	for(i=0;i<4;i++){
		scanf("%d %d",&t[i],&n[i]);
		if(t[i]==1) x=n[i]*6000;
		else if(t[i]==2) x=n[i]*4000;
		else if(t[i]==3) x=n[i]*3000;
		else x=n[i]*2000;
		printf("%d\n",x);
	}
	return 0;
}


Measured memory_bytes: 2068
#include <stdio.h>
int main(){
    long int n,a,b;
    scanf("%ld %ld %ld",&n,&a,&b);
    if(n%(a+b) >= a) printf("%ld",(n/(a+b)) * a + a);
    else printf("%ld",(n/(a+b)) * a + n%(a+b));
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,m,x,y,ans=0;
vector <int> g[100010];
bool vis[100010];

void dfs(int pos)
{
	vis[pos]=true;
	rep(i,g[pos].size()) if(!vis[g[pos][i]]) dfs(g[pos][i]);
}

int main()
{
	cin>>n>>m;
	rep(i,m)
	{
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	repn(i,n)
	{
		if(vis[i]) continue;
		ans++;
		dfs(i);
	}
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 9816
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main(void) {
	int n,a,b,worst=0,ans;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a >> b;
		if(a>worst){
			worst=a;
			ans=b;
		}
	}
	cout << worst+ans << endl;
	return 0;
}

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

const int mod = 1000000007;
//const int mod = 998244353;
const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dj[] = {0, -1, 0, 1, -1, 1, -1, 1};

struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];
    rep(i, 0, h){
        rep(j, 0, w) {
            if(s[i][j] == '#'){
                cout << '#';
                continue;
            }
            int cnt = 0;
            rep(dir, 0, 8){
                int ni = i + di[dir], nj = j + dj[dir];
                if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if(s[ni][nj] == '#') cnt++;
            }
            cout << cnt;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
from fractions import Fraction

def calc(s):
    n = ans = 0
    while len(s) >= 4:
        if s[-4] == 'w':
            s = s[:-4]
            if n == 0:
                ans = Fraction(90,1)
            else:
                ans += Fraction(90, 2**n)
        else:
            s = s[:-5]
            if n == 0:
                ans = Fraction(0,1)
            else:
                ans -= Fraction(90, 2**n)
        n += 1
    return ans

while True:
    S = input()
    if S == '#': break
    print(calc(S))

Measured memory_bytes: 6840
#include<bits/stdc++.h> 
#include<random> 
#define int long long 
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back 
#define mod 1000000007 
#define mk(arr,n,type) type *arr=new type[n]; 
#define sl s1.length(); 
#define yes cout<< "Yes"<<endl 
#define no cout<< "No"<<endl 
#define all(v) (v).begin(),(v).end() 
#define mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
using namespace std; 
void fastio() 
{ 
    #ifndef ONLINE_JUDGE 
    freopen("INPUT.txt","r",stdin); 
    freopen("OUTPUT.txt","w",stdout); 
    #endif 
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL) ; 
    cout.tie(NULL); 
    
}
int dp(int a[],int n)
{
    if(n==0)
    return 0;
    if(n==1)
    return a[n-1];
    if(n==2)
    return abs(a[n-1]-a[n-2]);
    if(abs(a[n-1]-a[n-3])<=abs(a[n-1]-a[n-2]))
    return abs(a[n-1]-a[n-3])+dp(a,n-2);//dp(a,n-3));
    else
    return dp(a,n-1)+abs(a[n-1]-a[n-2]);//,dp(a,n-2));
    //return min(abs(a[n-1]-a[n-2])+dp(a,n-1),abs(a[n-1]-a[n-3])+dp(a,n-2));
}
signed main() 
{ 
    fastio(); 
    int t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        int ss=0;
        for(int i=0;i<s.length();i++)
        {
            ss+=s[i]-'0';
        }
        //cout<<ss;
        if(ss%9==0)
        cout<<"Yes\n";
        else
        cout<<"No\n";
    }
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int a[125252];

const int N = 1<<17;
int dat[2*N];
void qset(int i, int x){
    i += N-1;
    dat[i] = x;
    while(i>0){
        i=(i-1)/2;
        dat[i] = max(dat[2*i+1],dat[2*i+2]);
    }
}
int qmax(int l, int r, int a, int b, int k){
    if(r<=a || b<=l)return -1<<30;
    if(l<=a && b<=r)return dat[k];
    int m = (a+b)/2;
    return max(qmax(l,r,a,m,2*k+1),qmax(l,r,m,b,2*k+2));
}

int main(){
    scanf("%d",&n);
    REP(i,n)scanf("%d",a+i);
    int ans = 0;
    fill(dat,dat+2*N,-1<<30);
    REP(i,n)qset(i,a[i]);
    set<int> ids;
    REP(i,n)ids.insert(i);
    while(ids.size()){
        ans++;
        int c = *ids.begin(); ids.erase(c);
        qset(c,-1<<30);
        while(true){
            int l = c+1;
            int ok = n+1;
            int ng = l;
            while(abs(ok-ng)>1){
                int x = (ok+ng)/2;
                (qmax(l,x,0,N,0)>a[c] ? ok : ng) = x;
            }
            if(ok==n+1)break;
            c = ok-1;
            ids.erase(c); qset(c,-1<<30);
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 7936
#include <iostream>
using namespace std;
#define ll long long


int N;
ll K;
int a,b;
int ab[100010] = {};



int solve(){
	ll count=0;
	int ans;
	int i=1;
	while(count < K && i <= 100000){
		ans = i;
		count += ab[i];
		i++;
	}
	cout << ans << endl;
	return 0;
}



int main(){
	cin >> N >> K;
	for(int i=0; i<N; i++){
		cin >> a >> b;
		ab[a] += b;
	}
	solve();
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long

int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}

int get(int a,int m){
    int c=0,x=1;
    do{
        x=x*a%m;
        c++;
    }while(x!=1);

    return c;
}

signed main(){
    int a,b,c,l,m,n;
    while(cin>>a>>l>>b>>m>>c>>n){
        if(!a&&!b&&!c&&!l&&!m&&!n)break;
        cout<<lcm(get(a,l),lcm(get(b,m),get(c,n)))<<endl;
    }
    return 0;
}

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

deque<pair<double, int> > q;

int n, L;

int main(void) {
  scanf("%d%d", &n, &L);
  double Ans = 0, t;
  for(int i = 1, v; i <= n; i++) {
    scanf("%lf%d", &t, &v);
    int res = v;
    while(!q.empty()) {
      pair<double, int> x = q.front(); q.pop_front();
      if(x.second > res) {
	x.second -= res;
	Ans -= x.first * res;
	q.push_front(x);
	break;
      } else {
	Ans -= x.second * x.first;
	res -= x.second;
      }
    }

    Ans += t * v;
    printf("%.10f\n", Ans / L);
    
    while((!q.empty()) && (q.back().first >= t)) {
      pair<double, int> x = q.back(); q.pop_back();
      t = (v * t + x.first * x.second) / (v + x.second);
      v += x.second;
    }
    q.push_back(make_pair(t, v));
  }
}
	   


Measured memory_bytes: 18704
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll> parent(n,-1);
    vector<vector<ll> > G(n);
    map<pll,ll> ind;
    for(ll i=1;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        G[a].pb(b);
        G[b].pb(a);
        ind[mp(a,b)]=i-1;
        ind[mp(b,a)]=i-1;
        parent[b]=a;
    }
    queue<ll> q;
    vector<bool> vis(n,0);
    vector<ll> colour(n-1,0);
    q.push(0);
    vis[0]=1;
    while(!q.empty())
    {
        ll v = q.front();
        q.pop();
        ll cc=0;
        ll nu=-1;
        if(parent[v]!=-1)
        {
            nu = colour[ind[mp(parent[v],v)]];
        }
        for(auto x:G[v])
        {
            if(vis[x]==0)
            {
                vis[x]=1;
                if(cc==nu)
                {
                    cc++;
                    colour[ind[mp(v,x)]] = cc;
                    cc++;
                    }
                else
                {
                    colour[ind[mp(v,x)]] = cc;
                    cc++;
                }
                q.push(x);
            }
        }
    }
    ll ans = *max_element(colour.begin(),colour.end());
    cout<<ans+1<<endl;
    for(auto x:colour)
    {
        cout<<x+1<<endl;
    }
    return 0;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 H, N;
	cin >> H >> N;
	vector<int64> A(N);
	REP(i, N) cin >> A[i];
	int64 sum = accumulate(all(A), 0LL);
	cout << (sum < H ? "No" : "Yes") << endl;
}


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

using namespace std;
//131073
typedef pair<int, int> pii;
typedef long long ll;

const int maxn = 100000 + 10;
int a[maxn];

int main(){
    ios_base::sync_with_stdio(0);
     cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    int idx = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    cout << (int)ceil((n - 1) * 1./(k - 1)) << endl;
    return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python3

def main():
    a,b,k = map(int,input().split())
    s = list(set(range(a,min(a+k,b+1))) | set(range(max(b-k+1,a),b+1)))
    s = sorted(s)

    for i in range(len(s)):
        print(s[i])


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
// inputに入力データ全体が入る
    function Main(input) {
    	input = input.split("\n");

      var N = parseInt(input[0], 10);
      
      if (parseInt(N / 10) === 0){ // 1桁の時
        console.log('Yes');
        return;  
      }

      var Sum = 0;
      var Mod = N; // 余り
      for (var i = 100000000; i >= 10; i = i / 10){
        Sum += parseInt(Mod / i);
        Mod = Mod % i;
        // console.log('%d', i);
        // console.log('%d', Sum);
        // console.log('%d', Mod);
        // console.log('--');        
      }
      Sum += Mod;
      // console.log('%d', Sum);
      // console.log('%d', Mod);
      // console.log('--');   

      if( N % Sum === 0){
      	console.log('Yes');
      }else{
        console.log('No');
      }
    
    }

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



Measured memory_bytes: 7372
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int a = sc.nextInt();
        if (h % a == 0) {
            System.out.println(h / a);
            return;
        }
        System.out.println(h / a + 1);
    }

}


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

int main(void){
    int n;
    cin >> n;
    vector<pair<pair<string,int>/* レストラン情報 */,int/* 入ってきた順番の番号 */>> rest(n);
    for(int i = 0;i < n;i++){
        cin >> rest[i].first.first >> rest[i].first.second;
        rest[i].first.second *= -1; //点数は降順でソートしてほしいので、-1を掛けてソート結果が逆になるようにする
        rest[i].second = i+1;
    }

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

    for(int i = 0;i < n;i++){
        cout << rest[i].second << endl;
    }

    return 0;
}

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

int main() {
        string S;
        int ans=0;

        cin >> S;

        for(int i=0; i<4; i++){
                if(S[i]=='+')ans++;
                else ans--;
        }
        cout << ans <<endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define rlp(i,n) for(int i = int(n);i >= 0;i--)
#define range1(i,a,b,c) for(int i = int(a);i <= int(b);i+=int(c))
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define sz(v) ((int)((v).size()))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void _run(){
   int n;
   cin>>n;
   vi v;
   v.resize(n);
   set<pair<int,pair<int,int>>>s;
   lp(i,n){
       cin>>v[i];
   }
   int ans =0;
   for(int i=0;i<n;i++){
       for(int j=0;j<n;j++){
           if(j==i)continue;
           for(int k=0;k<n;k++){
               if(k==j||k==i)continue;
               vi temp;
               if(v[i]!=v[j]&&v[j]!=v[k]&&v[i]!=v[k]){
                    temp.pb(v[i]);
                    temp.pb(v[j]);
                    temp.pb(v[k]);
                    sort(all(temp));
                    if(temp[0]+temp[1]>temp[2]&&temp[1]+temp[2]>temp[0]&&temp[0]+temp[2]>temp[1]&&!s.count({i,{j,k}})){
                        ans++;
                        // cout<<i<<" "<<j<<" "<<k<<endl;
                        s.insert({i,{j,k}});
                        s.insert({i,{k,j}});
                        s.insert({j,{i,k}});
                        s.insert({j,{k,i}});
                        s.insert({k,{j,i}});
                        s.insert({k,{i,j}});

                    }
                    
               }
           }
       }
   }
//    for(auto x:s){
//        cout<<x.first<<" "<<x.sc.fr<<" "<<x.sc.sc<<endl;
//    }
   cout<<ans<<endl;
}
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int t=1;
    // scanf("%d",&t);
    while(t--)_run();
    
    return 0;
}

Measured memory_bytes: 64020
import sys
input = sys.stdin.readline 
N=int(input())
L=list(map(int,input().split()))
Q=int(input())
R=[0]*(10**5)
for i in L:
  R[i-1]+=1
ans=sum(L)
for i in range(Q):
  a,b=map(int,input().split())
  R[b-1]+=R[a-1]
  ans+=(b-a)*R[a-1]
  R[a-1]=0
  print(ans)

Measured memory_bytes: 20268
#include<bits/stdc++.h>
#define infl INT_MAX
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
     int n,k;
     cin>>n>>k;
     int h[n],dp[n];
     for(int i=0;i<n;i++)
     {
     	cin>>h[i];
     	dp[i]=infl;
	 }
     dp[0]=0;

     for(int i=0;i<n;i++)
     {
     	
     	for(int j=1;j<k+1;j++)
     	{
     		if(i+j<n)
     		dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
		}
		
	 }
     cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long ll;
ll n, a[210000], res, ans;

bool func(ll x, ll y){
    bool t = true;
    while(x && y){
        if (x % 2 && y % 2) t = false;
        x /= 2, y /= 2;
    }
    return t;
}

int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++) cin >> a[i];
    ll j = 0;
    for (ll i = 0; i < n; i++) {
        while(j < n && func(res, a[j])) {
            res += a[j];
            j++;
        }
        ans += j - i;
        res -= a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
//
#include<bits/stdc++.h>
 
using namespace std;
 
#define PB push_back
#define f first
#define s second
 
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
 
const int MOD = 1000000007;
const int INF = 1000000007;
 
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int s, w;
    cin >> s >> w;
    if(w >= s)
    {
        cout << "unsafe";
    }
    else
        cout << "safe";
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main(){
	int n;
	int min=2000000000;
	int tmp=-2000000000;
	cin >> n;
	int x;
	for( int i=0 ; i<n ; i++ ){
		cin >> x;
	//	cout <<"       "<<x<<"  "<<min << endl;
		if( tmp < x-min && i!=0)
			tmp = x-min;
		if( min > x || i==0 )
			min = x;
		//cout << tmp <<"  " << min << endl;
	}
	cout << tmp << endl;
}

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

using namespace std;

int main(){
 

  while(1){
    int d, e;
    cin >> d >> e;
    if(d == 0 && e == 0) break;
    double sa = 0, min = 100000;

    int j = 0;
    for(int i = d ; i >= 0 ; i--){
      sa = abs(sqrt(i*i + j*j) - e);
      if(min > sa){
	min = sa;
      }
      j++;
    }
    cout << min << endl;
  }
}

Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define X first
#define Y second
using namespace std;

int main(){
	int w, h;
	cin >> h >> w;
	vector<vector<int> > dp(h, vector<int>(w, 0));
	for(int i = 0; i < h; i++){
		string val;
		cin >> val;
		for(int j = 0; j < w; j++){
			if(!i&&!j){
				dp[i][j] = val[j]-'0';
				continue;			
			}
			int valL = 20000, valU = 20000;
			if(j > 0) valL = dp[i][j-1];
			if(i > 0) valU = dp[i-1][j];
			dp[i][j] = valL > valU ? valU+(val[j]-'0') : valL+(val[j]-'0');
		}
	}
	cout << dp[h-1][w-1] << endl;
	return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;
int a[5];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	int ans=inf;
	for(int i=0;i<3;i++){
		for(int j=i+1;j<3;j++){
			ans=min(ans,a[i]+a[j]);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
def main():
    S = input()
    T = input()
    ns, nt = len(S), len(T)
    if nt > ns: return "UNRESTORABLE"
    cand = []
    for i in range(ns-nt+1):
        isFound = True
        for j in range(nt):
            if S[i+j] != "?" and S[i+j] != T[j]:
                isFound = False
                break
        if isFound:
            cand.append(S[:i] + T + S[i+nt:])
    if len(cand) == 0:
        return "UNRESTORABLE"
    else:
        filled = []
        for s in cand:
            t = ""
            for c in s:
                t += "a" if c == "?" else c
            filled.append(t)
        filled = sorted(filled)
        return filled[0]


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char[] arr = br.readLine().toCharArray();
        int score = 0;
        for (int i = 0; i < arr.length; i++) {
            if (i % 2 == 0) {
                if (arr[i] == 'p') {
                    score--;
                }
            } else {
                if (arr[i] == 'g') {
                    score++;
                }
            }
        }
        System.out.println(score);
    }
}

Measured memory_bytes: 23892
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	int N, M;
	cin >> N >> M;
	vector<set<int>>G(N);
	int a, b;
	rep(i, M) {
		cin >> a >> b;
		a--; b--;
		G[a].insert(b);
		G[b].insert(a);
	}

	bool ok = true;

	vector<int> v;
	rep(i, N) {
		v.push_back(i);
	}
	int ans = 0;
	do {
		if (v[0] == 0) {
			ok = true;
			rep(i, N - 1) {
				if (G[v[i]].count(v[i + 1])) {

				}
				else {
					ok = false;
				}
			}
			if (ok) {
				ans++;
			}
			ok = true;
		}
		

		

	} while (next_permutation(v.begin(), v.end()));
	cout << ans << endl;
}

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

typedef long long int ll;

const int MAX_N = 1001;
const int MAX_M = 1001;

const ll INF = (1LL << 60);

int main(){
  int N,M;
  ll x[MAX_N], y[MAX_N], z[MAX_N];
  cin >> N >> M;
  
  for(int i = 0 ; i < N ; i++){
    cin >> x[i] >> y[i] >> z[i];
  }

  ll res = 0;
  for(int i = 0 ; i < (1 << 3) ; i++){
    vector<ll>vec;
    for(int j = 0 ; j < N ; j++){
      ll sum = 0;
      if(i & 1)sum += x[j];
      else sum -= x[j];

      if((i >> 1) & 1)sum += y[j];
      else sum -= y[j];

      if((i >> 2) & 1)sum += z[j];
      else sum -= z[j];

      vec.push_back(sum);
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    ll r = 0;
    for(int j = 0 ; j < M ; j++){
      r += vec[j];
    }
    res = max(res, r);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#define ll long long
#define debug cout<<"debug"<<endl;
using namespace std;
const int maxn=2e5+50;
char s[maxn];
int c[maxn],cnt[maxn],ok,n;
bool vis[maxn];
vector<int> loc[30];///vector要放在main函数外 不然tle 

int lowbit(int x){
	return x&(-x);
}

void add(int x,int d){
	for(int i=x;i<=n;i+=lowbit(i)){
		c[i]+=d;
	}
}

int sum(int x){
	int ret=0;
	for(int i=x;i>0;i-=lowbit(i)){
		ret+=c[i];
	}
	return ret;
}

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
		memset(c,0,sizeof(c));
		memset(cnt,0,sizeof(cnt));
		memset(vis,0,sizeof(vis));
		ok=0; 

		for(int i=1;i<=n;i++){
			cnt[s[i]-'a']++;
			loc[s[i]-'a'].push_back(i);
		}
		for(int i=0;i<26;i++){
			if(cnt[i]%2) ok++;
		}
		if(ok>1){
			printf("-1\n");
			return 0;
		}
		for(int i=1;i<=n+1;i++){
			add(i,1);
		}
		ll ans=0;
		for(int i=1;i<=n;i++){
			if(vis[i]) continue;
			int c=s[i]-'a';
			int loc_right=loc[c].back();
			if(loc_right==i){
				ans+=(sum(n)-sum(loc_right))>>1;///当遍历到只有一个字母的时候 根据对称性得 
			}
			else{
				ans+=sum(n)-sum(loc_right);
			}
			loc[c].pop_back();
			add(i,-1); 
			add(loc_right,-1);
			vis[i]=vis[loc_right]=true;
		}
		printf("%lld\n",ans);
		//memset(s,0,sizeof(s));
	return 0;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){

    long long n;
    string s,t;

    cin >> n;
    cin >> s;
    cin >> t;

    long long i=0;
    for(;i<s.size();i++){
       // cout << s.substr(i,s.size()-i) <<" : "<< t.substr(0,s.size()-i)<<endl;
        if(s.substr(i,s.size()-i) == t.substr(0,s.size()-i)){
            break;
        }
    }
    cout << (s + t.substr(s.size()-i,i)).size();

}


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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int w,a,b;
	cin>>w>>a>>b;
	if(b>a+w) cout<<b-a-w<<'\n';
	else if(a>b+w) cout<<a-b-w<<'\n';
	else cout<<0<<'\n';
}




Measured memory_bytes: 3660
// https://atcoder.jp/contests/arc062/tasks/arc062_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    string s;
    cin >> s;
    int len = s.length(), ans = 0;
    // グーパーと繰り返すのが最適
    REP(i, len) {
        if (i % 2 == 0) {
            // 自分がグーのとき相手がパーなら負け
            if (s[i] == 'p') {
                ans--;
            }
        } else {
            // 自分がパーのとき相手がグーなら勝ち
            if (s[i] == 'g') {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3760