akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    vector<int> ans;
    int sum=0;
    rep(i,N) sum ^= A[i];
    rep(i,N){
        ans.push_back(sum^A[i]);
    }
    rep(i,N){
        cout << ans[i] << ' ';
    }
    cout << endl;
    return 0;
    
}



Measured memory_bytes: 4560
import sys
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        if 4*h*n-N*n-N*h != 0:
            w,r = divmod(N*h*n,4*h*n-N*n-N*h)
            if r == 0 and w > 0:
                print(h,n,w)
                sys.exit()

Measured memory_bytes: 69196
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;
int a[200010];
int b[200010];
int cnt[200010];

int main(){
   int n,m;
   cin>>n>>m;
   for(int i=0;i<m;i++){
      cin>>a[i]>>b[i];
      if(a[i]==1 || a[i]==n)cnt[b[i]]++;
      if(b[i]==1 || b[i]==n)cnt[a[i]]++;
   }
   for(int i=0;i<=n;i++){
      if(cnt[i]==2){
         cout<<"POSSIBLE"<<endl;
         return 0;
      }
   }
   cout<<"IMPOSSIBLE"<<endl;
   
}

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

constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

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

ll a[2010];
int n;

int bf(int i) {
    return (i + n - 1) % n;
}

int nxt(int i) {
    return (i + 1) % n;
}

void solve() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    REP(i,n) cin >> a[i];
    ll ans = 0;
    map<pair<int,int>,ll> dp;

    queue<pair<pair<int,int>,ll>> que;

    for (int i = 0; i < n; i++) {
        ll now = a[i];
        if (a[bf(i)] > a[nxt(i)]) {
            que.push({{bf(i), i}, now});
        } else {
            que.push({{i, nxt(i)}, now});
        }
        dp[{bf(i),i}] = now;
        dp[{i,nxt(i)}] = now;
        ans = max(ans,now);
    }

    while (!que.empty()) {
        pair<pair<int,int>,ll> tp = que.front();
        que.pop();
        int l = tp.fi.fi;
        int r = tp.fi.se;
        ll m = tp.se;
        ans = max(ans, m);
        if (bf(l) == r || l == r) continue;
        if (dp[{l,r}] > m) continue;

        // take front
        if (a[bf(bf(l))] > a[nxt(r)]) {
            if (dp[{bf(bf(l)), r}] < m + a[bf(l)]) {
                que.push({{bf(bf(l)), r}, m + a[bf(l)]});
                dp[{bf(bf(l)), r}] = m + a[bf(l)];
            }
        } else {
            if (dp[{bf(l), nxt(r)}] < m + a[bf(l)]) {
                que.push({{bf(l), nxt(r)}, m + a[bf(l)]});
                dp[{bf(l), nxt(r)}] = m +  a[bf(l)];
            }
        }

        // take back
        if (a[bf(l)] > a[nxt(nxt(r))]) {
            if (dp[{bf(l), nxt(r)}] < m +  a[nxt(r)]) {
                que.push({{bf(l), nxt(r)}, m + a[nxt(r)]});
                dp[{bf(l), nxt(r)}] = m + a[nxt(r)];
            }
        } else {
            if (dp[{l, nxt(nxt(r))}] < m + a[nxt(r)]) {
                dp[{l, nxt(nxt(r))}] = m + a[nxt(r)];
                que.push({{l, nxt(nxt(r))}, m + a[nxt(r)]});
            }
        }
    }
    cout << ans << endl;
}

int main(int argc, char *argv[]){

    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }

    /* AOJ */
    solve();

    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> vec){ return (ll)vec.size(); }
ll sz(string s){ return (ll)s.size(); }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }

int main(){
    ll n,m,q;
    cin >> n >> m >> q;
    ll imos[n][n] = {};

    rep(i,0,m){
        ll l,r;
        cin >> l >> r;
        imos[0][r-1] += 1;
        if(l != n) imos[l][r-1] -= 1;
    }

    rep(i,0,n) rep(j,1,n) imos[i][j] += imos[i][j-1];
    rep(j,0,n) rep(i,1,n) imos[i][j] += imos[i-1][j]; 
    
    rep(i,0,q){
        ll l,r;
        cin >> l >> r;
        cout << imos[l-1][r-1] << endl;
    }
    return 0;
}




Measured memory_bytes: 5544
from itertools import permutations
from operator import eq
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
a = 0
b = 0
for i, c in enumerate(permutations(range(1, N+1), N)):
    if all(map(eq, c, P)):
        a = i
    if all(map(eq, c, Q)):
        b = i
print(abs(a-b))

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

