akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int x,y;
  cin>>x>>y;
  bool ok=false;
  for(long long int i=0; i<=x; i++){
    if(i*2+(x-i)*4==y){
      ok=true;
    }
  }
  if(ok){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3632
import itertools
N = int(input())
r = int((N*2)**0.5)
if r * (r+1) == N*2:
    print('Yes')
    print(r+1)
    ans = [[r] for _ in range(r+2)]
    for i, c in enumerate(itertools.combinations(range(1, r+2), 2), start=1):
        ans[c[0]].append(i)
        ans[c[1]].append(i)
    for a in ans[1:]:
        print(*a)
else:
    print('No')


Measured memory_bytes: 76564
s = input()
k = int(input())

ss = []
m = min(len(s), k)
for i in range(len(s)):
    for j in range(1, m+1):
        if i+j > len(s):
            continue
        ss.append(s[i: i+j])
ss = sorted(list(set(ss)))
print(ss[k-1])

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

int  main()
{
	string s; cin >> s;
	int cnt = 0;
	rep(i, s.size())
	{
		if (s[i] == '?')
			s[i] = 'D';
	}
	rep(i, s.size())
	{
		if(s.substr(i, 2) == "PD")
			cnt++;
		if (s[i] == 'D')
			cnt++;
	}
	cout << s << endl;
	return (0);
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010

int main(){
	IOS;
	
	ll a,b,k;cin>>a>>b>>k;
	ll a1=a-min(a,k);
	k-=min(k,a);
	if(k<=0)k=0;
	ll b1=b-min(b,k);
	cout<<a1<<" "<<b1;
	return 0;
}



Measured memory_bytes: 256
import sys
from bisect import bisect_left
from bisect import bisect_right

input()
arr = list(map(int, input().split()))
nq = int(input())
lines = sys.stdin.readlines()

ans = [None] * nq
for i in range(nq):
    q = int(lines[i])
    ans[i] = '{} {}'.format(
        (bisect_left(arr, q)), bisect_right(arr, q))
print('\n'.join(ans))



Measured memory_bytes: 43968
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int temp = 0;
		
		if(a > b){
			temp = b;
			b = a;
			a = temp;
		}
		if (b > c){
			temp = c;
			c = b;
			b = temp;
		}
		if(a > b){
			temp = b;
			b = a;
			a = temp;
		}
		System.out.println(a + " "  + b + " " + c);
	}
}

Measured memory_bytes: 26148
# include <iostream>

using namespace std;

//https://atcoder.jp/contests/abc090/tasks/abc090_b

