akhauriyash/Code-Regression huggingface dataset:
/**
    *Makacha
**/
#include <bits/stdc++.h>
using namespace std;

template <typename T> inline void read (T &x) {bool b = 0; char c; while (!isdigit (c = getchar()) && c != '-');
if (c == '-') c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x<<3) + (x<<1) + c - 48; if (b)x=-x;}
template <typename T> inline void wrip(T x) {if (x > 9) wrip(x / 10); putchar(x%10 + 48); }

template <typename T> inline void write(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar(' ');}
template <typename T> inline void writeln(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar('\n');}
inline char readch() {char c; do c = getchar(); while (c == '\n' || c == ' '); return c;}
inline void reads(string &s) {char c; while((c=getchar())==' '||c =='\n'); s=c; while((c=getchar())!=' '&&c!='\n') s+=c;}
inline void getlines(string &s) {char c; while((c=getchar())=='\n'); s=c; while((c=getchar())!='\n') s+=c;}
typedef const int csint;

#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;

const ld pi = acos(-1);
const ll inf = 1e16;
const int mod = 1e9 + 7,
N = 5055;
int n, a[N];
ll A, B, f[N][N];
int main() {
    #ifdef makacha
        freopen("m.inp", "r", stdin);
        freopen("m.out", "w", stdout);
    #endif // makacha
    read(n);
    read(A);
    read(B);
    for (int i = 1; i <= n; i++)
        read(a[i]);
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            f[i][j] = inf;
    f[1][a[1]] = 0;
    f[1][0] = A;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
            f[i][j] = min(f[i][j], f[i][j - 1]);
            if (a[i + 1] >= j) {
                f[i + 1][a[i + 1]] = min(f[i + 1][a[i + 1]], f[i][j]);
                f[i + 1][j] = min(f[i + 1][j], f[i][j] + A);
            }
            else
                f[i + 1][j] = min(f[i + 1][j], f[i][j] + B);
        }
    cout << f[n][n];
}



Measured memory_bytes: 199040
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

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

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

	return gcd(a, b % a);
	


}

int main(int argc, char* argv[]) {
	int k;
	cin >> k;

	ll sum = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int l = 1; l <= k; l++) {
				sum += gcd(i, gcd(j, l));


			}
		}
	}

	cout << sum << endl;
}

Measured memory_bytes: 3632
#coding: UTF-8
# 0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
    
    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.number[0] = n0;
        self.number[1] = n1;
        self.number[2] = n2;
        self.number[3] = n3;
        self.number[4] = n4;
        self.number[5] = n5;

    def roll(self, loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])

    def get_Top(self):
                return self.number[0]

dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

loc_array = str(input())
for tmp_loc in loc_array:
    dice.roll(tmp_loc)

print("%d"%(dice.get_Top()))



Measured memory_bytes: 5616
x=int(input())
n=list(map(int,input().split()))
count=0
flag=0
while flag==0:
	flag=1
	a=0
	for i in range(1,len(n)):
		if n[i-1]>n[i]:
			a=n[i-1]
			n[i-1]=n[i]
			n[i]=a
			count+=1
			flag=0
print(' '.join(list(map(str,n))))
print(count)
	
		
		


Measured memory_bytes: 5600
import itertools
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
dic = list(itertools.permutations(range(1,n+1)))
for i in range(len(dic)):
    if dic[i] == p:
        p_num = i
    if dic[i] == q:
        q_num = i
print(abs(p_num - q_num))


Measured memory_bytes: 79620
<?php


$stdin1 = trim(fgets(STDIN));
$stdin2 = trim(fgets(STDIN));

$input1 = explode(" ", $stdin1);
$N = $input1[0];
$M = $input1[1];

$A = explode(" ", $stdin2);

for ($i = 0; $i < $M; $i++) {
    $N -= $A[$i];
}
if ($N > -1) {
    echo $N;
} else {
    echo -1;
}


Measured memory_bytes: 16792
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int n;
    cin >> n;
    
    map<int, int> cnt;
    for (int i = 2; i*i <= n; ++i) {
        while (n % i == 0) ++cnt[i], n /= i;
    }
    if (n > 1) ++cnt[n];
    
    int ans = 0;
    for (auto [p, times] : cnt) {
        /// times <= 60 ///
        for (int i = 1; i <= 11; ++i) {
            if (times * 2 < i * (i + 1)) {ans += i-1; break;}
        }
    }
    
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 3632
import java.io.*;
// import java.math.*;
// import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int N = Integer.parseInt (reader.readLine());
        System.out.println (Math.floor ((N + 1) / 2) / N);
        return;
    }
}

