akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N + 1, INF);
    rep(i, N) cin >> A[i + 1];

    ll now = 1000, K = 0, ans = 1000, v = A[0];
    bool B = true;
    
    rep(i, N){
        if(B){
            if(A[i + 1] > A[i]){
                B = false;
                K += now / v;
                now -= v * K;
                v = A[i + 1];
            }
            else{
                v = A[i + 1];
            }
        }
        else if(!B){
            if(A[i+1]<A[i]){
                B = true;
                now += v * K;
                K = 0;
                v = A[i + 1];
                chmax(ans, now);
            }
            else{
                v = A[i + 1];
            }
            
        }
    }

    if (K > 0) chmax(ans, now + v * K);
    cout << ans << endl;
}

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

using namespace std;

char other(char a, char b) {
    if (a != 'C' && b != 'C') {
        return 'C';
    }
    if (a == 'B' && b != 'B') {
        return 'B';
    }
    return 'A';
}

string req[200005];
int main() {
 int n, a, b, c;
 cin >> n >> a >> b >> c;

 vector <char> ans;
 vector <int> cnt(255, 0);
 cnt['A'] = a;
 cnt['B'] = b;
 cnt['C'] = c;
 int k = (a == 0) + (b == 0) + (c == 0);
 for (int i = 0; i < n; i++) {
    cin >> req[i];
 }
 for (int i = 0; i < n; i++) {
    string s = req[i];
    assert(cnt['A'] >= 0 && cnt['B'] >= 0 && cnt['C'] >= 0);
    if (cnt[s[0]] == 0 && cnt[s[1]] == 0) {
        cout << "No";
        return 0;
    }
    if (cnt[s[0]] == 0) {
        ans.push_back(s[0]);
        cnt[s[0]] = 1;
        cnt[s[1]]--;
        continue;
    }
    if (cnt[s[1]] == 0) {
        ans.push_back(s[1]);
        cnt[s[1]] = 1;
        cnt[s[0]]--;
        continue;
    }
    if (cnt[s[0]] == 1 && cnt[s[1]] == 1) {
        char c = other(s[0], s[1]);
        if (i == n - 1 || req[i] == req[i + 1] || (req[i + 1][0] == s[0] || req[i + 1][1] == s[0])) {
            ans.push_back(s[0]);
            cnt[s[0]]++;
            cnt[s[1]]--;
        }
        else {
            ans.push_back(s[1]);
            cnt[s[1]]++;
            cnt[s[0]]--;
        }
        continue;
    }
    if (cnt[s[1]] > cnt[s[0]]) {
        ans.push_back(s[0]);
        cnt[s[0]]++;
        cnt[s[1]]--;
    }
    else {
        ans.push_back(s[1]);
        cnt[s[1]]++;
        cnt[s[0]]--;
    }
 }
 cout << "Yes\n";
 for (int i = 0; i < n; i++) {
    cout << ans[i] << "\n";
 }
 return 0;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  int h,w,m;
  const int MAX = 3 * 1e5;
  cin >> h >> w >> m;
  int line_cnt[MAX + 1] = {};
  int column_cnt[MAX + 1] = {};
  int line_max = 0;
  int column_max = 0;
  int bx[MAX + 1];
  int by[MAX + 1];
  map<pair<int, int>, int> bomb;
  for(int i = 0; i < m; i++){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    bx[i] = x;
    by[i] = y;
    bomb[make_pair(x,y)] = 1;
    column_cnt[x] ++;
    line_cnt[y] ++;
    if(column_max < column_cnt[x]) column_max = column_cnt[x];
    if(line_max < line_cnt[y]) line_max = line_cnt[y];
  }
  vector<int> candidate_line;
  vector<int> candidate_column;
  vector<int> line_map(w, 0);
  vector<int> column_map(h,0);
  for(int i = 0; i < h; i++){
    if(column_cnt[i] == column_max) {
      candidate_column.push_back(i);
      column_map[i] = 1;
    }
  }
  for(int i = 0; i < w; i++){
    if(line_cnt[i] == line_max) {
      candidate_line.push_back(i);
      line_map[i] = 1;
    }
  }

  long long ans = line_max + column_max - 1;
  long long cross_cnt = candidate_line.size() * candidate_column.size();
  long long cnt = 0;
  bool flag = 0;
  for(int i = 0; i < m; i++){
    int x = bx[i];
    int y = by[i];
    if(column_map[x] == 1 && line_map[y] == 1) cnt ++;
  }
  // if(flag) ans ++;
  if(cross_cnt > cnt) ans ++;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 33224
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int K,N;
  cin>>K>>N; 
  vector<int>a(N);
  for(int i=0;i<N;++i){
    cin>>a.at(i);   
  }
  int b=a.at(0)+K-a.at(N-1);
  for(int i=0;i<N-1;++i){
    b=max(b,a.at(i+1)-a.at(i));
  }
    cout<<K-b<<endl;
  

}







Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long ans = 0;
    vector<string> s(n);
    for(int i = 0;i < n;i++){
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s.begin(),s.end());
    long long same = 1;
    for(int i = 0;i < n-1;i++){
        if(s[i] == s[i+1]){
            same++;
        }else{
            ans += (same*(same-1))/2;
            same = 1;
        }
    }
    ans += (same*(same-1))/2;
    cout << ans << endl;
}

