akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
#include <list>
#include <map>
#include <cmath>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <climits>
#include <queue>
#include <stack>
#include <cstdio>

using namespace std;


enum DRCT {L,R,U,D,NONE};

int R_table[6][4] = {
	{2,3,5,4},
	{3,1,4,6},
	{2,6,5,1},
	{1,5,6,2},
	{1,3,6,4},
	{4,5,3,2}
};

struct DIE{
	int t,f;

	int getR(){
		int id = find(R_table[t-1],R_table[t-1] + 4,f) - R_table[t-1];
		id = (id + 1) % 4;
		return R_table[t-1][id];
	}

	DRCT getDir(int x){
		if(x == t) return NONE;
		else if(t + x == 7) return NONE;
		else if(f == x) return U;
		else if(f + x == 7) return D;
		int r = getR();
		if(x == r) return R;
		else return L;
	}

	void rot(DRCT dr){
		if(dr == L){
			t = getR();
		} else if(dr == R){
			t = 7 - getR();
		} else if(dr == U){
			int nt = 7 - f;
			f = t;
			t = nt;
		} else {
			int nf = 7 - t;
			t = f;
			f = nf;
		}
	}
};
vector<int> use[400][400];

void next_xy(int &x,int &y,DRCT dr){
	if(dr == L) x--;
	else if(dr == R) x++;
	else if(dr == U) y++;
	else y--;
}

DRCT next_dir(DIE &d,int x,int y){
	int c_dep = (int)use[y][x].size();
	for (int i = 6; i >= 4; i--){
		DRCT dr = d.getDir(i);
		if(dr == NONE) continue;
		int nx = x,ny = y;
		next_xy(nx,ny,dr);
		int n_dep = (int)use[ny][nx].size();
		if(n_dep < c_dep) return dr;
	}

	return NONE;
}

int main(){
	int n;
	while(cin>>n,n){
		for(int i = 0; i < 400; i++) for(int j = 0; j < 400; j++) use[i][j].clear();

		for (int i = 0; i < n; i++){

			DIE d; cin>>d.t >> d.f;
			int x = 200, y = 200;
			DRCT dr;
			while( (dr = next_dir(d,x,y)) != NONE){
				d.rot(dr);
				next_xy(x,y,dr);
			}
			use[y][x].push_back(d.t); 
		}

		vector<int> ans(6);
		for(int i = 0; i < 400; i++)for(int j = 0; j < 400; j++){
			if(use[j][i].size() == 0) continue;
			int c = use[j][i][use[j][i].size() - 1];
			ans[c - 1]++;
		}
		for(int i = 0; i < 6; i++){
			printf("%d%c",ans[i],(i == 5) ? '\n' : ' ');
		}
	}


	return 0;
}

Measured memory_bytes: 2792
import sys
n = int(input())
l = 0
r = n-1
print(0)
sys.stdout.flush()
i = input()
if i == "Vancant": exit()

for _ in range(19):
    m = (l+r)//2
    print(m)
    sys.stdout.flush()
    j = input()
    if j == "Vancant": exit()
    if (m-l)%2 == 0 and i != j: r = m-1
    elif (m-l)%2 == 1 and i == j: r = m-1
    else:
        l = m+1
        i = "Male" if j == "Female" else "Female"

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

