akhauriyash/Code-Regression huggingface dataset:
A, B, C, X, Y = map(int, input().split())
C *= 2
if X == Y:
    print(min(X * C, X * (A + B)))
if X > Y:
    print(min(C * Y, A * Y + B * Y) + min(C, A) * (X - Y))
if Y > X:
    print(min(C * X, A * X + B * X) + min(C, B) * (Y - X))


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

int westnum[500000] = { 0 }, eastnum[500000] = {0};

int main() {
	
	int n, ans = INF;
	string s;
	cin >> n >> s;

	for (int i = 0; i < n; i++) {
		if (i == 0 && s[0] == 'W') {
			westnum[0]++;
			continue;
		}
		westnum[i] = westnum[i - 1];
		if (s[i] == 'W')westnum[i]++;
	}

	for (int i = n-1; i >=0; i--) {
		if (i == n-1 && s[n-1] == 'E') {
			eastnum[n-1]++;
			continue;
		}
		eastnum[i] = eastnum[i + 1];
		if (s[i] == 'E')eastnum[i]++;
	}


	for (int i = 0; i < n; i++) {
		int cnt = 0;
		cnt = westnum[i] + eastnum[i] - 1;
		ans = min(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll all = 0;
    rep(i,n) all += a[i];
    vector<ll> d;
    for(ll i=1;i*i<=all;i++){
        if(all%i==0){
            d.push_back(i);
            d.push_back(all/i);
        }
    }

    ll ans = 1;
    for(ll t:d){
        vector<ll> rem(n);
        rep(i,n) rem[i] = a[i]%t;
        sort(rem.begin(),rem.end());
        vector<ll> cum(n);
        rep(i,n) cum[i] = t - rem[i];
        for(ll i=n-2;i>=0;i--) cum[i] += cum[i+1];
        ll now = 0;
        ll res = max(now,cum[0]);
        rep(i,n-1){
            now += rem[i];
            res = min(res,max(now,cum[i+1]));
        }
        now += rem[n-1];
        res = min(res,max(now,0LL));
        if(res <= k) ans = max(ans,t);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		// make(3,4);
		// test();
		for(;;){
			int n=sc.nextInt();
			int m=sc.nextInt();
			int k=sc.nextInt();
			if((n|m|k)==0){
				break;
			}
			solve(n, m, k);
		}
	}

	void test(){
		int m=4;
		int[] a=new int[m*3+1];
		for(int i=1; i<=m; i++){
			// a[i]++;
			for(int j=1; j<=m; j++){
				// a[i+j]++;
				for(int k=1; k<=m; k++){
					a[i+j+k]++;
				}
			}
		}
		for(int i=0; i<a.length; i++){
			debug(i, a[i]);
		}
	}

	void solve(int n, int m, int cut){
		int[] a=new int[n*m+2];
		int[] b=new int[n*m+2];
		for(int i=1; i<=m; i++){
			a[i]=1;
		}
		for(int j=1; j<n; j++){
			System.arraycopy(a, 0, b, 0, n*m+1);
			// debug(a);
			// bツづーツ用ツつ「ツづツづーツ更ツ新
			Arrays.fill(a, 0);
			for(int i=1; i<=m; i++){
				for(int k=j;; k++){
					if(b[k]==0){
						break;
					}
					a[i+k]+=b[k];
				}
			}
		}
		// debug(a);

		double sum=Math.pow(m, n);
		double ans=0;
		for(int i=0; i<a.length; i++){
			int bill=Math.max(1, i-cut);
			ans+=a[i]*bill/sum;
		}
		println(ans+"");
	}

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

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		try{
			// System.setIn(new FileInputStream("in.txt"));
		}catch(Throwable e){
			e.printStackTrace();
		}
		new Main().run();
	}
}

Measured memory_bytes: 12000
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	
	static BufferedReader reader;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		
		int[] is = readLine().chars().toArray();
		
		boolean before = is[0]=="1".charAt(0);
		int cnt = 0;
		for(int i=0;i<is.length;i++) {
			char c = (char) is[i];
			if(c==-1) break;
			if(before^(c=="1".charAt(0))) {cnt++;}
			before = !before;
		}
		if(cnt*2>is.length) {System.out.println(is.length-cnt);}
		else {System.out.println(cnt);}
		
	}

	private static String readLine(){
		try{
			return reader.readLine();
		}catch(Exception e){
			return e.getMessage();
		}
	}
}


Measured memory_bytes: 28628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n=sc.nextInt();
	
	if(n>=30) {
		System.out.println("Yes");
	}else {
		System.out.println("No");
	}
	
	sc.close();
	}
}


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