int main(){
    int A,B;
    cin >> A >> B;

    int sum = 0;

    for(int i=A;i<B+1;i++){
        
        int tmp = i;
        int num[5];

        for(int j=0;j<5;j++){
            num[j] = tmp % 10;
            tmp /= 10.0;   
        }

        if((num[0] == num[4]) && (num[1] == num[3])){
            sum += 1;
        }
    }

    cout << sum << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 0; i < a.size(); i++)
    {
        a[i] = 0;
    }
    for (int i = 2; i <= n; i++)
    {
        int ai;
        cin >> ai;
        a[ai]++;
    }
    for (int i = 1; i < a.size(); i++)
    {
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4000
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0

for i in range(N-1):
    ans += B[A[i]-1]
    if A[i] + 1 == A[i+1] :
        ans += C[A[i]-1]
ans += B[A[N-1]-1]
print(ans)


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

int main(){
  int N;
  cin >> N;
  int K;
  cin >> K;
  vector<int> l(N);

  for (int i = 0; i < N; i++)
  {
    cin >> l.at(i);
  }

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

  int sum = 0;
  for (int i = 0; i < K; i++)
  {
    sum += l.at(l.size() - (i + 1));
  }
  cout << sum << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
const int MAX=1e6+10;
const int modn=1e9+7;
typedef long long ll ;
#define endl '\n'
#define cwk     freopen("D:\\workplace\\CLion\\in.in","r",stdin),freopen("D:\\workplace\\CLion\\out.out","w",stdout)
using namespace std;
int n,a[MAX];
bool vis[MAX];
vector<int>prime;
int cnt[MAX];
int mp[MAX];
void prepare(){
    for(int i=2;i*i<=MAX;i++){
        if(!vis[i]){
            for(int j=i*i;j<MAX;j+=i)
                vis[j]=true;
        }
    }
    int k=1;
    for(int i=2;i<MAX;i++){
        if(!vis[i]) {
            prime.push_back(i);
            mp[i]=k++;
        }
    }
    vis[1]=true;
    //cout<<k;
}
void solve(){
    cin>>n;
    for(int i=0;i<n;i++) {
        cin >> a[i];
    }
    int ans=a[0];
    for(int i=1;i<n;i++){
        ans=__gcd(ans,a[i]);
    }
    if(ans!=1){
        cout<<"not coprime\n";
        return;
    }
    for(int i=0;i<n;i++){
        int k=a[i];
        if(k==1){
            continue;
        }
        if(!vis[k]){
            cnt[mp[k]-1]++;
            if(cnt[mp[k]-1]>=2) {
                cout << "setwise coprime\n";
                return;
            }
            continue;
        }
        for(int j=0;k!=1;j++){
            //int flag=0;
            if(k%prime[j]==0) {
               // flag=prime[j];
                ++cnt[j];
                if(cnt[j]>=2) {
                    cout << "setwise coprime\n";
                    return;
                }
            }
            while(k%prime[j]==0){
                k/=prime[j];
            }
            if(!vis[k]){
                ++cnt[mp[k]-1];
                if(cnt[mp[k]-1]>=2) {
                    cout << "setwise coprime\n";
                    return;
                }
                break;
            }
        }
    }
    cout<<"pairwise coprime\n";
}
signed main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    //cwk;
    prepare();
    int _=1;
    //cin>>_;
    while(_--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 12436
#include<stdio.h>
#include<math.h>
int main(void){
        int a,b,out;
        while(scanf("%d %d",&a,&b)!=EOF){
                if(a+b==0){
                        out=0;
                }else{
                        out=(int)(log10(a+b)+1);
                }
                printf("%d\n",out);
        }
        return 0;
}

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

int main(){
  long long n;
  cin >> n;
  
  if(n == 0){
    cout << 0 << endl;
    return 0;
  }
  int ans=0;
  while(n > 0){
    n /= 2;
    ans++;
  }
  
  cout << ans << endl;
  return 0;
}


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

using ll = long long;
using pii = pair<int, int>;

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, m; cin >> n >> m;
  vector<pii> p(m);
  for(int i=0; i<n; i++) cin >> p[i].first >> p[i].second;

  vector<int> dp(n+20001, 1e9);
  dp[0] = 0;
  for(int i=1; i<=n+20000; i++) {
    for(int j=0; j<m; j++) {
      if(i >= p[j].first) dp[i] = min(dp[i], dp[i-p[j].first] + p[j].second);
    }
  }

  int res = 1e9;
  for(int i=n; i<=n+20000; i++) res = min(res, dp[i]);
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 384
n, m = gets.chomp.split.map(&:to_i)

a = []
b = []
c = Array.new(n, 0)

n.times do
a << gets.chomp.split.map(&:to_i)
end

m.times do
b << gets.to_i
end

n.times do |i|
 m.times do |j|
c[i] += a[i][j] * b[j]
end
end
puts c.join("\n")




Measured memory_bytes: 7024
#include <iostream>

using namespace std;

int main(){
	char S[100],T[100],sum[200];
	int i,j,N;
	
	cin>>N;
	for(i=0;i<N;i++){
		cin>>S[i];
	}
	for(i=0;i<N;i++){
		cin>>T[i];
	}
  sum[0]=S[0];
  sum[1]=T[0];
	for(j=1,i=1;i<N;i++,j++){
		sum[2*i]=S[i];
      	sum[2*i+1]=T[i];
	}
	cout.write(sum,N*2);
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    ll a, b;
    char c;
    scanf("%lld %c %lld", &a, &c, &b);
    ll ans;
    if(c == '+')ans = a+b;
    else ans = a-b;
    cout<<ans;



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
 
int main()
{
    int a, b, bans, flag = 0;

    std::cin >> a >> b;
    if(b / 10 == 10){
        bans = a * 1000 + b;
    }
    else if(b / 10 >= 1){
        bans = a *100 + b;
    }
    else{
        bans = a * 10 + b;
    }

    for(int i = 1;i * i <= bans;i++){
        if(bans == i * i){
            flag = 1;
            break;
        }
    }

    if(flag){
        std::cout << "Yes";
    }
    else{
        std::cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template<class T>
void read(T&);
template<class T>
void write(const T&);

typedef long long ll;
typedef unsigned long long ull;
typedef const long long & cll;
typedef const int & ci;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;
using std::min;
using std::max;
using std::abs;
using std::sort;

const int N = 605;
const int M = 360005;

long double dp[N];
bool to[N][N];
int u[M], v[M];
int n, m;

int main () {
  read(n), read(m);
  for (int i = 1; i <= m; ++i) {
    read(u[i]), read(v[i]);
    to[u[i]][v[i]] = true;
  }
  long double ans = 1e20;
  for (int i = 1; i <= n; ++i) {
    dp[n] = 0;
    for (int j = n - 1; j >= 1; --j) {
      long double sum = 0;
      long double maxi = 0;
      int cnt = 0;
      for (int k = j + 1; k <= n; ++k) {
        if (to[j][k]) {
          ++cnt;
          sum += dp[k];
          maxi = max(maxi, dp[k]);
        }
      }
      if (j == i) {
        --cnt;
        sum -= maxi;
      }
      if (!cnt) {
        dp[j] = 1e20;
      } else {
        dp[j] = sum / cnt + 1;
      }
    }
    ans = min(ans, dp[1]);
  }
  std::cout.precision(8);
  std::cout << std::fixed << ans << std::endl;
  return 0;
}

template<class T>
inline void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!isNum(ch)) {
    if (ch == '-') {
      flag = -1;
    }
    ch = getchar();
  }
  while (isNum(ch)) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template<class T>
inline void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}


Measured memory_bytes: 5528
NUM = input()
Y1, M1 = int(NUM[:2]), int(NUM[2:])
Y2, M2 = M1, Y1

if 0 < M1 < 13 and 0 < M2 < 13:
    print("AMBIGUOUS")
elif 0 < M1 < 13:
    print("YYMM")
elif 0 < M2 < 13:
    print("MMYY")
else:
    print("NA")


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

using ld = long double;
const ld eps = 1e-8, pi = acos(-1.0);

bool eq(ld a, ld b) {
	return abs(a - b) < eps;
}

using Point = complex<ld>;
// ?????????????????´???
class Line {
public:
	Point a, b;
};
// ??????
ld dot(Point a, Point b) {
	return real(conj(a) * b);
}

// ??????
ld cross(Point a, Point b) {
	return imag(conj(a) * b);
}

int ccw(Point a, Point b, Point c) {
	b -= a, c -= a;
	if (cross(b, c) > eps) return 1;	// a,b,c??????????¨???¨???
	if (cross(b, c) < -eps) return -1;	// a,b,c???????¨???????
	if (dot(b, c) < 0) return 2;		// c,a,b????????§??´???
	if (norm(b) < norm(c)) return -2;	// a,b,c???????????´???
	return 0;							// a,c,b???????????´???
}

// ?????´??????????????????
bool isis_ll(Line l, Line m) {
	return abs(cross(l.b - l.a, m.b - m.a)) > eps;
}

// ??´?????¨?????????????????????
bool isis_ls(Line l, Line s) {
	return (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps);
}

// ??´????????????????????¨??????????????????
bool isis_lp(Line l, Point p) {
	return abs(cross(l.b - p, l.a - p)) < eps;
}

// ???????????????????????¨??????????????????
bool isis_sp(Line s, Point p) {
	return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps;
}

// ???????????´????????????????????????????¶?
Point proj(Line l, Point p) {
	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
	return l.a + t * (l.a - l.b);
}

// ??´?????¨??´????????????
Point is_ll(Line s, Line t) {
	Point sv = s.b - s.a, tv = t.b - t.a;
	assert(cross(sv, tv) != 0);
	return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

// ????????¨?????????????????????
bool isis_ss(Line s, Line t) {
	if (isis_ll(s, t)) return isis_ls(s, t) && isis_ls(t, s);
	return isis_sp(s, t.a) || isis_sp(s, t.b) || isis_sp(t, s.a);
}

// ??´?????¨???????????¢
ld dist_lp(Line l, Point p) {
	return abs(p - proj(l, p));
}

// ??´?????¨??´???????????¢
ld dist_ll(Line l, Line m) {
	return isis_ll(l, m) ? 0 : dist_lp(l, m.a);
}

// ??´?????¨??????????????¢
ld dist_ls(Line l, Line s) {
	return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b));
}

// ????????¨???????????¢
ld dist_sp(Line s, Point p) {
	Point r = proj(s, p);
	return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p));
}

// ????????¨??????????????¢
ld dist_ss(Line s, Line t) {
	if (isis_ss(s, t)) return 0;
	return min({ dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b) });
}