int main(){

	int W,H,x,y,r;

	cin >> W >> H >> x >> y >> r;

	if(x+r <= W && x-r >= 0 && y+r<=H && y-r>=0 ){
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main()
{
	int a;
	cin >> a;
	int b;
	cin >> b;
	if (a % 2 == 0)
	{
		cout << "Even" << endl;
	}
	
	else if (b % 2 == 0)
	{
		cout << "Even" << endl;
	}
	else
	{
		cout << "Odd" << endl;
	}
}

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

int main(){
    vector<int> x(6);
    for(int i=0; i<5; i++) cin >> x[i];
    for(int i=0; i<5; i++){
        if(x[i] == 0){
            cout << i+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

map< int64_t, int64_t > prime_factor(int64_t n) {
    map< int64_t, int64_t > ret;
    for(int64_t i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

int main(){
    int64_t n, p;
    cin >> n >> p;
    int64_t out = 1;
    for(auto e: prime_factor(p)){
        while(e.second >= n){
            out *= e.first;
            e.second -= n;
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
ll dp[5][5555];
int main(){
  dp[0][0] = 1;
  for(int i=0;i<4;i++){
    for(int j=0;j<=4000;j++){
      if( dp[i][j] == 0 ) continue;
      for(int k=0;k<=1000;k++){
	if( j+k > 4000 ) break;
	dp[i+1][j+k] += dp[i][j];
      }
    }
  }
  while ( cin >> N ){
    cout << dp[4][N] << endl;
  }
  
}

Measured memory_bytes: 1252
#include <iostream>

using namespace std;

int main() {
	int W, H, x, y;

	cin >> W >> H >> x >> y;

	//長方形の中心にあると二つ存在。それ以外なら1つ
	//面積は必ず等しくできる
	cout << ((long long)H * W) / 2.0;

	//長方形の中心にある
	if (x == W/2.0 &&y == H/2.0)
		cout << ' ' << 1 << endl;
	else
		cout << ' ' << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next()) - 1;
		int y = Integer.parseInt(sc.next()) - 1;

		int[][] distances = new int[n][n];
		int[] counts = new int[n];
		for (int i = 0; i < n; ++i) {
			for (int j = i + 1; j < n; ++j) {
				if (hasOnlyOnePath(i, j, x, y)) {
					distances[i][j] = j - i;
				} else {
					distances[i][j] = Math.min(j - i, Math.abs(x - i) + 1 + Math.abs(j - y));
				}

				++counts[distances[i][j]];
			}
		}

		for (int d = 1; d < n; ++d) {
			System.out.println(counts[d]);
		}
	}

	static boolean hasOnlyOnePath(int i, int j, int x, int y) {
		if (y <= i) {
			return true;
		} else if (x <= i) {
			return false;
		} else {
			return j <= x;
		}
	}
}


Measured memory_bytes: 54612
input = gets.chomp.split(" ")

stack = []

input.count.times do |i|
  if input[i] == '-' || input[i] == '+' || input[i] == '*'
    a = stack.pop
    b = stack.pop
    c = eval(b + input[i] + a)
    stack << c.to_s
  else
    stack << input[i]
  end
end


puts stack.pop


Measured memory_bytes: 6924
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> T(N,0);
    vector<ll> A(N,0);
    for(ll i=0;i<N;++i)cin>>T[i]>>A[i];
    for(ll i=1;i<N;++i){
        ll K=max((T[i-1]+T[i]-1)/T[i],(A[i-1]+A[i]-1)/A[i]);
        T[i]*=K;A[i]*=K;
    }
    prt(T[N-1]+A[N-1])
    return 0;
}


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

using namespace std;

const long long mod=1e9+7;

long long mod_pow(int x,int n){//xのn乗
    if(n==-1){
        return 0;
    }
    if(n%2==0){
        if(n==0){
            return 1;
        }else{
            long long c=mod_pow(x,n/2);
            return c*c%mod;
        }
    }else{
        if(n==1){
            return (long long) x;
        }else{
            long long c=mod_pow(x,(n-1)/2);
            return (long long)(c*c%mod)*x%mod;
        }
    }
}


long long solve(int numA,int numQ_left,int numQ_right,int numC){
    long long ret;
    long long left  = (long long) (numA*mod_pow(3,numQ_left)  + numQ_left *mod_pow(3,numQ_left -1))%mod;
    long long right = (long long) (numC*mod_pow(3,numQ_right) + numQ_right*mod_pow(3,numQ_right-1))%mod;
    ret=(left*right)%mod;
    return ret;
}

int main(){
    string str;
    cin>>str;
    long long ans=0;
    int N=str.size();
    int numA[100000],numQ_left[100000],numQ_right[100000],numC[100000];
    numA[0]=0; numQ_left[0]=0;
    for(int i=0;i<N-1;i++){
        numA[i+1]=numA[i];
        numQ_left[i+1]=numQ_left[i];
        if(str[i]=='A') numA[i+1]++;
        if(str[i]=='?') numQ_left[i+1]++;
    }
    numC[N-1]=0; numQ_right[N-1]=0;
    for(int i=N-1;i>0;i--){
        numC[i-1]=numC[i];
        numQ_right[i-1]=numQ_right[i];
        if(str[i]=='C') numC[i-1]++;
        if(str[i]=='?') numQ_right[i-1]++;
    }
    for(int i=0;i<N;i++){
        if(str[i]=='B' || str[i]=='?'){
            ans = (ans+solve(numA[i],numQ_left[i],numQ_right[i],numC[i]))%mod;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=1,m=1e18;cin>>n;
  lvector A(n);rep(i,n) cin>>A[i];
  sort(ALL(A));
  for(ll a:A) {
    if(a>0&&ans>m/a) {ans=-1;break;}
    ans*=a;
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 3976
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using intl = int64_t;
using Graph = vector<vector<int> >;

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // 頂点 s をスタートとした探索
    vector<int> dist(N, -1);
    queue<int> que;
    vector<int> friends(N,1);
    
    for (int v = 0; v < N; ++v) {
        if (dist[v] != -1) continue; // v が探索済みならスルー
        dist[v] = 0, que.push(v); 
        while (!que.empty()) {
            int w = que.front(); que.pop();
            for (auto nv : G[w]) {
                if (dist[nv] == -1) {
                    dist[nv] = dist[w] + 1;
                    que.push(nv);
                    friends.at(v)++;
                }
            }
        }
        //++count;
    }

    int mi=0;
    for(int i=0;i<N;i++) mi = max(mi,friends.at(i));
    cout << mi << endl;
    //cout << count << endl;
}

Measured memory_bytes: 16292
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int d;
  cin>>d;

  vector<ll> p(26);
  rep(i,26) {
    cin>>p[i];
  }


  vector<vector<ll>> q(d,vector<ll>(26));
  rep(i,d) {
    rep(j,26) {
      cin>>q[i][j];
    }
  }

  ll pre=0;
  vector<int> r(26,0);
  rep(i,d-5){
    ll ans=-INF;
    ll memo;
    rep(j,26){
      ll sum=pre;
      auto last=r;
      sum+=q[i][j];
      last[j]=i+1;
      rep(k,26){
        sum-=pow(p[k],1.5)*(i+1-last[k]);
      }
      if(sum>ans) {
        memo=j;
        chmax(ans,sum);
      }
    }
    cout << memo+1 << endl;
    pre=ans;
    r[memo]=i+1;
  }

  ll answer=-INF;
  ll A,B,C,D,E;
  vector<int> zen(5);
  rep(i,26){
    rep(j,26){
      rep(k,26){
        rep(l,26){
          rep(m,26){
            zen[0]=i;
            zen[1]=j;
            zen[2]=k;
            zen[3]=l;
            zen[4]=m;

            ll sum=0;
            auto last=r;
            rep(n,5){
              sum+=q[d-5+n][zen[n]];
              last[zen[n]]=d-5+n+1;
              rep(o,26){
                sum-=p[o]*(d-5+n+1-last[o]);
              }
            }

            if(sum>answer) {
              A=zen[0];
              B=zen[1];
              C=zen[2];
              D=zen[3];
              E=zen[4];
            }
            chmax(answer,sum);

          }
        }
      }
    }
  }

  cout << A+1 << endl;
  cout << B+1 << endl;
  cout << C+1 << endl;
  cout << D+1 << endl;
  cout << E+1 << endl;
  
}

Measured memory_bytes: 4152
import sys
import socket

if socket.gethostname() == 'N551J':
    sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    a, b, c, d, e, f = read_int_list()
    best_sugar = 0
    best_total = 100 * a
    for i in range(31):
        for j in range(31):
            water = i * 100 * a + j * 100 * b
            for k in range(3001):
                if water + k * c <= f and k * c * 100 <= water * e:
                    l1 = int((f - water - k * c) / d)
                    l2 = int((water * e // 100 - k * c) / d)
                    l = min(l1, l2)
                    if (i, j, k, l) != (0, 0, 0, 0):
                        sugar = k * c + l * d
                        total = water + sugar
                        density = sugar / total
                        best_density = best_sugar / best_total
                        if density > best_density:
                            best_sugar = sugar
                            best_total = total
    return best_total, best_sugar


def main():
    res = solve()
    print(*res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

  int a, b, c;
  cin >> a >> b >> c;

  if ((b - a) == (c - b)){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
/*
ABHIJEET BISWAS
CSE 4th SEM 
MNNIT ALLAHBAD
https://atcoder.jp/contests/dp/tasks/dp_l
*/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define MAX 1000009
#define pb push_back
#define mp map<int,int>
#define f first
#define s second
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ld pi=2.0*acos(0.0);
ll dp[3001][3001][2];
ll arr[3003];
ll n;
ll solve(int a,int b,int p)
{
	if(a>b)
	return 0;
	if(dp[a][b][p]!=-1)
	return dp[a][b][p];
	ll p1=solve(a+1,b,(p+1)%2)+ ((p==0)?arr[a]:-1*arr[a]);
	ll p2=solve(a,b-1,(p+1)%2)+ ((p==0)?arr[b]:-1*arr[b]);
	if(p==0)
	return dp[a][b][p]=max(p1,p2);
	else
	return dp[a][b][p]=min(p1,p2);
	
	
}
int main() {
	fastIO
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>arr[i];
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	for(int k=0;k<2;k++)
	dp[i][j][k]=-1;
	cout<<solve(1,n,0)<<endl;
	return 0;
}

Measured memory_bytes: 141184
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  lint n, r; cin >> n >> r;
  cout << r + 100 * (10 - min(10LL, n)) << endl;
  return 0;
}


Measured memory_bytes: 256
n,k=map(int, input().split())
s=input()
if s[k-1]=='A':
  s=s[:k-1]+'a'+s[k:]
if s[k-1]=='B':
  s=s[:k-1]+'b'+s[k:]
if s[k-1]=='C':
  s=s[:k-1]+'c'+s[k:]
print(s)

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

int main(void) {
  long long H, N;
  cin >> H >> N;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    long long A;
    cin >> A;
    sum += A;
  }

  cout << (H - sum > 0 ? "No" : "Yes") << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	a := 1
	for i := 0; i < 3; i++ {
		a = a * N
	}
	fmt.Println(a)

}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func Max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Min(s, v)
	}
	return s
}

func MaxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Max(s, v)
	}
	return s
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 640
import java.util.*;

class Main {
	Scanner sc;
	int N;
	long M;
	int[] A;
	long[] s;
	
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextLong();
		A = new int[N+1];
		for (int i = 1; i <= N; i++) A[i] = sc.nextInt();
		Arrays.sort(A, 1, N+1);
		for (int i = 0; i < N/2; i++) {
			int tmp = A[i+1]; A[i+1] = A[N-i]; A[N-i] = tmp;
		}
		s = new long[N+1];
		s[0] = A[0];
		for (int i = 1; i <= N; i++) s[i] = s[i-1] + A[i];
		System.out.println(binSearch());
	}
	
	private long[] ansOfSum(int sum) {
		long ans = 0;
		long cnt = 0;
		
		int b = N;
		for (int a = 1; a <= N; a++) {
			while (A[a] + A[b] < sum && b > 0) b--;
			if (b == 0) break;
			ans += (long)b*A[a] + s[b];
			cnt += b;
		}
		return new long[] { ans, cnt };
	}
	
	private long binSearch() {
		int l = 0;
		int r = 200000;
		long[] mv = null;
		
		while (l <= r) {
			int m = (l + r) >>> 1;
			mv = ansOfSum(m);
			
			if (mv[1] > M) l = m+1;
			else if (mv[1] < M) r = m-1;
			else {
				return mv[0];
			}
		}
		return mv[0] + (l-1)*(M-mv[1]);
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}

Measured memory_bytes: 51308
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	int n, l;

	scanf("%d", &n);
	scanf("%d", &l);

	vector<int> a(n);

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}

	vector<pair<int, int> > b;

	for (int i = 0; i < n; i++)
	{
		b.push_back(make_pair(a[i], i));
	}

	sort(b.begin(), b.end(), greater<pair<int, int> >());

	vector<long long> d(n, 0);

	for (int i = 0; i < n; i++)
	{
		int ptr = b[i].second;

		bool lc = true, rc = true;

		if (ptr != 0)
		{
			lc = (a[ptr] > a[ptr - 1]);
		}

		if (ptr + 1 != n)
		{
			rc = (a[ptr] > a[ptr + 1]);
		}

		if (lc && rc)
		{
			d[ptr] = l - a[ptr];
		}

		if (lc && !rc)
		{
			d[ptr] = d[ptr + 1] + l - a[ptr];
		}

		if (!lc && rc)
		{
			d[ptr] = d[ptr - 1] + l - a[ptr];
		}

		if (!lc && !rc)
		{
			d[ptr] = max(d[ptr + 1], d[ptr - 1]) + l - a[ptr];
		}
	}

	long long ret = 0;

	for (int i = 0; i < n; i++)
	{
		ret = max(ret, d[i]);
	}

	printf("%lld\n", ret);

	return 0;
}

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

typedef long long ll;

const int INF = 101234567;

int main() {
    int N;
    int ans = INF;
    string S;
    cin >> N >> S;

    vector<int>black(N+1);
    vector<int>white(N+1);
    black[0] = 0;
    white[0] = 0;
    int black_cnt = 0;
    int white_cnt = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '.') {
            white_cnt++;
        } else {
            black_cnt++;
        }
        black[i+1] = black_cnt;
        white[i+1] = white_cnt;
    }

    int total;
    for (int i = 0; i <= N; i++) {
        total = black[i] + white[N] - white[i];
        ans = min(ans, total);
    }

    cout << ans << endl;
}


Measured memory_bytes: 2180
#include<iostream>
#include<cstring>
#define N 100000
using namespace std;
typedef long long LL;
LL a[N+1];
LL x[N+1];
int main()
{
	int n; cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i], a[i] *= 2LL;
		
	x[n] = a[n];
	for(int i = 1; i < n; i++)
		x[n] += a[i]*((i&1LL)?(-1LL):1LL);
	x[n] /= 2LL;
	
	LL sum = -x[n];
	for(int i = n-1; i >= 1; i--)
	{
		sum += a[i];
		x[i] = sum;
		sum *= -1LL;
	}
	for(int i = 1; i <= n; i++)
		cout<<x[i]<<(i==n ? '\n' : ' ');
	cout<<flush;
	
	return 0;
}

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

int main () {
    long N;
    scanf("%ld", &N);
    long double sqrtNum = sqrt(N);
    long a = 1;
    long b = 1;
    long min = N - 1;
    for (long i = 2; i <= sqrtNum; i++) {
        if (N % i == 0) {
            a = i;
            b = N / i;
            if ((a + b - 2) < min)
                min = a + b - 2;
        }
    }

    printf("%ld\n", min);

    return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Integer[] d1 = new Integer[n];
    for(int i = 0; i < n; i++){
      d1[i] = sc.nextInt();
    }
    Arrays.sort(d1, Collections.reverseOrder());

    int count = 1;
    for(int i = 0; i+1 < n; i++){
      if(d1[i] > d1[i+1]){
        count++;
      }
    }
    System.out.println(count);
  }
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

const int N=4;

struct state{
  vector<char> board;
  char dist;
  char bi,bj;
  char mh_dist;
  char pre;
};

map<vector<char>,bool> vis;

bool operator<(const state& a,const state& b){
  return a.dist+a.mh_dist > b.dist+b.mh_dist;
}

int di[]={0,1,0,-1};
int dj[]={1,0,-1,0};

/*
int ans[N][N]={
  {0,1,2},
  {3,4,5},
  {6,7,-1},
};*/

int ans[N][N]={
  {0,1,2,3},
  {4,5,6,7},
  {8,9,10,11},
  {12,13,14,-1},
};

P ans_ps[N*N];

int main(){

  clock_t start=clock();

  rep(i,N)rep(j,N){
    if(ans[i][j]==-1)continue;
    ans_ps[ans[i][j]].fi=i;
    ans_ps[ans[i][j]].se=j;
  }

  state inistate;
  inistate.board=vector<char>(N*N);
  inistate.dist=0;
  inistate.mh_dist=0;
  inistate.pre=-1;
  rep(i,N)rep(j,N){
    int input;
    cin>>input;
    input--;
    inistate.board[i*N+j]=input;
    if(input==-1){
      inistate.bi=i;
      inistate.bj=j;
    }else{
      int ai=ans_ps[input].fi;
      int aj=ans_ps[input].se;
      inistate.mh_dist+=abs(ai-i)+abs(aj-j);
    }
  }

  priority_queue<state> que;
  que.push(inistate);
  while(que.size()){
    state crtstate=que.top(); que.pop();
    if(crtstate.mh_dist==0){
      cout<<(int)crtstate.dist<<endl;
      break;
    }
    vis[crtstate.board]=true;
    rep(dir,4){
      if(dir==crtstate.pre)continue;
      int bi=crtstate.bi;
      int bj=crtstate.bj;
      int ni=bi+di[dir];
      int nj=bj+dj[dir];
      if(ni<0||ni>=N||nj<0||nj>=N)continue;
      state nxtstate;
      nxtstate.board=crtstate.board;
      nxtstate.dist=crtstate.dist;
      nxtstate.mh_dist=crtstate.mh_dist;

      char num=crtstate.board[ni*N+nj];
      int ai=ans_ps[num].fi;
      int aj=ans_ps[num].se;
      nxtstate.mh_dist-=abs(ai-ni)+abs(aj-nj);
      nxtstate.mh_dist+=abs(ai-bi)+abs(aj-bj);

      swap(nxtstate.board[bi*N+bj],nxtstate.board[ni*N+nj]);
      nxtstate.dist++;
      nxtstate.bi=ni; nxtstate.bj=nj;
      nxtstate.pre=(dir+2)%4;
      if(!vis[nxtstate.board]){
        vis[nxtstate.board]=true;
        que.push(nxtstate);
      }
    }
  }

  clock_t end=clock();
  //cerr<<"duration = "<<(double)(end-start)/CLOCKS_PER_SEC<<" sec."<<endl;

	return 0;
}

Measured memory_bytes: 135024
#include <stdio.h>

int A[100000];

int Partition(int A[], int p, int r) {
	int x,i,j,tmp;
	x = A[r];
	i = p - 1;
	for (j = p; j < r ; j++) {
		if (A[j] <= x) {
			i++;
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	tmp = A[i + 1];
	A[i + 1] = A[r];
	A[r] = tmp;
	return i + 1;
	
}

int main() {

	int i,n,q;
	scanf("%d", &n);

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

	q = Partition(A, 0, n - 1);

	for (i = 0; i < q; i++) printf("%d ", A[i]);

	printf("[%d]", A[q]);

	for (i = q + 1; i < n; i++) printf(" %d", A[i]);

	printf("\n");

	return 0;
}


Measured memory_bytes: 2148
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
	int N, K;
	int x[100001];
	int zero = 0, positive = 0, negative=0;


	cin >> N >> K;

	for (int i = 0; i < N; i++){
		cin >> x[i];
		if (x[i] == 0) zero++;
		if (x[i] < 0) negative++;
		if (x[i] > 0) positive++;
	}

	int result = 300000000;

	// 右にr個、つけて左に折り返しK-r個
	int current_dist = 0;
	for (int r =0; r <= K; r++){
		int right = negative + r - 1;
		int left = negative - (K - r);
		current_dist = 0;
		if (left < 0 || left >= N || right<0 || right >= N) continue;

		current_dist += abs(x[right]);
		current_dist += abs(x[left]-x[right]);
//		cout << r << " " << current_dist << endl;
		if (current_dist < result) result = current_dist;

	}

//	cout << "..." << endl;

	// 左にr個、つけて右に折り返しK-r個
	for (int r = 0; r <= K; r++){
		int current_dist = 0;
		int left = negative - r ;
		int right = negative + (K - r) -1;

		if (left < 0 || left >= N || right<0 || right >= N) continue;

		current_dist += abs(x[left]);
		current_dist += abs(x[left] - x[right]);
//		cout << r << " " << current_dist << endl;
		if (current_dist < result) result = current_dist;
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 640
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
d = gets.chomp.to_i
c = gets.chomp.split.map(&:to_i)
s = []
d.times do
  s.push gets.chomp.split.map(&:to_i)
end

d.times do |i|
  puts (i % 26) + 1
end


Measured memory_bytes: 14724
import sys
input=lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
mod=10**9+7
n_max=(10**6+1)
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
FI[n_max-1]=pow(F[n_max-1],mod-2,mod)
for i in reversed(range(n_max-1)):
  FI[i]=(FI[i+1]*(i+1))%mod
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod

ans=0
for i in range(n+1):
  if i%2==0:
    ans=(ans+comb(n,i)*F[m]*FI[m-i]*((F[m-i]*FI[m-n])**2))%mod
  else:
    ans=(ans-comb(n,i)*F[m]*FI[m-i]*((F[m-i]*FI[m-n])**2))%mod
print(ans)

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

int main()
{
    string s[55], tmp;
    int H, W;
    cin >> H >> W;
    REP(i, W + 2) s[0].append(".");
    for (int i = 1; i < H + 1; i++)
    {
        cin >> tmp;
        s[i] = "." + tmp + ".";
    }
    REP(i, W + 2) s[H + 1].append(".");
    //データ加工終了
    int ar_ans[55][55] = {0};
    int search_for[8][2] = {
        {-1, -1}, {-1, 0}, {-1, 1},
        {0, -1}, {0, 1},
        {1, -1}, {1, 0}, {1, 1}
    };
    for (int i = 1; i < H + 1; i++)
    {
        for (int j = 1; j < W + 1; j++)
        {
            if (s[i][j] == '#')
            {
                ar_ans[i][j] = -1;
            }
            else
            {
                REP(k, 8) if (s[i + search_for[k][0]][j + search_for[k][1]] == '#') ar_ans[i][j]++;
            }
        }
    }
    for (int i = 1; i < H + 1; i++)
    {
        for (int j = 1; j < W + 1; j++)
        {
            if (ar_ans[i][j] == -1) cout << "#";
            else cout << ar_ans[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define MAX 2000000
#define MOD 1000000007
#define endl "\n"
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s == "ABC")
        cout<<"ARC";
    else
    {
        cout<<"ABC";
    }
    
    

}

Measured memory_bytes: 3556
#a, b, m = list(map(int, input().split()))
#a = list(map(int, input().split()))
#b = list(map(int, input().split()))

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]

k = int(input())

print(a[k-1])


Measured memory_bytes: 2940
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
count_a = Counter(a)
new_a = [i for i in count_a.keys() if count_a[i] >= 2]
#print(new_a)
if len(new_a) < 2:
    print(0)
    exit()
new_a = sorted(new_a, reverse=True)
if count_a[new_a[0]] >= 4:
    ans = new_a[0] ** 2
else:
    ans = new_a[0] * new_a[1]
print(ans)

Measured memory_bytes: 93404
#include<iostream>
#include<cstring>
using namespace std;
int a[7]; int n, p;
int main() {
	while (true) {
		memset(a, 0, sizeof(a));
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> p;
			p /= 10;
			if (p > 6) { p = 6; }
			a[p]++;
		}
		for (int i = 0; i < 7; i++) {
			cout << a[i] << endl;
		}
	}
}

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

const int N = 1005, INF = 0x3f3f3f3f;

vector<int>V[N];
int f[N][5005], g[N], h[N];

int n;

void Dfs (int x) {
	int a, b;
	f[x][0] = 0;
	for (auto v : V[x]) {
		Dfs(v);
		a = min(g[v], h[v]); b = max(g[v], h[v]);
		for (int j = h[x]; j >= a; --j) {
			if (b > j) f[x][j] = f[x][j - a] + b;
			else f[x][j] = min(f[x][j - a] + b, f[x][j - b] + a);
		}
		for (int j = 0; j < a; ++j) f[x][j] = INF;
	}
	g[x] = f[x][0];
	for (int i = 0; i <= h[x]; ++i) g[x] = min(g[x], f[x][i]);
	if (g[x] >= INF) puts("IMPOSSIBLE"), exit(0);
}

int main () {
	scanf("%d", &n);
	memset(f, 0x3f, sizeof f);
	for (int i = 2, j; i <= n; ++i) scanf("%d", &j), V[j].emplace_back(i);
	for (int i = 1; i <= n; ++i) scanf("%d", &h[i]);
	Dfs(1);
	return puts("POSSIBLE"), 0;
}

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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int x,a,b;
  cin>>x>>a>>b;
  cout<<(-a+b<=0 ? "delicious" : -a+b <= x ? "safe" : "dangerous")<<endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    A = [0] * (N + 1)
    for _ in range(M):
        L, R = map(int, input().split())
        A[L - 1] += 1
        A[R] -= 1
    c = 0
    ans = 0
    for a in A:
        c += a
        if c == M:
            ans += 1
    print(ans)


main()


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

using namespace std;
int ans = 0;

void bubbleSort(vector<int>& vec)
{
	bool flag = true;
	while (flag)
	{
		flag = false;
		for (int i = vec.size() - 1; i >= 1; --i)
		{
			if (vec[i] < vec[i - 1])
			{
				int temp = vec[i];
				vec[i] = vec[i - 1];
				vec[i - 1] = temp;
				flag = true;
				++ans;
			}
		}
	}
}

void solve()
{
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> vec[i];
	}
	bubbleSort(vec);
	for (int i = 0; i < vec.size() - 1; ++i)
	{
		cout << vec[i] << " ";
	}
	cout << vec[vec.size() - 1] << endl;
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1196
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

int N, K;
string S;
int hanten = 1;
int ans = 0;

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

	REP(i, N - 1) {
		if (S[i] != S[i + 1]) hanten++;
		else ans++;
	}
	for (int i = K - 1; i >= 0; i--) {
		if (hanten > 2) {
			hanten -= 2;
			ans += 2;
		}
		else {
			cout << N - 1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main(){
    int n; cin >> n;
    int a[n];
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }   
    sum = round((double)sum / n);
    int res = 0;
    for(int i = 0; i < n; i++){
        res += (sum - a[i]) * (sum - a[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ss(double n){
	int a=n;
	return a;
}
int main(){
	int n;
	scanf("%d",&n);
	int a=0,b=46297,mid;
	while(b-a>1){
		mid=(a+b)/2;
		if(mid*1.08>n)
		b=mid;
		else
		a=mid;
	}

    double ans1=a*1.08;
	double ans2=(a+1)*1.08;

	if(ss(ans1)!=n&&ss(ans2)!=n)
	cout<<":(";
	else
	{
		if(ss(ans1)==n&&ss(ans2)==n)
		cout<<a;
		else if(ss(ans1)==n)
		cout<<a;
		else
		cout<<a+1;
	}
	
	
	
	return 0;
}

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

int main() {
  long long n;
  cin>>n;
  vector<pair<long long, long long>> ba(n);
  
  for(int i=0; i<n; i++) {
    long long a, b; cin>>a>>b;
  	ba.at(i).first=b;
    ba.at(i).second=a;
  }
  
  sort(ba.begin(), ba.end());
  long long sum=0;
  
  for(int i=0; i<n; i++) {
    sum += ba.at(i).second;
    if(sum > ba.at(i).first) {
    	cout << "No" <<endl;
    	return 0;
    }
  }
  cout << "Yes" <<endl;
}

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

template< typename Monoid >
struct SegmentTree
{
	using F = function< Monoid(Monoid, Monoid) >;

	int sz;
	vector< Monoid > seg;

	const F f;
	const Monoid M1;

	SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
	{
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x)
	{
		seg[k + sz] = x;
	}

	void build()
	{
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x)
	{
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b)
	{
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid operator[](const int &k) const
	{
		return seg[k + sz];
	}
};
//min
//SegmentTree< int > seg(N, [](int a, int b){ return min(a, b); }, INT_MAX);

//max
//SegmentTree< int > seg(N, [](int a, int b){ return a + b; }, 0);

int main() {
	int n, q;
	cin >> n >> q;
	SegmentTree<int> seg(n, [](int a, int b) {return min(a, b);}, INT_MAX);
	for (int i = 0; i < q; i++) {
		int c, a, b;
		cin >> c >> a >> b;
		if (!c) {
			seg.update(a, b);
		} else {
			cout << seg.query(a, b + 1) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3800
import java.util.*;

class Main {

    static int toInt (ArrayList<Integer> data) {
        int result = 0;
        int mult = 1;
        
        for (int i = 7; i >= 0; i--) {
            result += data.get(i) * mult;
            mult *= 10;
        }
        return result;
    }

    static void solve (ArrayList<Integer> data) {
        int max, min;

        Collections.sort(data);
        min = toInt(data);
        Collections.reverse(data);
        max = toInt(data);

        System.out.println(max - min);
    }

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);
        sc.nextLine();

        while (sc.hasNext()) {
            String line = sc.nextLine();
            ArrayList<Integer> data = new ArrayList<Integer>();

            for(int i = 0; i < 8; i++) {
                data.add(Integer.parseInt(line.substring(i,i+1)));
            }

            solve(data);
        }
            
                
    }
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

ll a[120];
int main2() {
  int N = nextInt();
  REP(i, N) a[i] = nextInt();
  if (N % 2 == 1) a[N++] = 0;
  sort(a, a+N);
  reverse(a, a+N);
  ll ans = 0;
  for (int i = 0; i < N; i += 2) {
    ans += a[i] - a[i+1];
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main(){
	int T;scanf("%d",&T);
	rep(Case,T){
		ll a,b,c,d;cin>>a>>b>>c>>d;
		if(a<b)puts("No");
		else if(d<b)puts("No");
		else if(b<=c)puts("Yes");
		else{
			ll g=__gcd(b,d);
			ll l=(c-a%b+b)%b,r=(b-a%b)%b;
			if(l>r)r+=b;
			if((r-1)/g*g>l)puts("No");
			else puts("Yes");
		}
	}
}

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

typedef vector< vector<int> > vvi;
typedef vector< vector<bool> > vvb;
typedef vector< vector<char> > vvc;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef long long ll;

int main(){
    int x;

    cin >> x;
    if(x>=30) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
using ll = long long;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N;cin>>N;
    vector<ll> v(N*3);
    REP(i,N*3) cin >> v[i];
    sort(v.begin(),v.end());

    ll ans = 0;
    for(int i=N;i<N*3;i+=2) ans += v[i];
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 2560
// ProblemURL : https://atcoder.jp/contests/abc042/tasks/abc042_a
// ---------------------------------------------
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	ok := a*b*c == 5*5*7 && a+b+c == 5+5+7
	if ok {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    int N;
    cin >> N;

    vi A(N);
    rep(i, N) cin >> A[i];

    ll ans = 0;

    rep(i, N)
    {
        ans += A[i] / 2;
        A[i] %= 2;

        if (i < N - 1)
        {
            ll count = min(A[i], A[i + 1]);
            ans += count;
            A[i] -= count;
            A[i + 1] -= count;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

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

ll dp[3010][3010][4]={};

int main(){
  int r,c,k,v[3010][3010]={};
  cin>>r>>c>>k;
  rep(i,k){
    int r1,c1;
    cin>>r1>>c1;
    cin>>v[r1-1][c1-1];
  }
  
  
  dp[0][0][1]=v[0][0];
  
  rep(i,r){
    rep(j,c){
      int val=v[i][j];
      int c0=j,r0=i,c1=c0-1,r1=r0-1;
      dp[r0][c0][1]=val;
      if(c1>=0){
        rep(k,4){
          dp[r0][c0][k]=max(dp[r0][c0][k],dp[r0][c1][k]);
        }
        rep(k,3){
          dp[r0][c0][k+1]=max(dp[r0][c0][k+1],dp[r0][c1][k]+val);
        }
      }
      if(r1>=0){
        rep(k,4){
          dp[r0][c0][0]=max(dp[r0][c0][0],dp[r1][c0][k]);
          dp[r0][c0][1]=max(dp[r0][c0][1],dp[r1][c0][k]+val);
        }
      }
    }
  }  

  ll ans=0;
  rep(i,4){
    ans=max(ans,dp[r-1][c-1][i]);
  }
  
  cout<<ans;
  
  return 0;
}


Measured memory_bytes: 321168
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  cout << X - K + 1;
  for(int i = 1; i < K * 2 -1; i++){
    int ans = X - K + 1 + i ;
    cout << " " << ans;
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

int powmod(int a)
{
    int t = 1;
    REP(i, a)
    {
        t *= 2;
        t %= MOD;
    }
    return t;
}
/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    map<string, pair<int, int>> m;
    int zeroxy = 0;
    int zerox = 0;
    int zeroy = 0;
    REP(i, N)
    {
        int a, b;
        cin >> a >> b;
        if (a == 0 && b == 0)
            zeroxy++;
        else if (b == 0)
            zeroy++;
        else if (a == 0)
            zerox++;
        else
        {
            int t = GCD(a, b);
            a /= t;
            b /= t;
            if (a > 0 && b > 0)
                m[to_string(a) + ' ' + to_string(b)].first++;
            else if (a < 0 && b < 0)
                m[to_string(-a) + ' ' + to_string(-b)].first++;
            else if (a < 0 && b > 0)
                m[to_string(b) + ' ' + to_string(-a)].second++;
            else if (a > 0 && b < 0)
                m[to_string(-b) + ' ' + to_string(a)].second++;
        }
    }
    m["zero"].first = zerox;
    m["zero"].second = zeroy;

    int ans = 1;
    for (auto iter = m.begin(); iter != m.end(); iter++)
    {
        int tmp = 1;
        string s = iter->first;
        int a = m[s].first;
        int b = m[s].second;
        tmp += powmod(a) - 1;
        tmp %= MOD;
        tmp += powmod(b) - 1;
        tmp %= MOD;
        ans *= tmp;
        ans %= MOD;
        // cout << s << " " << m[s].first << " " << m[s].second << endl;
        // cout << ans << endl;
    }
    ans -= 1;
    ans += MOD;
    ans %= MOD;
    cout << (ans + zeroxy) % MOD << endl;

    return 0;
}

Measured memory_bytes: 39260