int main() {
	string Ans[6] = { "abc","acb","bac","bca","cab","cba" };
	string S;
	cin >> S;
	for (int i = 0; i < 6; i++) if (S == Ans[i]) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main( void ) {

    int N, count;
    cin >> N;
    count = 0;

    for ( int i = 1; i <= N; i++ ) {
        if ( i % 2 == 1 ) {
            count++;
        }
    }

    cout << (double)count  / N << endl;


    return 0;   
}

Measured memory_bytes: 256
S = input()

a1, a2 = -1, -1
for i in range(26):
    t = chr(ord('a') + i)

    s0 = ''
    s1 = ''
    for j, s2 in enumerate(S):
        if s2 == t:
            if s2 == s1:
                a1, a2 = j, j + 1
                break
            elif s2 == s0:
                a1, a2 = j - 1, j + 1
                break
        s0, s1 = s1, s2
    else:
        continue
    break

print(a1, a2)


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

using namespace std;

int n;
const int N = 110;
int A[N][N];
typedef pair<int, int> P;
vector<P> G[N];

struct Edge {
    int u, v, cost;
    
    bool operator<(const Edge& other) const {
        return cost < other.cost;
    }
};

vector<Edge> edges;
vector<int> parent(N), height(N);

int min_cost = 0;

void prim() {
    priority_queue<P, vector<P>, greater<P>> heap;
    heap.push({0, 1});
    vector<bool> vis(n + 1, false);
    vector<int> dis(n + 1, INT_MAX);

    while (!heap.empty()) {
        int u = heap.top().second, cost = heap.top().first;
        heap.pop();
        if (vis[u]) continue;
        vis[u] = true;
        min_cost += cost;
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i].second, len = G[u][i].first;
            if (!vis[v] && len < dis[v]) {
                dis[v] = len;
                heap.push({len, v});
            }
        }
    }    
}

void init() {
  for (int i = 1; i <= n; i++) {
    parent[i] = i;
    height[i] = 1;
  }
}

int find(int x) {
  if (parent[x] == x) return x;
  return parent[x] = find(parent[x]);
}

void merge(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (height[x] < height[y]) {
        parent[x] = y;
    } else {
        parent[y] = x;
        if (height[x] == height[y]) height[x]++;
    }
}

void kruskal() {
    sort(edges.begin(), edges.end());
    init();
    for (auto &edge : edges) {
        int u = edge.u, v = edge.v, cost = edge.cost;
        
        if (find(u) != find(v)) {
            merge(u, v);
            min_cost += cost;
        }
    }
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> A[i][j];
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (A[i][j] != -1)
            edges.push_back({i, j, A[i][j]});
        }
    }

    kruskal();
    // prim();
    cout << min_cost << endl;

    return 0;
}


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

using namespace std;

int main()
{
    int N, W;
    cin >> N;
    vector<int> X(N), Y(N);
    map<int, map<int, int>> coor;
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i] >> W;
        coor[X[i]][Y[i]] = W;
    }
    int res = 0;
    for (int i = 0; i < N; i++) {
        res = max(res, coor[X[i]][Y[i]] +
                       coor[X[i]+1][Y[i]] +
                       coor[X[i]][Y[i]+1] +
                       coor[X[i]+1][Y[i]+1]);

        res = max(res, coor[X[i]][Y[i]] +
                       coor[X[i]+1][Y[i]] +
                       coor[X[i]][Y[i]-1] +
                       coor[X[i]+1][Y[i]-1]);
    }
    cout << res << " / " << 1 << endl;
    return 0;
}

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

vector <int> vec;
int main()
{
    int n,t,T,c,flag=0;
    cin>>n>>T;
    for(int i=0;i<n;i++)
    {
        cin>>c>>t;
        if(t<=T)
        {
            vec.push_back(c);
            flag++;
        }
    }
    sort(vec.begin(),vec.end());

    if(flag!=0)
    {
        cout<<vec[0]<<endl;
    }
    else
        cout<<"TLE"<<endl;
}


Measured memory_bytes: 256
A, B =map(int, input().split())
num_palin = [0] * (B+1)
for i in range(1,B+1):
    if str(i) == str(i)[::-1]:
        num_palin[i] = num_palin[i-1] + 1
    else:
        num_palin[i] = num_palin[i-1]
print(num_palin[B]-num_palin[A-1])


Measured memory_bytes: 9452
from collections import deque

H,W=map(int,input().split())
S=[input() for i in range(H)]
black=0
for i in range(H):
    black+=S[i].count("#")

C=[[0 for _ in range(W)] for j in range(H)]
F=[[False for _ in range(W)] for j in range(H)]

def bfs():
    q=deque([[0,0]])
    F[0][0]=True
    d=[[0,1],[1,0],[-1,0],[0,-1]]
    while q:
        y,x=q.popleft()
        for a,b in d:
            ny=y+a
            nx=x+b
            if 0<=ny<H and 0<=nx<W:
                if S[ny][nx]=="." and F[ny][nx]!=True:
                    q.append([ny,nx])
                    C[ny][nx]=C[y][x]+1
                    F[ny][nx]=True
bfs()
if F[H-1][W-1]==False:
    print(-1)
    exit()

ans=H*W-C[H-1][W-1]-1-black
print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int a[n+1],b[n+1],c[n+1];
  for(int i=1;i<=n;i++)
          cin >> a[i];
  for(int i=1;i<=n;i++)
          cin >> b[i];
  for(int i=1;i<=n;i++)
          cin >> c[i];
  unsigned long long int sum=b[a[1]];
  for(int i=2;i<=n;i++)
  {
            sum+=b[a[i]];
            if(a[i]-a[i-1]==1)
            {
                      sum+=c[a[i-1]];
            }
  }
  cout << sum <<  endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace AOJ.Volume5
{
    public class Change
    {
        public static int Main()
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }

                int c = 1000 - n;
                int answer = 0;
                // 500??????1?????\???????????????
                if (c >= 500)
                {
                    answer++;
                    c -= 500;
                }
                // 100???
                while (c >= 100)
                {
                    answer++;
                    c -= 100;
                }
                // 50???
                if (c >= 50)
                {
                    answer++;
                    c -= 50;
                }
                // 10???
                while (c >= 10)
                {
                    answer++;
                    c -= 10;
                }
                // 5???
                if (c >= 5)
                {
                    answer++;
                    c -= 5;
                }
                // 1???
                answer += c;
                Console.WriteLine(answer);
            }
            return 0;
        }
    }
}

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