int main()
{
    int d, t, s;
    cin >> d >> t >> s;
    int dist = s * t;
    if (dist >= d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++)
            list.add(in.nextInt());

        int index = 0, cost = 0;
        for (int i : list) {
            cost += Math.abs(index - i);
            index = i;
        }
        cost += Math.abs(index);

        System.out.println(cost - Math.abs(list.get(0))
                - Math.abs(list.get(1) - list.get(0)) + Math.abs(list.get(1)));

        for (int i = 1; i < n - 1; i++) {
            System.out.println(cost - Math.abs(list.get(i - 1) - list.get(i))
            - Math.abs(list.get(i) - list.get(i + 1))
            + Math.abs(list.get(i - 1) - list.get(i + 1)));
        }

        System.out.println(cost - Math.abs(list.get(n - 1))
                - Math.abs(list.get(n - 1) - list.get(n - 2)) + Math.abs(list.get(n - 2)));
    }
}

Measured memory_bytes: 75084
(let* ((n (read))
       (m (read))
       (lst (loop :repeat n :collect (read))))
  (princ (- (+ (car (last lst)) m)
            (reduce #'+ (mapcar (lambda (j k)
                                  (if (plusp (- (- k j) m))
                                      (- (- k j) m)
                                      0))
                                lst (cdr lst))))))

Measured memory_bytes: 59748
n, x =map(int, input().split())
a = list(map(int, input().split()))
ans = 0

for i in range(n):
  if a[i]>x:
    ans+=a[i]-x
    a[i] = x

for i in range(n-1):
  if a[i]+a[i+1]>x:
    ans += (a[i]+a[i+1])-x
    a[i+1] -= ((a[i]+a[i+1])-x)
print(ans)

Measured memory_bytes: 14252
from collections import deque
H,W = map(int, input().split())
#a = [['#'] * (W+2) for i in range(H+2)]
cnt = [[-5] * (W+2) for i in range(H+2)]
c = 0
fin = 0
st = deque()
sts = deque()
push, pop = st.append, st.pop
pushs, pops = sts.append, sts.pop
for h in range(1,H+1):
    ai = input()
    for w in range(1,W+1):
        #a[h][w] = ai[w-1]
        if ai[w-1] == '#':
            cnt[h][w] = c
            push([h,w])
            fin += 1
        else:
            cnt[h][w] = -1


dxy = ([1,0],[0,1],[-1,0],[0,-1])

while fin < H*W:
    while st:
        [h,w] = pop()
        for dx,dy in dxy:
            if cnt[h+dx][w+dy] == -1:
                #print(c,fin)
                cnt[h+dx][w+dy] = c+1
                pushs([h+dx,w+dy])
                fin += 1
    c += 1
    while sts:
        [h,w] = pops()
        push([h,w])


print(c)

Measured memory_bytes: 136796
#include<cstdio>
#include<algorithm>

using namespace std;

#define A 5011
#define PRI 1000
#define PRIME 1100000

int main(int argc, char *argv[]){

  int N, P;
  int i, j, cnt=0;
  int prime[PRI], a[A];
  bool isprime[PRIME];



    fill(isprime, isprime+PRIME,true);
    isprime[0] = false;
    isprime[1] = false;

    for(i=2;i<PRIME+1;i++){
      isprime[i]=true;
    }
    
    cnt=0;
    for(i=2;i<PRIME+1;i++){
      if(isprime[i]){
	//	printf("%d is prime\n", i);
	for(j=2;j<PRIME/i;j++){
	  isprime[i*j]=false;
	}
      }
    }

  while(true){

    fill(a, a+A, 0);
    fill(prime, prime+PRI, 0);

    scanf("%d %d", &N, &P);
    if(N==-1 && P==-1){break;}

    cnt=0;
    for(i=N+1;i<PRIME;i++){
      if(cnt==100){break;}
      if(cnt<100 && isprime[i]){
	prime[cnt++] = i;
	//	printf("%d is selected prime\n", prime[cnt-1]);
      }
    }

    cnt=0;
    for(i=0;i<100;i++){
      for(j=0;j<i+1;j++){
	a[cnt++] = prime[i]+prime[j];
	//     	printf("%d is %dth sum of two primes\n", a[cnt-1], cnt-1);
      }
    }


    sort(a, a+5010);

    printf("%d\n", a[P-1]);
  }

  return 0;
}

Measured memory_bytes: 2136
n = int(input())
h = [int(i) for i in input().split()]
can_move = [0 for _ in range(n)]
for i in range(1, n):
    if h[n - 1 - i] >= h[n - i]:
        can_move[n - 1 - i] += can_move[n - i] + 1
    else:
        can_move[n - 1 - i] = 0
print(max(can_move))