int main()
{
	char c;
	ld x[4], y[4];
	while (cin >> x[0] >> c >> y[0]) {
		for (int i = 1; i < 4; i++) {
			cin >> c >> x[i] >> c >> y[i];
		}
		vector<Point> p(4);
		for (int i = 0; i < 4; i++) {
			p[i] = Point(x[i], y[i]);
		}
		bool flag = true;
		for (int i = 0; i < 2; i++) {
			if (isis_ss((Line) { p[(i + 0) % 4], p[(i + 1) % 4] }, (Line) { p[(i + 2) % 4], p[(i + 3) % 4] })) {
				flag = false;
				break;
			}
		}
		int tmp = 0;
		for (int i = 0; i < 4; i++) {
			int val = ccw(p[i], p[(i + 1) % 4], p[(i + 2) % 4]);
			if (abs(tmp) == 1 && val == -tmp) {
				flag = false;
				break;
			}
			else if (abs(val) == 1) {
				tmp = val;
			}
		}
		cout << (flag ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 3224
#include<stdio.h>
int main (void)
{
    int x,i;
    i = 1;

    while(1){
        scanf("%d",&x);

    if( x > 0 ){
        printf("Case %d: %d\n",i,x);
    i = i + 1;
        }else if(x == 0)break;
    }

    return 0;
}

Measured memory_bytes: 600
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
int fun(int a[],int n)
{
    int dp[n];
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            dp[i]=0;
        }
        else
        if(i==1)
        {
            dp[i]=abs(a[i]-a[i-1]);
        }
        else if(i>1)
        {
            dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
        }
    }
    return dp[n-1];
}
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
cout<<fun(a,n)<<endl;
    return 0;
}


