akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

int main(void){
  string str;
  int n, k=0;
  cin >> n >> k;
  cin >> str;
  // cout << str[k-1] << endl;
  switch (str[k-1]) {
    case 'A':
      str[k-1] = 'a';
      break;
    case 'B':
      str[k-1] = 'b';
      break;
    case 'C':
      str[k-1] = 'c';
      break;
  }
  cout << str << endl;
  return 0;
}

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

int main() {
	int n;
	cin>>n;
	int a[n][3];
	int i,j;
	for(i=0;i<n;i++){
	    for(j=0;j<3;j++){
	        cin>>a[i][j];
	    }
	}
	
	int dp[n][3];
	for(j=0;j<3;j++){
	    dp[0][j] = a[0][j];
	}
	for(i=1;i<n;i++){
	        dp[i][0] = a[i][0] + max(dp[i-1][1] , dp[i-1][2]);
	        dp[i][1] = a[i][1] + max(dp[i-1][0] , dp[i-1][2]);
	        dp[i][2] = a[i][2] + max(dp[i-1][0] , dp[i-1][1]);
	}
    int mx = INT_MIN;
    for(i=0;i<3;i++){
        mx = max(dp[n-1][i],mx);
    }
    cout<<mx<<endl;
	return 0;
}


Measured memory_bytes: 2560
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int[] a = new int[3];

      for (int i = 0; i < a.length; i++) {
         a[i] = sc.nextInt();
      }

      Arrays.sort(a);

      int c;

      if ((a[1] + a[2]) % 2 == 0 && (a[1] + a[0]) % 2 == 0) {
         c = a[2] - ( a[0] + a[1] ) / 2;
         System.out.println(c);
      }

      else if ((a[0] + a[1]) % 2 == 0) {
         c = a[2] - ( a[0] + a[1] + 2) / 2 + 1;
         System.out.println(c);
      }

      else {
         c = a[2] - ( a[0] + a[1] - 1) / 2 + 1;
         System.out.println(c);
      }
   }
}

Measured memory_bytes: 21844
#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>;


int main (){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll asset = 1000;
  ll stock = 0;
  
  rep(i, n-1){
    if(a[i] < a[i+1]){
      ll add = asset / a[i];
      stock += add;
      asset -= a[i] * add;
    }if(a[i] > a[i+1]){     
      if(a[i-1] < a[i]){
        asset += a[i] * stock;
        stock = 0;
      }
      int t =i;
      while(a[t-1] == a[i]){
        t--;
        if(a[t-1] < a[t]){
        asset += a[i] * stock;
        stock = 0;
        }
      }
    }
  }
  asset += a[n-1] * stock;
  
  cout << asset << endl; 
  
  return 0;
}


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