Measured memory_bytes: 14252
/* 
 * Project: AtCoder Beginners Contest 137 A - +-x
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/09/01
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
#include <algorithm>
using namespace std;

int32_t a;
int32_t b;

void solve() {

    int32_t plus = a+b;
    int32_t minus = a-b;
    int32_t product = a*b;

    printf("%d\n", max({plus, minus, product}));
}

int main() {

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

    solve();

}

Measured memory_bytes: 3228
from collections import defaultdict

n = int(input())
a = list(map(int,input().split()))
ans = sum(a)
d = defaultdict(int)
for i in a:
    d[i] += 1

q = int(input())
for _ in range(q):
    b,c = map(int,input().split())
    count = d[b]
    ans += (c-b)*count
    print(ans)
    d[b] = 0
    d[c] += count


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

int main() {
  char S[101010];
  cin >> S;
  
  bool app[26];
  for (int i = 0; i < 26; ++i) {
    app[i] = false;
  }
  for (int i = 0; S[i] != '\0'; ++i) {
    app[S[i] - 'a'] = true;
  }
  for (int i = 0; i < 26; ++i) {
    if (!app[i]) {
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }
  cout << ("None");
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define double long double
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool integer(double n){
	if(n==long(n))return true;
	else return false;	
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
} 
pair<pair<int,int>,int> pa[1145];
int a[8][3];
signed main(){
	ic(n)
	ic(m)
	rep(0,i,n)cin>>pa[i].f.f>>pa[i].f.s>>pa[i].s;
	for(int bit=0;bit<(1<<3);bit++)rep(0,i,3)if(bit&(1<<i))a[bit][i]=1;
	int ans=0;
	rep(0,i,8){
		int sum=0;
		pair<pair<int,int>,int> pp[1145];
		int wa[1145];
		if(a[i][0]==1)rep(0,j,n)pp[j].f.f=pa[j].f.f;
		else rep(0,j,n)pp[j].f.f=-pa[j].f.f;
		if(a[i][1]==1)rep(0,j,n)pp[j].f.s=pa[j].f.s;
		else rep(0,j,n)pp[j].f.s=-pa[j].f.s;
		if(a[i][2]==1)rep(0,j,n)pp[j].s=pa[j].s;
		else rep(0,j,n)pp[j].s=-pa[j].s;
		rep(0,j,n)wa[j]=pp[j].f.f+pp[j].f.s+pp[j].s;
		sort(wa,wa+n);
		reverse(wa,wa+n);
		rep(0,j,m)sum+=wa[j];
		ans=max(ans,sum);
	}
	c(ans)
}	


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll n;
    cin >> n;
    VL x(n), a(n);
    REP(i,n){
        x[i] = lin();
        a[i] = lin();
    }
    VL s(n + 1);
    REP(i,n) s[i + 1] = s[i] + a[i];

    ll ans = 0, mi = 1e18;
    REP(i,n){
        chmin(mi, s[i] - x[i]);
        chmax(ans, s[i + 1] - x[i] - mi);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

// #define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

template <typename T>
T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T>
T lcm(T m, T n) { return n * m / gcd(n, m); }

signed main(void)
{
  int x, y;
  cin >> x >> y;

  // x, y
  // -x, y
  // x, -y
  // -x, -y

  int num = -1;

  if (x <= y)
  {
    int tmp = y - x;
    if (num == -1)
    {
      num = tmp;
    }
    else
    {
      num = min(num, tmp);
    }
  }
  if (-x <= y)
  {
    int tmp = 1 + y - (-x);

    if (num == -1)
      num = tmp;
    else
      num = min(num, tmp);
  }
  if (x <= -y)
  {
    int tmp = 1 + (-y) - x;
    if (num == -1)
      num = tmp;
    else
      num = min(num, tmp);
  }
  if (-x <= -y)
  {
    int tmp = 1 + (-y) - (-x) + 1;
    if (num == -1)
      num = tmp;
    else
      num = min(num, tmp);
  }
  cout << num << endl;
}


Measured memory_bytes: 256
// bfsで解く
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int x = sc.nextInt() - 1;
        int y = sc.nextInt() - 1;

        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            int[] dist = new int[n];
            Arrays.fill(dist, -1);  // 配列初期化
            Queue<Integer> queue = new ArrayDeque<>();
            queue.add(i);
            dist[i] = 0;

            while (!queue.isEmpty()) {
                int p = queue.poll();

                // 一つ前
                if (p-1 >= 0 && dist[p-1] == -1) {
                    dist[p-1] = dist[p] + 1;
                    queue.add(p-1);
                }
                // 一つ後
                if (p+1 < n && dist[p+1] == -1) {
                    dist[p+1] = dist[p] + 1;
                    queue.add(p+1);
                }
                // xからy
                if (p == x && dist[y] == -1) {
                    dist[y] = dist[p] + 1;
                    queue.add(y);
                }
                // yからx
                if (p == y && dist[x] == -1) {
                    dist[x] = dist[p] + 1;
                    queue.add(x);
                }
            }

            for (int j = i; j < n; j++)
                ans[dist[j]]++;
        }

        for (int i = 1; i < n; i++)
            System.out.println(ans[i]);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 44216
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	double n;
	while(cin>>n,n>=0){
		int s[20];
		double a;
		int i;
		for(a=128,i=0;i<12;a/=2,i++){
			if(n>=a){
				n-=a;
				s[i]=1;
			}else{
				s[i]=0;
			}
		}
		if(n>1e-9){
			cout<<"NA"<<endl;
		}else{
			for(i=0;i<8;i++){
				cout<<s[i];
			}
			cout<<".";
			for(i=8;i<12;i++){
				cout<<s[i];
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/300 < b.F.F/300)
		return 1;
	if(a.F.F/300 > b.F.F/300)
		return 0;
	if(a.F.S < b.F.S)
		return 1;
	if(a.F.S > b.F.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (1e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 2*550;
const int SQRT = BUCK+9;

ll x[11];

void solve()
{
	ll r, d;
	int i;
	cin >> r >> d >> x[0];
	fo(i,1,11)
		x[i] = x[i-1]*r - d;
	fo(i,1,11)
		cout << x[i] << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 256
#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()
#define mod 1000000007
typedef long long ll;

int main(){
  string str;
  cin >> str;
  int initLength = str.length();
  int length = str.length();
  int s = 0;
  rep(i, initLength){
    if(str[i] == 'S') s++;
    else{
      if(s>0){
        s--;
        length -= 2;
      }
    }
  }
  cout << length << endl;
  return 0;
}
      
      

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define FOR(i,k,n) for((i)=(k);(i)<(n);(i)++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define pb push_back
#define all(a) (a).begin(),(a).end()  //greater<int>()
using namespace std;

int main(){
	int N,x,y;
	cin>>N;
	x=800*N;
	y=200*int(N/15);
	cout<<x-y<<endl;
   	return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        if(N<10){
        System.out.print(N);
        }else if(N>=10 && N<100){
        System.out.print("9");
        }else if(100<=N && N<1000){
        System.out.print(9+(N-99));
        }else if(1000<=N && N<10000){
        System.out.print("909");        
        }else if(10000<=N && N<100000){
        System.out.print(909+(N-9999));
        }else{
         System.out.print("90909");    
        }
}
}


Measured memory_bytes: 21844
#include<stdio.h>
int gcd(int x,int y);


int main()
{
  int x,y;
  int atai;
  scanf("%d %d",&x,&y);
  atai = gcd(x,y);
  printf("%d\n",atai);

  return 0;
}


int gcd(int x ,int y)
{
  int j;
  int r;
  if(x < y){
    j = x;
    x = y;
    y = j;
  }
  if(x >= y){
  while(y > 0){
    r = x%y;
    x = y;
    y = r;
  }
  }

  return x;
}

	
    



Measured memory_bytes: 2104
s = int(input())
mod = 10 ** 9 + 7

dp = [0] * (s + 1)
dp[0] = 1

for i in range(1, s + 1):
    for j in range(0, (i - 3) + 1):
        dp[i] += (dp[j] % mod)
print(dp[s] % mod)        
        

Measured memory_bytes: 9156
N, M = map(int, input().split())
lh = list(map(int, input().split()))

lm = list()
for i in range(M):
    lm.append(list(map(int, input().split())))

lm = sorted(lm)

llose = list()

for i in range(M):
    if lh[lm[i][0]-1] == lh[lm[i][1]-1]:
        llose.append(lm[i][0])
        llose.append(lm[i][1])
    elif lh[lm[i][0]-1] < lh[lm[i][1]-1]:
        llose.append(lm[i][0])
    else:
        llose.append(lm[i][1])

llose = list(set(llose))

print(N - len(llose))

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

using namespace std;

#define ll long long int
#define MOD 1000000007
#define mt make_tuple
#define eb emplace_back
#define error(args...){string _s = #args; replace(_s.begin(),_s.end(),',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args){cerr<<*it<<" = "<<a<<endl; err(++it,args...);}

ll solve(vector<ll> &V, ll b){
ll ans=0;
for(auto it:V){
    ans+=abs(it-b);
}
return ans;
}


int main()
{
	ll i,j,k,l,n,m;
	cin>>n;
	vector<ll> V;
	for(i=0;i<n;++i)
        cin>>l,V.push_back(l-i-1);
    ll low=-1e9,high = 1e9,mid1,mid2;
    while(high-low>3){
        mid1 = (low + high)/2;
        mid2 = mid1+1;
        ll l1 = solve(V,mid1),l2 = solve(V,mid2);

        if(l1<=l2){
            high = mid2;
        }else{
            low = mid1;
        }
    }
    ll ans = solve(V,low);
    for(i=low;i<=high;++i)
        ans = min(ans,solve(V,i));
    cout<<ans;

	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;

void escape(string& s)
{
  if (s.find_first_of("\n") != string::npos)
    s.erase(s.end()-1);
  if (s.find_first_of("\r") != string::npos)
    s.erase(s.end()-1);
}

int main()
{
  string s, t;
  getline(cin, t);

  int T = atoi(t.c_str());
  for (int dataset = 0; dataset < T; ++dataset) {
    getline(cin, s);
    escape(s);
    getline(cin, t);

    int M = atoi(t.c_str()), cur = 0;
    for (int i = 0; i < M; ++i) {
      getline(cin, t);
      escape(t);

      if (t == "forward char") {
	if (cur < s.size())
	  ++cur;
      } else if (t == "forward word") {
	while (cur < s.size() && s[cur] == ' ')
	  ++cur;
	while (cur < s.size() && s[cur] != ' ') {
	  ++cur;
	}
      } else if (t == "backward char") {
	if (cur > 0)
	  --cur;
      } else if (t == "backward word") {
	if (cur != 0) {
	  while (cur > 0 && s[cur-1] == ' ')
	    --cur;
	  while (cur > 0 && s[cur-1] != ' ')
	    --cur;
	}
      } else if (t == "delete char") {
	if (cur < s.size())
	  s.erase(cur, 1);
      } else if (t == "delete word") {
	if (cur < s.size()) {
	  int end = cur;
	  while (end < s.size() && s[end] == ' ')
	    ++end;
	  if (end < s.size()) {
	    while (end < s.size() && s[end] != ' ')
	      ++end;
	    s.erase(cur, end-cur);
	  }
	}
      } else {
	string ins = t.substr(t.find_first_of("\"")+1);
	ins.erase(ins.end()-1);
	s.insert(cur, ins);
	cur += ins.size();
      }
    }
    for (unsigned int i = 0; i <= s.size(); ++i) {
      if (i == cur)
	cout << "^";
      if (i < s.size())
	cout << s[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;



int main() {
	int N;
	string S;
	cin >> N;
	cin >> S;
	map<char, LL>mp;
	for (char c : S)mp[c]++;
	LL ans = mp['R'] * mp['G'] * mp['B'];

	for (int i = 0; i < N; i++) {
		for (int j = i + 2; j < N; j += 2) {
			int k = (i + j) / 2;
			if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) {
				ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG

 // 深さ優先探索
vector<bool> seen;
int dfs(const Graph &G, ll v) {
    seen[v] = true; // v を訪問済にする
    int score = 0; 

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー

        // 負荷さ優先探索中の処理



        dfs(G, next_v); // 再帰的に探索, 毎回mat渡してええの？
    }
    return score;
} 

/*
//桁数の計算
ll keta(ll num){
  ll ans= 0 ;
  ll rem;

  for (ll i = 4; i >= 0 ; i--){
    rem = pow(10,i);
    ans += (num / rem); 
    num = num % rem;
  }
  return ans;
}
*/


