akhauriyash/Code-Regression huggingface dataset:
# from sys import stdin #入力の高速化(0.2秒ぐらい早くなる)
A, B, Q = list(map(int, input().split()))
# もし神社(寺)が1つしかなかった場合に両端に仮想の神社を建築して処理の一貫性を保つ。かりにこれが選ばれても最大のコストなので最終的に最適になることはない。
INF = 10 ** 18

# S = [-INF] + list(map(int, (stdin.readline() for _ in [0] * A))) + [INF]
# T = [-INF] + list(map(int, [stdin.readline() for _ in [0] * B])) + [INF]
S = [-INF] + [int(input()) for _ in range(A)]+[INF]
T = [-INF] + [int(input()) for _ in range(B)]+[INF]

from bisect import bisect_right
# from bisect import bisect_left as bisect_right #これでも通ったりする。
from itertools import product

for q in range(Q):  # 各問に答える
    x = int(input())  # 位置の指定
    s_idx, t_idx = bisect_right(S, x), bisect_right(T, x)
    ans = INF
    # 左右の神社と寺のの組み合わせ
    for s, t in product(S[s_idx - 1:s_idx + 1], T[t_idx - 1:t_idx + 1]):
        t_root = abs(t - x) + abs(s - t)  # 寺から最初に回るルート
        s_root = abs(s - x) + abs(s - t)
        ans = min(ans, t_root, s_root)
    # 最小をとって終わり
    print(ans)

'''
bisect_right

ソートされた順序を保ったまま x を a に挿入できる点を探し当てます。リストの中から検索する部分集合を指定するには、パラメータの lo と hi を使います。デフォルトでは、リスト全体が使われます。x がすでに a に含まれている場合、挿入点は既存のどのエントリーよりも後(右)になります。戻り値は、list.insert() の第一引数として使うのに適しています。a はすでにソートされているものとします。


In[3]: A
Out[3]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In[4]: bisect.bisect_right(A, 2.5)
Out[4]: 3

In[5]: bisect.bisect_right(A, 3)
Out[5]: 4
'''


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

int main() {
  int64_t N;
  cin>>N;
  int64_t sum=0;
  for(int64_t i=1;i*i<=N;i++){
    int64_t r=N/i;
    if(r-1>0&&N%(r-1)==N/(r-1)){sum+=r-1;}
    if(i-1>0&&N%(i-1)==N/(i-1)){sum+=i-1;}
  }
  cout<<sum<<endl;
  return 0;  
}

Measured memory_bytes: 3604
x,k,d = gets.chomp.split(" ").map(&:to_i)

# 正で統一
x = x.abs

num = [x / d, k].min
# まだxは正
x -= d * num
k -= num

# 原点をまたぐ操作を繰り返す
if k % 2 == 0
  # 往復
  puts x
else
  # 往復の往
  puts (x - d).abs
end


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

typedef long long ll;
int main() {
   ll N;
   cin >> N;
  vector<ll> a(N);
  for(ll i = 0;i<N;i++){
    cin >> a[i];
  }
    sort(a.begin(),a.end());
    ll min = a[0];
    ll max = a[N-1];
    ll ans = 100000000000000;
    
   for(ll k = min;k<=max;k++){
     ll cost = 0;
    for(ll i = 0;i<N;i++){
      cost += (k-a[i])*(k-a[i]);
    }
     if(cost <= ans){
     ans  = cost;
     }
   }
    cout << ans << endl;
      
}