int main()
{
  int n;
  cin>>n;
  vector<double> a(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  double sum=0;
  for(auto&& e: a) {
    sum+=1/e;
  }
  cout<<1/sum;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main() {
	string str;
	int n;//シャッフル回数
	
	int h; //何枚目か
	string sub1, sub2, rep1, rep2;

	while (1) {
		cin >> str;
		if (str == "-") break;
		cin >> n;

		for (int i = 0; i < n; i++) {
			cin >> h;
			sub1 = str.substr(0, h);
			//cout << sub1 << endl;
			sub2 = str.substr(h, str.size() - 1);
			//cout << sub2 << endl;

			str = sub2 + sub1;
		}

		cout << str << endl;

	}

	return 0;

}


Measured memory_bytes: 3156
#include <stdio.h>

int isPrime(int x){
	int i;
	if ( x == 2 ){
		return 1;
	}
	else if ( x < 2 || x % 2 == 0 ){
		return 0;
	}
		for( i = 3 ; i * i <= x ; i+=2 ){
			if( x % i == 0 ){
				return 0;
			}
                }
			return 1;
		}
		
	int main(void){
		int n,x,i;
		int ans = 0;
		
		scanf("%d",&n);
		for( i = 0 ; i < n ; i++ ){
			scanf("%d",&x);
			if ( isPrime(x) ){
				ans = ans + 1 ;
			}
        }
			printf("%d\n",ans);
			
			return 0;
			
		}
		

Measured memory_bytes: 1840
#include <stdio.h>

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;

void ACoffee(std::istream& in, std::ostream& out) {
  string s;
  in >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    out << "Yes\n";
  } else {
    out << "No\n";
  }
}

int main(int argc, char** argv) { ACoffee(cin, cout); return 0; }


Measured memory_bytes: 760
H, W = [int(a) for a in input().split()]
cambus = []
cambus.append(list("."*(W+2)))
for i in range(H):
     cambus.append(["."] + list(input()) + ["."])
cambus.append(list("."*(W+2)))
stop_num = 0


for i in range(H):
    for j in range(W):
        if cambus[i+1][j:j + 3] == [".", "#", "."]:
            if cambus[i][j+1] == "." and cambus[i+2][j+1] == ".":
                stop_num = 1
                break
if stop_num == 1:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3064
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,k;
int a[200005],cnt0[200005];
int dp[45][2];
int dfs(int pos,bool free){
	if(pos==-1)return 0;
	if(~dp[pos][free])return dp[pos][free];
	int ret=0;
	for(int i=0;i<=(free?1:(k>>pos)&1);i++){
		ret=max(ret,dfs(pos-1,(free|(i<((k>>pos)&1))))+(1ll<<pos)*(i==0?n-cnt0[pos]:cnt0[pos]));
	}
	return dp[pos][free]=ret;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	memset(dp,-1,sizeof dp);
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=0;i<=42;i++)for(int j=1;j<=n;j++)cnt0[i]+=((a[j]&(1ll<<i))==0);
	cout<<dfs(42,0)<<endl;
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

struct P{
  int x;
  int y;
};

struct St{
  P mp;
  P cp;
  int cost;
};

int xdir[4] = {0, 1, 0, -1}, ydir[4] = {1, 0, -1, 0};

bool mbfs(int a[8][8], int w, int h, P mn, P cg, int gy, int gx)
{
  bool f = false;
  queue<P> que;
  P p, q;
  bool vis[8][8];
  fill(&vis[0][0], &vis[7][7], true);
  vis[mn.y][mn.x] = false;
  que.push(mn);

  while(!que.empty()){
    p = que.front();
    que.pop();
    if(p.x == gx && p.y == gy){
      f = true;
      break;
    }

    for(int i = 0; i < 4; i++){
      q.x = p.x + xdir[i];
      q.y = p.y + ydir[i];
      if(0 <= q.x && q.x < w && 0 <= q.y && q.y < h && a[q.y][q.x] != 1 && !(q.y == cg.y && q.x == cg.x)){
	if(vis[q.y][q.x]){
	  vis[q.y][q.x] = false;
	  que.push(q);
	}
      }
    }
  }

  return f;
}

int bfs(int a[8][8], int w, int h, P mn, P cg)
{
  int r = -1;
  queue<St> que;
  bool vis[8][8][8][8];
  St st1, st2;
  st1.mp = mn;
  st1.cp = cg;
  st1.cost = 0;
  que.push(st1);
  fill(&vis[0][0][0][0], &vis[7][7][7][7], true);

  while(!que.empty()){
    st1 = que.front();
    que.pop();
    if(a[st1.cp.y][st1.cp.x] == 3){
      r = st1.cost;
      break;
    }

    for(int i = 0; i < 4; i++){
      int dx = st1.cp.x + xdir[i];
      int dy = st1.cp.y + ydir[i];
      int mdx = st1.cp.x - xdir[i];
      int mdy = st1.cp.y - ydir[i];

      if(0 <= dx && dx < w && 0 <= dy && dy < h && a[dy][dx] != 1){
	if(0 <= mdx && mdx < w && 0 <= mdy && mdy < h && a[mdy][mdx] != 1 && vis[mdy][mdx][st1.cp.y][st1.cp.x]){
	  if(mbfs(a, w, h, st1.mp, st1.cp, mdy, mdx)){
	    vis[mdy][mdx][st1.cp.y][st1.cp.x] = false;
	    st2.cp.y = dy;
	    st2.cp.x = dx;
	    st2.mp = st1.cp;
	    st2.cost = st1.cost + 1;
	    que.push(st2);
	  }
	}
      }
    }
  }

  return r;
}

int main()
{
  int w, h, a[8][8];
  P mn, cg;

  while(cin>>w>>h && (w+h)){
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	cin >> a[i][j];
	if(a[i][j] == 2){
	  cg.x = j;
	  cg.y = i;
	} else if(a[i][j] == 4){
	  mn.x = j;
	  mn.y = i;
	}
      }
    }

    cout << bfs(a, w, h, mn, cg) << endl;
  }

  return 0;
}

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

if m == 2:
    ans = n
    for i in range(2):
        t = 0
        for j in range(n):
            idx = (i+j)%2 + 1
            if idx != a[j]:
                t += 1
        ans = min(ans, t)
else:
    ans = 0
    prev = a[0]
    for i in range(1,n):
        if prev == a[i]:
            ans += 1
            a[i] = -1
        prev = a[i]

print(ans)



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

using ll = long long;

ll gcd(ll a, ll b)
{
    while (b != 0) {
        ll r = a%b;
        a = b;
        b = r;
    }
    return a;
}

int main()
{
    int T;
    scanf("%d", &T);
    while (T--) {

        ll a, b, c, d;
        scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
        ll ft = max(1ll, (a-c+b-1)/b);
        a -= ft*b;
        bool ans = true;
        if (a < 0) {
            ans = false;
        } else if (d < b) {
            ans = false;
        } else if (b <= c) {
            ans = true;
        } else {
            ll g = gcd(b, d);
            ll x = (b-a-1)/g;
            a += x*g;
            if (a > c) ans = false;
            else ans = true;
        }
        if (ans) printf("Yes\n");
        else printf("No\n");

    }

    return 0;
}