Measured memory_bytes: 7296
n = int(input())
s = input()
t = input()

flag = 0

for i in reversed(range(n)):
	j = (-1) * i - 1
	if t[:(i+1)] == s[j:]:
		flag = 1
		break
	else:
		continue

if i == 0 and flag == 0:
	print(len(s + t))
else:
	print(len(s[:j] + t))

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

int main(){
    string s, t;
    cin >> s >> t;
    for(int i=0; i<s.size(); i++){
        if(s[i] != t[2-i]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 764
import math
import fractions
n,m=map(int, input().split())
a=list(map(int, input().split()))
b=[]
s=math.floor(math.log2(max(a)))
buf=0
for i in range(n): #aは偶数なので、1/2した値の配列を作った
    b.append(int(a[i]//2))

for i in range(s+1): #2のi乗ですべての数が割れるかどうか
    for j in b:
        if j%(2**i)==0:
            buf+=1
        else:
            continue
    if buf==n:
        buf=0
        continue
    else:
        break

def lcm(x,y): #最小公倍数を求める関数の定義
    return (x*y)//fractions.gcd(x,y)

if buf!=0 and buf!=n: #偶奇が入り混じってるとき
    print(0)
elif n==1: #配列の要素が1つしかないとき
    d=int(m//b[0])
    print(int((d+1)//2))
else:
    c=[lcm(b[0],b[1])] #以下のサイクルで求めた最小公倍数を入れる配列
    for i in range(1,n-1):
        x=lcm(c[i-1],b[i+1])
        c.append(x)
        if x<m:
            continue
        else:
            break
    d=int(m//c[len(c)-1]) #最後の値(c[len(c)-1])が配列bの最小公倍数
    ans=int((d+1)//2)
    print(ans)


Measured memory_bytes: 17040
#include <stdio.h>
int main(){
  
  int a, b;
  scanf("%d%d", &a, &b );
  if ( a < b ) {
    printf("a < b\n");
  } else if ( a > b ) {
    printf("a > b\n");
  } else if ( a == b ){
    printf("a == b\n");
  }

  return 0;
}



Measured memory_bytes: 2104
#!/usr/bin/env python
# coding: utf-8

# In[9]:


import collections


# In[32]:


N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))


# In[34]:


t_count = collections.Counter(T)
d_count = collections.Counter(D)

for key,c in t_count.items():
    if key in d_count.keys():
        if d_count[key] < c:
            print("NO")
            break
    else:
        print("NO")
        break
else:
    print("YES")


# In[ ]:






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

class UnionFind {
public:
    int S;
    vector <int> par;
    vector <int> siz;
 
    UnionFind(int n){
    	for (int i = 0; i < n; i++) {
    		par.push_back(i);
    		siz.push_back(1);
    	}
        S = n;
    }
 
    int root(int x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        S--;
        return true;
    }
 
    bool is_same(int x, int y) {
        return root(x) == root(y);
    }
 
    int size(int x) {
        return siz[root(x)];
    }
	int allsize() {return S;}
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
        v[i]--;
    }

    UnionFind tree(n); // 要素数nのUnion-Find treeを作成

    for(int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        x--; y--;
        tree.unite(x, y); // xのグループとyのグループを併合する
    }

    int cnt = 0;
    for(int i = 0; i < n; i++) {
        if (tree.is_same(i, v[i])) { // P[i]とiが同じグル―プに属するかを調べる
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h, w, n;
	cin >> h >> w >> n;
	vector<set<pii>> st(9);
	auto update = [&](int a, int b) {
		if (a > 0 && b > 0 && a < h - 1 && b < w - 1) {
			bool done = false;
			pii p(a, b);
			RREP(i, st.size()) {
				if (st[i].count(p)) {
					done = true;
					st[i].erase(p);
					st[i + 1].insert(p);
					break;
				}

			}
			if (!done)st[0].insert(p);
		}
	};
	REP(i, n) {
		int a, b; cin >> a >> b;
		a--; b--;
		update(a, b);
		REP(k, 8)update(a + dx[k], b + dy[k]);
	}
	ll cnt = 0;
	vl ans(10);
	REP(i, 9) {
		ans[i + 1] = st[i].size();
		cnt += st[i].size();
	}
	ans[0] = (h - 2)*(w - 2) - cnt;
	REP(i, 10)cout << ans[i] << endl;
}

Measured memory_bytes: 42496
n = int(input())
list_v = list(map(int,input().split()))
list_c = list(map(int,input().split()))
 
ans = 0
for i in range(n):
  if list_v[i] - list_c[i] > 0:
    ans += list_v[i] - list_c[i]
print(int(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    vector<double> v(n);
    rep(i,n) cin >> v[i];
    sort(ALL(v));
    double ans = v[0];
    REP(i,1,n){
        ans = (ans+v[i])/2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	int k;
	string s;
	cin >> k >> s;
	if (s.size() <= k) cout << s << endl;
	else cout << s.substr(0, k) + "..." << endl;
}

Measured memory_bytes: 3632
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String today = sc.next();
    
    if(today.equals("Sunny")){
      System.out.println("Cloudy");
    }else  if(today.equals("Cloudy")){
      System.out.println("Rainy");
    }else if(today.equals("Rainy")){
      System.out.println("Sunny");
    }
  }
}

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

Measured memory_bytes: 9180
#include <bits/stdc++.h>
    using namespace std;
    int main()
    {
      int n,ca=0,ct=0,cw=0,cr=0;
      cin>>n;
      while(n--)
      {
        string s;
        cin>>s;
        if(s=="AC")
          ca++;
        if(s=="WA")
          cw++;
        if(s=="TLE")
          ct++;
        if(s=="RE")
          cr++;
      }
      cout<<"AC x "<<ca<<endl;
      cout<<"WA x "<<cw<<endl;
      cout<<"TLE x "<<ct<<endl;
      cout<<"RE x "<<cr<<endl;
    return 0;
    }

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll n;
	cin >> n;

	vector<vector<ll>> a(10, vector<ll>(10));

	for (ll i = 1; i <= n; i++)
	{
		vector<ll> d;

		for (ll j = i; j > 0; j /= 10)
		{
			d.push_back(j % 10);
		}

		ll p = d.front();
		ll q = d.back();

		if (p > 0 && q > 0)
		{
			a[p][q]++;
		}
		
	}

	ull res = 0;

	for (ll i = 1; i <= 9; i++)
	{
		for (ll j = 1; j <= 9; j++)
		{
			res += a[i][j] * a[j][i];
		}
	}

	println(res);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<int,ll>;
using Pd = pair<double,double>;
using T = tuple<double,double,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N = 100005;
const ll lmod = 1e9+7;

int main(){
  int a,b; string s;
  cin >> a >> b >> s ;
  bool ok = true;
  rep(i,a) ok &= (s[i]>='0' && s[i]<='9');
  ok &= (s[a] == '-');
  rep(i,b) ok &= (s[i+a+1]>='0' && s[i+a+1]<='9');
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
# ABC054B - Template Matching
n, m = list(map(int, input().rstrip().split()))
lst_n = [input().rstrip() for _ in range(n)]
lst_m = [input().rstrip() for _ in range(m)]

for i in range(n - m + 1):
    for j in range(n - m + 1):
        if [lst_n[j + k][i : i + m] for k in range(m)] == lst_m:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll n,st,m;
    cin >> n;
    vector<ll> t(n + 1,0),x(n + 1,0),y(n + 1,0);
    rep1(i, n + 1)cin >> t[i] >> x[i] >> y[i];
    rep1(i, n + 1){
        st = t[i] - t[i - 1];
        m = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
        if (m <= st) {
            if (st % 2 == 1 && m % 2 == 0) {
                No;
                return 0;
            }else if(st % 2 == 0 && m % 2 == 1){
                No;
                return 0;
            }
        }else{
            No;
            return 0;
        }
    }
    Yes;
    return 0;
}


Measured memory_bytes: 2560
N, C = map(int, input().split())
x = []
v = []
for i in range(N):
    a, b = map(int, input().split())
    x.append(a)
    v.append(b)

R = [0] * N
L = [0] * N
for i in range(N):
    if i == 0:
        R[i] = v[i] - x[i]
        L[N-1-i] = v[N-1-i] - (C - x[N-1-i])
    else:
        R[i] = R[i - 1] + v[i] - (x[i] - x[i - 1])
        L[N-1-i] = L[N-i] + v[N-1-i] - (x[N-i] - x[N-1-i])

Rmax = [0] * N
Lmax = [0] * N
for i in range(N):
    if i == 0:
        Rmax[i] = R[i]
        Lmax[N-1-i] = L[N-1-i]
    else:
        Rmax[i] = max(Rmax[i-1], R[i])
        Lmax[N-1-i] = max(Lmax[N-i], L[N-1-i])

R2L = 0
L2R = 0
for i in range(N-1):
    R2L = max(R2L, R[i] - x[i] + Lmax[i+1])
    L2R = max(L2R, L[i+1] - (C - x[i+1]) + Rmax[i])

print(max(0, max(R), max(L), R2L, L2R))

Measured memory_bytes: 21728
import collections

def resolve():
    N = int(input())
    S = [input() for i in range(N)]
    # 値と出現個数のリスト
    S_counter_dict = collections.Counter(S)
    result_list = ["AC", "WA", "TLE", "RE"]
    for result in result_list:
        if result in S_counter_dict.keys():
            print("{result} x {count}"
            .format(result=result, count=S_counter_dict[result]))
        else:
            print("{result} x 0".format(result=result))

resolve()

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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

vector<LL> InputVec(LL size) {
	vector<LL> vec((size_t)size);
	REP(i, size) {
		cin >> vec[(size_t)i];
	}
	return vec;
}

vector<LL> tbl;

LL CalcCost(vector<LL> const& hs, int i) {
	if (i == hs.size() - 1) {
		return 0;
	}

	if (tbl[i] >= 0) {
		return tbl[i];
	}

	LL cost = 0;
	{
		LL c = abs(hs[i] - hs[i + 1]);
		c += CalcCost(hs, i + 1);
		cost = c;
	}

	if (i + 2 < hs.size()) {
		LL c = abs(hs[i] - hs[i + 2]);
		c += CalcCost(hs, i + 2);
		cost = min(cost, c);
	}

	tbl[i] = cost;

	return cost;
}

int main()
{
	LL N;
	cin >> N;
	vector<LL> hs = InputVec(N);
	tbl.resize(N, -1);

	LL cost = CalcCost(hs, 0);
	cout << cost << endl;

	return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    bool flag=true;
    int a,b;
    char s[100];
    scanf("%d %d",&a,&b);
    scanf("%s",s);
    for(int i=0;i<a;i++) if(s[i]<'0'||s[i]>'9') flag=false;
    for(int i=a+1;i<a+b+1;i++) if(s[i]<'0'||s[i]>'9') flag=false;
    if(s[a]!='-') flag=false;
    if(flag) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val aa = 0.until(a).map { b }.joinToString(separator = "")
    val bb = 0.until(b).map { a }.joinToString(separator = "")
    if (aa > bb) {
        println(bb)
    } else {
        println(aa)
    }
}


Measured memory_bytes: 37856
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
#define REP(i,n) for (int i = 1; i<= (n); i++)
const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    int k;
    string s;
    cin >> k;
    cin >> s;
    if (s.length() <= k) {
        cout << s << endl;
    } else {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i

}

type node struct {
	item int
	prev *node
	rank int
}

func (n *node) root() *node {
	var parent *node
	for parent = n; parent.prev != nil; parent = parent.prev {
		continue
	}
	return parent
}

func issame(nodeX, nodeY *node) bool {
	return nodeX.root() == nodeY.root()

}

func merge(nodeX, nodeY *node) {
	parentX := nodeX.root()
	parentY := nodeY.root()

	if nodeX.rank < nodeY.rank {
		nodeX, nodeY = nodeY, nodeX
	}

	if nodeX.rank == nodeY.rank {
		nodeX.rank += 1
	}

	if parentX.prev != nil || parentY.prev != nil {
		panic(fmt.Sprintf("%v, %v", parentX, parentY))
	}
	if parentX.item != parentY.item {
		parentX.prev = parentY

	}

}

func main() {
	sc.Split(bufio.ScanWords)
	var n, q int
	fmt.Scanf("%d %d", &n, &q)

	groups := make([]*node, n)
	for i := 0; i < n; i++ {
		groups[i] = &node{item: i, prev: nil, rank: 0}
	}

	for i := 0; i < q; i++ {
		com, x, y := next(), next(), next()
		if com == 0 {
			merge(groups[x], groups[y])

		} else {
			if issame(groups[x], groups[y]) {
				fmt.Println("1")
			} else {
				fmt.Println("0")
			}
		}
	}

}



Measured memory_bytes: 2684
def main ():
  N = int(input())
  A = list(map(int,input(). split ()))
  
  if 0 in A:
    print(0)
    return
  prod = 1
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
    
  print(prod)
  
main ()


Measured memory_bytes: 21484
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}
double max(double a, double b) {
	if (a < b) return b;

	return a;
}




vector<ll> A;
int main() {
	ll N;
	cin >> N;
	A.resize(N);
	
	ll numki = 0;
	rep(i, N) {
		cin >> A[i];
		if (A[i] % 2 == 1) {
			numki += 1;
		}
	}

	if (numki % 2 == 1) {
		cout << "NO" << endl;
	}

	else {
		cout << "YES" << endl;
	}



	return 0;
}

Measured memory_bytes: 1024
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
//#include <vector>
//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int N;
    cin >> N;
    int K;
    cin >> K;
    int h[N];

    for( int ni = 0 ; ni < N ; ni++ ){
        cin >> h[ni];
    }
    sort(h,h+N);
    int min;
    min = h[K-1] - h[0];
    for( int ni = 1 ; ni < N - (K-1); ni++ ){
        if(min > h[K-1+ni]-h[ni]) min = h[K-1+ni]-h[ni];
    }

    cout << min;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,d;
int cnt[1001][1001];
int deg[1001][1001];
int sum[2005][2005];
vector<int> de;
int ma;

bool C(int v){
    memset(sum,0,sizeof(sum));
    int co=0;
    for(int k=0;k<d;k++){
        for(int l=0;l<d;l++){
            if(deg[k][l]!=ma)continue;
            co++;
            if(cnt[k][l]<=ma*(ma-1)){
                sum[k+1][l+1]++;
                sum[d+k+1][d+l+1]++;
                sum[d+k+1][l+1]--;
                sum[k+1][d+l+1]--;

                sum[k+1][l+1]--;
                sum[d+k-v][d+l-v]--;
                sum[d+k-v][l+1]++;
                sum[k+1][d+l-v]++;
            }else{
                sum[d+k+1][d+l+1]++;
                sum[d+k+1][d+l-v]--;
                sum[d+k-v][d+l+1]--;
                sum[d+k-v][d+l-v]++;
            }
        }
    }
    for(int i=0;i<=d*2;i++){
        for(int j=0;j<d*2;j++){
            sum[i][j+1]+=sum[i][j];
        }
    }
    for(int i=0;i<=d*2;i++){
        for(int j=0;j<=d*2;j++){
            sum[j+1][i]+=sum[j][i];
        }
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<d;j++){
            if(sum[i][j]+sum[i+d][j+d]+sum[i][j+d]+sum[i+d][j]>=co)return true;
        }
    }
    return false;
}

int main(void){
    de.push_back(0);
    for(int i=1;i<=1000;i++){
        de.push_back(i*i);
    }
    scanf("%d%d",&n,&d);
    for(int i=0;i<n;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        x%=d;
        y%=d;
        cnt[x][y]++;
    }
    ma=0;
    for(int i=0;i<d;i++){
        for(int j=0;j<d;j++){
            deg[i][j]=lower_bound(de.begin(),de.end(),cnt[i][j])-de.begin();
            ma=max(deg[i][j],ma);
        }
    }
    int l=-1,r=d-1;
    while(l+1<r){
        int mid=(l+r)/2;
        if(C(mid))r=mid;
        else l=mid;
    }
    printf("%d\n",d*(ma-1)+r);
    return 0;
}


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


int main(){
    int N,K; cin >> N >> K;
    int h[N]; rep(i,N) cin >> h[i];
    const ll INF = 1LL << 60;
    ll dp[100200]; rep(i,100200) dp[i] = INF;
    dp[0] = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 1; j <= K; j++)
        {
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
        
    }    
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(void)
{
	int   m, f, r, sum;


	for (; ; ) {
		scanf("%d %d %d", &m, &f, &r);
		if (m == -1 && f == -1 && r == -1) {
			break;
		}
		sum = m + f;
		
		if (m == -1 || f == -1) {
			printf("F\n");
		}
		else {

			if (sum >= 80) {
				printf("A\n");
			}
			if (sum >= 65 && sum < 80) {
				printf("B\n");
			}
			if (sum >= 50 && sum < 65) {
				printf("C\n");
			}
			if (sum >= 30 && sum < 50) {
				if (r >= 50) {
					printf("C\n");
				}
				else
				printf("D\n");
			}
			if (sum < 30) {
				printf("F\n");
			}
		}
	}	
	return 0;
}


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

int main(){
    int n;
	vector<int> List;
	int count = 0;
	
    cin >> n;
	
	for(int i = 0; i < n; i++){
		int Value;
		cin >> Value;
		List.push_back(Value);
	}
	
	for(int i = 0; i < n; i++){
		int Min = i;
		for(int j = i; j < n; j++){
			if(List[j] < List[Min]){
				Min = j;
			}
		}
		if(i != Min){
			swap(List[i], List[Min]);
			count++;
		}
	}
	
	for(int i = 0; i < n; i++){
		if(i > 0)	cout << " ";
		cout << List[i];
	}
	cout << endl;
	
	cout << count << endl;
}

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

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

	set<string> cnt;

	int n;
	cin >> n;
	string s;
	for (int i = 0; i < n; i++) {
		cin >> s;
		cnt.insert(s);
	}

	cout << cnt.size() << "\n";


	return 0;
}

Measured memory_bytes: 19236
n,k = map(int,input().split())
lis = list(map(int,input().split()))
if n == 1:
  print(lis[0])
  exit()
ans = []
for i in range(n-k+1):
  if lis[i+k-1] <=0 or 0 <= lis[i]:
    ans.append(max(abs(lis[i+k-1]),abs(lis[i])))
  else:
    ans.append(min(abs(lis[i+k-1]),abs(lis[i]))+abs(lis[i+k-1])+abs(lis[i]))
print(min(ans))

Measured memory_bytes: 14252
#include <cstdio>

int n, a[100001];
int cnt[100001];

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

	int ans=n, p=0;

	for(int i=1; i<=100000; i++){
		if(cnt[i]==0) continue;

        if(cnt[i]%2==1){
			ans-=(cnt[i]-1);
			cnt[i]=1;
        }
        else{
			ans-=(cnt[i]-2);
			cnt[i]=2;
			p++;
        }
	}
	if(p%2==0) ans-=p;
	else ans-=(p+1);

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

	return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
int main(){
  int n,f,m;
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    printf("Case %d:\n",i+1);
    scanf("%d",&f);
    for(j=0;j<10;j++){      
      m=f*f;
      m/=100;
      m%=10000;
      f=m;
      printf("%d\n",f);
    }
  }
  return 0;
}

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

using ll = long long;

int main() {
  ios::sync_with_stdio(false); 
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) 
    cin >> a[i];
  ll cur = 1000;
  for (int i = 1; i < n; i++) if (a[i] > a[i - 1]) {
    ll cnt = cur / a[i - 1];
    cur -= cnt * a[i - 1];
    cur += cnt * a[i];
  }
  cout << cur << '\n';
  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(void)
{
	int a, b, c, i;
	int num_of_devisor = 0;

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

	for (i = a; i <= b; i++)
	{
		if (c % i == 0)
		{
			num_of_devisor++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <limits>
 
using namespace std;
 
int N;
vector<long long> v;
vector<vector<vector<long long>>> dp;
long long LIM = std::numeric_limits<long long>::min();
 
long long deque(long long i, long long j)
{ 
  long long c = (N - (j-i)) % 2 == 0 ? 1 : -1;
  
  if (i+1 == j) return v[i] * c;
  
  int k = c < 0 ? 0 : 1;
  
  if (dp[i][j][k] != LIM)
  { 
    return dp[i][j][k];
  }
  
  long long a = v[i]*c + deque(i+1, j);
  long long b = v[j-1]*c + deque(i, j-1);
  
  dp[i][j][k] = c < 0 ? min(a, b) : max(a, b);
  return dp[i][j][k];
}
 
int main()
{ 
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
 
  std::cin >> N;
  v.resize(N);
  dp = vector<vector<vector<long long>>>(N+1, vector<vector<long long>>(N+1, vector<long long>(2, LIM)));
 
  for (int i = 0; i < N; ++i)
  { 
    long long val;
    cin >> val;
    v[i] = val;
  }
 
  std::cout << deque(0, N);
 
  return 0;
}

Measured memory_bytes: 493312
def gcd(_a, _b):
	if _a%_b==0:return _b
	else:return gcd(_b, _a%_b)

n=int(input())
a=sorted(map(int,input().split()))
INF=2*10**9
ans=INF
for i in range(len(a)-1):
	tmp=gcd(a[i],a[i+1])
	if tmp!=0 and tmp<ans:
		ans=tmp
print(ans)

Measured memory_bytes: 14252
#include<cstdio>
#include<iostream>

using namespace std;

int main(){
    int N, X;
    int M[100000], Msum = 0, Mmin;
    scanf("%d%d", &N, &X);
    for(int i = 0; i < N; i++){
        scanf("%d", &M[i]);
        Msum += M[i];
    }
    Mmin = M[0];
    for(int i = 0; i < N; i++) if(Mmin > M[i]) Mmin = M[i];
    X -= Msum;
    printf("%d", N+X/Mmin);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc166/abc166_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, K;
  cin >> N >> K;

  vector<int> c(N, 0);
  rep(i, K) {
    int d;
    cin >> d;
    rep(j, d) {
      int a;
      cin >> a;
      a--;
      c[a]++;
    }
  }

  ll ans = 0;
  rep(i, N) {
    if (c[i] == 0) ans++;
  }

  cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll d;
  cin>>d;
  vll c(26);
  vvll s(d,vll(26));
  REP(i,26)cin>>c[i];
  REP(i,d)REP(j,26)cin>>s[i][j];

  vll ans(d);
  REP(i,d)cout<<i%26+1<<endl;

}



Measured memory_bytes: 3720
# import numpy as np

from operator import or_

class segtree:

    def __init__(self, n,operator,identity):
        nb = bin(n)[2:]
        bc = sum([int(digit) for digit in nb])
        if bc == 1:
            self.num_leaves = 2**(len(nb)-1)
        else:
            self.num_leaves = 2**(len(nb))

        self.array = [identity for i in range(self.num_leaves * 2)]
        self.identity = identity
        self.operator =operator
        self.n = n

    def build(self,init_arr):
        for i in range(self.n):
            self.array[i+self.num_leaves] = init_arr[i]
        for i in range(self.num_leaves):
            pt = self.num_leaves-1-i
            self.array[pt] = self.operator(self.array[pt*2],self.array[pt*2+1])


    def update(self,x,val):
        actual_x = x+self.num_leaves
        # self.array[actual_x] = self.operator(self.array[actual_x],val)
        self.array[actual_x] = val
        while actual_x > 0 :
            actual_x = actual_x//2
            self.array[actual_x] = self.operator(self.array[actual_x*2],self.array[actual_x*2+1])

    def get(self,q_left,q_right,arr_ind=1,leaf_left=0,depth=0):
        width_of_floor = self.num_leaves//(2**depth)
        leaf_right = leaf_left+width_of_floor-1

        if leaf_left > q_right or leaf_right < q_left:
            return  self.identity

        elif leaf_left >= q_left and leaf_right <= q_right:
            return self.array[arr_ind]

        else:
            val_l = self.get(q_left,q_right,2*arr_ind,leaf_left,depth+1)
            val_r = self.get(q_left,q_right,2*arr_ind+1,leaf_left+width_of_floor//2,depth+1)
            return self.operator(val_l,val_r)

    def find(self, l, r):
        #findの方が高速
        l += self.num_leaves
        r += self.num_leaves+1
        ret = self.identity
        while l < r:
            if l & 1:
                ret = self.operator(ret, self.array[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.operator(ret, self.array[r])
            l //= 2
            r //= 2
        return ret







n = int(input())
s = input()
q = int(input())

tree = segtree(n, or_, 0)
buf = [0 for i in range(n)]

for i in range(n):
    c = ord(s[i]) - 97
    buf[i] = 1<<c


for i in range(26):
    tree.build(buf)




s = list(s)

for i in range(q):
    ty, i, c = input().split()

    if ty == "1":
        i = int(i)
        t = ord(c) - 97
        tree.update(i-1,1<<t)


    else:
        i = int(i)
        c = int(c)
        i -= 1
        c -= 1
        tp = 0
        hoge = tree.find(i,c)
        print(sum(map(int,bin(hoge)[2:])))


Measured memory_bytes: 116188
#include<bits/stdc++.h>
using namespace std;
int prime(int x) {
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (int i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}
int main() {
	int X, a, b;
	cin >> X >> a >> b;
	if (b - a <= 0)cout << "delicious" << endl;
	else if (b - a <= X)cout << "safe" << endl;
	else cout << "dangerous" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long k,a,b,i;
int main(){
	cin>>k>>a>>b;
	if(k<=a){
		cout<<1<<endl;
		exit(0);
	}
	if(a<=b){
		cout<<-1<<endl;
		return 0;
	}
	if((k-a)%(a-b)>=1)i=1;
    cout<<((k-a)/(a-b)+i)*2+1<<endl;
	return 0;
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            var C = int.Parse(Console.ReadLine());
            var X = int.Parse(Console.ReadLine());
            int ret = 0;
            for (int i = 0; i <= A; i++)
            {
                for (int j = 0; j <= B; j++)
                {
                    for (int k = 0; k <= C; k++)
                    {
                        if (500 * i + 100 * j + 50 * k == X)
                        {
                            ret++;
                        }
                    }
                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main()
{
    int a,b,c;
    int dp[10];
    memset(dp,0,sizeof(dp));
    cin>>a>>b>>c;
    dp[a]++;
    dp[b]++;
    dp[c]++;
    if(dp[5] == 2 && dp[7] == 1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			Map<Integer, Integer> map = new HashMap<Integer, Integer>();
			while (sc.hasNextLine()) {
				String[] s = sc.nextLine().split(",");
				map.put(Integer.parseInt(s[0]), Integer.parseInt(s[1]));
			}

			int totalPrice = 0;
			int totalQuantity = 0;
			for (int unitPrice : map.keySet()) {
				int quantity = map.get(unitPrice);
				totalPrice += unitPrice * quantity;
				totalQuantity += quantity;
			}

			int quantityAve = new BigDecimal(totalQuantity).divide(
					new BigDecimal(map.size()), RoundingMode.HALF_UP)
					.intValue();

			System.out.println(totalPrice);
			System.out.println(quantityAve);

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 26244
n = int(input())
nlist = list(map(int, input().split()))
W = [0for i in range(n)]
def M(l,r):      ##l~r-1 까지의 리스트.
    if (l+1 >= r):
        return 0
    elif (l+2 == r):
        if (nlist[l] <= nlist[l+1]):
            return 0
        else:
            nlist[l],nlist[l+1] = nlist[l+1],nlist[l]
            return 1
    ##위의 if문으로 (r-l)가 2이하일 경우는 해놓음
    m = (l+r)//2
    i = l
    j = m
    k = l
    cl = M(l,m)
    cr = M(m,r)
    c = 0
    while (i<m and j<r):
        if (nlist[i] <= nlist[j]):
            W[k] = nlist[i] ##l부터 r까지 W에 크기순으로 대입해나감
            k += 1
            i += 1
        else:
            W[k] = nlist[j]  ##일단 W[k]에는 더 작은쪽을 저장하는듯
            k += 1
            j += 1
            c += (m-i)  ##만약 nlist[i] > nlist[j]라면 i~m-1 까지 반전 하고있기 때문
                        ##그러고 더 작은 nlist[j]를 안에 넣는것.
    while (i<m):   ##i번째쪽에 더 큰것들이 남았을 경우 (j=r 이 되있는 상황이기에 더 반전수를 늘리지는 않음)
        W[k] = nlist[i]
        k += 1
        i += 1
    while (j<r):   ##j쪽에 큰게 남아있는경우도 동일
        W[k] = nlist[j]
        k += 1
        j += 1
    for i in range(l,r): 
        nlist[i] = W[i]
    return cl+cr+c
        
print(M(0,n))


Measured memory_bytes: 27480
s = input() #sys.stdin.readlineは最後が改行
n=len(s)

from collections import Counter
c = Counter(s)
cnt = 0

for k,v in c.items():
    if v>1:
        cnt+=v*(v-1)//2

ans = n*(n-1)//2 -cnt + 1

print(ans)


Measured memory_bytes: 3560
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int a[4];
    int b[2];
    
    for(int i=0;i<4;i++)
        cin >>a[i] ;
        
        sort(a,a+4);
    
    
    for(int i=0;i<2;i++)
        cin >>b[i] ;
        
        sort(b,b+2);
    
    
    cout<<a[1]+a[2]+a[3]+b[1]<<endl;
    
    
    
}



Measured memory_bytes: 3120
exec("def nWord(): nWord.cache = raw_input() if not hasattr(nWord, 'cache') or nWord.cache=='' else nWord.cache ; pos = nWord.cache.find(nWord.sep) ; ret, nWord.cache = (nWord.cache, '') if pos==-1 else (nWord.cache[:pos], nWord.cache[pos+1:].lstrip(nWord.sep)) ; return ret") ; exec("nWord.sep = ' '") ; exec("def ___nLine2(): ret, nWord.cache = (raw_input(), nWord.cache if hasattr(nWord, 'cache') else '') if not hasattr(nWord, 'cache') or nWord.cache=='' else (nWord.cache, '') ; return ret") ; exec('def nInt(): return int(nWord())') ; exec('def nFloat(): return float(nWord())') ; exec("def ___nAuto2():\n ret = nWord()\n try: return int(ret)\n except: pass\n try: return float(ret)\n except: return ret") ; exec("def nAuto(n=None): return ___nAuto2() if n is None else [___nAuto2() for i in range(n)]") ; exec("def nLine(n=None): return ___nLine2() if n is None else [___nLine2() for i in range(n)]")

import itertools

A, B, C, K = nAuto(4)

if K%2==0:
    print A-B
else:
    print B-A


Measured memory_bytes: 28652
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;
long long a[100004];
int n, res;
bool cp(const long long &u, const long long &v){
	return u<v;
}
bool kt(int j){
	int i;
	long long s = a[j];
	for (i = 1; i <= n; i++)
	if (i != j)
		if (a[i] <= s * 2) s = s + a[i];
		else break;
	return s * 2 >= a[n];
}
void pro(){
	int d = 1, c = n, g;
	while (d <= c){
		g = d + (d - c) / 2;
		if (kt(g) == true) {
			res = n - g + 1; c = g - 1;
		}
		else d = g + 1;
	}
}
void pro1(){
	int i;
	for (i = 1; i <= n; i++) a[i] += a[i - 1];
	for (i = n - 1; i > 0; i--)
	if (2 * a[i] < a[i + 1] - a[i]) {
		res = n - i;
		return;
	}
	res = n;
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	int i;
	for (i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1, cp);
	pro1();
	cout << res;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
Formatter frm=new Formatter();
int a=scan.nextInt();
int b=scan.nextInt();
int d=a/b;
int r=a%b;
frm.format("%.5f",(double)a/b);
System.out.println(d+" "+r+" "+frm);
}}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll dp[101][101010];
ll w[101], v[101];

int main() {
    ll N, W;
    cin >> N >> W;
    rep(i, N) cin >> w[i] >> v[i];

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

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


Measured memory_bytes: 79104
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
    Node *cur = nil->next; //??????????¬????????´????????????????
    while ( cur != nil && cur->key != key ) {
        cur = cur->next;
    }
    return cur;
}

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while( 1 ) {
        if( cur == nil ) break;
        if( isf++ > 0 ) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t) {
    if (t == nil) return; // t??????????????´?????????????????????
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    // ????´¢????????????????????????
    deleteNode(listSearch(key));
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    // ???????????´??????????´??????????
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main(int argc, char const* argv[])
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;

    scanf("%d", &n);
    init();
    for ( i = 0; i < n; i++) {
        scanf("%s%d", com, &key); // ?????????????????¢??°
        if(com[0] == 'i') {insert(key); np++; size++;}
        else if(com[0] == 'd') {
            if( strlen(com) > 6 ) {
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            }else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }
    printList();

    return 0;
}

Measured memory_bytes: 33992
until(s=gets.gsub(/\d+/){|k|?1*k.hex})[?#]
n=1+s.index(?/)
eval"s[n*c-n+e-1]=?1;s[n*g-n+i-1]=?bdfh".tr('c-i',gets)
$><<s.gsub(/1+/,&:size)
end

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

public class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer st;

    public static void main(String[] args) throws IOException {
        String S = br.readLine();
        String T = br.readLine();

        int res = T.length();
        for (int i = 0; i <= S.length() - T.length(); i++) {
            int count = 0;
            for (int j = 0; j < T.length(); j++) {
                if (S.charAt(i + j) != T.charAt(j)) count++;
            }
            res = Math.min(res, count);
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 32656
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  int32_t main()
  {        

      IOS

      string s,t;
      cin >> s >> t;

      int ans = 0 ;

      for(int i=0;i<3;i++)
      {
        if(s[i]==t[i])
        {
          ans++;
        }
      }

      cout << ans;


    return 0;
 
     }

Measured memory_bytes: 256
//Kaori Miyazono, did I reach you ?
//"I can't die because... I have to protect you." -Asuna Yuuki

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

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int a, b;
	cin >> a >> b;
	double x = (double) (a + b) / 2.0;
	int x1 = x, x2 = x + 1;
	if (abs(x - x1) < abs(x - x2)) {
		cout << x1;
	} else {
		cout << x2;
	}
	return 0;
}

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

int main(){
    string card,sub;
    int n,h;
    for(int i = 0;i<10;i++){
        cin >> card >> n;
        if(card=="-")break;
        for(int j = 0;j<n;j++){
            cin >> h;
            sub = card.substr(0,h);
            card =  card.erase(0,h);
            card = card + sub;
        }
        cout << card << endl;
    }
    return 0;
}


Measured memory_bytes: 3208