Measured memory_bytes: 256
/*
csc -debug A.cs && mono --debug A.exe <<< "2 16"
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;

public class HelloWorld {
    public static void SolveCodeForces() {
        var A = cin.NextLong();
        var B = cin.NextLong();

        if (A % 2L != B % 2L) {
            System.Console.WriteLine("IMPOSSIBLE");
        }
        else {
            var K = (A + B) / 2L;
            System.Console.WriteLine(K);
        }
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // IncreaseStack(SolveCodeForces);
        // System.Console.Write(cout.ToString());
    }

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public static class Helpers {
    public static string Join<T>(this IEnumerable<T> arr, string sep = " ") {
        return string.Join(sep, arr);
    }

    public static void Swap<T>(ref T a, ref T b) {
        var tmp = a;
        a = b;
        b = tmp;
    }

    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int ask(int u, int v){
    cout << "? " << u + 1 << " " << v + 1 << endl;
    int ret;
    cin >> ret;
    return ret;
}

int main() {
    int n, s, t;
    cin >> n >> s >> t;
    s--;
    t--;
    int d = ask(s, t);
    vector<P> cands;
    REP(i,n){
        if (i == s || i == t) continue;
        int d1 = ask(i, s), d2 = ask(i, t);
        if (d1 + d2 == d){
            cands.push_back(P(d1, i));
        }
    }
    sort(ALL(cands));
    VI ans({s});
    int x = 0;
    for (P p : cands){
        if (x + ask(ans.back(), p.second) == p.first){
            ans.push_back(p.second);
            x = p.first;
        }
    }
    ans.push_back(t);
    cout << "!";
    for (int x : ans) cout << " " << x + 1;
    cout << endl;

    return 0;
}



Measured memory_bytes: 4652
#include <bits/stdc++.h>
using namespace std;
typedef long long   ll;
int main(){
    int a,b,d;
    cin >> a >>b >>d ;
    if(a==b && a!= d){
        cout << "Yes" ;
    }
    else if(a==d && a!=b){
        cout << "Yes";
    }
    else if(b==d && a!= b){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

Measured memory_bytes: 256
import sys
from collections import Counter

from functools import reduce

# sys.stdin = open('a1.in')


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


def read_int_list():
    return int(input())


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


def read_str():
    return input()


s = read_str()
n = len(s)
c = [set() for l in s]
for i in range(n, 0, -1):
    d = n - i
    for j in range(i):
        c[j].add(s[j + d])
    intersection = reduce(lambda x, y: x & y, c[:i])
    if intersection:
        print(d)
        break


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

int main() {
    int64_t n;
    cin >> n;
    int64_t ans = 2 * n;
    for (int64_t i = 1; i * i <= 2 * n; i++) {
        if (2 * n % i) continue;
        int64_t q = 2 * n / i;
        int64_t r0 = crt({0, -1}, {i, q}).first, r1 = crt({0, -1}, {q, i}).first;
        if (r0) ans = min<int64_t>(ans, r0);
        if (r1) ans = min<int64_t>(ans, r1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int n, k;
    cin >> n >> k;

    if(n % 2 == 1) n += 1;

    if(k <= n/2) cout << "YES" << endl;
    else cout << "NO"  << endl;

    return 0;
}

Measured memory_bytes: 256
/****************************************************************
# @Author:      iLovePKU_zbtxdy
# @DateTime:    2020-01-27 11:19:53
# @Description: You build it. You run it
# @More: Once lots of AC, try Brute-force,dynamic programming
****************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define close std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define eps 1e-8
typedef long long ll;
const int maxn = 1e6+10;
const int INF = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
ll mod = 1e9+7;
int a[maxn],b[maxn];
int zcj(char c){
    return c - '0';
}
int main()
{
    int ans = 100000;
    int n , k;
    cin >> n >> k;
    for(int i = 0; i < k; i++){
        cin >> a[i];
        b[a[i]] = 1;
    }
    for(int i = 100000; i >= n ; i--){
        string s = to_string(i);
        int len = s.length();
        int f = 0;
        for(int i = 0; i < len ; i++){
            if(b[zcj(s[i])]){
                f=1;break;
            }
        }
        if(!f){
            ans = i;
        }
    }
    cout << ans << endl;
}
/***************************************************************************
*stuff you should look for
*int overflow, array bounds
*special cases (n=1?), set tle
*do smth instead of nothing and stay organized
***************************************************************************/

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


int findmincost(vector <int> h, int k){
    int n=h.size();
    vector <int> cumulative(n);
    cumulative[0]=0;
    cumulative[1]=abs(h[1]-h[0]);
    for (int i=2; i<n; i++){
        if (i<k){
        int min=abs(h[i]-h[0]);
        for (int j=1; j<i; j++){
            if  ( cumulative[j]+abs((h[i]-h[j])) <min ) min=cumulative[j]+abs((h[i]-h[j]));
        }
        cumulative[i]= min;
    }
    else{

        int min=abs(h[i]-h[i-k])+cumulative[i-k];
        for (int j=i-k+1; j<i; j++){
            if  ( cumulative[j]+abs((h[i]-h[j])) <min ) min=cumulative[j]+abs((h[i]-h[j]));
        }
        cumulative[i]= min;
    }
    }
    return cumulative[n-1];
}
int main(){
    int n, k;
    cin>>n>>k;
    vector <int> h(n);
    for (int i=0; i<n; i++){
        cin>>h[i];  
    }
    
    cout<<findmincost(h, k);
}

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

int a,b,c,d,n,cnt,tmp;
string str;
int id[300],id2[300],ac[300],wa[300],used[1001];