Measured memory_bytes: 4156
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    // input
    auto n = std::size_t(0);
    std::cin >> n;

    auto input_vec = [&n]() {
        auto v = std::vector<std::uint64_t>();
        v.reserve(n);
        for (auto i_ = std::size_t(0); i_ < n; ++i_) {
            auto l = 0;
            std::cin >> l;
            v.emplace_back(l);
        }

        std::sort(v.begin(), v.end());

        return v;
    };

    const auto a = input_vec();
    const auto b = input_vec();
    const auto c = input_vec();

    auto counter = std::uint64_t(0);
    for (const auto& middle : b) {
        auto upper_itr = std::lower_bound(a.begin(), a.end(), middle);
        const auto upper_candidate = std::distance(a.begin(), upper_itr);

        auto lower_itr = std::upper_bound(c.begin(), c.end(), middle);
        const auto lower_candidate = std::distance(lower_itr, c.end());

        counter += static_cast<std::uint64_t>(upper_candidate * lower_candidate);
    }

    std::cout << counter << std::endl;

    return 0;
}

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

bool d[10];

bool check(int n) {
  while (n > 0) {
    if (d[n % 10]) return false;
    n /= 10;
  }
  return true;
}

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    int t;
    cin >> t;
    d[t] = true;
  }
  for (int i = n;; ++i) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

void search_prime ( set<int>& prime ) {
    const int N = 55555;
    bool is_prime[N];

    rep(i, N) is_prime[i] = true;

    is_prime[0] = is_prime[1] = false;
    reep(i, 2, N) {
        if ( is_prime[i] == false ) continue;
        for( int j = 2*i; j < N; j += i ) is_prime[j] = false;
    }

    rep(i, N) if ( is_prime[i] ) prime.insert(i);
}

int N, ans[55];
set<int> prime;
bool verify ( int v[5], int prev, int depth ) {
    if ( depth == 4 ) {
        int sum = v[0] + v[1] + v[2] + v[3] + v[4];
        cout << sum << " " << (prime.find(sum) == prime.end()) << endl;
        return prime.find(sum) == prime.end();
    }

    bool ret = true;
    reep(i, prev+1, N) {
        v[depth] = ans[i];
        ret &= verify(v, i, depth+1);
    }

    return ret;
}

int main()
{
    cin >> N;
    
    search_prime(prime);

    int sum = 0;
    auto itr = prime.begin();
    rep(i, N) {
        while( itr != prime.end() && *itr%5 != 1 ) ++itr;
        ans[i] = *itr;
        ++itr;
    }

    rep(i, N) {
        if ( i != 0 ) cout << " ";
        cout << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

char S[105];

typedef long long ll;

int main(){

	ll K;

	scanf("%s",S);

	scanf("%lld",&K);

	int i;

	int len=strlen(S);

	ll t=0ll;
	for(i=0;i<len;i++){
		if(S[i]!='1' && t==0){
			t=(ll)i;
			break;
		}
	}

	if(K<=t){
	printf("1\n");
	}
	else{
	printf("%c\n",S[t]);
	}


	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

#define N 100

void selectionSort(int*Sort,int n){

  int i,j,min,tmp,cnt=0;

  for(i = 0;i < n;i++){
    min = i;
    for(j = i;j < n;j++){

      if(Sort[j] < Sort[min]){
	min = j;

      }
    }   
    if(Sort[i] != Sort[min]){ 
      tmp = Sort[i];
      Sort[i] = Sort[min];
      Sort[min] = tmp;
      cnt++;
    }
    
  }

  for(i = 0;i < n-1;i++)
    printf("%d ",Sort[i]);
  printf("%d\n",Sort[n-1]);
  printf("%d\n",cnt);
}

int main(){

  int n,i;
  int Sort[N];

  scanf("%d",&n);

  for(i = 0;i < n; i++)
    scanf("%d",&Sort[i]);

  selectionSort(Sort,n);

  return 0;
}

Measured memory_bytes: 2744
n = int(input())
S = [int(x) for x in input().split()]
q = int(input())
T = [int(x) for x in input().split()]

cnt = 0
for t in T:
    left = 0
    right = n
    while right - left > 1:
        mid = (right + left) // 2
        if t < S[mid]:
            right = mid
        else:
            left = mid
        if S[left]==t:
            cnt += 1
#             print('#', t)
            break
        
print(cnt)


Measured memory_bytes: 16896
#include "bits/stdc++.h"
using namespace std;typedef long long lint;typedef vector<lint> liv;
//#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define linf 1152921504606846976
#define MAXN 100010
#define md 1000000007//998244353

#define pb push_back
#define _vcppunko4(tuple) _getname4 tuple
#define _getname4(_1,_2,_3,_4,name,...) name
#define _getname3(_1,_2,_3,name,...) name
#define _trep2(tuple) _rep2 tuple
#define _trep3(tuple) _rep3 tuple
#define _trep4(tuple) _rep4 tuple
#define _rep1(n) for(lint i=0;i<n;++i)
#define _rep2(i,n) for(lint i=0;i<n;++i)
#define _rep3(i,a,b) for(lint i=a;i<b;++i)
#define _rep4(i,a,b,c) for(lint i=a;i<b;i+=c)
#define _trrep2(tuple) _rrep2 tuple
#define _trrep3(tuple) _rrep3 tuple
#define _trrep4(tuple) _rrep4 tuple
#define _rrep1(n) for(lint i=n-1;i>=0;--i)
#define _rrep2(i,n) for(lint i=n-1;i>=0;--i)
#define _rrep3(i,a,b) for(lint i=b-1;i>=a;--i)
#define _rrep4(i,a,b,c) for(lint i=a+(b-a-1)/c*c;i>=a;i-=c)
template<class T>
istream& operator>>(istream& is,vector<T>& vec);
template<class T,size_t size>
istream& operator>>(istream& is,array<T,size>& vec);
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p);
template<class T>
ostream& operator<<(ostream& os,vector<T>& vec);
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p);
template<class T>
istream& operator>>(istream& is,vector<T>& vec){ for(T& x: vec) is>>x;return is; }
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p){ is>>p.first;is>>p.second;return is; }
//template<class T>
//ostream& operator<<(ostream& os,vector<T>& vec){ os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; }
//template<class T>
//ostream& operator<<(ostream& os,deque<T>& deq){ os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; }
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p){ os<<p.first<<" "<<p.second;return os; }