Measured memory_bytes: 32996
n=int(input())
for i in range(1,3501):
    for j in range(1,3501):
        if (4*i*j-n*i-n*j)>0 and (n*i*j)%(4*i*j-n*i-n*j)==0:
            w=(n*i*j)//(4*i*j-n*i-n*j)
            print(i,j,w)
            exit()

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

int main(void)
{
    int n;

    cin >> n;

    for (int i=1;i<=n;++i)
    {
        int x = i;
        if (x % 3 == 0) {
            cout << " " << i;
        }
        else {
            do {
                if (x % 10 == 3) {
                    cout << " " << i;
                    break;
                }
                else {
                    x /= 10;
                }
            } while (x);
        }
    }

    cout << endl;
}



Measured memory_bytes: 3092
#include<stdio.h>

#define N 200000


int main(){

  int n,i,max,min;
  int kawase[N];

  scanf("%d",&n);

  for(i = 0;i < n;i++)
    scanf("%d",&kawase[i]);
  
  max = -999999999;
  min = kawase[0];
  for(i = 1;i < n;i++){
    
    if(max <  kawase[i]-min)
      max = kawase[i]-min;

    if(min > kawase[i])
      min = kawase[i];

  }
      
    
  printf("%d\n",max);

  return 0;
}

Measured memory_bytes: 1376
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

#pragma GCC optimize("O3")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << 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;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int K;
  string s;
  cin >> K;
  cin >> s;
  if (s.size() <= K)
    cout << s << endl;
  else {
    cout << s.substr(0, K) << "..." << endl;
  }
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;


bool check(int w, const vector<int> &x, int mls){
	int n = x.size() - 1;

	vector<int> tbl(n + 3);
	int wsum = 0;
	int ssum = 0;
	int i;
	for(i = n; i > 0; --i){
		ssum += x[i] + mls;
		wsum += x[i] + 1;
		if(wsum - 1 > w) break;
		tbl[i] = tbl[i+1] + 1;
	}
	int wlim = n, slim = n;
	while(i > 0){
		while(ssum - mls >= w){
			ssum -= x[slim--] + mls;
		}
		while(wsum - 1 > w){
			wsum -= x[wlim--] + 1;
		}
		//end at (slim, wlim]
		tbl[i] = tbl[i+1] + (tbl[slim+2] > tbl[wlim+2]);

		--i;
		ssum += x[i] + mls;
		wsum += x[i] + 1;
	}

	return tbl[1] > tbl[2];
}


int main(){
	int w, n;
	while(scanf("%d%d", &w, &n), n){
		vector<int> x(n + 1);
		for(int i = 1; i <= n; ++i){
			scanf("%d", &x[i]);
		}

		int lt = 1, rt = w;
		while(lt < rt){
			int md = (lt + rt) / 2;
			if(check(w, x, md)){
				rt = md;
			}
			else{
				lt = md + 1;
			}
		}

		printf("%d\n", lt);
	}
}

Measured memory_bytes: 1268
l,r=map(int,input().split())
if r-l>=2019:
    minimum=0
else:
    left,right=l%2019,r%2019
    minimum=2018**2
    for i in range(left,right+1):
        for j in range(i+1,right+1):
            minimum=min(minimum,i*j%2019)
print(minimum)

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

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

  int n;
  cin >> n;

  vector<P> v(n);
  rep(i, 0, n) cin >> v[i].first >> v[i].second;

  vector<int> perm(n);
  rep(i, 0, n) perm[i] = i;

  double ans = 0;
  int c = 0;
  do {
    c++;
    int x = v[perm[0]].first, y = v[perm[0]].second;
    rep(i, 1, n) {
      ll t1 = abs(x - v[perm[i]].first);
      t1 *= t1;
      ll t2 = abs(y - v[perm[i]].second);
      t2 *= t2;
      ans += sqrt(t1 + t2);
      x = v[perm[i]].first, y = v[perm[i]].second;
    }
  } while (next_permutation(perm.begin(), perm.end()));

  cout << fixed << setprecision(10) << ans / c << endl;
}


Measured memory_bytes: 3764
N, X, Y = map(int, input().split())
X -= 1
Y -= 1

R = [0 for _ in range(N - 1)]

for i in range(N - 1):
    for j in range(i + 1, N):
        res = min(j - i, abs(Y - j) + abs(X - i) + 1)
        R[res - 1] += 1
for r in R:
    print(r)

Measured memory_bytes: 3444
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