void dfs(int n, int &t, vector< vector<int> >& g, vector<int>& d, vector<int>& f, vector<bool>& seen)
{
    t++;
    if (d[n] == 0) d[n] = t;
    seen[n] = true;
    for (int i = 0; i < g[n].size(); i++)
    {
        if (seen[g[n][i]]) continue;
        dfs(g[n][i], t, g, d, f, seen);
    }
    t++;
    f[n] = t;
}

int main()
{
    int n; cin >> n;
    vector< vector<int> > g(n, vector<int>());
    for (int i = 0; i < n; i++)
    {
        int u, k; cin >> u >> k; u--;
        for (int j = 0; j < k; j++)
        {
            int v; cin >> v; v--;
            g[u].push_back(v);
        }
    } 
    vector<int> d(n, 0);
    vector<int> f(n, 0);
    vector<bool> seen(n, false);
    int t = 0;
    for (int i = 0; i < n; i++)
        if (seen[i] == false)
            dfs(i, t, g, d, f, seen);
    for (int i = 0; i < n; i++)
    {
        cout << i + 1 << " " <<  d[i] << " " << f[i] << endl;
    }
}


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

const int N = 16;
const int mod = 1000000007;
typedef long long  ll;

ll cost[(1<<16)+10];
int n;
ll arr[N+5][N+5];
ll dp[(1<<16)+10];

ll rec(int mask)
{
    if(mask==0) return 0;
    ll &ret=dp[mask];
    if(ret!=-1) return ret;
    ret=0;
    for(int i=mask; i>0; i=(i-1)&mask)
    {
        ret=max(ret,cost[i]+rec(mask^i));
    }
    return ret;
}

int main()
{
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++) scanf("%lld",&arr[i][j]);
    }
    for(int i=0; i<(1<<n); i++)
    {
        for(int j=0; j<n; j++)
        {
            for(int k=j+1; k<n; k++)
            {
                if((i&(1<<j)) && (i&(1<<k))) cost[i]+=arr[j][k];
            }
        }
    }

    memset(dp,-1,sizeof dp);
    printf("%lld\n",rec((1<<n)-1));

}


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

int main(){
  int n, t, a;
  cin >> n;
  ll ans1 = 1, ans2 = 1;
  for(int i=0; i<n; ++i){
    cin >> t >> a;
    ll n = max((ans1 -1) /t +1, (ans2 -1) /a +1);
    ans1 = n * t;
    ans2 = n * a;
    //cout << "i:" << i << " r:" << ans1 << " l:" << ans2 << endl;
  }
  cout << ans1 + ans2 << endl;
}

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

using namespace std; 
const int mod = 1e9+7;
vector<pair<int,int> > fa;
long long dp[101][70000];
int main(){
	long long n,k;
	cin>>n>>k;
	for(int i=1;i*i<=n;i++){
		fa.push_back({i,0});
		fa.push_back({n/i,0});
	}
	sort(fa.begin(),fa.end());
	fa.erase(unique(fa.begin(),fa.end()),fa.end());
	map<long long,long long> pos;
	int m=(int)fa.size();
	for(int i=0;i<m-1;i++){
		long long l=n/(fa[i+1].first);
		long long r=n/(fa[i].first);
		fa[i].second=r-l;
	}
	fa.back().second=1;
	for(int i=0;i<m;i++) pos[fa[i].first]=i;
	dp[0][pos[n]]=1;
	for(int i=0;i<k;i++){
		for(int j=m-2;j>=0;j--) dp[i][j]=(dp[i][j]%mod+dp[i][j+1]%mod)%mod;
		for(int j=0;j<m;j++){
			int nj=pos[n/fa[j].first];
			dp[i+1][j]=(dp[i+1][j]%mod+(dp[i][nj]%mod*fa[j].second%mod)%mod)%mod;
		}
	}
	long long ans=0;
	for(int i=0;i<m;i++) ans=(ans%mod+dp[k][i]%mod)%mod;
	cout<<ans%mod<<endl;
	return 0;
} 

Measured memory_bytes: 59640
#include <bits/stdc++.h>
#define rep(i,n) for (double i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<double,double> P;
const int INF=1001001001;


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  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;}
    //a^tを求める
    //例：d[i] = mint(k/i).pow(n);
  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, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
  ll n,m;
  cin>>n>>m;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  ll l=0;
  ll r=200005;