inline void in(){}
template <class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){ cin>>head;in(move(tail)...); }
template <class T>
inline bool out(T t){ cout<<t<<'\n';return 0; }
inline bool out(){ cout<<'\n';return 0; }
template <class Head,class... Tail>
inline bool out(Head head,Tail... tail){ cout<<head<<' ';out(move(tail)...);return 0; }

#define rep(...) _vcppunko4((__VA_ARGS__,_trep4,_trep3,_trep2,_rep1))((__VA_ARGS__))
#define rrep(...) _vcppunko4((__VA_ARGS__,_trrep4,_trrep3,_trrep2,_trrep1))((__VA_ARGS__))
#define lin(...) lint __VA_ARGS__;in(__VA_ARGS__)
#define stin(...) string __VA_ARGS__;in(__VA_ARGS__)
#define vin(type,name,size) vector<type> name(size);in(name)
#define fi i.first
#define se i.second
#define YES(c) cout<<((c)?"YES\n":"NO\n")
#define Yes(c) cout<<((c)?"Yes\n":"No\n")

int main(){
	lin(a,b,c,d);
	Yes((abs(a-b)<=d&&abs(b-c)<=d)||abs(a-c)<=d);
}

//sub-EOF


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;



void main() {
    immutable EPS = 1.0e-10;
    string[] input = new string[](8);

    while ((input = readln.chomp.split(" ")).length != 0) {
        auto points = input.map!(to!double);
        auto innerProduct = fabs((points[2] - points[0])*(points[6] - points[4]) + (points[3] - points[1])*(points[7] - points[5]));

        if (innerProduct < EPS) {
            writeln("YES");
        } else {
            writeln("NO");
        }
    }
}

Measured memory_bytes: 1076
vdata = [0.0]
for n in range(1, 411):
    vdata.append((2 * 9.8 * (5 * n - 5)) ** 0.5)

while True:
    try:
        v = float(input())
    except EOFError:
        break
    for n, u in enumerate(vdata):
        if v < u:
            print(n)
            break

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

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	int N;
	string S;
	cin >> N >> S;

	vector<int> a(N);
	rep(i, N) {
		if (S[i] == 'R')a[i] = 0;
		if (S[i] == 'G')a[i] = 1;
		if (S[i] == 'B')a[i] = 2;
	}

	vector<ll> cnt(3);
	rep(i, N)cnt[a[i]]++;

	ll ans = 1;
	rep(i, 3)ans *= cnt[i];

	rep(j, N)rep(i, j) {
		int k = j + (j - i);
		if (k >= N)continue;
		if (a[i] == a[j])continue;
		if (a[j] == a[k])continue;
		if (a[k] == a[i])continue;
		ans--;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3648
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			// t
			scanner.nextInt();
			int[] a = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			// max[i] はa[i]〜a[n-1]の最大値
			int[] max = new int[n];
			max[n - 1] = a[n - 1];
			IntStream.range(1, n).map(i -> n - 1 - i).forEach(i -> max[i] = Math.max(max[i + 1], a[i]));
			Map<Integer, Integer> map = new HashMap<>();
			int maxResult = IntStream.range(0, n).map(i -> {
				int result = max[i] - a[i];
				map.put(result, map.getOrDefault(result, 0) + 1);
				return result;
			}).max().getAsInt();
			System.out.println(map.get(maxResult));
		}
	}
}