defeated_monster = 0
for i in range(N):
    _a = A[i] + A[i+1]
    if B[i] > _a:
        defeated_monster += _a
        A[i+1] = 0
    else:
        defeated_monster += B[i]
        if B[i] > A[i]:
            A[i+1] = _a - B[i]

print(defeated_monster)



Measured memory_bytes: 18624
import collections
K=int(input())
 
q = collections.deque([1,2,3,4,5,6,7,8,9])


for i in range(K-1):
    t = q.popleft() #リスト最左側の数字を取り出す
    if t%10!=0:     #１０の倍数の時はtの数に１０欠けたもの＋１引いたもの（一つ数の位を上げた中で最小のもの）
                    #１引いても位が変わらないもの
        q.append(t*10+t%10-1) #10, 21, 32 , 121 etc...
    q.append(t*10+t%10)  #11, 22, 122 etc...
    if t%10!=9:     #1足しても位が変わらないもの
        q.append(t*10+t%10+1) #12, 23, 123 etc...
        
        
print(q.popleft())  #上のコードでqの前からK-1の数が後ろに変換して付けられていく
                    #一番左のものを取り付ければそれがK番目のものとなる

Measured memory_bytes: 40944
#include<bits/stdc++.h>
using namespace std;
int dp[250][150],T[250],x[250][3],D,N,MAX;
main(){memset(dp,-999999,sizeof(dp));
    cin>>D>>N;
    for(int i=1;i<=D;i++){cin>>T[i];}
    for(int i=1;i<=N;i++){
        cin>>x[i][0]>>x[i][1]>>x[i][2];
        if(T[1]>=x[i][0] && T[1]<=x[i][1]){dp[1][x[i][2]]=0;}
    }
    for(int i=2;i<=D;i++){
        for(int j=1;j<=N;j++){
            if(T[i]>=x[j][0] && T[i]<=x[j][1]){
                for(int k=0;k<=100;k++){
                    dp[i][x[j][2]]=max(dp[i][x[j][2]],dp[i-1][k]+abs(x[j][2]-k));
                }
            }
        }
    }
    for(int i=0;i<=100;i++){MAX=max(MAX,dp[D][i]);}
    cout<<MAX<<endl;
    return 0;
}

Measured memory_bytes: 3164
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = 0;
	long N; cin >> N;

	long L[10000]; for (int i = 0; i < 2 * N; i++) cin >> L[i];

	sort(L, L + 2 * N);

	for (int i = 0; i < 2 * N; i = i + 2) res += L[i];

	cout << res << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

ll N, K;

struct Sushi{
    ll neta;
    ll delicious;

    Sushi(ll a, ll b){
        neta = a;
        delicious = b;
    }

    bool operator<(const Sushi &another) const
    {
        return delicious < another.delicious;
    }

    bool operator>(const Sushi &another) const
    {
        return delicious > another.delicious;
    }
};
vector<Sushi> S;

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

    // input
    cin >> N >> K;

    S.reserve(N);

    FOR(i, 0, N){
        ll t, d;
        cin >> t >> d;
        S.push_back(Sushi(t, d));    
    }
    // おいしさソート
    sort(ALL(S), greater<Sushi>());
    
    vector<Sushi> Sa;
    Sa.reserve(K);
    vector<Sushi> NotSa;
    NotSa.reserve(N-K);

    ll delicious_sum = 0;
    map<int, int> neta_count; // そのネタをいくつ食べたか
    // 食べる
    FOR(i, 0, K){
        auto sushi = S[i];
        delicious_sum += sushi.delicious;
        neta_count[sushi.neta]++;
        Sa.push_back(sushi);
    }
    // 食べない
    FOR(i, K, N){
        auto sushi = S[i];
        NotSa.push_back(sushi);
    }

    ll neta_num = neta_count.size();
    // 美味しさ重視での最大値
    ll max_score = delicious_sum + neta_num * neta_num;
    // pn(max_score);

    ll j_start = Sa.size()-1;
    // 食べてないネタの中で、ネタ数を増やせる物があるか
    FOR(i, 0, N-K){
        auto sushi = NotSa[i];

        // not yet eat
        if(neta_count[sushi.neta]==0){
            // cout << "これは新ネタ " << i << " " << sushi.neta << endl;

            // Saから１つとりのぞく
            for(int j=j_start; j>=0; j--){
                j_start = j;
                auto bad_taste_sushi = Sa[j];
                if(neta_count[bad_taste_sushi.neta]>1){
                    // とりのぞく
                    neta_count[bad_taste_sushi.neta]--;
                    delicious_sum -= bad_taste_sushi.delicious;

                    // 新ネタを食べる
                    neta_count[sushi.neta]++;
                    neta_num++;
                    delicious_sum += sushi.delicious;

                    // 新スコア
                    ll score = delicious_sum + neta_num * neta_num;
                    // pn(score);
                    max_score = max(max_score, score);

                    j_start = j-1;
                    break;
                }
            }
        }
    }

    p(max_score);
    
    return 0;
}