int main() {
    ll H, W;
    cin >> H >> W;
    vector<vector<char>> s(H, vector<char>(W));

    for (ll i =0; i<H; i++){
      for (ll j =0; j<W; j++){
        cin >> s[i][j];
      }
    }
    vector<int> dx = {0,-1,1,0};
    vector<int> dy = {-1,0,0,1};

    for (ll i =0; i<H; i++){
      for (ll j =0; j<W; j++){
        if(s[i][j] == '#'){
          bool flag = false;
          for(ll d=0; d<4; d++){
            ll x = i + dx[d];
            ll y = j + dy[d];

            if (x < 0 || x>=H) continue;
            if (y < 0 || y>=W) continue;

            if(s[x][y] == '#') flag = true;
          }
          if (!flag) {
            cout << "No" << endl;
            //cout << i << endl;
            //cout << j << endl;
            goto end;

          }
        }
      }
    }

    cout << "Yes" << endl;
    end:
    return 0;
}

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

int main() {

    int n;
    scanf("%d", &n);
    if (n == 7) {
        puts("YES");
    } else if (n == 5) {
        puts("YES");
    } else if (n == 3) {
        puts("YES");
    } else {
        puts("NO");
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j==n){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a;
  cin>>b;
  if(a<10&&a>0&&b<10&&b>0)
  {
    cout<<a*b;
  }
  else
  {
    cout<<"-1";
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int cost[7][7]={{0,6,10,12,14,27,33},
				{6,0,7,9,12,23,30},
				{13,7,0,5,8,20,27},
				{18,12,5,0,5,17,26},
				{23,17,10,5,0,12,23},
				{43,37,30,25,20,0,10},
				{58,52,45,40,35,15,0}};
int main(){
	int i,j,s,t,a,b,h,m;
	
	while(1){
		scanf("%d",&a);
		if(a==0)break;
		scanf("%d%d",&h,&m);
		s=h*60+m;
		scanf("%d",&b);
		scanf("%d%d",&h,&m);
		t=h*60+m;
		a--;b--;
		if(a>=b){
			i=a;
			a=b;
			b=i;
		}
		//printf("(%d) ",cost[a][b]);
		if(cost[b][a]<=40 && ((17*60+30<=s && s<=19*60+30) || (17*60+30<=t && t<=19*60+30)))printf("%d\n",((cost[a][b]+1)/2)*50);
		else printf("%d\n",cost[a][b]*50);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>;
using L = vector<long long>;
using M = map<int,long long>;
using A = vector<vector<long long>>;
using Q = priority_queue<long long>;
using U = unordered_map<int,long long>; //mapとの違いはkeyの順番を保持していない

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define sortedreverce(vector) sort(vector.rbegin(),vector.rend()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    long long n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;
    L l={a,b,c,d,e};
    if (vmin(l)>=n){
        cout<<5<<endl;
    }else{
        cout<<(n-1)/vmin(l)+5<<endl;
    }
}

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

// dp[i][j][k][l] :=  i: 上位 i 桁目まで決定  j: 数字を自由に選べるか
//                    k: 数字を書き込んだか   l: {3,5,7} を選んだかのflag
//                    としたときの753数の数
int dp[11][2][2][8];

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

  string n;
  cin >> n;

  int len = n.size();
  dp[0][0][0][0] = 1;
  for (int i = 0; i < len; ++i)
  {
    for (int j = 0; j < 2; ++j)
    {
      for (int k = 0; k < 2; ++k)
      {
        for (int l = 0; l < 8; ++l)
        {
          if (!dp[i][j][k][l]) continue;

          if (j == 1)                  // [0, 9] から数字を選べる
          {
            if (k == 0)                // 数字をまだ書き込んでいない
              dp[i + 1][1][0][0] += dp[i][1][0][l];                // nothing

            dp[i + 1][1][1][l | 1] += dp[i][1][k][l];              // +3
            dp[i + 1][1][1][l | 2] += dp[i][1][k][l];              // +5
            dp[i + 1][1][1][l | 4] += dp[i][1][k][l];              // +7
          }
          else                         // [0, d] から数字を選べる
          {
            int d = (int)(n[i] - '0');

            if (k == 0)                // 数字をまだ書き込んでいない
              dp[i + 1][1][0][0] += dp[i][0][0][l];                // nothing

            if (d == 3) dp[i + 1][0][1][l | 1] += dp[i][0][k][l];  // +3
            if (3 < d)  dp[i + 1][1][1][l | 1] += dp[i][0][k][l];  // +3
            if (d == 5) dp[i + 1][0][1][l | 2] += dp[i][0][k][l];  // +5
            if (5 < d)  dp[i + 1][1][1][l | 2] += dp[i][0][k][l];  // +5
            if (d == 7) dp[i + 1][0][1][l | 4] += dp[i][0][k][l];  // +7
            if (7 < d)  dp[i + 1][1][1][l | 4] += dp[i][0][k][l];  // +7
          }
        }
      }
    }
  }

  int ans = dp[len][0][1][7] + dp[len][1][1][7];
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
/*
*  Problem Link: https://atcoder.jp/contests/abc172/tasks/abc172_d
*  Author: Raunak Sett
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long 
#define vi vector<int>


const int MAX = 100000001; 
  
// array to store prime factors 
int factor[MAX] = { 0 }; 
  
// function to generate all prime factors 
// of numbers from 1 to 10^6 
void generatePrimeFactors() 
{ 
    factor[1] = 1; 
  
    // Initializes all the positions with their value. 
    for (int i = 2; i < MAX; i++) 
        factor[i] = i; 
  
    // Initializes all multiples of 2 with 2 
    for (int i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
  
    // A modified version of Sieve of Eratosthenes to 
    // store the smallest prime factor that divides 
    // every number. 
    for (int i = 3; i * i < MAX; i++) { 
        // check if it has no prime factor. 
        if (factor[i] == i) { 
            // Initializes of j starting from i*i 
            for (int j = i * i; j < MAX; j += i) { 
                // if it has no prime factor before, then 
                // stores the smallest prime divisor 
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 

// function to calculate number of factors 
int calculateNoOFactors(ll n) 
{ 
    if (n == 1) 
        return 1; 
  
    int ans = 1; 
  
    // stores the smallest prime number 
    // that divides n 
    int dup = factor[n]; 
  
    // stores the count of number of times 
    // a prime number divides n. 
    int c = 1; 
  
    // reduces to the next number after prime 
    // factorization of n 
    int j = n / factor[n]; 
  
    // false when prime factorization is done 
    while (j != 1) { 
        // if the same prime number is dividing n, 
        // then we increase the count 
        if (factor[j] == dup) 
            c += 1; 
  
        /* if its a new prime factor that is factorizing n,  
           then we again set c=1 and change dup to the new  
           prime factor, and apply the formula explained  
           above. */
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
  
        // prime factorizes a number 
        j = j / factor[j]; 
    } 
  
    // for the last prime factor 
    ans = ans * (c + 1); 
  
    return ans; 
} 


int main() {
    IOS
    // Code Here
    ll n;
    cin>>n;
    generatePrimeFactors();
    
    ll ans = 0;
    for (ll i=1; i <= n; i++) {
        ans += i*calculateNoOFactors(i);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 394228
#include <iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin >>a >> b >> c >> d;
	int at = c / b;
	int aa = a / d;
	if(c % b){
		at += 1;
	}
	if(a % d){
		aa += 1;
	}
	if(at <= aa){
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define INF (int)1e9+5
#define nax (int)1e5+2
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hello\n"
#define f first
#define s second
using namespace std;



int main(){
	fast;
	ll n,k;
	cin>>n>>k;
	int ans = 0;
	while(n>=1){
		n = n/k;
		ans++;
	}
	cout<<ans;
	
	return 0;
}


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

int main() {
    int n;
    cin >> n ;
    double p[n];
    for(int i=0;i<n;i++)cin >> p[i];

    double dp[n][n+1];

    dp[0][0] = 1.0-p[0];
    dp[0][1] = p[0];

    for(int i=2;i<n+1;i++)dp[0][i] = 0;
    for(int i=1;i<n;i++)dp[i][0] = dp[i-1][0]*(1-p[i]);
    for(int i=1;i<n;i++)for(int j=1;j<n+1;j++)dp[i][j] = dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);

    double ans = 0;
    for(int i=0;i<n+1;i++)if(i>n-i)ans += dp[n-1][i];
    cout << setprecision(10)<<ans << endl;

}



Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
#define MAX_N 200005
class UnionFind
{
public:
  int par[MAX_N];
  int depth[MAX_N];
  int nGroup[MAX_N];
  UnionFind(int n) {
    init(n);
  }
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
int main() {
  int N, M;
  cin >> N >> M;
  UnionFind uf(N+M);
  rep(i, N) {
    int K;
    cin >> K;
    rep(k, K) {
      int l;
      cin >> l;
      l--;
      uf.unite(i, l+N);
    }
  }
  bool ok = true;
  rep(i, N) {
    if(uf.root(0) != uf.root(i)) ok = false;
  }
  cout << (ok ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n, a, b;

    cin >> n >> a >> b;

    if ((b - a) % 2 == 0)
    {
        cout << (b - a) / 2 << endl;
    }
    else
    {
        cout << min({b - 1, n - a, (n * 2 - a - b + 1) / 2, (a + b - 2 + 1) / 2}) << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
char g[8][8][8];
int n, m, p;
int dx[]={1, 0, 0, 1, 0, 1, 1, 0, 1, 1, -1, 1, 1};
int dy[]={0, 1, 0, 1, 1, 0, -1, 1, 0, 1, 1, -1, 1};
int dz[]={0, 0, 1, 0, 1, 1, 0, -1, -1, 1, 1, 1, -1};

bool check(int X, int Y, int turn){// 0->Black, 1->White

   for(int z=0; z<n; z++){
      if(g[X][Y][z]=='.')for(int _z=z; _z-1>=0; _z--){
         swap(g[X][Y][_z], g[X][Y][_z-1]);
      }
   }

   int Z=-1;
   for(int z=n-1; z>=0; z--){
      if(g[X][Y][z]!='.') Z=z;
   }

   //cout<< g[X][Y][Z]<< endl;
   for(int k=0; k<13; k++){
      int seq=1;
      int _X=X;
      int _Y=Y;
      int _Z=Z;
      while(1){
         _X+=dx[k];
         _Y+=dy[k];
         _Z+=dz[k];
         if(!(0<=_X&&_X<n&&0<=_Y&&_Y<n&&0<=_Z&&_Z<n)) break;
         if(g[_X][_Y][_Z]!=g[X][Y][Z]) break;
         seq++;
      }
      _X=X;
      _Y=Y;
      _Z=Z;
      while(1){
         _X-=dx[k];
         _Y-=dy[k];
         _Z-=dz[k];
         if(!(0<=_X&&_X<n&&0<=_Y&&_Y<n&&0<=_Z&&_Z<n)) break;
         if(g[_X][_Y][_Z]!=g[X][Y][Z]) break;
         seq++;
      }
      //cout<< seq<< endl;
      if(seq>=m) return true;
   }

   return false;
}

int main(){

   while(1){
      cin>> n>> m>> p;
      if(!n) break;
      for(int i=0; i<n; i++){
         for(int j=0; j<n; j++){
            for(int k=0; k<n; k++){
               g[i][j][k]='.';
            }
         }
      }

      int turn=-1;
      for(int _p=0; _p<p; _p++){
         int x, y;
         cin>> x>> y;
         if(_p&1){
            g[x-1][y-1][0]='W';
         }else{
            g[x-1][y-1][0]='B';
         }
         if(check(x-1, y-1, _p)){
            if(turn==-1) turn=_p;
         }
      }

      if(turn>=0){
         if(turn&1){
            cout<< "White "<< turn+1<< endl;
         }else{
            cout<< "Black "<< turn+1<< endl;
         }
      }else{
         cout<< "Draw"<< endl;
      }
   }
   return 0;
}

Measured memory_bytes: 2972
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    char b;
    cin>>b;
    char a;
    if(b=='A')a='T';
    else if(b=='T')a='A';
    else if(b=='G')a='C';
    else a='G';
    cout<<a<<endl;
}

Measured memory_bytes: 256
//created by krishna
#include <bits/stdc++.h>
using namespace std;
#define endl "\n" 
typedef long long ll;
typedef unsigned long long ull;
#define debug(x) cout<<"the value of "<<#x<<" is "<<x<<endl;
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int n;
    cin>>n;
    vector<int>arr(n);
    for(auto& i:arr)
        cin>>i;
    int maxx=*max_element(arr.begin(),arr.end());
    int dp[maxx+1];
    for(int i=1;i<=maxx;i++)
        dp[i]=0;
    for(auto i:arr){
        int index=2;
        while(i*index<=maxx){
            dp[i*index]=1;
            index++;
        }
    }
    unordered_map<int,int>ma;
    for(auto i:arr)
        ma[i]++;
    for(auto i:ma){
        if(i.second>1)
            dp[i.first]=1;
    }
    int ans=0;
    for(auto i:arr)
        if(dp[i]==0)
            ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 15964
#include <bits/stdc++.h>
using namespace std;
bool mp[10][10];
int h,w;

void dfs(int i,int j){
  if(mp[i][j]==0) return;
  mp[i][j]=0;
  if(mp[i+1][j]) return dfs(i+1,j);
  return dfs(i,j+1);
}

int main(){
  cin>>h>>w;
  string s;
  for(int i=0;i<h;i++){
    cin>>s;
    for(int j=0;j<w;j++)
      mp[i][j]=(s[j]!='.');
  }
  dfs(0,0);
  bool f=0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(mp[i][j]){f=1;break;}
  if(f)cout<<"Impossible";
  else cout<<"Possible";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

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

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

const ll MOD = 1000000007;
const ll INF = 100000;

int n, m, cnt;

int prime[100010];
bool is_prime[1000010];
int like[100010];
void sieve(int n){

    int p = 0;
    for (int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;

    for (int i = 2; i <= n; i++){
        if (is_prime[i]){
            if (is_prime[(i + 1) / 2]) like[cnt++] = i;
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
    }
}

int main(void){
    int Q;
    cin >> Q;
    cnt = 0;
    sieve(100000);
    for (int i = 0; i < Q; i++){
        int l, r;
        cin >> l >> r;
        l--; r++;
        cout << lower_bound(like, like + cnt, r) - lower_bound(like, like + cnt, l) << endl;
    }

}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, a[50], b[50], t[51][51];
bool f[50][51];
ll res;

int main() {
	for (int i = 0; i <= 50; ++i) {
		for (int j = 0; j <= 50; ++j) {
			t[i][j] = 0xE869120;
		}
		t[i][i] = -1;
	}
	for (int i = 0; i <= 50; ++i) {
		for (int j = 1; j <= i; ++j) {
			t[i][i%j] = min(t[i][i%j], j);
			for (int k = 0; k < i%j; ++k) {
				if (t[i%j][k] != 0xE869120) {
					t[i][k] = min(t[i][k], j);
				}
			}
		}
	}
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		f[i][a[i]] = true;
	}
	for (int i = 0; i < N; ++i) {
		cin >> b[i];
	}
	while (true) {
		int ma = -1;
		for (int i = 0; i < N; ++i) {
			int mi = 0xE869120;
			for (int j = 0; j <= 50; ++j) {
				if (f[i][j]) {
					mi = min(mi, t[j][b[i]]);
				}
			}
			ma = max(ma, mi);
		}
		if (ma == -1) {
			cout << res << endl;
			return 0;
		}
		if (ma == 0xE869120) {
			cout << -1 << endl;
			return 0;
		}
		res += (1ll << ma);
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j <= 50; ++j) {
				if (f[i][j]) {
					f[i][j%ma] = true;
				}
			}
		}
	}
}

Measured memory_bytes: 256
n=int(input())
L=input().split( )
A=[int(L[i]) for i in range(n)]
k=10002
C=[]
for i in range(k):
    C += [0]
#print(C[:20])

for j  in range(n):
     C[A[j]]+=1
#print(C[:20])
B=[]

for j in range(k):
    for l in range(C[j]):
        B.append(j)

print(*B)



Measured memory_bytes: 256000
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1000+10;
int main()
{
    int n;
    while(~scanf("%d",&n)){
        set<int>se;
        int x;
        for(int i=0;i<n;i++){
            scanf("%d",&x);
            se.insert(x);
        }
        printf("%d\n",se.size());
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long,long long>
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
bool prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int k=((n+1000-1)/1000);
    cout<<(k*1000)-n;
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

int n,z,w;
int a[2005];

int main(){
  cin>>n>>z>>w;
  for(int i=0;i<n;i++)cin>>a[i];

  if(n == 1){
    cout<<abs(w-a[0])<<endl;
    return 0;
  } else {
    if(abs(w-a[n-1]) > abs(a[n-2]-a[n-1])){
      cout<<abs(w-a[n-1])<<endl;
    } else {
      cout<<abs(a[n-2]-a[n-1])<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256