Measured memory_bytes: 60128
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
int main(){
  ll H,W,D,i,j,a,Q,l,r;scanf("%lld%lld%lld",&H,&W,&D);
  pair<ll,ll> P[H*W];vector<ll> v[D];
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      scanf("%lld",&a);a--;
      P[a] = make_pair(i,j);
    }
  }
  for(i=0;i<D;i++){
    v[i].emplace_back(0);
    for(j=i+D;j<H*W;j+=D) v[i].emplace_back(v[i].back()+abs(P[j].first-P[j-D].first)+abs(P[j].second-P[j-D].second));
  }
  scanf("%lld",&Q);
  for(i=0;i<Q;i++){
    scanf("%lld%lld",&l,&r);l--;r--;
    printf("%lld\n",v[r%D][r/D]-v[l%D][l/D]);
  }
}

Measured memory_bytes: 9932
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define max 100001
int main(){
  int a[max]={},n,tmp,q,b,c;
  unsigned long long sum =0;
  cin>>n;
  for (int i=0;i<n;i++){
    cin>>tmp;
    a[tmp]++;
  }
  for(int i=1;i<max;i++){
    sum+=(unsigned long long )i*a[i];
  }
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>b>>c;
    sum-=(unsigned long long )b*a[b];
    sum+=(unsigned long long )c*a[b];
    a[c]+=a[b];
    a[b]=0;
    printf("%llu\n",sum);
  }
  return 0;
}



Measured memory_bytes: 4124
s = input()
q = int(input())

count = 0
top = []
bottom = []

for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    count = (count + 1) % 2  
  if query[0] == "2":    
    if query[1] == "1":      
      if count == 0:        
        top.append(query[2])    
      else:
        bottom.append(query[2])
    if query[1] == "2":      
      if count == 0:        
        bottom.append(query[2])        
      else:       
        top.append(query[2])
  
t = "".join(top)
b = "".join(bottom)

lst = [t[::-1], s, b]
ans = "".join(lst)

if count == 1:
  ans = ans[::-1]
  
print(ans)

Measured memory_bytes: 69208
n=int(input())
s=[None]*n
for i in range(n):
  s[i]="".join(sorted(input()))

s=sorted(s)

total=0
count=1
for j in range(1,n):
  if s[j]==s[j-1]:
    count = count+1
  else:
    if count>1:
      total = total+(count*(count-1))//2
    count=1

if count>1:
  total = total+(count*(count-1))//2

print(total)

Measured memory_bytes: 11368
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <time.h>
#define last(x, y) (x)[(x).size() - y]
#define endl '\n'
#define flush fflush(stdout), cout.flush()
#define fast ios::sync_with_stdio(0), cin.tie(0)
#define debug cout << "ok" << endl
#define in(X) ((X) - '0')
const int md = 1e9 + 7;
typedef long long ll;
typedef long double ldb;
using namespace std;

ll mn1, mn2, a, b, c, d, n;

int main() {
	fast;
	cin >> a >> b >> c >> d >> n;
	mn1 = min(min(4 * a, 2 * b), c);
	mn2 = min(min(min(8 * a, 4 * b), 2 * c), d);
	cout << (n / 2) * mn2 + (n & 1) * mn1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	char c1, c2, delim, ball = 'A';
	while( cin >> c1 >> delim >> c2 ){
		if( c1 == ball )	ball = c2;
		else if( c2 == ball )	ball = c1;	
	}
	cout << ball << endl;
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll n,ans=1,cnt;
    cin >> n;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    REP(i,1,n){
        cnt = 0;
        rep(j,i){
            if(h[i]>=h[j]) cnt++;
        }
        if(cnt==i) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.buffer.readline
    H, N = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    dp = [[10**9]*(H+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+1):
            nH = max(0, j-AB[i][0])
            dp[i+1][j] = min(dp[i][j], dp[i+1][j],
                             dp[i+1][nH] + AB[i][1])
    ans = 10**9
    for i in range(N+1):
        ans = min(ans, dp[i][H])
    print(ans)
    # print(*dp, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 120172
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };

template<int MOD> struct ModInt {
	static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
	ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
	ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
	int get() const { return (int)x; }
	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
	ModInt inverse() const {
		long long a = x, b = MOD, u = 1, v = 0;
		while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
		return ModInt(u);
	}
	bool operator==(ModInt that) const { return x == that.x; }
	bool operator!=(ModInt that) const { return x != that.x; }
	ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
	ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r;
}
typedef ModInt<1000000007> mint;


int sum[510][510];

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

	rep(i, 0, m) {
		int l, r;
		cin >> l >> r;
		sum[l][r]++;
	}

	rep(i,1,505)rep(j,1,505){
		sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i-1][j-1];
	}


	rep(i, 0, Q) {
		int p, q;
		cin >> p >> q;
		cout << sum[q][q] - sum[q][p-1] - sum[p - 1][q] + sum[p - 1][p - 1] << endl;
	}

	return 0;
}

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