Measured memory_bytes: 8064
S=input()
m=13
d=[0]*m
d[0]=1
for s in S:
  n=[0]*m
  for j in range(m):
    for k in range(10) if s=='?' else [int(s)]:
      n[(10*j+k)%m]+=d[j]
  d=[l%(10**9+7) for l in n]
print(d[5])

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    string s;
    cin >> s;

    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    
    return 0;
}


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

int main() {
    int H, W, i, j;
    while (1) {
        cin >> H >> W;
        if (H == 0 && W == 0) {return 0;}
        for (i = 0; i < H; ++i) {
            for (j = 0; j < W; ++j) {
                if (i == 0 || i == H - 1 || j == 0 || j == W -1) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i=0; i<N; i++){
    int d;
    cin>>d;
    vec.at(i) = d;
  }
  sort(vec.begin(),vec.end());
  int j=1;
  for(int i=0; i<N-1; i++){
    if(vec.at(i)<vec.at(i+1))
      j++;
  }
  cout<<j<<endl;
}



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

int S[100];
int top;

int pop();
void push(int);
void init();

void init(){
  top = 0;
}

int pop(){
  return S[top--];
}

void push(int n){
  S[++top]=n;
}

int main(){
  char s[100];
  int i,a,b;
  init();
 
  while(scanf("%s",s) != EOF){
    if(s[0] == '*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else if(s[0] == '+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(s[0] == '-'){
      a=pop();
      b=pop();
      push(b - a);
    }
    else if(s[0] == ' ') {
      continue;
    }
    else {
      push(atoi(&s[0]));
    }
  }
  printf("%d\n",pop());

  return 0;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 100010;
int n;
vector<int> d[MAX];
// PII dfs(int v,int par){
//   PII res = {SZ(d[v]) == 1,0};
//   for(int el:d[v])if(el!=par){
//     PII pom = dfs(el,v);
//     res.SE = min(res.SE + pom.FI, pom.SE + res.FI);
//     res.FI += pom.FI;
//   }
//   return res;
// }
int il[MAX];
void dfs(int v, int par){
  debug(v,par);
  for(int el:d[v])if(el!=par){
    if(SZ(d[el]) != 2){
      il[el]++;
      return;
    }else{
      dfs(el,v);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  R(i,n-1){
    int a,b;
    cin >> a >> b;
    d[a].PB(b);
    d[b].PB(a);
  }
  R(i,n){
    if(SZ(d[i]) == 1){
      dfs(i,-1);
    }
  }
  
  int res = 0;
  R(i,n){
    res += max(0ll,il[i]-1);
  }
  cout << max(res,1ll) << "\n";
}


Measured memory_bytes: 10496
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    s = input_raw[0]
    input_raw = read_func().strip().split()
    t = input_raw[0]

    for i in range(N):
        all_ok = True
        for j in range(N):
            if i + j < N:
                if s[i + j] != t[j]:
                    all_ok = False
                    break
        if all_ok == True:
            break

    if all_ok == True:
        print N + i
    else:
        print N + i + 1


if __name__ == '__main__':
    main()

Measured memory_bytes: 2932
#include <stdio.h>

int main()
{
  long a,b,c,k;
  scanf("%ld%ld%ld%ld",&a,&b,&c,&k);
  if (k <= a)
  {
    printf("%ld",k);
  }
  else if (k > a && k <= a + b)
  {
    printf("%ld",a);
  }
  else
  {
    printf("%ld",a - (k - a - b));
  }
}

Measured memory_bytes: 1688
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  double a,l,x;
  while(cin>>a>>l>>x){
    double ans=0;
    double kaku=acos((l*l*2-a*a)/(2*l*l));
    ans+=l*l*sin(kaku)/2;
    double ll=l+x;
    ll/=2;
    double high=sqrt(ll*ll-l*l/4);
    ans+=l*high;
    printf("%.10f\n",ans);
  }

}

Measured memory_bytes: 1324
#include <iostream>
using namespace std;
#define MAX_N 100
#define MAX_W 10000

int main()
{
  int N, W;
  cin >> N >> W;
  int v[MAX_N+1], w[MAX_N+1];
  int dp[MAX_N+1][MAX_W+1];

  for(int i=0; i<N; ++i){
    cin >> v[i] >> w[i];
  }
  for(int i=0; i<N+1; ++i){
    for(int j=0; j<W+1; ++j){
      dp[i][j] = -1;
    }
  }

  for(int j=0; j<W+1; ++j)
    dp[N][j] = 0;

  for(int i=N-1; i>=0; --i){
    for(int j=0; j<=W; ++j){
      if(j < w[i])
	dp[i][j] = dp[i+1][j];
      else
	dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
    }
  }

  cout << dp[0][W] << endl;
}

Measured memory_bytes: 7016
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 55

struct LOC{
	LOC(){
		x = y = z = 0;
	}

	LOC(int arg_x,int arg_y,int arg_z){
		x = arg_x;
		y = arg_y;
		z = arg_z;
	}
	int x,y,z;
};

int H,W,N;
LOC loc[SIZE];
bool used[SIZE][SIZE];

int main(){

	scanf("%d %d %d",&W,&H,&N);

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){

			used[row][col] = false;
		}
	}

	int ans = 0;

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

		scanf("%d %d %d",&loc[i].x,&loc[i].y,&loc[i].z);
		loc[i].x--;
		loc[i].y--;
		used[loc[i].y][loc[i].x] = true;

		ans += loc[i].z;
	}

	for(int i = 0; i < N-1; i++){
		for(int k = i+1; k < N; k++){

			int diff_z = abs(loc[i].z-loc[k].z);
			int diff_x = abs(loc[i].x-loc[k].x);
			int diff_y = abs(loc[i].y-loc[k].y);

			if(diff_z > diff_x+diff_y){

				printf("No\n");
				return 0;
			}
		}
	}

	for(int x = 0; x < W; x++){
		for(int y = 0; y < H; y++){
			if(used[y][x])continue;

			int maximum = -BIG_NUM;
			for(int i = 0; i < N; i++){

				int diff_x = abs(loc[i].x-x);
				int diff_y = abs(loc[i].y-y);
				maximum = max(maximum,loc[i].z-(diff_x+diff_y)); //なるべく低くする
			}

			used[y][x] = true;
			ans += maximum;
		}
	}

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




Measured memory_bytes: 3200
import sys
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def input():
    return next(args)
def parse(*params):
    if len(params) == 1:
        return params[0](next(args))
    return tuple(p(v) for p, v in zip(params, next(args).split()))
def debug(*v):
    if __debug__:
        print(*v, file=sys.stderr)

# エントリーポイント
def main():
    N, Q = parse(int, int)
    edges = [[] for _ in range(N + 1)]
    for _ in range(N - 1):
        a, b = parse(int, int)
        edges[a] += [b]
        edges[b] += [a]
    vals = [0] * (N + 1)
    for _ in range(Q):
        p, x = parse(int, int)
        vals[p] += x

    counter = [0] * (N + 1)
    que = [(1, 0)]
    alr = [False] * (N + 1)
    while que:
        v, x = que.pop()
        alr[v] = True
        counter[v] += x + vals[v]
        for n in edges[v]:
            if not alr[n]:
                que.append((n, counter[v]))

    for v in counter[1:]:
        print(v)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split("\n"))
    main()


Measured memory_bytes: 93496
def solve(n, a_list, b_list):
    a_list_s = sorted(a_list)
    b_list_s = sorted(b_list)

    # check 1
    for i in range(n):
        if a_list_s[i] > b_list_s[i]:
            return "No"

    # check 2
    for i in range(n - 1):
        if a_list_s[i + 1] <= b_list_s[i]:
            return "Yes"

    # check 3
    # do it
    # arg sort
    a_list_s_arg = dict()
    b_list_s_org = dict()
    res_list = [0] * n
    for j in range(n):
        a_list_s_arg[a_list_s[j]] = j
    for k in range(n):
        b_list_s_org[b_list[k]] = k
    for i in range(n):
        j = a_list_s_arg[a_list[i]]
        k = b_list_s_org[b_list_s[j]]
        res_list[i] = k

    i = 0
    cnt = 0
    while True:
        i = res_list[i]
        cnt += 1
        if i == 0:
            break
    if cnt == n:
        return "No"
    else:
        return "Yes"


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    res = solve(n, a_list, b_list)
    print(res)


def test():
    assert solve(3, [1, 3, 2], [1, 2, 3]) == "Yes"
    assert solve(3, [1, 2, 3], [2, 2, 2]) == "No"
    assert solve(6, [3, 1, 2, 6, 3, 4], [2, 2, 8, 3, 4, 3]) == "Yes"


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 95976
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
  	int a[n+10],dp[n+10];
    dp[0]=0;dp[1]=0;
    for(int i=1;i<=n;i++)cin>>a[i];
    dp[2] = abs(a[1]-a[2]);
    for(int i=3;i<=n;i++){
        dp[i] = min(abs(a[i]-a[i-1])+dp[i-1],dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n];
 
    return 0;
} 

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

using namespace std;

int main() {
	long long n, sum = 0;
	cin >> n;
	long long arr[n + 1];
	for(long long i = 1; i <= n; ++i){
        cin >> arr[i];
        sum += arr[i];
	}
	long long k;
	cin >> k;
	for(long long i = 0; i < k; ++i){
        long long p, x;
        cin >> p >> x;
        cout << sum - (arr[p] - x) << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int gcd(int a,int b){
  if(b==0)
  return a;
  return gcd(b,a%b);
}
int main(){
  int c,i,tmp,N,X,x[101000],dx[101000];
  scanf("%d %d",&N,&X );
  for(i=0;i<N;i++){
  scanf("%d",&x[i] );
  dx[i]=abs(X-x[i]);
}

  if(dx[0]<dx[1]){
    tmp=dx[0];
    dx[0]=dx[1];
    dx[1]=tmp;
  }
  c=gcd(dx[0],dx[1]);
  for(i=2;i<N;i++){
    if(c<dx[i]){
      tmp=c;
      c=dx[i];
      dx[i]=tmp;
    }
    c=gcd(c,dx[i]);
  }
  printf("%d",c );

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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 ll MOD = 1e9+7;

ll N;
ll M;
vector<ll> A;
vector<ll> S;

bool judge(ll x){
    ll num = 0;
    for(int i = N-1; i >= 0; i--){
        ll a = A[i];
        if(a+a >= x) num++;
        ll val = x - a;
        int minus = N-i;
        ll tmp = A.end() - minus - lower_bound(A.begin(), A.end()-minus, val);
        num += tmp*2;
    }

    if(num >= M)
        return true;
    else
        return false;
}

ll calc(ll x){
    ll ret = 0;
    ll num = 0;
    for(int i = N-1; i >= 0; i--){
        ll a = A[i];
        if(a+a >= x) {
            num ++;
            ret += a+a;
        }

        if(i != 0){
            ll val = x - a;
            int minus = N-i;
            ll add = 0;
            ll tmp = A.end() - minus - lower_bound(A.begin(), A.end()-minus, val);
            num += tmp*2;
            add += a * tmp;

            ll idx = lower_bound(A.begin(), A.end()-minus, val) - A.begin();
            add += S[i-1];
            if(idx > 0) add -= S[idx-1];
            ret += add*2;
        }
    }

    if(num > M){
        ret -= x*(num-M);
    }

    return ret;
}

int main(){
    cin >> N;
    cin >> M;

    S.resize(N);
    REP(i,N){
        ll a;
        cin >> a;
        A.push_back(a);
    }

    sort(A.begin(), A.end());
    REP(i,N){
        ll a = A[i];
        S[i] = a;
        if(i != 0)
            S[i] += S[i-1];
    }


    ll left = 0;
    ll right = 3e5;
    while(right - left > 1){
        ll mid = (left + right) / 2;
        bool valid = judge(mid);
        if(valid){
            left = mid;
        }
        else{
            right = mid;
        }
    }

    ll ans;
    ans = calc(left);
    
    //cout << left << endl; 
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long n, a, b;
vector<long long> h;
bool judge(long long counts) {
	long long failing = 0;
	for (int i = 0;i < h.size();++i) {
		failing += max((long long)0, (h[i] - (b*counts)+a-1) / a);
	}
	if (failing <= counts) return true;
	return false;
}
int main() {
	cin >> n >> a >> b;
	a -= b;
	REP(i, n) {
		int a;
		cin >> a;
		h.push_back(a);
	}
	long long top = 10000000000;
	long long bot = 0;
	while (top - bot > 1) {
		long long mid = (top + bot) / 2;
		if (judge(mid)) {
			top = mid;
		}
		else bot = mid;
	}
	if (judge(bot)) {
		cout << bot << endl;
	}
	else cout << top << endl;
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;



const int INF = 100000;
int n,m;
vector<int> vn,vm;
int def;

void init(){
  vn.clear();
  vm.clear();
  def=0;
}

pair<int,int> solve(){
  pair<int,int> res(INF,INF);
  for(int i=0;i<vn.size();i++){
    for(int j=0;j<vm.size();j++){
      if(2*(vn[i]-vm[j])==def){
        if(res.first+res.second>vn[i]+vm[j]){
	  res.first=vn[i];
	  res.second=vm[j];
	}
      }
    }
  }
  return res;
}

int main(){
  while(cin>>n>>m,n!=0||m!=0){
    //cout<<n<<" "<<m<<endl;
    init();
    for(int i=0;i<n;i++){
      int tmp;
      cin>>tmp;
      def+=tmp;
      vn.push_back(tmp);
    }
    for(int i=0;i<m;i++){
      int tmp;
      cin>>tmp;
      def-=tmp;
      vm.push_back(tmp);
    }
    sort(vn.begin(),vn.end());
    sort(vm.begin(),vm.end());
    //cout<<"def="<<def<<endl;

    pair<int,int> ans=solve();
    if(ans.first==INF){
      cout<<-1<<endl;
    }else{
      cout<<ans.first<<" "<<ans.second<<endl;
    }

   
  }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())
#define DEBUG

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef pair<long,long> pr;
typedef map<double,pr> mp;

int A, B, C;


int main(void){
	cin >> A >> B >> C;

    if (A + B >= C) cout << "Yes";
    else cout << "No";

    return 0; 
}

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

int main(){
        int n, ans=0, amin=10000;
        cin>>n;
        int a[n], b[n], T[10000];
        bool V[n];
        for(int i=0;i<n;i++) V[i] = true;
        for(int i=0;i<n;i++) {
                cin>>a[i];
                b[i]=a[i];
                amin=min(a[i], amin);
        }
        sort(b, b+n);
        for(int i=0;i<n;i++) T[b[i]] = i;

        for(int i=0;i<n;i++) {
                if(!V[i]) continue;
                int j = i, tmpmin = a[i], c=0;
                int S = 0;
                while(V[j]){
                        c++;
                        tmpmin = min(tmpmin, a[j]);
                        S += a[j];
                        V[j] = false;
                        j = T[a[j]];
                }
                ans += min(S+(c-2)*tmpmin, S+tmpmin+(c+1)*amin);
        }

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


Measured memory_bytes: 3180
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

int main(int argc, char* argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	set<int> s;
	for(int i=0;i<n;++i)
	{
		int x;
		cin>>x;
		s.insert(x);

	}
	if(s.size()==n)
	cout<<"YES";
	else
	cout<<"NO";
	return 0;
}

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

int main(){
	long long N, L;
	cin >> N >> L;
	long a[N];
	for(int i=0; i<N; i++) cin >> a[i];
	bool check = false;
	int p;
	for(int i=0; i<N-1; i++){
		if(a[i] + a[i+1] >= L){ check = true; p = i+1; }
	}
	if(check){
		cout << "Possible" << endl;
		for(int i=1; i<p; i++){
			cout << i << endl;
		}
		for(int i=N-1; i>p; i--){
			cout << i << endl;
		}
		cout << p << endl;
	}else{
		cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++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 irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
 
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  vi xs(n);
  rep(i,n)cin>>xs[i];
  vi ys(m);
  rep(i,m)cin>>ys[i];
  vsort(xs);
  vsort(ys);
  string ans="War";
  if(xs[n-1]<ys[0]){
    if(x<ys[0]&&xs[n-1]<y&&x<y)ans="No War";
  }
  cout(ans);

  return 0;
}

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

class Main {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);
        
        while(true){
            int a   = scan.nextInt();
            char op = scan.next().charAt(0);
            int b   = scan.nextInt();
            
            if(op == '?'){
                break;
            }
            
            switch(op){
            case '+':
                System.out.println(a + b);
                break;
            
            case '-':
                System.out.println(a - b);
                break;
            
            case '*':
                System.out.println(a * b);
                break;
            
            case '/':
                System.out.println(a / b);
                break;
            }
        }
    }
}


Measured memory_bytes: 26072
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
using namespace std;
const int N = 5e5+5;
ll n, m, k, x, y, a, b, t,two,one,q, ans, sum;
char c;
string str;
vector< ll >v;
ll A[N],B[N];
main()
{
	ios::sync_with_stdio(0);
	for(int i=0;i<3;i++){
		cin>>a>>b;
		A[a]++;
		A[b]++;
	}
	
	for(int i=1;i<=4;i++)
	if(A[i]==2)
	two++;
	else
	if(A[i]==1)
	one++;
	
	if(two==one && two==2)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
}







Measured memory_bytes: 2304
#include <stdio.h>

#define max(a,b) ( ((a)>(b)) ? (a) : (b) )
#define min(a,b) ( ((a)<(b)) ? (a) : (b) )

int right[4] = {1,2,3,0};
int left[4]  = {3,0,1,2};

int main(){
	int x, y, a, b, d, l, sign;
	char s[50];

	loop:
		scanf("%d %d",&x,&y);
		if(!x&&!y)goto end;
		a=b=1;d=0;
		while(1){
			scanf("%s",s);
			if(!strcmp(s,"STOP")){
				printf("%d %d\n",a,b);
				goto loop;
			}
			if(!strcmp(s,"RIGHT")){d=right[d];continue;}
			if(!strcmp(s,"LEFT")) {d=left[d]; continue;}

			scanf("%d",&l);
			if(!strcmp(s,"FORWARD")) sign=1;
			if(!strcmp(s,"BACKWARD"))sign=-1;
			switch(d){
				case 0: b+=sign*l;break;
				case 1: a+=sign*l;break;
				case 2: b-=sign*l;break;
				case 3: a-=sign*l;break;
			}
			a=max(a,1);a=min(a,x);
			b=max(b,1);b=min(b,y);
		}
	goto loop;

	end:
	return 0;
}

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

using namespace std;
typedef long long ll;
const long double pi=3.14159265358979323846;
#define x  first
#define y  second


int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll x,y;
        cin>>x>>y;
        if(y%x==0&&y/x== 4)cout<<"Yes";
        else if(y%x==0&&y/x == 2)cout<<"Yes";
        else if(y> x*4 || y< x*2)cout<<"No";
        else
        {
            while(x&&y)
            {
                y-=4;
                x--;
                if(!x)break;
                if(!y)break;
                if(y%x==0&&y/x==2){cout<<"Yes";return 0;}
            }
            cout<<"No";
        }
    }
    return 0;
}


Measured memory_bytes: 3648
import java.math.BigDecimal
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val t = (0 until n).map { sc.nextLong() }
    println(problem070c(n, t))
}

fun problem070c(n: Int, t: List<Long>): Long {
    /**
     * 最大公約数
     * @param big 2つの値の大きな方
     * @param small 2つの値の小さな方
     */
    fun computeGreatestCommonDivisor(big: Long, small: Long): Long {
        val rest = big % small
        return if (rest == 0L) small else computeGreatestCommonDivisor(small, rest)
    }

    /**
     * 最小公倍数
     * @param big 2つの値の大きな方
     * @param small 2つの値の小さな方
     */
    fun computeLeastCommonMultiple(small: Long, big: Long): Long {
        return BigDecimal(small).multiply(BigDecimal(big)).div(BigDecimal(computeGreatestCommonDivisor(big, small))).toLong()
    }
    var ans = t[0]
    for (i in 1 until n) {
       ans = computeLeastCommonMultiple(Math.min(ans, t[i]), Math.max(ans, t[i]))
    }
    return ans
}

Measured memory_bytes: 29856
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 p = Integer.parseInt(sc.next());
		int odd = 0;
		long even = 0;
		for (int i= 0; i < n; i++)
			if (Integer.parseInt(sc.next()) % 2 != 0)
				odd++;
			else
				even++;
		long a = (long)Math.pow(2, even);
		long b = 0;
		for (int i = 0; i <= odd; i += 2)
			b += combination(odd, i);
		if (p == 0)
			System.out.println(a * b);
		else
			System.out.println((long)Math.pow(2, n) - a * b);
	}
	public static long combination(int n, int r) {
		if (r == 0 || r == n)
			return 1;
		else if (r == 1)
			return n;
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}
}

Measured memory_bytes: 25172
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, C, K = [int(x) for x in input().split()]
    T = [int(input()) for _ in range(N)]
    
    T.sort()

    ans = 1
    cnt = 1
    mi = T[0]
    for i in range(1, N):
        if cnt == C:
            ans += 1
            cnt = 1
            mi = T[i]
        else:
            if T[i] > mi + K:
                ans += 1
                cnt = 1
                mi = T[i]
            else:
                cnt += 1

    print(ans)

    
    
    

if __name__ == '__main__':
    main()



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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  ans += n / 11 * 2;
  n %= 11;
  if (n == 0)
    cout << ans << endl;
  else if (n <= 6)
    cout << ans + 1 << endl;
  else
    cout << ans + 2 << endl;
}


Measured memory_bytes: 256