Measured memory_bytes: 256
// ABC105_B
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

int main() {
    // input
    ll N;
    cin >> N;
    
    // calculation
    if (N%4 == 0 || N%7 == 0 || N%11 == 0) {
        cout << "Yes" << "\n";
    } else {
        ll num_4 = N/4, num_7 = N/7;
        for (ll i = 0; i <= num_4; ++i) {
            for (ll j = 0; j <= num_7; ++j) {
                if (N == 4*i + 7*j) {
                    cout << "Yes" << "\n";
                    return 0;
                }
            }
        }
        cout << "No" << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
N=int(input())
S=input()

count=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            tmp_number=str(i) + str(j) + str(k)
            a = S.find(tmp_number[0])
            if a == -1:
                continue
            b = S[(a+1):].find(tmp_number[1])
            # print(S[a:])
            if b == -1:
                continue
            c = S[(a+b+2):].find(tmp_number[2])
            # print(S[(a+b):])
            if c == -1:
                continue
            count+=1
            # print(a,b,c)
            # print(tmp_number)
print(count)


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

const int N = 2e5 + 10;
int a[N];

void solve() {
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    for(int i = k + 1; i <= n; i++) {
        if(a[i] > a[i - k]) puts("Yes");
        else puts("No");
    }
}

int main() {
//    freopen("in.txt", "r", stdin);
//    int t; cin >> t; while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 4436
def read_input():
    a, b, c = input().strip().split()
    return a, b, c

def submit():
    a, b, c = read_input()

    if a[-1] == b[0] and b[-1] == c[0]:
        print('YES')
    else:
        print('NO')



if __name__ == '__main__':
    submit()

Measured memory_bytes: 38256
N, Ma, Mb = map(int, input().split())
items = []
for i in range(N):
    a, b, c = map(int, input().split())
    items.append((a, b, c))

a_sum = sum([item[0] for item in items])
b_sum = sum([item[1] for item in items])
inf = float("inf")
dp = [[[inf for _ in range(a_sum + 50)] for _ in range(b_sum + 50)] for i in range(N + 1)]
dp[0][0][0] = 0

for i in range(N):
    for a in range(a_sum):
        for b in range(b_sum):
            if dp[i + 1][a][b] > dp[i][a][b]:
                dp[i + 1][a][b] = dp[i][a][b]
            if dp[i + 1][a + items[i][0]][b + items[i][1]] > dp[i][a][b] + items[i][2]:
                dp[i + 1][a + items[i][0]][b + items[i][1]] = dp[i][a][b] + items[i][2]

ans = inf
for a in range(1, a_sum + 1):
    for b in range(1, b_sum + 1):
        if a * Mb == b * Ma:
            ans = min(ans, dp[N][a][b])
if ans != inf:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 112604
#include <iostream>

using namespace std;

int main(void) {
	int num, i, a, ans = 0;
	cin >> num;
	for (i = 1; i <= num; i++) {
		scanf("%d", &a);
		if (a == i) {
			ans++;
			if (i < num) {
				scanf("%d", &a);
				i++;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N;
    cin >> N;
    vector<ll> A(N+1);
    vector<ll> B(N);
    REP(i,N+1)cin >> A[i];
    REP(i,N)cin >> B[i];
    ll sum = 0;
    REP(i,N+1){
        if(i != 0){
            sum += min(B[i-1],A[i]);
            A[i] -= min(B[i-1],A[i]);
        }
        if(i != N){
            sum += min(B[i],A[i]);
            B[i] -= min(B[i],A[i]);
        }
    }
    cout << sum << "\n";
}

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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int A,B; cin >> A>>B;
    cout << max(A,B)*2-(A==B?0:1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
using namespace std;
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    unordered_map<int, int> s;
    int n;
    for (cin >> n; n--;) {
        int x;
        cin >> x;
        s[x]++;
    }
    auto e = s.end(), i = s.find(1);
    int r = i != e && i->second == 1;
    if (i == e) {
        for (auto p : s) {
            if (p.second == 1) {
                int x = p.first;
                int i;
                for (i = 2; i * i <= x && (x % i || s.find(i) == e &&  s.find(x / i) == e); i++);
                if (i * i > x)
                    r++;
            }
        }
    }
    cout << r << '\n';
    return 0;
}


Measured memory_bytes: 11240
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    int[][] happiness = new int[N][3];
    for(int i = 0; i < N; i++){
      String[] s = sc.nextLine().split(" ");
      happiness[i][0] = Integer.parseInt(s[0]);
      happiness[i][1] = Integer.parseInt(s[1]);
      happiness[i][2] = Integer.parseInt(s[2]);
    }
    
    int[][] result = new int[N][3];
    result[0][0] = happiness[0][0];
    result[0][1] = happiness[0][1];
    result[0][2] = happiness[0][2];
    for(int i = 0; i < N-1; i++){
      for(int j = 0; j < 3; j++){
        for(int k = 0; k < 3; k++){
          if(j == k){
            continue;
          }
          
          if(result[i][j] + happiness[i+1][k] > result[i+1][k]){
            result[i+1][k] = result[i][j] + happiness[i+1][k];
          }
        }
      }
    }
    int max = 0;
    for(int i = 0; i < 3; i++){
      if(result[N-1][i] > max){
        max = result[N-1][i];
      }
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 128204
n = int(input())
numlist = [int(i) for i in input().split()]
oddnum = [j for j in numlist if j%2 == 0]
checknum = [k for k in oddnum if k%3 == 0 or k%5 == 0]
if len(oddnum) == len(checknum) :
    print("APPROVED")
else :
    print("DENIED")

Measured memory_bytes: 3060
#ifndef ONPC
  #define _FORTIFY_SOURCE 0
  #pragma GCC optimize("Ofast")
  #pragma GCC optimize("no-stack-protector")
  #pragma GCC optimize("unroll-loops")
  #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
  #pragma GCC optimize("fast-math")
#endif

#include <bits/stdc++.h>

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int a, b, m;
    cin >> a >> b >> m;
    vector<int> aa(a);
    for (int i =0; i < a; i++)  cin >> aa[i];
    vector<int> bb(b);
    for (int i = 0; i < b; i++) cin >> bb[i];

    int ans = INF;
    for (int i = 0; i < m; i++){
      int x, y, c;
      cin >> x >> y >> c;
      x--; y--;
      ans = min(ans, aa[x] + bb[y] - c);
    }

    sort(aa.begin(), aa.end());
    sort(bb.begin(), bb.end());
    ans = min(ans, aa[0] + bb[0]);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1024
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		if(x==0) {
			System.out.println(1);
		} else {
			System.out.println(0);
		}


	}
}


Measured memory_bytes: 35596
#include<stdio.h>

int main(void){
    int x[5];
    for (int i=0; i<5; i++) scanf("%d",&x[i]);
    for (int i=0; i<5; i++){
        if (x[i] == 0) { 
            printf("%d\n", i + 1);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1692
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll inf=99999999999999999;
#define rep(i,t,n) for(int i=t;i<n;i++)
const int maxn=1e2+7;
ll d[maxn][maxn];
int main(){
    int a,n,m,x;ll z;
    scanf("%d",&n);
    rep(i,0,n) rep(j,0,n) d[i][j]=inf;
    rep(i,0,n) d[i][i]=0;
    rep(i,0,n){
        scanf("%d%d",&a,&m);
        rep(j,0,m){
            scanf("%d%lld",&x,&z);
            d[a][x]=min(d[a][x],z);
        }
    }
    if(n==1){
        printf("0 0\n");
        return 0;
    }
    rep(k,0,n) rep(i,0,n) rep(j,0,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    rep(i,0,n) printf("%d %lld\n",i,d[0][i]);
    return 0;
}


Measured memory_bytes: 3260
#include<iostream>
#include<vector>

using namespace std;

int main(void){
    int H, W, N;
    cin >> H >> W;
    cin >> N;
    vector<int> v;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        for(int k=0;k<a;k++) v.push_back(i+1);
    }

    vector<vector<int>> m(H, vector<int>(W));
    for(int i=0;i<v.size(); i++){
        int y = i / W;
        int x = y%2 ? W-i%W-1 : i%W;
        m[y][x] = v[i];
    }

    for(int y=0; y<H;y++) {
        for(int x=0; x<W;x++) cout << m[y][x] << " ";
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// ケース数取得
	int liN, liM;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d%d", &liN, &liM);

	// 時間
	int liTime = 1900 * liM + 100 * (liN - liM);
	for (i = 0; i < liM; i++) {
		liTime *= 2;
	}

	// 結果セット
	sprintf(lc1Out, "%d\n", liTime);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    // 整数の入力
    int n;
    cin >> n;

    vector<int> a;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;

        a.push_back(t);
    }

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    int dif = 0;
    
    int l = 1;

    for(int i = 0; i < n; i++){
       dif = dif + a[i] * l;
       l = l * -1;
    }
    
    // 出力
    cout << dif << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
int main(){
    {rep1(i,50) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    ll ans=0;
    vector<ll> A(N,0);
    rep(i,N) cin>>A[i];
    
    ll l=0,r=0;
    ll tmp_sum=A[0],tmp_xor=A[0];
    while(1){
        //(l,r):(N-2,N-2)->(N-1,N-1)と来たときの終了
        if(r==N-1){
            ans+=1; //ans+=((r-l+2)*(r-l+1))/2;
            cout<<ans<<endl;
            return 0;
        }
        
        //次rがOKなら進める
        while(tmp_sum+A[r+1] <= (tmp_xor^A[r+1])){
            tmp_sum+=A[r+1];
            tmp_xor^=A[r+1];
            r++;
            
            //lastまでOKなら計算して終了
            if(r==N-1){
                ans+=((r-l+2)*(r-l+1))/2;
                cout<<ans<<endl;
                return 0;
            }
        }
        //l~r:OK
        ans+=(r-l+1);
        
        //lを外してやる
        tmp_sum-=A[l];
        tmp_xor^=A[l];
        l++;
        
        //lがrを超えるならこうしてやる
        if(chmax(r,l)){
            tmp_sum+=A[r];
            tmp_xor^=A[r];
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4848
#include <iostream>
#include <utility>
#include <list>
#include <algorithm>

int main() {
	int n, m, p, q, r;
	while (std::cin >> n, n != 0) {
		std::list<std::pair<int, int>> cards;
		cards.push_back({ 1, n });

		std::cin >> m >> p >> q >> r;
		for (int i = 0; i < m; ++i) {
			int x, y;
			std::cin >> x >> y;

			decltype(cards)::iterator sec1 = cards.end(), sec2;
			int num = 0;
			for (auto itr = cards.begin(); itr != cards.end(); ++itr) {
				num += itr->second - itr->first + 1;

				if (num >= x && sec1 == cards.end()) {
					if (num == x) {
						sec1 = itr;
						sec2 = cards.end();
						continue;
					}

					cards.insert(
						itr,
						{
							{itr->first, itr->second - (num - x)},
							{itr->second - (num - x) + 1, itr->second}
						}
					);
					sec1 = itr = cards.erase(itr);
					--itr, ----sec1;
					sec2 = cards.end();

					num = x + itr->second - itr->first + 1;
				}
				if (num >= y && sec2 == cards.end()) {
					if (num == y) {
						sec2 = itr;
						++sec2, ++sec1;
						break;
					}
					cards.insert(
						itr,
						{
							{ itr->first, itr->second - (num - y) },
							{ itr->second - (num - y) + 1, itr->second }
						}
					);
					sec2 = itr = cards.erase(itr);
					--itr, --sec2, ++sec1;

					break;
				}
			}

			cards.splice(cards.end(), cards, sec1, sec2);
			cards.splice(cards.end(), cards, cards.begin(), sec2);
		}

		int count = 0, ans = 0;
		for (auto&& rng : cards) {
			const int rngSize = rng.second - rng.first + 1;
			int prev = count;
			count += rngSize;

			if (count < p)
				continue;

			if (prev < p && count >= p)
				rng.first = rng.second - (count - p);

			if (count > q) {
				ans += std::min(q - prev, std::max(r - rng.first + 1, 0));
				break;
			}

			ans += std::min(rng.second - rng.first + 1, std::max(r - rng.first + 1, 0));
		}

		std::cout << ans << std::endl;
	}
}

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

int main()
{
  int a, b;
  string s;
  cin >> a >> b;
  cin >> s;
  
  if (s.at(a) != '-')
  {
    cout << "No";
    return 0;
  }
  
  for (int i = 0; i < s.size(); i ++)
  {
    if (s.at(i) == '-' && i != a)
    {
      cout << "No";
      return 0;
    }
  }
  
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
long long f[maxn], g[maxn];
int main(){
	f[0] = 1;
	g[0] = 1;
	for(int i = 1; i < maxn; i++) f[i] = 2 * f[i - 1] + 1;
	for(int i = 1; i < maxn; i++) g[i] = 2 * g[i - 1] + 3;
	int n; long long x; cin >> n >> x;
	long long ans = 0;
	while(n > 0 && x){
		if(x == 1){
			n = 0;
			x = 0;
		} else if(abs(x - g[n]) <= 1){
			ans += f[n];
			n = 0;
			x = 0;
		} else {
			x--;
			if(x < g[n - 1]){
				n--;
			} else if(x == g[n - 1]){
				ans += f[n - 1];
				n = 0;
				x = 0;
			} else {
				ans += f[n - 1];
				ans += 1;
				x -= g[n - 1];
				x--;
				n--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}



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

const int MAX = 1e5 + 5;

#define dbg(a) cout << "-> " << __LINE__ << ": " << #a << " = " << a << endl

using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector <int> a(n + 1);
	long long sum = 0, now = 1, ans = 1;
	for (int i = 0; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	if (n == 0) {
		if (a[0] == 1) {
			cout << "1\n";
		}
		else {
			cout << "-1\n";
		}
		return 0;
	}
	else if (a[0] != 0) {
		cout << "-1\n";
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		now = min(now * 2, sum);
		ans += now;
		now -= a[i];
		sum -= a[i];
		if (now < 0) {
			ans = -1;
			break;
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, X;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;
    int ans = 0;
    for(int i=0; i<=A; i++){
        for(int j=0; j<=B; j++){
            for(int k=0; k<=C; k++){
                if(500*i+100*j+50*k==X){
                    ans += 1;
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
	int a,b;
	cin >> a >> b;
	int k = 0;
	if(a >= 13)
	{
		k = b;
	}
	else if(a < 6)
	{
		k = 0;
	}
	else
	{
		k = b / 2;
	}
	cout << k << endl;
	return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int H=in(),W=in();
	vector<char> B(H*W);
	deque<bool> F(H*W,false);
	REP(i,H){
		REP(j,W){
			B[j+i*W]=in<char>();
		}
	}
	for(int i=0;i<H;i++){
		bool flag = false;
		REP(j,W){
			if(B[i*W+j]=='#'){
				flag = true;
				break;
			}
		}
		if(!flag){
			REP(j,W){
				F[i*W+j] = true;
			}
		}
	}
	for(int j=0;j<W;j++){
		bool flag = false;
		REP(i,H){
			if(B[i*W+j]=='#'){
				flag = true;
				break;
			}
		}
		if(!flag){
			REP(i,H){
				F[i*W+j] = true;
			}
		}
	}

	REP(i,H){
		bool flag=false;
		REP(j,W){
			if(!F[i*W+j]){
				cout << B[i*W+j];
				flag = true;
			}
		}
		if(flag) cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> X;
    cout << (X / 500) * 1000 + ((X % 500) / 5) * 5 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	if (N == 100) N++;

	cout << N;
	for (int i = 0; i < D; i++) {
		cout << "00";
	}
	cout << endl;
}

Measured memory_bytes: 3532
import java.util.*;

public class Main{
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args){
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = (b * 2 >= a) ? 0 : a - b * 2;
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
L,R = map(int,input().split())
ans = 2019

for i in range(L,R+1):
    for j in range(i+1,R+1):
        if(j % 2019 == 0):
            print(0)
            exit()
        ans = min(ans, (i*j) % 2019)
print(ans)

Measured memory_bytes: 9068
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  ll n, k;
  cin >> n >> k;
  int x, y;
  map<ll, ll> a;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    a[x] += y;
  }
  for (auto i : a) {
    if (k > i.second) k -= i.second;
    else {
      cout << i.first << endl;
      return 0;
    }
  }
}


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

int main(){
    int n;
    vector<pair<int,int>> rec;

    cin >> n;
    for(int i=1;i<=n;++i){
        int a;
        cin >> a;
        rec.emplace_back(a, i);
    }
    sort(rec.begin(), rec.end());
    for(int i=0;i<n;++i){
        cout << rec[i].second << " \n"[i==n-1];
    }

    return 0;
}

Measured memory_bytes: 1780
#include<stdio.h>

int main(){
  int n,k;
  scanf("%d %d",&n,&k);

  int ans =1;
  int i;
  for(i-0;i<n;i++){
    if(2*ans>ans+k){
      ans += k;
    }else{
      ans *= 2;
    }
  }

  printf("%d\n",ans);


  return 0;

}


Measured memory_bytes: 128
N, A, B, C, *l = map(int, open(0).read().split())

INF = 1e9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(A - a) + abs(B - b) + abs(C - c) - 30 if a * b * c != 0 else INF
    
    v1 = dfs(cur + 1, a, b, c)
    v2 = dfs(cur + 1, a + l[cur], b, c) + 10
    v3 = dfs(cur + 1, a, b + l[cur], c) + 10
    v4 = dfs(cur + 1, a, b, c + l[cur]) + 10
    
    return min(v1, v2, v3, v4)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3188
N = int(input())
T, A = list(map(int, input().split(" ")))
height = list(map(int, input().split(" ")))

place_temperature = 0
diff_A =[]
for i in range(N):
    place_temperature= T - height[i] * 0.006
    diff_A.append(abs(A - place_temperature))

print(diff_A.index(min(diff_A)) + 1)

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int i;
    scanf("%d",&i);
    printf("%d\n",a[i-1]);
  return 0;
}

Measured memory_bytes: 128
from bisect import bisect_left

N, M = map(int, input().split())
d = dict()
A = list(map(int, input().split()))
for i in range(N):
	d[A[i]] = d.get(A[i], 0) + 1
for i in range(M):
	B, C = map(int, input().split())
	d[C] = d.get(C, 0) + B

ans = 0
keys = sorted(list(d.keys()), reverse = True)
for k in keys:
	kosuu = min(N, d.get(k))
	ans += k * kosuu
	N -= kosuu
	if N == 0:
		break
print(ans)

Measured memory_bytes: 108396
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
#define lli long long int
#define uli unsigned long long int
#define INF 9999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000010
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  long long A,B,C,D,E,F,N,K,M,Z,sum=0,num=0,flag=0;string S,T;
  cin >> N >> K;
  Vec(P,Bint,N+1,1);
  rep(i,1,N+1)cin >> P[i];
  rep(i,K+1,N+1){
    if(P[i]>P[i-K])Out("Yes");
    else Out("No");
  }
}

Measured memory_bytes: 9608
#include <stdio.h>
#include <math.h>

double X(int s[],int n,double ave);

int main(void) {
	int s[1000];
	int n,i,sum;
	double ave;
	for(;;){
		scanf("%d",&n);
		if(n==0) break;
		sum=0;
		for(i=0;i<n;i++){
			scanf("%d",&s[i]);
			sum+=s[i];
		}
		ave=(double)sum/(double)n;
		printf("%lf\n",sqrt(X(s,n,ave)));
	}
	return 0;
}

double X(int s[],int n,double ave){
	double sum=0;
	for(int i=0;i<n;i++){
		sum+=(s[i]-ave)*(s[i]-ave);
	}
	return sum/(double)n;
}


Measured memory_bytes: 2044
n, m = (int(x) for x in input().split())
A = [[0 for i in range (m)] for j in range (n)]
B = [0]*m

for _ in range(n):
    a = [int(x) for x in input().split()]
    for i,j in enumerate(a):
        A[_][i] = j

for _ in range(0, m):
    B[_] = int(input())

for i in range(0, n):
    sum = 0 
    for j in range(0, m):
        sum += A[i][j]*B[j]
    print(sum)


Measured memory_bytes: 5792
import * as fs from 'fs';
// main
function main(input: string[]) {
    // param
    let n: number = 0;
    let ans: number = 0;
    // init
    n = Number(input.shift());
    // solve
    ans = Math.floor((n + 1) / 2);
    // answer
    console.log(ans);
}
// entrypoint
function entrypoint() {
    try {
        // linux
        let input = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        console.debug = function () { };
        main(input);
    }
    catch (ex) {
        // windows
        const lines: string[] = [];
        // @ts-ignore
        const reader = require('readline').createInterface({
            // @ts-ignore
            input: process.stdin,
            // @ts-ignore
            output: process.stdout
        });
        reader.on('line', function (line: string) {
            lines.push(line);
        });
        reader.on('close', function () {
            let input = lines;
            main(input);
        });
    }
}
entrypoint();


Measured memory_bytes: 29612
import sys
input = sys.stdin.readline
def print_ans(n, ws):
    """Test Case
    >>> print_ans(3, [1, 2, 3])
    0
    >>> print_ans(4,[1, 3, 1, 1])
    2
    >>> print_ans(8, [27, 23, 76, 2, 3, 5, 62, 52])
    2
    """
    target = sum(ws) 
    tmp = 0
    ans = 10000
    for w in ws:
        tmp += w
        ans = min(abs(target - (tmp * 2)), ans)
    print(ans)



if __name__ == '__main__':
    n = int(input().rstrip())
    ws = list(map(int, input().rstrip().split()))
    print_ans(n, ws)




Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
int n;
int calc(vector<int> v, int p[8]) {
  int r = 1;
  int l = n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (v[j] == p[i]) {
        int x = 1;
        for (int i = 1; i <= l - 1; i++) {
          x *= i;
        }
        r += j * x;
        v.erase((v.begin() + j));
        l--;
        break;
      }
    }
  }
  return r;
}
int main() {
  int m, a, b;
  int p[8] = { };
  int q[8] = { };
  vector<int> v1, v2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> m;
    p[i] = m;
  }
  for (int i = 0; i < n; i++) {
    cin >> m;
    q[i] = m;
  }
  for (int i = 0; i < n; i++) {
    v1.push_back(p[i]);
    v2.push_back(q[i]);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  a = calc(v1, p);
  b = calc(v2, q);
  cout << abs(a - b);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"

int32_t main()
{
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	for(int i=n-2;i>=0;i--)
	{
		if(v[i]>v[i+1])
		{
			v[i]--;
		}
		if(v[i]>v[i+1])
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
/*    #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
//ll  t;cin>>t;while(t--)
{
  ll a,b,c,x=0;
  cin>>a>>b;
  cout<<(a-1)*(b-1)<<endl;
  
  

}
return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint a,b;cin >> a>>b;
    lint ans=0;

    if(b>=0){
        if(a>0){
            ans = 1;
        }else{
            ans = 0;
        }
    }else{
        if((b-a)%2==0){
            ans = -1;
        }else{
            ans = 1;
        }
    }

    if(a==b){
        if(a==0)
            ans = 0;
            else
                ans = 1;
    }
    string s;
    if(ans==-1){
        s = "Negative";
    }else if(ans==0){
        s = "Zero";
    }else{
        s = "Positive";
    }
    cout << s <<"\n";

    return 0;
}

Measured memory_bytes: 256
import sys

n = int(input())
t = list(map(int, input().split()))
m = int(input())

s = sum(t)
ans = []
for i in range(m):
    p, x = map(int, input().split())
    ans.append(s - t[p-1] + x)

for i in ans:
    print(i)

Measured memory_bytes: 3060
class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * (n+1)  # parentは親の番号を格納。　親だった時は-サイズを格納。

    # 親の番号を返す
    def root(self, A):
        if self.parent[A] < 0:
            return A
        else:
            return self.root(self.parent[A])

    # サイズを返す
    def size(self, A):
        return - self.parent[self.root(A)]

    # AとBをくっつける(直接ではなくroot(A)とroot(B)を繋げる)
    def connect(self, A, B):
        A = self.root(A)
        B = self.root(B)

        if A == B:  # 既に同じ塊内にいる
            return False

        if self.size(A) < self.size(B):
            A, B = B, A

        self.parent[A] += self.parent[B]  # サイズを更新
        self.parent[B] = A

        return True


N, M = map(int, input().split())  # 複数数値入力
A = list()
B = list()
for i in range(M):
    a, b = map(int, input().split())  # 複数数値入力
    A.append(a)
    B.append(b)

ans = [N * (N - 1) / 2] * M  # とりあえず不便性最大で初期化
Uni = UnionFind(N)

for i in reversed(range(1, M)):
    if Uni.root(A[i]) != Uni.root(B[i]):    # 繋がってなかったとき
        ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i])
        Uni.connect(A[i], B[i])
    else:
        ans[i-1] = ans[i]

for i in range(len(ans)):
    print(int(ans[i]))


Measured memory_bytes: 16240
import java.util.*;

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

		int a = scan.nextInt();
		int b = scan.nextInt();
		int k = scan.nextInt();

		int cnt = 0;
		List<Integer> l = new ArrayList<>();
		for(int i = 1; i <= b; i++){
			if(a % i == 0 && b % i == 0){
				cnt++;
				//				System.err.println(i);
				l.add(i);
			}
		}
		System.out.println(l.get(l.size() - k));
	}
}


Measured memory_bytes: 23124
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c;
    
    cin >> a >> b >> c;
    if (a <= b && b <= c )
      cout << a << " " << b << " " << c <<endl;

     else if (a >= b && b <= c && c <= a)
      cout << b << " " << c << " " << a <<endl;
      
      else if( a <= b && b >= c && c <= a)
      cout << c << " " << a << " " << b <<endl;
      
      else if(a <= b && b >= c && c >= a )
      cout << a << " " << c << " " << b <<endl;
      
      else if( a >= b && b <= c && c >= a)
       cout << b << " " << a << " " << c <<endl;
       
      else
      cout << c << " " << b << " " << a <<endl;
   
    return 0;
}


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


int main(){
	ll n,m;
	cin>>n>>m;
	ll tmp=pow(2,n);
	ll dp[m][tmp];
	fo(i,m){
		fo(j,tmp){
			dp[i][j]=10000000000000;
		}
	}
	
    ll k;
    ll tmpp;
    ll our=0;
    ll a;
    cin>>a>>k;
    fo(p,k) {
    cin>>tmpp;
    our=our|(1<<(tmpp-1));

    }
    //dbg(our);
    dp[0][0]=0;
    fo(i,tmp) {
    	if(i==0) dp[0][i]=0;
    	else if(((our&i)^i)==0) {dp[0][i]=a; }
    	
    }
    //dbg(dp[0][1]);

	FOR(i,1,m-1){
        cin>>a;
		cin>>k;
		our=0;
		fo(p,k) {
			cin>>tmpp;
			our=our|(1<<(tmpp-1));



		}
		//dbg(our);
		fo(j,tmp){
			if(j==0) dp[i][j]=0;
			else {
				if(j&our) dp[i][j]=min(dp[i-1][j],dp[i-1][((our^j)&j)]+a);
				dp[i][j]=min(dp[i-1][j],dp[i][j]);
			}
			
		}
		//dbg(dp[i][1]);


	}
	if(dp[m-1][tmp-1]>=10000000000000) cout<<-1<<endl;
	else cout<<dp[m-1][tmp-1]<<endl;


}

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


typedef long long ll;


int main(){
  ll t,n;
  while(cin>>t && t){
  vector<ll> a(t);
  for(int i=0;i<t;i++){cin>>a[i];}
  cin>>n;
  vector<ll> inter(112,23);
  for(int i=0;i<n;i++){
    ll d,t;
    cin>>d>>t;
    d--;
    inter[d]=min(inter[d],t);
  }
  ll INF=100000000;
  vector<ll> dp(112,INF);
  dp[0]=-1;
  for(int i=0;i<110;i++){
    for(int j=0;i+j<110;j++){
      if(inter[i+j]>=a[j%t]){dp[i+j+1]=min(dp[i+j+1],dp[i]+1);}
      else{break;}
    }
  }
  cout<<dp[105]<<endl;
  }



  return 0;
}



Measured memory_bytes: 3016