int main(void)
{
    long int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0)
    {
        cout << "Zero" << endl;
    }
    else if (a < 0 && b != 0)
    {
        if (abs(b - a) % 2 == 1)
        {
            cout << "Positive" << endl;
        }
        else 
        {
            cout << "Negative" << endl;
        }
    }
    else 
    {
        cout << "Positive" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

int main() {
	int m, nmin, nmax;
	while (cin >> m >> nmin >> nmax&&m) {
		vector<int>v;
		for (int i = 0; i < m; i++) {
			int a;
			cin >> a;
			v.emplace_back(a);
		}
		sort(v.begin(), v.end(), greater<int>());
		nmin--, nmax--;
		int gap = 0;
		int ans = 0;
		for (int i = nmin; i <= nmax; i++) {
			if (gap <= v[i] - v[i + 1]) {
				gap = v[i] - v[i + 1];
				ans = i;
			}
		}
		cout << ans+1 << endl;
	}
}

Measured memory_bytes: 3092
import java.util.Scanner;
  
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int h,w,i,j;
        while(true){
        h = s.nextInt();
        w = s.nextInt();
        if(h==0&&w==0)break;
        for(i=1;i<=h;i++){
            for(j=1;j<=w;j++){
                if(i==1||i==h||j==1||j==w)System.out.print("#");
                else System.out.print(".");
            }
            System.out.println();
        }
        System.out.println();
    }
    }
}


Measured memory_bytes: 32612
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
set<P> s;
P seiza[201];
P sky[1001];
ll m,n,x,y,dx,dy;
int main()
{while(1){
	scanf("%lld",&m);
	if(!m) return 0;
	s.clear();
	for(ll i=0;i<m;i++){
		scanf("%lld%lld",&seiza[i].first,&seiza[i].second);
	}
	scanf("%lld",&n);
	for(ll i=0;i<n;i++){
		scanf("%lld%lld",&x,&y);
		s.insert(P(x,y));
	}
	for(P a:s){
		P p=a;
		for(ll i=0;i<m-1;i++){
			dx=seiza[i+1].first-seiza[i].first;
			dy=seiza[i+1].second-seiza[i].second;
			if(!s.count(P(p.first+dx,p.second+dy))) goto en;
			p.first+=dx;
			p.second+=dy;
		}
		printf("%lld %lld\n",-seiza[0].first+a.first,-seiza[0].second+a.second);
		break;
		en: ;
	}
}}

Measured memory_bytes: 3256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
using namespace std;
using s64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int get_mp(int idx, int a, vector<int>& vec, int len, int mp)
{
    int n = vec.size();
    if(n == 0) return 1 << 29;

    if(idx < n)
    {
        int min_mp = 1 << 29;
        rep(i,2)
        {
            int mp_next = i==0 || len == 0? mp : mp + 10;
            int len_next = i==0? len : len + vec[idx];
            int tmp_mp = get_mp(idx+1, a, vec, len_next, mp_next);
            if(tmp_mp < min_mp)
                min_mp = tmp_mp;
        }
        return min_mp;
    }
    else
    {
        if(len == 0) return 1 << 29;
        
        return mp + abs(len - a);
    }    
}

int get_min_mp(int idx, int n, int a, int b, int c, vector<int>& l, vector<int>& m)
{
    if(idx < n)
    {
        int min_mp = 1 << 29;
        rep(i,3)
        {
            m[idx] = i;
            int tmp_mp = get_min_mp(idx+1,n,a,b,c,l,m);
            if(tmp_mp < min_mp)
                min_mp = tmp_mp;
        }
        return min_mp;
    }
    else // idx == n
    {
        vector<vector<int>> ls(3);
        rep(i,n)
            ls[m[i]].push_back(l[i]);

        int sum_mp = get_mp(0, a, ls[0], 0, 0) + get_mp(0, b, ls[1], 0, 0) + get_mp(0, c, ls[2], 0, 0);
        return sum_mp;      
    }    
}