//  cout<<c;

    while(l+1<r){
      ll c=(l+r)/2;

    ll cnt=0;
    rep(i,n){
      ll rest=c-a[i];
      ll id=lower_bound(a.begin(),a.end(),rest)-a.begin();
      cnt+=n-id;
    //  cout<<id<<endl;
    //
  //  cout<<cnt<<endl;
    }
    if (cnt<m)r=c;
    else l=c;
  //  cout<<l<<' '<<r<<endl;
  }

  vector<ll>suma(n+1);
  suma[0]=0;
  suma[1]=a[0];
  rep(i,n-1){
    suma[i+2]=suma[i+1]+a[i+1];
  }

  ll ans=0;
  ll cnt=m;


  rep(i,n){
    ll rest=l-a[i];
    ll id=upper_bound(a.begin(),a.end(),rest)-a.begin();
  //  cout<<id<<endl;
    ans+=suma[n]-suma[id];
    cnt-=n-id;
    ans+=(n-id)*a[i];
  //  cout<<ans<<"ans"<<cnt<<"cnt"<<endl;
  }
  ans+=cnt*l;
  cout<<ans;

}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		int H = Integer.parseInt(st.nextToken());
		int A = Integer.parseInt(st.nextToken());
		int i;
		for(i=1; i<10001; i++) {
			H -= A;
			if(H <= 0)
				break;
		}
		
		System.out.println(i);
	}	

}

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

int N,M;
struct data{
    int total,id;
    data(int a,int b):total(a),id(b){}
};
bool comp(const data &a,const data &b){
    return a.total!=b.total?a.total>b.total:a.id<b.id;
}
void solve(){
    int cnt[100]={0};
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            int t;cin>>t;
            cnt[j]+=t;
        }
    }

    vector<data>V;
    for(int i=0;i<M;i++)V.push_back(data(cnt[i],i));
    sort(V.begin(),V.end(),comp);
    for(int i=0;i<M;i++){
        cout<<V[i].id+1<<(i!=M-1?" ":"\n");
    }
}

int main(){
    while(cin>>N>>M)solve();
}

Measured memory_bytes: 1200
from math import sqrt as s

N = int(input())
x, y = [], []
for i in range(1, int(s(N))+1):
  if N % i == 0:
    x.append(i)
    y.append(N // i)

ans, M = float("INF"), len(x)
for i in range(M):
  ans = min(ans, x[i] + y[i] - 2)

print(ans)

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
   LL x,k,d;
   cin>>x>>k>>d;
  x=abs(x);
  if(k<x/d)
    cout<<x-k*d;
  else
  {
      if(x/d%2==k%2)
        cout<<x%d;
      else
        cout<<d-x%d;
  }

}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 K,X;
    cin>>K>>X;
    for(int64 i=X-K+1;i<=X+K-1;i++){
        cout<<i<<" ";
    }
    cout<<endl;
    return 0;
}

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

int N;
const int MAX_N = 1.0e5 + 100;
int A[MAX_N + 1], B[MAX_N];


int main() {
    cin >> N;
    for (int i = 0; i < N+1; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] >= B[i]) {
            ans += B[i];
            A[i] -= B[i];
        }
        else {
            int tmp = max(A[i+1] - B[i] + A[i], 0);
            ans += min(B[i], A[i] + A[i+1]);
            A[i] = 0;
            A[i+1] = tmp;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
// aribon2-3-2_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt");
    cin.rdbuf(in.rdbuf());
#endif

    string A,B;
    cin >> A >> B;
    int a = A.size(), b = B.size();
    int dp[a+1][b+1] = {};

    REP(i, a+1) dp[i][0] = i;
    REP(j, b+1) dp[0][j] = j;

    REP(i, a){
        REP(j, b){
            if (A[i] == B[j]){
                dp[i+1][j+1] = dp[i][j];
            } else {
                dp[i+1][j+1] = min(min(dp[i+1][j]+1, dp[i][j+1]+1), dp[i][j]+1);
            }
        }
    }
    print(dp[a][b]);

    return 0;
}



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