void change(int x){
  tmp=id[x];id[x]=id[x+1];id[x+1]=tmp;
  tmp=id2[x];id2[x]=id2[x+1];id2[x+1]=tmp;
  tmp=ac[x];ac[x]=ac[x+1];ac[x+1]=tmp;
  tmp=wa[x];wa[x]=wa[x+1];wa[x+1]=tmp;
}
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>id[i]>>id2[i]>>ac[i]>>wa[i];
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(id[j]>id[j+1]){
	  change(j);
	}
      }
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(wa[j]>wa[j+1]){
	  change(j);
	}
      }
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(ac[j]<ac[j+1]){
	  change(j);
	}
      }
    }
    cnt=0;
    for(int i=0;i<1001;i++)used[i]=0;

    for(int i=0;i<n;i++){
      if(cnt<10){
	if(used[id2[i]]<3){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }else if(cnt<20){
	if(used[id2[i]]<2){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }else if(cnt<26){
	if(used[id2[i]]==0){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }
    }


  }
  
  return 0;
}

Measured memory_bytes: 1168
S = input()
S = S[::-1]
S += '0'

n = len(S)
dp = [[10**20 for j in range(2)] for i in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(2):
        x = ord(S[i])-ord('0')
        x += j
        for a in range(10):
            ni = i+1
            nj = 0
            b = a-x
            if b < 0:
                nj = 1
                b += 10
            dp[ni][nj] = min(dp[ni][nj], dp[i][j]+a+b)

print(dp[n][0])


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	string s;
	cin >> n >> s;
	int ans=0;
	for(int i=0; i+3<=n; i++){
		if(s.substr(i, 3)=="ABC") ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int n, ans = 20000;
	cin >> n;
	int p[5000], q[5000];

	for (int i = 0; i < n; i++) {
		cin >> p[i];
		q[i] = p[i];
	}//??\?????¨

	for (int j = 0; j < 4; j++) {
		int counti = 0;//???????????´??§????????????
		for (int i = 0; i < n; i++)
			p[i] = q[i];
		p[0] -= j;//????????????????????????????????????

		for (int i = 0; i < n - 1; i++) {
			if (p[i] <= 0)continue;
			counti += p[i] * 2;
			p[i + 1] -= p[i];
		}
		if (p[n - 1] < 0)
			p[n - 1] = 0;
		if (ans > counti + p[n - 1] + j)
			ans = counti + p[n - 1] + j;//a[n-1]?????????????\\??????????????£????????????????????°j??????????????????????????????????????????	
	}
	cout << ans << endl;
}

Measured memory_bytes: 3112
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
ll modPow(ll a, ll n, ll p) { //繰り返し二乗法 a**n % p
  if (!n) return 1;
  if (n == 1) return a % p;
  if (n & 1) return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}
ll choose(ll n, ll k, vector<ll> &fact, vector<ll> &inv){
  return fact[n] * (inv[k] * inv[n - k] % mod) % mod;
}
int main(){
  const int len = 2000002;
  vector<ll> fact(len), inv(len);
  fact[0] = fact[1] = 1;
  for(int i = 2; i < len; i++) fact[i] = fact[i - 1] * i % mod;
  inv[len - 1] = modPow(fact[len - 1], mod - 2, mod);
  for(int i = len - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  ll ans = 0;
  rep(x, k + 1){
    ll num = choose(k + n - x - 1, n - 1, fact, inv);
    (num *= modPow(26, x, mod)) %= mod;
    (num *= modPow(25, k - x, mod)) % mod;
    (ans += num) %= mod;
  }
  cout << ans << endl;
}

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

int main(){
    string s;
    cin>>s;
    char fir = s[0];
    for(int i=1;i<s.length();i++){
        if(s[i]!=fir){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <assert.h>   
#include <vector>
#include <algorithm>
#include <time.h>
#include <numeric>
#include <string>
#include <cstring>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <numeric>
#include <deque>
#include <iomanip>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <cstdio>
using namespace std;


//#define double long double
//#define int long long
//#define int unsigned long long

#define ll long long
#define ld long double 
#define pi pair<int, int> 
#define pl pair<ll,ll>  
#define pd pair<ld,ld> 
#define str string  
#define mp make_pair
#define vi vector<int> 
#define vl vector<ll> 
#define vd vector<ld> 
#define vs vector<str> 
#define vpi vector<pi> 
#define vpl vector<pl> 
#define vpd vector<pd> 
#define si set<int> 
#define FF(i,j,n) for(signed i=j;i<=n;i++)  
#define DD(i,j,n) for(signed i=j;i>=n;i--) 
#define F(i,j,n) for(signed i=j;i<n;i++)   
#define D(i,j,n) for(signed i=j;i>n;i--) 
#define mem(a,b) memset(a,b,sizeof(a))
#define ndl cout << endl
#define ull unsigned long long 

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;


#define sz(x) (signed)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() 
#define rsz resize
#define ins insert 
#define ft front() 
#define bk back() 
#define fi first
#define se second
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define lb lower_bound 
#define ub upper_bound 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

//math


const int mod = 1e9 + 7;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int pct(int x) { return __builtin_popcount(x); } 
int bit(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) 
int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0 


//DEBUG, compile with -DLOCAL
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
  cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
  DBG(t...); }
#ifdef LOCAL 
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#define HERE cout << "===GOTHERE===" << endl
#else
#define dbg(...) 42
#define HERE 42
#endif


 /* ============== END OF HEADER ============== */





const int maxn = 1e5*3+20;

int n,_,q,k;

void solve(){
	str s,t,u;
	int a,b;
	cin >> s >> t >> a >> b >> u;
	if(u==t){
		b--;
	}else{
		a--;
	}
	cout << a << " " << b << endl;
}

signed main(){
  //clock_t t1 = clock();  
	IOS
	solve();
  
  //cout << "THE ALGORITHM TOOK: " << (clock() - t1) * 1.0 / CLOCKS_PER_SEC * 1000 << "ms"<< endl;
	return 0;
}

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

#define ll long long

int main()
{
    double A, B;
    std::cin >> A >> B;

    for(int i=0; i < 1100; i++) {
        int check_A = i * 8 / 100;
        int check_B = i * 10 / 100;
        if(check_A == A and  check_B == B) {
            std::cout << i << std::endl;
            return 0;
        }
    }
    std::cout << "-1" << std::endl;
}

Measured memory_bytes: 3696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		String S = scanner.next();
		scanner.close();

		char[] c = S.toCharArray();

		int[] sumBlack = new int[N+1];
		int[] sumWhite = new int[N+1];

		for (int i = 0; i < N; i++) {
			sumBlack[i+1] = sumBlack[i] + (c[i] == '#' ? 1: 0);
			sumWhite[i+1] = sumWhite[i] + (c[i] == '.' ? 1: 0);
		}

		// this code is learned by : https://atcoder.jp/contests/tenka1-2019-beginner/submissions/5069772
		// take max value of Integer 
		/*
		 * We add value to sumBlack and sumWhite, so all sumValue of each color is the time when "N".
		 * And shoule think Last time because the most right point is N.
		 */
		int min = Integer.MAX_VALUE;
		for (int j = 0; j <= N; j++) {
			// add value to sumBlack and sumWhite, so all sumValue of each color is the time when "N".
			min = Math.min(min, (sumBlack[j] + (sumWhite[N] - sumWhite[j])));
		}

		System.out.println(min);

	}

}


Measured memory_bytes: 28612
package main

import "fmt"

func main() {
	var N, A int
	fmt.Scan(&N)

	board := make([][]int, 0, 2)
	for i := 0; i < 2; i++ {
		row := make([]int, N)
		board = append(board, row)
	}

	for i := 0; i < 2; i ++ {
		for j := 0; j < N; j++ {
			fmt.Scan(&A)
			board[i][j] = A
		}
	}

	max := 0
	for downColumn := 0; downColumn < N; downColumn++ {
		row := 0
		candies := 0
		for column := 0; column < N; column++ {
			candies += board[row][column]
			if column == downColumn {
				row++
				candies += board[row][column]
			}
		}
		if candies > max {
			max = candies
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


N, M = map(int, input().split())
lamps = [list(map(lambda x:int(x)-1, input().split()))[1:]
         for _ in range(M)]
# 1番目だけを除いて繋がっているスイッチを表している,-1しているのはリストと合わせるため


p = list(map(int, input().split()))
ans = 0


# bit全探索
for i in range(2**N):
    for r in range(M):  # ランプがすべてついているかのチェック
        on_sum = 0  # 何個スイッチがonになっているか
        for j in range(N):  # スイッチのｊ番目について、
            if i >> j & 1 and j in lamps[r]:
                on_sum += 1 # スイッチjがランプrに繋がってて、onならon_sum+=1
        if on_sum % 2 != p[r]:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3064
def set(a, b):
  R[a].append(b)
  R[b].append(a)

N = int(input())
xy = [[i] + list(map(int, input().split())) for i in range(N)]
R = [[] for _ in range(N)]
xy.sort(key = lambda x: x[1])
for i in range(1, N):
  a = xy[i]
  b = xy[i - 1]
  set(a[0], b[0])
xy.sort(key = lambda x: x[2])
for i in range(1, N):
  a = xy[i]
  b = xy[i - 1]
  set(a[0], b[0])

xy.sort()
import heapq
q = [[0, 0]]
L = [True] * N
pop = heapq.heappop
push = heapq.heappush
ans = 0

for _ in range(N):
  k, t = pop(q)
  while not L[t]:
    k, t = pop(q)
  L[t] = False
  ans += k
  for i in R[t]:
    if L[i]:
      x = abs(xy[t][1] - xy[i][1])
      x = min(x, abs(xy[t][2] - xy[i][2]))
      push(q, [x, i])
print(ans)


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code
ll sum[N];
int main()
{
	int n,q;
	cin>>n>>q;
	string s;
	cin>>s;
	rep(i, 1, n)
	{

		if(s[i-1] == 'A' && s[i] == 'C')
		{
			sum[i] = sum[i-1] + 1;
		}
		else
		{
			sum[i] = sum[i-1];
		}
	}
	sum[n] = sum[n-1];
	while(q--)
	{
		ll x, y;
		cin>>x>>y;
		ll ans = sum[y] - sum[x-1];
		if(s[y-1] == 'A' && s[y] == 'C') ans--;
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int read()
{
	char ch=getchar();int f=0,x=1;
	while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
	return f*x;
}
int c[305][305],f[305][305],g[305][305],mod,n,k;

int main()
{
	n=read();k=read();mod=read();
	for(int i=0;i<=n;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=i;j++)
		{
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
		}
	}
	for(int i=0;i<=k;i++)
	f[1][i]=1,g[1][i]=k-i+1;
	for(int i=2;i<=n+1;i++)
	{
		for(int j=k;j>=0;j--)
		{
			for(int l=1;l<i;l++)
			{
				f[i][j]+=1LL*f[i-l][j]*g[l][j+1]%mod*c[i-2][l-1]%mod;
				f[i][j]%=mod;
			}
			g[i][j]=(g[i][j+1]+f[i][j])%mod;
		}
	}
	cout<<f[n+1][0];
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;

int main() {
    
	int a, b, c;
	cin >> a >> b >> c;
	if (c % __gcd(a, b)) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	
    
}


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

bool dfs(string S) {
	if (S == "ABC") return true;

	for (int i = 0; i < 3; i++) {
		string T = ""; bool OK = false;
		for (int j = 0; j < (int)S.size(); j++) {
			if ((j + 2 < (int)S.size()) && S.substr(j, 3) == "ABC") {
				T += ('A' + i); j += 2;
			}
			else {
				T += S[j]; if (S[j] == ('A' + i)) OK = true;
			}
		}
		if (OK == true) continue;
		if (S.size() == T.size()) break;
		bool ret = dfs(T);
		if (ret == true) return true;
	}
	return false;
}

string S;

int main() {
	cin >> S;
	bool ans = dfs(S);
	if (ans == true) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 21896
l=[]
for i in range(3):
    l.append(list(map(int,input().split())))
d=list(zip(*l))
s=[]
f=0
n=int(input())
for i in range(n):
    s.append(int(input()))
for i in range(3):
    c=0
    for j in range(3):
        if(l[i][j] in s):
            c+=1
    if(c==3):
        f=1
        break
if(l[1][1] in s and l[0][0] in s and l[2][2] in s):
    f=1
if(l[0][2] in s and l[1][1] in s and l[2][0] in s):
    f=1
for i in range(3):
    c=0
    for j in range(3):
        if(d[i][j] in s):
            c+=1
    if(c==3):
        f=1
        break
if(f==1):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 62032
# -*- coding: utf-8 -*-

import sys
import os

N = int(input())
A = []
is_all_ten = True
for i in range(N):
    a = int(input())
    if a % 10 != 0:
        is_all_ten = False
    A.append(a)
A.sort()

if is_all_ten:
    print(0)
elif sum(A) % 10 != 0:
    print(sum(A))
else:
    not_ten_list = [x for x in A if x % 10 != 0]
    print(sum(A) - not_ten_list[0])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define forsn(i,x,y) for(long long i = (x) ; i <= (y) ; ++i)
typedef long long ll;
typedef long double ld;

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

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

int main() {
	string s;
	int b,c;
	stack<int> a;
	while(cin>>s){
		if(s=="+" ){
			b=a.top();
			a.pop();
			c=a.top();
			a.pop();
			a.push(b+c);
			
		}
		else if(s=="-" ){
			b=a.top();
			a.pop();
			c=a.top();
			a.pop();
			a.push(c-b);
			
		}
	    else if(s=="*" ){
			b=a.top();
			a.pop();
			c=a.top();
			a.pop();
			a.push(c*b);
			
		}
		else{
			a.push(stoi(s));
			
			
		}
	
		
	}
	cout<<a.top()<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3176
#if loc||local
#define _GLIBCXX_DEBUG
#endif

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  ll ans = 0;
  ll mx = -1;
  rep(i,n){
    int ai;
    cin>>ai;
    if(mx==-1)mx=ai;
    else if(mx>ai){
      ans += mx-ai;
    }
    else if(mx<ai)mx=ai;
  }
  cout<<(ans)<<endl;

}


Measured memory_bytes: 3632
index = int(input())
liststr = '1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51'
list = liststr.split(',')
print(int(list[index-1]))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define N 55
using namespace std;
int a[2*N],k,n,m,x,y,o,sum,ans;
vector<int>b;
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<=min(n,k);i++){
		for(int j=0;j<=min(n,k);j++){
			if(i+j>n||i+j>k)break;
			b.clear();
			for(int l=0;l<i;l++)b.push_back(a[l]);
			for(int l=0;l<j;l++)b.push_back(a[n-1-l]);
			sort(b.rbegin(),b.rend());
			sum=0;
			for(int l=0;l<i+j;l++)sum+=b[l];
			ans=max(ans,sum);
			x=k-i-j;y=i+j-1;
			while(x>0&&b.size()>0&&b[y]<0){
				sum-=b[y];
				y--;
				x--;
			}
			ans=max(ans,sum);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3520
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()

    ans_list = [1] * n

    for i in range(2,n+1):
        for j in range(i,n+1,i):
            ans_list[j-1] += 1

    count = 0
    for i, ans in enumerate(ans_list):
        count += (i+1) * ans

    print(count)
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 156636
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;


int main(){

    string S;
    cin >> S;

    if(S=="AAA"||S=="BBB"){
        cout << "No";
    }else{
        cout << "Yes";
    }

    return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const char mp[] = "RYGB";
int n, m, d;

int main() {
  scanf("%d %d %d", &n, &m, &d);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x = (i + j + 505) / d;
      int y = (i - j + 505) / d;
      putchar(mp[(x & 1) << 1 | (y & 1)]);
    }
    putchar(10);
  }
  return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  int sum = 0;
  int count = 0;

  vector<int> A(N);
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  
  for(int i = 0; i < N; i++) {
    if(A.at(i)*4*M >= sum) count++;
  }  
  
  if(count >= M) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


signed main(){
  string s;cin>>s;int sum = 0;
  rep(i,s.size()){
    if(s[i] == 'o')sum++;
  }
  if(sum+15-s.size() >= 8)cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, sum;
  cin >> N;
  sum = 0;
  for(int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    sum += r - l + 1;
    
  
  }
  cout << sum << endl;


}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void){
  char s[27] = { '\0' };
  scanf("%s", s);
  int i = 0;
  while(s[i] != '\0') i++;
  char temp;
  int j, k;
  for(j = 0; j < i; j++){
    for(k = j + 1; k < i; k++){
      if(s[j] < s[k]){
	temp = s[j];
	s[j] = s[k];
	s[k] = temp;
      }
    }
  }
  int flag = 1;
  for(j = 0; j < i - 1; j++){
    if(s[j] == s[j + 1]){
      flag = 0;
      break;
    }
  }
  if(flag) printf("yes\n");
  else printf("no\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	double ans = 0;
	int n; cin >> n;
	rep(i, 0, n - 1)
	{
		double a; cin >> a;
		ans += 1 / a;
	}
	printf("%.6f", 1 / ans);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/math/common_factor_rt.hpp>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define SENTINEL 2000000000
typedef long long ll;

using namespace std;
// namespace mp = boost::multiprecision;
// namespace mt = boost::math
// using Bint = mp::cpp_int;

int main() {
    ll s;
    cin >> s;
    ll x[3], y[3];
    x[0] = 0;
    y[0] = 0;
    for (x[1] = 1000000000;; x[1] /= 10) {
        y[2] = s / x[1];
        if (y[2] > 0)
            break;
    }
    if (x[1] * y[2] < s)
        y[2]++;
    x[2] = 1;
    y[1] = ((x[1] * y[2]) - s);
    rep(i, 3) {
        cout << x[i] << " ";
        if (i != 2)
            cout << y[i] << " ";
        else
            cout << y[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
// const int MOD = 1000000007;
const int MOD = 998244353;

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

   int n, s;
   cin >> n >> s;
   vector<ll> dp(s + 1);
   ll ans = 0;
   rep(i, 0, n) {
      int a;
      cin >> a;
      dp[0] += 1;
      vector<ll> dp2(s + 1);
      rep(j, 0, s + 1) {
         (dp2[j] += dp[j]) %= MOD;
         if (j + a <= s) (dp2[j + a] += dp[j]) %= MOD;
      }
      dp = dp2;
      (ans += dp[s]) %= MOD;
   }

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 

ll chmin(ll &a, ll b){ return a = min(a, b);}

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> a(M), b(M);
	vector<int> c(M, 0);// c[i]: i行目のcの2進表記
	for(int i=0; i<M; i++){
		cin >> a[i] >> b[i];
		for(int j=0; j<b[i]; j++){
			int c_tmp; 
			cin >> c_tmp; 
			c_tmp--;
			c[i] += (1<<c_tmp);
		}
	}

	const int INF = 1001001001;
	//dp[s]: 状態sになるために必要な最小コスト
	vector<ll> dp(1<<N, INF);
	dp[0] = 0;// どれも開けない場合は0円ですむ
	for(int i=0; i<M; i++){
		for(int j=0; j<(1<<N); j++){
			int s = j | c[i];
			chmin(dp[s], dp[j]+a[i]);
		}
	}

	int ans = dp.back();
	if(ans == INF) ans = -1;
	cout << ans << endl;

}


Measured memory_bytes: 3588
object Main {
  def main(args: Array[String]): Unit = {
    val factors           = io.StdIn.readLine.split(" ").map{_.toInt}
    val special_skills    = io.StdIn.readLine.split(" ").map{_.toInt}
    var all_skill_damages = 0

    special_skills.foreach{ i =>
      all_skill_damages += i
    }

    if( factors( 0 ) <= all_skill_damages ) println( "Yes" )
    else                                    println( "No" )
  }
}

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

int main()
{
	long long k;
	cin>>k;
	cout<<50<<endl;
	long long count=k/50,t=k%50;
	long long ans[50];
	for(int i=0;i<t;i++)
		ans[i]=count+100-t;
	for(int i=t;i<50;i++)
		ans[i]=count+49-t;
	for(int i=0;i<50;i++)
		cout<<ans[i]<<" ";
	cout<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        char []S;
        int count=0;
        S=input.next().toCharArray();
        for(int i=0;i<3;i++)
        {
            for(int j=i+1;j<4;j++)
            {
                if(S[i]==S[j])
                {
                    count++;
                }
            }
        }
        if(count==2)
        {
            System.out.println("Yes");
        }
        else
            System.out.println("No");
    }
}


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

int d, n, day[222], cloth[222][4], dp[222][222], res;

int main(){
  cin >> d >> n;
  for(int i = 0;i < d;i++){
    cin >> day[i];
  }
  for(int i = 0;i < n;i++){
    cin >> cloth[i][0] >> cloth[i][1] >> cloth[i][3];
  }
  for(int i = 0;i < d;i++){
    for(int j = 0;j < n;j++){
      if(i == 0){
	if(cloth[j][0] <= day[i] && day[i] <= cloth[j][1]){
	  dp[i][j] = 0;
	}
	else{
	  dp[i][j] = -1;
	}
	continue;
      }
      if(!(cloth[j][0] <= day[i]  && day[i] <= cloth[j][1])){
	dp[i][j] = -1;
	continue;
      }
      for(int k = 0;k < n;k++){
	if(dp[i - 1][k] == -1)continue;
	dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(cloth[j][3] - cloth[k][3]));
      }
    }
  }
  for(int i = 0;i < n;i++){
    res = max(res, dp[d - 1][i]);
  }
  cout << res << endl;
}

Measured memory_bytes: 1340
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int a,b;
  while(1){
    cin>>a>>b;
    if(a==0 & b==0)break;
    int sum=b-a;
    int n100=0,n500=0,n1000=0;
    while(sum>=1000){
      n1000++;
      sum-=1000;
    }
    if(sum>=500)n500++,sum-=500;
    n100=sum/100;
    cout<<n100<<" "<<n500<<" "<<n1000<<endl;
  }
}

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

vector<int> seen;

void dfs(vector<vector<int>> &A, int v, int k){
    if(seen.at(v) != 0) return;
    seen.at(v) = k;
    for(auto nv: A.at(v)){
        dfs(A, nv, k);
    }
}

int main(){
    int n, m, k; cin >> n >> m >> k;
    seen.resize(n);
    map<int, int> mp;
    vector<vector<int>> F(n), B(n);
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        F.at(a).push_back(b);
        F.at(b).push_back(a);
    }
    for(int i = 0; i < k; i++){
        int c, d; cin >> c >> d;
        c--; d--;
        B.at(c).push_back(d);
        B.at(d).push_back(c);
    }
    int idx = 1;
    for(int i = 0; i < n; i++){
        dfs(F, i, idx);
        idx++;
    }
    for(int i = 0; i < n; i++){
        mp[seen.at(i)]++;
    }
    for(int i = 0; i < n; i++){
        int ans = mp[seen.at(i)];
        for(int j = 0; j < F.at(i).size(); j++){
            if(seen.at(i) == seen.at(F.at(i).at(j))) ans--; //すでにとも
        }
        for(int k = 0; k < B.at(i).size(); k++){
            if(seen.at(i) == seen.at(B.at(i).at(k))) ans--; //お前は無理
        }
        ans--; //自分は自分
        cout << ans << " ";
    }
}

Measured memory_bytes: 13440
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};

fn sort(v: Vec<i32>) -> Vec<i32> {
    let l = v.len();
    if l == 1 {
        return v;
    }

    let m = if l % 2 == 0 { l / 2 } else { (l + 1) / 2 };
    let vl = sort(Vec::from(&v[..m]));
    let vr = sort(Vec::from(&v[m..]));

    let mut vm: Vec<i32> = vec![];
    let mut il = 0;
    let mut ir = 0;
    for _ in 0..l {
        if il >= vl.len() {
            vm.push(vr[ir]);
            ir += 1;
        } else if ir >= vr.len() {
            vm.push(vl[il]);
            il += 1;
        } else if vl[il] >= vr[ir] {
            vm.push(vl[il]);
            il += 1;
        } else {
            vm.push(vr[ir]);
            ir += 1;
        }
    }
    return vm;
}

pub fn solve<R: Read, W: Write>(input: R, output: W) {
    let mut reader = BufReader::new(input);
    let mut writer = BufWriter::new(output);

    let mut buf = String::new();
    reader.read_to_string(&mut buf).unwrap();
    let mut lines = buf.split_terminator("\n");
    let n = lines.next().unwrap().trim().parse::<usize>().unwrap();
    let a = lines
        .next()
        .unwrap()
        .split_whitespace()
        .map(|s| s.parse::<i32>().unwrap())
        .collect::<Vec<i32>>();

    let a_sorted = sort(a);
    let mut sa = vec![];
    let mut sb = vec![];
    for i in 0..n {
        if i % 2 == 0 {
            sa.push(a_sorted[i]);
        } else {
            sb.push(a_sorted[i]);
        }
    }

    let ret = sa.iter().fold(0, |acc, x| acc + x) - sb.iter().fold(0, |acc, x| acc + x);
    writer.write(ret.to_string().as_bytes()).unwrap();
    writer.write(b"\n").unwrap();
}

fn main() {
    solve(stdin(), stdout());
}


Measured memory_bytes: 4352
import sys
input = sys.stdin.readline
from heapq import heappop, heappush

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    H = []
    for i in A:
        heappush(H, -i)
    for _ in range(M):
        j = heappop(H)
        j = - ( -j // 2)
        heappush(H, j)
    ans = - sum(H)
    print(ans)

if __name__ == '__main__': main()

Measured memory_bytes: 14168
#include <stdio.h>

#define N 250

int parent(int);
int left(int);
int right(int);

main(){

  int a,p,l,r,i,A[N];

  scanf("%d",&a);
  for(i = 1; i <= a; i++){
    scanf("%d",&A[i]);
  }


  for(i = 1; i <= a; i++){
    p = parent(i);
    l = left(i);
    r = right(i);
    printf("node %d: key = %d, ",i,A[i]);

    if(i  != 1){
 printf("parent key = %d, ",A[p]);
 if(l > a  && r > a) printf("\n");
    }
    if(l <= a){
      printf("left key = %d, ",A[l]);
      if(r > a) printf("\n");
    }
    if(r <= a) printf("right key = %d, \n",A[r]);
  }
 

  return 0;
}

int parent(int i){
  return i / 2;
}



int left(int i){
  return 2 * i;
}


int right(int i){
  return 2 * i +1;
}
             

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------
signed main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += read() - i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <cinttypes>
#include <cinttypes>

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;

i32 n, m;
i64 memo[1000][1000];
std::tuple<i64, i64, i64> C[1000], in[1000];
constexpr i64 INF_L = -100100100100100100ll;

i64 dp(i32 i, i32 j) {
  if (j == m) return 0;
  if (i == n) return INF_L + 1;
  if (memo[i][j] != INF_L) return memo[i][j];
  i64 x, y, z;
  std::tie(x, y, z) = C[i];

  return memo[i][j] = std::max(dp(i + 1, j + 1) + x + y + z, dp(i + 1, j));
}

int main() {
  std::cin >> n >> m;
  for (i32 i = 0; i < n; ++i) {
    i64 x, y, z;
    std::cin >> x >> y >> z;
    in[i] = std::make_tuple(x, y, z);
  }

  i64 res = INF_L;
  for (i32 s = 0; s < (1 << 3); ++s) {
    std::fill_n(memo[0], 1000 * 1000, INF_L);
    for (i32 i = 0; i < n; ++i) {
      i64 x, y, z;
      std::tie(x, y, z) = in[i];
      x *= s & 1 ? -1 : 1;
      y *= (s >> 1) & 1 ? -1 : 1;
      z *= (s >> 2) & 1 ? -1 : 1;
      C[i] = std::make_tuple(x, y, z);
    }
    res = std::max(res, dp(0, 0));
  }
  std::cout << res << std::endl;
}


Measured memory_bytes: 8192