int main()
{
    int n,a,b,c;
    cin >> n >> a >> b >> c;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    vector<int> m(n);

    cout << get_min_mp(0, n, a, b, c, l, m) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace std::tr1;
using namespace std;
/* cau troi cho Garena nhap de con Bach */
#define FSYNC ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f
#define lb lower_bound
#define pob pop_back
#define ub upper_bound
#define ite ::iterator
#define db(x) {cout <<"#db " << x << endl;}
#define here() {cout <<"here \n";}
#define mod 1000000007
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int MOD = 1e9 + 7;
const int N = 2e5+5;


int n,a[N];
int mido;
signed main(){
	cin >> n;int ans = 0;
	for(int i = 1 ; i <= n ; i ++){
		cin >> a[i]; a[i] -= i;
	}
	sort(a+1,a+n+1);
	if(n%2 == 1){
		mido = a[(n>>1)+1];
		for(int i = 1 ; i <= n ;i ++){
			ans += abs(a[i]-mido);
		}
		cout << ans;
	}
	else {
		for(int i = 1 ; i <= n ; i ++){
			if(i<=n/2){
				ans -= a[i];
			}else{
				ans += a[i];
			}
		}
		cout << ans;
	}
}


Measured memory_bytes: 1792
import sys

def main():
    for input_line in sys.stdin:
        num1 = int(input_line.split(' ')[0])
        num2 = int(input_line.split(' ')[1])
        
        sum = str(num1 + num2)
        
        count = 0
        for num in sum:
            count += 1
        else:
            print(count)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 4204
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

max_x = max(x)
min_y = min(y)
if max_x < min_y and X < min_y and Y > max_x:
    print('No War')
else:
    print('War')


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
#include <cstdlib>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
 
int n, m;
ll d[1123];
int a[2123], b[2123], c[2123];
bool loop[1123];

int main() {
	cin >> n >> m;
	REP(i, m) {
		scanf("%d %d %d", a + i, b + i, c + i);
		a[i]--; b[i]--;
	}
	
	fill(d, d + n, -INF);
	d[0] = 0;
	
	REP(i, n - 1) {
		REP(j, m) {
			chmax(d[b[j]], d[a[j]] + c[j]);
		}
	}
	
	REP(i, n) {
		REP(j, m) {
			if (chmax(d[b[j]], d[a[j]] + c[j])) loop[b[j]] = true;
		}
	}
	
	if (loop[n - 1]) puts("inf");
	else cout << d[n - 1] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    ll H = inputValue();
    ll W = inputValue();
    ll ans = H * W;
    if(ans % 2 == 1){
        ans = 1 + ans / 2;
    }else{
        ans = ans / 2;
    }
    if(H == 1 || W == 1){
        ans = 1;
    }
    cout << ans << endl;
}


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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

int ans;
const int N = 100100;
vi a[N];
bool use[N];

bool dfs(int v) {
    use[v] = 1;
    int kol = 0;
    forn(i, sz(a[v])) {
     	int to = a[v][i];
     	if (!use[to]) {
     		kol += !dfs(to);
     	}
    }
    debug(mt(v, kol));
    int p = max(0, kol - 1);
    ans += p;
	return !(sz(a[v]) == 1 || (sz(a[v]) == 2 && kol == 1));
}

int main () {
	//std::ios::sync_with_stdio(false);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	int n;
	cin >> n;
	if (n == 2) {
		cout << 1 << endl;
		return 0;
	}
	forn(i, n - 1) {
		int u, v;
		cin >> u >> v;
		//u--, v--;
		a[u].pb(v);
		a[v].pb(u);
	}
	int root = -1;
	int maxx = 0;
	forn(i, n) {
	    if (umx(maxx, sz(a[i])))
	    	root = i;
	}	
	if (maxx == 2) {
		cout << 1 << endl;
		return 0;
	}
	ans = 0;
	dfs(root);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9344
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

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

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int main()
{
    int s,w;
    cin >> s >> w;

    if(s > w) cout << "safe" << endl;
    else cout << "unsafe" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
long take(long x){
	long n=x%2?0:x;
	n^=((x+1)/2)%2;
	return n;
}
int main(void){
	long A,B;
		cin >> A >> B;
	if(A==0){
		cout << take(B) << endl;
		return 0;
	}
	cout << (take(A-1)^take(B)) << endl;
	return 0;
}

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

int main(){
	int N, A, B;
	scanf("%d%d%d", &N, &A, &B);
	if((B - A) % 2 == 0){
		printf("Alice\n");
	}
	else{
		printf("Borys\n");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
 
public class Main {
 
	public static final MyScanner in = new MyScanner();
 
	public static int answer=Integer.MAX_VALUE;
 
	public static int N;
	public static int M;
	public static int X;
 
	public static int[] C;
	public static int[][] A;
 
	public static void main(String[] args) {
 

		char[] N = in.next().toCharArray();


		String answer;
		char c = ' ';
		for(int i=0;i<N.length;i++) c = N[i];
		
		if(c == '2' || c == '4' || c == '5' || c == '7' || c == '9') answer = "hon";
		else if(c== '0' || c == '1' || c == '6' || c == '8') answer = "pon";
		else answer = "bon";
		System.out.println(answer);
 
	}

 
	public static class MyScanner {
		Scanner sc = new Scanner(System.in);
		String next() { return sc.next();}
		int nextInt() { return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next()); }
	}
}

Measured memory_bytes: 35608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;ll n;
	cin>>s>>n;
	for(int i=0;i<s.size();i+=n){
		cout << s[i];
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256