int n, m;
map<int, vector<int> > cave;
map<int,int> room;

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        cave[a].push_back(b);
        cave[b].push_back(a);
    }
    queue<int> q;
    q.push(1);
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (int i = 0; i < cave[p].size(); i++) {
            if (room[cave[p][i]] == 0) {
                room[cave[p][i]] = p;
                q.push(cave[p][i]);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 2; i <= n; i++) {
        cout << room[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 20020
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
#define pb push_back
#define endl '\n'
bool cmp(char a, char b){
	return a<b;
}
ll solve(){
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	ll start=0,end=10000000000,mid,mini;
	while((start+1)!=end){
		mid=(start+end)/2;
		//cout<<mid<<endl;
		ll cnt=0,ans=0;
		for(int i=0;i<n;i++){
			if(arr[i]<mid){
				continue;
			}
			else{
				ans+=ceil((arr[i]+0.00)/(mid+0.00))-1;
			}
		}
		if(ans>k) start=mid;
		else {
			mini=mid;
			end=mid;
		}
	}
	cout<<mini;
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


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

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	string s, t;
	cin >> s >> t;
	reverse(s.begin(), s.end());
	reverse(t.begin(), t.end());
	rep(i, m + k + 5) s.push_back('0');
	rep(i, n + k + 5) t.push_back('0');
	// cerr << "s = " << s << endl;
	// cerr << "t = " << t << endl;
	for (int i = n + m - 1; i >= 0; i --) {
		// cerr << "s = " << s << endl;
		// cerr << "t = " << t << endl;
		if (s[i] == '1' && t[i] == '1') {
			s[i] = '0';
			t[i] = '0';
			s[i + 1] ++;
			t[i + 1] ++;
			int life = k - 1;
			int j = i + 1;
			while (life) {
				if (s[j] == '2') {
					s[j] = '0';
					s[j + 1] ++;
				} else if (t[j] == '2') {
					t[j] = '0';
					t[j + 1] ++;
				} else if (s[j] == '1' && t[j] == '1') {
					life --;
					s[j] = '0';
					t[j] = '0';
					s[j + 1] ++;
					t[j + 1] ++;
				} else {
					break;
				}
				j ++;
			}
			if (s[j] == '2') {
				s[j] = '0';
				s[j + 1] ++;
			}
			if (t[j] == '2') {
				t[j] = '0';
				t[j + 1] ++;
			}
		}
	}
	while (s.back() == '0') s.pop_back();
	while (t.back() == '0') t.pop_back();
	reverse(s.begin(), s.end());
	reverse(t.begin(), t.end());
	cout << s << endl;
	cout << t << endl;
        return 0;
}


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

int n,m,l,s,inf=1e5+1,t,a,c,b,ok;
int g[305][305],G[305][305],re;
int ind[25],cost[25],dp[20][(1<<18)];


int f(int cur,int vis){
if(dp[cur][vis]!=-1) return dp[cur][vis];
if((vis&(~(1<<cur)))==0) return dp[cur][vis]=G[l][cur]+cost[cur];
dp[cur][vis]=1e9;
for(int j=0;j<l;j++){
    if((j!=cur)&&(((1<<j)&vis)!=0)){
        dp[cur][vis]=min(dp[cur][vis],f(j,vis&(~(1<<cur)))+G[j][cur]);
    }
}
dp[cur][vis]+=cost[cur];
return dp[cur][vis];
}

int main(){
while(cin>>n>>m>>l>>s>>t){
    if(n+m+l+s+t==0) break;
    memset(dp,-1,sizeof(dp));s--;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) g[i][j]=inf;
        g[i][i]=0;
    }
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        a--;b--;
        g[a][b]=c;
        g[b][a]=c;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++)
                g[i][j]=min(g[i][k]+g[k][j],g[i][j]);
        }
    }
    for(int i=0;i<l;i++){
        cin>>ind[i]>>cost[i];
        ind[i]--;
    }
    for(int i=0;i<l;i++){
        G[i][l]=g[ind[i]][s];
        G[l][i]=g[ind[i]][s];
        for(int j=0;j<l;j++) G[i][j]=g[ind[i]][ind[j]];
    }
    re=0;
    for(int i=0;i<(1<<l);i++){
        int cnt=0;
        for(int j=0;j<l;j++) if(i&(1<<j)) cnt++;
        for(int j=0;j<l;j++){
            if(i&(1<<j)){
                if(f(j,i)+G[j][l]<=t) re=max(re,cnt);
            }
        }
    }
    cout<<re<<endl;
}
return 0;
}

Measured memory_bytes: 23900
#include <iostream>
#include <string>
using namespace std;
int main(void){
    long long ans = 0;
    int cnt[200010] = {};
    string s;
    cin >> s;
    if(s[0] == 'B'){
        cnt[0] = 1;
    }else{
        cnt[0] = 0;
    }
    for(int i = 1;i < s.length();i++){
        if(s[i] == 'B'){
            cnt[i] = (cnt[i-1]+1);
        }else{
            cnt[i] = cnt[i-1];
        }
    }
    for(int i = 0;i < s.length();i++){
        if(s[i] == 'W'){
            ans += cnt[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a,b;
int main()
{
	scanf("%d",&n);
	if(n==1)
	{
		cout<<"Hello World"<<endl;return 0;
	}
	if(n==2)
	{
			scanf("%d%d",&a,&b);
	printf("%d\n",a+b);
	}

	return 0;
}

Measured memory_bytes: 256
#include<cstdio> 
#include<cstring>

const int N = 1000000;  
char s[N], t[N];  
int sp[N], tp[N], q, a, b, c, d;
int main() {
    scanf("%s%s%d", s + 1, t + 1, &q); 
    for (int i = 1; s[i]; i++) {
        sp[i] = sp[i - 1] + s[i] - 'A' + 1;  
    }
    for (int i = 1; t[i]; i++) {
        tp[i] = tp[i - 1] + t[i] - 'A'  + 1;  
    }
    while(q--) {  
        scanf("%d%d%d%d", &a, &b, &c, &d);  
        if ( (sp[b] - sp[a - 1]) % 3 == (tp[d] - tp[c - 1]) % 3)	{
            printf("YES\n");
		}
        else {
            printf("NO\n"); 
		}
    }  
    return 0;  
}  

Measured memory_bytes: 7168
N=int(input())
A=list(map(int,input().split()))
a1=A[0]
SumA=a1
SumA2=a1^a1
for i in range(1,N):
    a=A[i]
    SumA^=a
    SumA2^=a^a

if(SumA==SumA2):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14116
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		sc.close();

		int nLen = String.valueOf(N).length();
		int ans = 0;


		for(int i=1; i<nLen; i++) {
			if(i == 1) {
				ans += 9;
			}else if(i % 2 == 1) {
				ans += 9 * Math.pow(10, i - 1);
			}
		}
		if(nLen == 1) {
			ans += N;
		}else if(nLen%2 == 1) {
			ans += N - (Math.pow(10, nLen - 1)-1);
		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 21844
import java.io.PrintWriter
import java.util.*
import java.math.*

val pw = PrintWriter(System.out)

fun main(args: Array<String>) {
    val (k, s) = readListOfInt()

    var cnt = 0
    for(i in 0..k) {
        for(j in 0..k) {
            val x = s - i - j
            if(x >= 0 && x <= k) {
                cnt++
            }
        }
    }
    println(cnt)
    pw.flush()
}

fun inputList() = 
    readLine()!!.split(" ").map(String::toInt)

fun sum_digits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

/****** Decrared Functions ******/

// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }


fun println(value : Any) {
    pw.println(value)
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    if(b==0L) a else gcd(b, a % b)


Measured memory_bytes: 35996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;

int main() {
    int n, m;
    map<string,vector<int> > drink;
    cin >> n;
    for(int i=0;i<n;i++){
        string c;
        int d;
        cin >> c >> d;
        drink[c].push_back(d);
    }
    for(auto& col : drink){
        sort(col.second.begin(), col.second.end());
        col.second.push_back(IINF);
    }
    cin >> m;
    vector<string> order(m);
    for(int i=0;i<m;i++){
        cin >> order[i];
    }
    int x = 0;
    for(int i=0;i<m;i++){
        if(drink.count(order[i])==0){
            x = IINF;
            break;
        }
        vector<int> col = drink[order[i]];
        x = *upper_bound(col.begin(), col.end(), x);
        if(x == IINF)break;
    }
    cout << (x != IINF ? "Yes" : "No") << endl;
    return 0;
}



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

int main() {
    int x;
    cin >> x;
    if(x==1){
        cout << 0;
        return 0;
    }
    int y[x];
    for(int i = 0; i < x; ++i){
        cin >> y[i];
    }
    int co = 0;
    int c = 0;
    for(int j = x-1; 0 < j; j--){
        if(y[j-1] >= y[j]){
            c += 1;
            if(j==1){
                if(c>co){
                    co=c;
                }
            }
        }else{
            if(c>co){
                co=c;
            }
            c=0;
        }
    }
    cout << co;
        return 0;
}

Measured memory_bytes: 640
while(1):
    try:
        N,M=map( int,raw_input().split())
        W=[[] for i in range(3)]
        for i in range(N):
            name=raw_input()
            inp=map( int,raw_input().split())
            c=inp[0]
            for i in range(3):
                W[i].append([c, inp[1+i]])
        for i in range(3):
            W[i].sort(key = lambda x:x[0])
        ans=0
        for i in range(3):
            U=[0 for x in range(M+1)]
            V=[0 for x in range(M+1)]
            for y in range(N):
                for t in range(M+1):
                    ci=W[i][y][0]*t
                    if ci <= M:
                        U[ci]=max(U[ci], W[i][y][1]*t)
                    else:
                        break
            for j in range(M+1):
                for k in range(j+1):
                    V[j]=max(V[j], V[j-k]+U[k])
            ans=max(ans, V[-1])
        print ans
    except:
        break



Measured memory_bytes: 4720
#include<iostream>
using namespace std;
int main(void)
{

    int a;
    int b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b<c+d){
      cout << "Right" << endl;
    }else if (a+b==c+d) {
      cout << "Balanced" << endl;
    }else{
      cout << "Left" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 4005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
int L[MAXN],R[MAXN],N;
char a[MAXN],b[MAXN];
vector<int> v[MAXN];
int cnt[MAXN];
bool checkpos(int x) {
    if(x >= N) return false;
    for(auto t : v[x]) {
        cnt[t]--;
    }
    bool flag = 1;
    for(auto t : v[x]) if(!cnt[t]) flag = 0;
    for(auto t : v[x]) cnt[t]++;
    return flag;
}
void Solve() {
    scanf("%s%s",a,b);
    N = strlen(a);
    int ca = 0,cb = 0;
    for(int i = 0 ; i < N ; ++i) {
        if(a[i] == '1') ++ca;
        if(b[i] == '1') ++cb;
    }
    if(!cb) {
        if(!ca) puts("0");
        else puts("-1");
        return;
    }
    for(int i = 0 ; i < N ; ++i) {
        if(a[i] == '1') {
            int t = i;
            int cnt = 0;
            while(b[t] == '0') {
                t = (t - 1 + N) % N;
                ++cnt;
            }
            L[i] = cnt % N;
            t = i,cnt = 0;
            while(b[t] == '0') {
                t = (t + 1) % N;
                ++cnt;
            }
            R[i] = (N - cnt) % N;
        }
    }
    for(int i = 0 ; i < N ; ++i) a[i + N] = a[i];
    int ans = 1e9;
    for(int i = 0 ; i < N ; ++i) {
        int now = 0;
        for(int j = 0 ; j < N ; ++j) v[j].clear();
        memset(cnt,0,sizeof(cnt));
        for(int j = 0 ; j < N ; ++j) {
            if(b[j] != a[i + j]) {
                ++now;
                if(a[i + j] == '1') {
                    int t = (i + j) % N;
                    v[L[t]].pb(t);v[R[t]].pb(t);
                    cnt[t] += 2;
                }
            }
        }
        int p = 0,q = 1;
        while(p < N) {
            while(checkpos(q)) {
                for(auto t : v[q]) cnt[t]--;
                ++q;
            }
            int tmp = p + 2 * (N - q);
            tmp += min(abs(p - i),N - abs(p - i));
            ans = min(ans,tmp + now);
            tmp = N - q + 2 * p;
            tmp += min(abs(q - i),N - abs(q - i));
            ans = min(ans,tmp + now);
            ++p;
            for(auto t : v[p]) cnt[t]++;
        }
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
    Solve();
}


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

int main(void){
 string str;
  cin >> str;
  if(str[0] == str[1] && str[1] == str[2]){
   cout << "No" << endl; 
  }
  else cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 3600
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
using namespace std;

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

long long lcm(long long a, long long b) {
	long long g = gcd(a, b);
	return a / g * b;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	int num = 1;
	int ans = 0;
	bool ok = false;
	for (int i = 0; i < n; ++i) {
		if (a[i] == 1) ok = true;
		if (a[i] == num) {
			++num;
		}
		else {
			++ans;
		}
	}
	if (ok) cout << ans;
	else cout << -1;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	char s;
	int n1=0,n2=0,n=0,i;
	while(cin>>s)
	{
		n++;
		if(s=='C')
		{
			n1++;
			i=n;
		}
		if(s=='F'&&n>i&&n!=1)    n2++;
	}
	if(n1>=1&&n2>=1)
		printf("Yes");
	else 
		printf("No");
	cout<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

const double EPS=1e-9;
const double INF=1e77;

struct point{
	double x,y;
	point operator+(const point &p)const{ return (point){x+p.x,y+p.y}; }
	point operator-(const point &p)const{ return (point){x-p.x,y-p.y}; }
};

point operator*(double c,const point &p){ return (point){c*p.x,c*p.y}; }

struct line{ point a,b; };

struct segment{
	point a,b;
	operator line()const{ return (line){a,b}; }
};

struct circle{
	point c;
	double r;
};

double dot(const point &a,const point &b){
	return a.x*b.x+a.y*b.y;
}

double abs2(const point &p){
	return p.x*p.x+p.y*p.y;
}

double abs(const point &p){
	return sqrt(abs2(p));
}

point proj(const point &p,const line &L){
	return L.a+dot(p-L.a,L.b-L.a)/abs2(L.b-L.a)*(L.b-L.a);
}

double dist(const point &a,const point &b){
	return abs(a-b);
}

bool cover(const segment &S,const point &p){
	return dist(S.a,p)+dist(p,S.b)<dist(S.a,S.b)+EPS;
}

int get_intersect(const circle &C,const segment &S,vector<point> &res){
	point h=proj(C.c,S);
	double d=dist(C.c,h);
	if(d>C.r+EPS) return 0;
	if(d>C.r-EPS){
		int cnt=0;
		if(cover(S,h)) res.push_back(h), cnt++;
		return cnt;
	}
	else{
		point v=S.b-S.a;
		v=(sqrt(C.r*C.r-d*d)/abs(v))*v;
		int cnt=0;
		if(cover(S,h+v)) res.push_back(h+v), cnt++;
		if(cover(S,h-v)) res.push_back(h-v), cnt++;
		return cnt;
	}
}

double solve(int h,int w,double r,double vx,double vy,point p,point q){
	if(vx<=0){
		vx*=-1;
		p.x=w-p.x;
		q.x=w-q.x;
	}
	if(vy<=0){
		vy*=-1;
		p.y=h-p.y;
		q.y=h-q.y;
	}

	double v=sqrt(vx*vx+vy*vy);
	vx/=v;
	vy/=v;

	segment S={p,p+(point){10000*vx,10000*vy}};
	int m=(10000*vy)/h+10;
	int n=(10000*vx)/w+10;
	circle C; C.r=2*r;
	vector<point> res;
	rep(i,m) rep(j,n) {
		C.c.x=j*w+(j%2==0?q.x:w-q.x);
		C.c.y=i*h+(i%2==0?q.y:h-q.y);
		get_intersect(C,S,res);
	}

	double d=INF;
	rep(i,res.size()) d=min(d,dist(p,res[i]));
	return d;
}

int main(){
	for(int n;scanf("%d",&n),n;){
		n--;
		int w,h,r,vx,vy; scanf("%d%d%d%d%d",&w,&h,&r,&vx,&vy);
		point p0,p[10];
		scanf("%lf%lf",&p0.x,&p0.y);
		rep(i,n) scanf("%lf%lf",&p[i].x,&p[i].y);

		w-=2*r;
		h-=2*r;
		p0.x-=r;
		p0.y-=r;
		rep(i,n){
			p[i].x-=r;
			p[i].y-=r;
		}

		int ans=-1;
		double d_ans=INF;
		rep(i,n){
			double d=solve(h,w,r,vx,vy,p0,p[i]);
			if(d_ans>d) d_ans=d, ans=i+2;
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1188
// Problem : A - Beginner
// Contest : AtCoder - AtCoder Beginner Contest 156
// URL : https://atcoder.jp/contests/abc156/tasks/abc156_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n,r;
    cin>>n>>r;
    if(n > 10) cout<<r<<endl;
    else cout<<r+100*(10-n)<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3604
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int Jiezhi[1001];int n;
vector<int> vs[1001];
queue<int> Now;
void dfs(int now){
//	cout<<now<<endl;
	queue<int> Nex;
//	Nex.clear();
	map<int,int> ISS;
	int OK1=0,OK2=0;
	while(!Now.empty()){
		int i=Now.front();Now.pop();
//		cout<<i<<endl;
		if(Jiezhi[i]<=n-2&&!ISS[i]){
			OK1=1;
			if(Jiezhi[vs[i][Jiezhi[i]]]>n-2){
				cout<<"-1";
				return;
			}
			if(!ISS[vs[i][Jiezhi[i]]]&&vs[vs[i][Jiezhi[i]]][Jiezhi[vs[i][Jiezhi[i]]]]==i){
				ISS[vs[i][Jiezhi[i]]]=ISS[i]=1;
				OK2=1;
				Jiezhi[vs[i][Jiezhi[i]]]++,Jiezhi[i]++;
				
				if(Jiezhi[i]<=n-2) Nex.push(i);
				if(Jiezhi[vs[i][Jiezhi[i]-1]]<=n-2) Nex.push(vs[i][Jiezhi[i]-1]);
			}
		}
	}
	Now=Nex;
	if(!OK1){
		cout<<now-1;
		return ; 
	}
	else{
		if(!OK2){
			cout<<"-1";
			return;
		}
	}
	dfs(now+1);
}
int main(){
	cin>>n;
	rb(i,1,n){
		Now.push(i);
		rb(j,1,n-1){
			int ai;
			scanf("%d",&ai);
			vs[i].PB(ai);
		}
	}
	dfs(1);
	return 0;
}

Measured memory_bytes: 534912
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
#define S second
#define F first
typedef pair<int,int> Pi;

int mx[] = {1,0,-1,0};
int my[] = {0,1,0,-1};

int main()
{
  int H, W, N;
  int sx,sy;
  char mas[1005][1005];
  Pi point[10];
  cin >> H >> W >> N;
  Rep(i,H) Rep(j,W) {
    cin >> mas[i][j];
    if(mas[i][j] == 'S') {
      sx = j, sy = i;
    }
    if(mas[i][j] >= '1' && mas[i][j] <= '9') {
      point[mas[i][j] - '0'] = Pi(i,j);
    }
  }

  int sum = 0;
  for(int p = 1; p <= N; p++) {
    int mc[1005][1005];
    fill(mc[0],mc[1005],INF);
    queue<Pi>que;
    mc[sy][sx] = 0;
    que.push(Pi(sy,sx));
    while(!que.empty()) {
      int x = que.front().S;
      int y = que.front().F;
      que.pop();
      if(mas[y][x] == p + '0')break;
      Rep(i,4) {
	int nx = x + mx[i];
	int ny = y + my[i];
	if(nx >= 0 && ny >= 0 && nx < W && ny < H && mas[ny][nx] != 'X' && mc[ny][nx] == INF) {
	  mc[ny][nx] = mc[y][x] + 1;
	  que.push(Pi(ny,nx));
	}
      }
    }
    sum += mc[point[p].F][point[p].S];
    sy = point[p].F, sx = point[p].S;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 7984
#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 unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

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};

// https://beta.atcoder.jp/contests/abc076/tasks/abc076_b

int main() {
    int N, K;
    cin >> N >> K;

    int current = 1;
    REP(i, N) {
        if (current + K > current * 2) {
            current = current * 2;
        } else {
            current = current + K;
        }
    }

    cout << current << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
using namespace std;
 
//  =========     /\       /|    |====/|
//      |        /  \       |    |   / |
//      |       /____\      |    |  /  |
//      |      /      \     |    | /   |
//  ========= /        \  =====  |/====|  
//  code

typedef long long int ll;

ll dp[405][405];
ll a[405];
long long int func(int i,int j){
    // cout<<i<<" "<<j<<endl;
    if(i == j)
        return dp[i][j] = 0;
    
        if(dp[i][j] != 1e15)
            return dp[i][j];
    
        ll l = 1e15;
        ll s = 0;
        for(int k=i;k<=j;k++)
            s += a[k];
        for(int k = i+1;k<=j;k++){
            l = min(l ,func(i,k-1) + func(k,j) + s);
        }
        return dp[i][j] = l;
    
}
int main(){
    init;
    ll N,i,j,k,l;
    cin>>N;

    for(i=0;i<N;i++)
        for(j=0;j<N;j++)
                dp[i][j] = 1e15;
    
    for(i=0;i<N;i++){
        cin>>a[i];
    }

    cout<<func(0,N-1)<<endl;
    return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <iterator>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef long long LL;
const int maxn = 1000020;
const LL INF = 100000000000000LL;
const LL mod = 998244353;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define For(i,a,b) for(int i=a;i<=b;++i)

int n;
LL a, b, c, d;

void solve() {
    cin >> a >> b >> c >> d;
    int ok = 1;
    if(a < b) {
        ok = 0;
    }
    else {
        if(d < b) {
            ok = 0;
        }
        else if(d % b == 0) {
            if(a % b > c)
                ok = 0;
        }
        else {
            if(b > c + 1) {
                a %= b;
                d %= b;
                if(d == 0) return ;
                int cnt = 0;
                LL x;
                while(cnt++ <= 100000 && ok) {
                    if(a > c) ok = 0;
                    x = (b - a) % d;
                    if(x == 0) x = b - d;
                    else {
                        x = b - x;
                    }
                    if(x > c) ok = 0;
                    a = (x + d) % b;
                }
            }
        }
    }
    ok ? puts("Yes") : puts("No");
}

int main() {
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256