akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;
bool isok=false;
string s;
vector<string> v{ "dream", "dreamer", "erase", "eraser"};

int main() {
  cin >> s;
  bool isfound= true;
  while(isfound && s.size()>0){
    bool tmp = false;
    for (int i=0;i<4;++i){
      auto pos = s.rfind(v[i]);
      if(pos == s.size()-v[i].size()){
        tmp = true;
        s= s.substr(0,s.size()-v[i].size());
      }
    }
    isfound = tmp;
  }
  if(isfound) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 512
D,G = list(map(int,input().split()))
pc = [list(map(int,input().split())) for i in range(D)]

ans = sum([p for p,c in pc])
for i in range(2**D-1):
    score = 0
    unused_max = D-1
    sum_p = 0
    for j in range(D-1,-1,-1):
        if (i>>j)%2:
            score += pc[j][1] + pc[j][0]*(j+1)*100
            sum_p += pc[j][0]
            if unused_max == j:
                unused_max -= 1
    if G - score <= (pc[unused_max][0]-1)*(unused_max+1)*100:
        ans = min(ans,sum_p+max(0,(G-score-1)//(100*(unused_max+1))+1))
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,K;
  cin>>n>>K;
  int x,ans;
  ans=0;
  for (int i=0;i<n;i++){
    cin>>x;
    ans+=min(2*x,2*(K-x));
  }
  cout<<ans<<endl;
}
      


Measured memory_bytes: 256
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <ios>
#include <iomanip>

using namespace std;

int main(){
    int N,ans=0;
    cin >> N;

    vector<int> s(N);
    REP(i,N){
        cin >> s[i];
        ans += s[i];
    }

    SORT(s);

    if(ans%10!=0){
        cout << ans << endl;
    }else{
        REP(i,N){
            if(s[i]%10!=0){
                ans-=s[i];
                break;
            }
        }
        if(ans%10==0){
            cout << "0" << endl;
        }else{
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 512
S = input()
MOD = 2019
cnt = [0]*MOD
cur = 0 # 現在考えている部分文字列
cnt[cur] = 1 # 部分文字列'0'も作れたと考える
d = 1 # 位を表す
for s in S[::-1]: # 右から作る
    cur += int(s)*d # 新たな桁を追加
    cur %= MOD
    cnt[cur] += 1
    # 後処理
    d *= 10 # 位を上げる
    d %= MOD # ただし数が巨大になるため、計算量を減らすために剰余をとる
ans = 0
for c in cnt:
    ans += c*(c-1)//2
print (ans)

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  vector<size_t> idx(N);
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(), [&A](size_t i1, size_t i2){
    return A[i1]<A[i2];
  });
  
  for(auto v : idx){
    cout << v+1 << " ";
  }
  
  return 0;
}

Measured memory_bytes: 2048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String inputed[] = new String[2];
		String command[] = new String[3];

		StringBuilder ans = new StringBuilder();

		try {
			inputed = br.readLine().split("\\s+");
			int N = Integer.parseInt(inputed[0]);
			int Q = Integer.parseInt(inputed[1]);

			UnionFind unionTree = new UnionFind(N);
			unionTree.init();

			for(int loop = 0; loop < Q; loop++){
				command = br.readLine().split("\\s+");
				if(command[0].equals("0")){ //unite
					unionTree.unite(Integer.parseInt(command[1]),Integer.parseInt(command[2]));
				}else{
					if(unionTree.is_same(Integer.parseInt(command[1]), Integer.parseInt(command[2]))){
						ans.append("1\n");
					}else{
						ans.append("0\n");
					}
				}
			}

			System.out.print(ans.toString());

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

class UnionFind{
	private int boss[];
	private int height[];
	private int size;

	UnionFind(int size){
		boss = new int[size];
		height = new int[size];
		this.size = size;
	}

	public void init(){
		for(int i = 0; i < size; i++){
			boss[i] = i;
			height[i] = 0;
		}
	}

	public int get_boss(int id){
		if(boss[id] == id)return id; //自分が代表なら、自分の値を返す
		else{
			return boss[id] = get_boss(boss[id]); //代表でないなら、自分が所属する組織の代表を返しつつ、経路圧縮
		}
	}

	public boolean is_same(int x,int y){
		return get_boss(x) == get_boss(y);
	}

	void unite(int x,int y){
		int boss_x = get_boss(x);
		int boss_y = get_boss(y);

		//既に同じグループなら何もしない
		if(boss_x == boss_y)return;

		//高さが高い方に吸収する
		if(height[x] > height[y]){

			boss[boss_y] = boss_x;

		}else if(height[x] < height[y]){

			boss[boss_x] = boss_y;

		}else{ //height[x] == height[y]

			boss[boss_y] = boss_x;
			height[x]++;
		}
	}
}




Measured memory_bytes: 70728
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    string str;
    cin >> str;
    int num = 0;
    while(1){
        string s;
        cin >> s;
        if (s == "END_OF_TEXT") break;
            for(int i=0;i<s.size();i++) {
      if('A'<=s[i]&&s[i]<='Z') s[i]+='a'-'A';
    }   
        if (str == s){
            num++;
        }
    }
    cout << num << endl;
}


Measured memory_bytes: 3164
H, W = map(int, input().split())
costs = [list(map(int, input().split())) for _ in range(10)]

nums = [0 for _ in range(10)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j])

ans = 0
for i in range(H):
    for num in list(map(int, input().split())):
        if num == -1:
            continue
        else:
            ans += costs[num][1]

print(ans)


Measured memory_bytes: 73800
#include <stdio.h>
int main()
{
    int n,c[4][13]={0};
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int rank;
        char design;
        scanf("%*c%c%*c%d",&design,&rank);
        switch(design){
            case 'S':
                c[0][rank-1]=1;
                break;
            case 'H':
                c[1][rank-1]=1;
                break;
            case 'C':
                c[2][rank-1]=1;
                break;
            case 'D':
                c[3][rank-1]=1;
                break;
        }
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            if(c[i][j]==0){
                switch(i){
                    case 0:
                        printf("S %d\n",j+1);
                        break;
                    case 1:
                        printf("H %d\n",j+1);
                        break;
                    case 2:
                        printf("C %d\n",j+1);
                        break;
                    case 3:
                        printf("D %d\n",j+1);
                        break;
                }
            }
        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
    }
    return 0;
}

Measured memory_bytes: 1024
###
### atcorder test program
###

### math class
class math:
    ### pi
    pi = 3.14159265358979323846264338

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

math = math()

### input sample
#i = input()
#A, B, C = [x for x in i.split()]
#R = float(input())
#A = [int(x) for x in input().split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))

N = int(input())
mat = [int(w) for w in input().split()]

print(min(mat), max(mat), sum(mat))



Measured memory_bytes: 6624
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)

#define DumpArray(cont,from,to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

using namespace std;
typedef long long ll;
typedef long double ld;
struct O{
    int v[26];
    O() {
        for(int i=0;i<26;++i)v[i]=0;
    }
    bool operator<(const O& o) const{
        for(int i=0;i<26;++i) {
            if (v[i]<o.v[i])return true;
            if (v[i]>o.v[i])return false;
        }
        return false;
    }
    bool operator==(const O& o)const{
        return ! (*this<o) && !(o<*this);
    }
};
int main() {
    int N;
    vector<O> os;
    cin >> N;
    for (int i=0;i<N;++i) {
        string s;
        cin >> s;
        O o;
        for (int j=0;j<10;++j)
            o.v[s[j]-'a']+=1;
        os.pb(o);
    }
    sort(os.begin(),os.end());
    int i=0;
    ll ans=0;
    while(i<os.size()) {
        int j=i+1;
        while(j<os.size()&&os[i]==os[j])j++;
        ans+=((ll)j-i)*((ll)j-i-1)/2;
        i=j;
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

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

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

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

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

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin>>n>>m;
    vi s(m);
    vector<char> c(m);
    REP(i,m) {
        cin>>s[i]>>c[i];
        s[i]--;
    }

    int i=0;
    int ans = -1;
    while(i<1000){
        string is = to_string(i);

        bool flg=true;
        REP(j,m){
            if(is.size() < s[j]+1){
                flg=false;
                break;
            }

            if(is[s[j]] != c[j]){
                flg=false;
                break;
            }
        }
        if(flg && is.size()==n){
            ans=i;
            break;
        }
        i++;
    }
    cout << ans << endl;
    return 0;
}

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


int main(){
int a,b,c;
int i;
int z=0;
scanf("%d%d%d",&a,&b,&c);
if(a<b&&b<c){
	
	
	printf("Yes\n");
}else{
	
	printf("No\n");
}
	return 0;
}

Measured memory_bytes: 580
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#pragma comment(linker, "/STACK:336777216")  

using namespace std;

int X;

void Work()
{
	scanf("%d", &X);
	for (int i = 1; ; i ++)
	{
		X -= i;
		if (X <= 0)
		{
			printf("%d\n", i);
			return;
		}
	}
}

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

Measured memory_bytes: 128
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

int dfs(int x, vvint &vv, vint &X){
	if(vv[x].size()==0) return 0;
	vint v;
	for(int y: vv[x]){
		v.PB(dfs(y,vv,X));
		if(v.back()==-1) return -1;
	}
	vint dp(X[x]+1,INF);
	rep(i,vv[x].size()){
		int y = vv[x][i];
		if(i==0){
			if(X[y]<=X[x]) dp[X[y]] = v[0];
			if(v[0]<=X[x]) dp[v[0]] = X[y];
			continue;
		}
		vint dp2(X[x]+1, INF);
		rep(j,X[x]+1){
			if(j+X[y]<=X[x]) mins(dp2[j+X[y]], dp[j]+v[i]);
			if(j+v[i]<=X[x]) mins(dp2[j+v[i]], dp[j]+X[y]);
		}
		dp = dp2;
	}
	int ret = INF;
	rep(i,X[x]+1){
		mins(ret, dp[i]);
	}
	return (ret==INF?-1:ret);
}

void mainmain(){
	int n;
	cin>>n;
	vvint vv(n);
	rep(i,n-1){
		int p;
		cin>>p;
		p--;
		vv[p].PB(i+1);
	}
	vint X(n);
	rep(i,n){
		cin>>X[i];
	}
	if(dfs(0,vv,X)!=-1){
		cout<<"POSSIBLE"<<endl;
	}
	else{
		cout<<"IMPOSSIBLE"<<endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

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

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
ll rpow(ll x, ll n) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) k *= x;
        x *= x;
    }
    return k * x;
}
ll modpow(ll x, ll n, ll mod) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) (k *= x) %= mod;
        (x *= x) %= mod;
    }
    return k * x % mod;
}
ll modcomb(ll n, ll r, ll mod) {
    if (r < 0 || n < r) return 0;
    chmin(n - r, r);
    ll mul = 1, div = 1;
    for (ll i = 0; i < r; i++) {
        (mul *= n - i) %= mod;
        (div *= i + 1) %= mod;
    }
    return mul * modpow(div, mod - 2, mod) % mod;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}
void solve() {
    ll x;
    std::cin >> x;

    ll ans = -1;
    for (ll i = 1; i <= 32; i++) for (ll j = 2; j <= 10; j++)
        if (rpow(i, j) <= x) chmax(rpow(i, j), ans);
        else break;

    std::cout << ans << '\n';
}


Measured memory_bytes: 3632
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, K,L, W, H, P, Q, R, X, Y;
  ll ans;
  string S, T;
  cin >>N;
  
  rep_s(i, 1, 10){
    A = N/i;
    if (i*A == N && A<=9){
      cout <<"Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  
  
  
   




}


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

int main() {
  string S;
  long long int K, N;
  cin >> S >> K;
  N = S.size();
  for (int i = 0; i <= min(K, N); i++) {
    if (i == min(K, N)) {
      cout << 1 << endl;
      break;
    }
    else if (S.at(i) != '1') {
      cout << S.at(i) << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n,l;
    cin >> n >> l;

    int s = 0;
    for(int i = 1;i <= n;i++){
        s += l + i - 1;
    }

    int sa = INF;
    int ans = 1;
    for(int i = 1;i <= n;i++){
        int ss = s - (l+i-1);
        if(sa > abs(ss-s)){
            sa = abs(ss-s);
            ans = ss;
        }
    }
    cout << ans << endl;    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc131.contest.atcoder.jp/tasks/abc131_a


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

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
typedef vector<int> vi;
int main(){
    int m,n;
    while(cin>>m>>n){
        int ans=0;
        rep(i,m){
            int so=0;
            rep(j,n){
                int k;cin>>k;
                so+=k;
            }
            ans=max(ans,so);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size()-1;i++)
	{
		if(s[i]==s[i+1])
		{
			cout<<i+1<<" "<<i+2;
			return 0;
		}
	}
	for(int i=0;i<s.size()-2;i++)
	{
		if(s[i]==s[i+2])
		{
			cout<<i+1<<" "<<i+3;
			return 0;
		}
	}
	cout<<-1<<" "<<-1;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	ini(n);
	vi a(n);
	vi b(n-1);
	FOR(i,0,n-1){
		in(b[i]);
		if(i == 0){
			a[i] = a[i+1] = b[i];
			continue;
		}
		if(b[i]>b[i-1])a[i+1] = b[i];
		if(b[i]<=b[i-1])a[i] = a[i+1] = b[i];
	}
	int total = 0;
	FOR(i,0,n){total+=a[i];}
	out(total);
	return 0;
}

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

char F[102][102];
void DFSA(int y,int x){
	if(F[y][x]!='@')
		return;
	F[y][x]='.';
	DFSA(y-1,x  );
	DFSA(y  ,x+1);
	DFSA(y+1,x  );
	DFSA(y  ,x-1);
}
void DFSP(int y,int x){
	if(F[y][x]!='#')
		return;
	F[y][x]='.';
	DFSP(y-1,x  );
	DFSP(y  ,x+1);
	DFSP(y+1,x  );
	DFSP(y  ,x-1);
}
void DFSO(int y,int x){
	if(F[y][x]!='*')
		return;
	F[y][x]='.';
	DFSO(y-1,x  );
	DFSO(y  ,x+1);
	DFSO(y+1,x  );
	DFSO(y  ,x-1);
}
int main(){
	int n,m;
	while(1){
		cin>>n>>m;
		if(n==0&&m==0) break;
		for(int y=1;y<=n;y++){
			for(int x=1;x<=m;x++){
				cin>>F[y][x];
			}
		}		

		int c=0;
		for(int y=1;y<=n;y++){
			for(int x=1;x<=m;x++){
				if(F[y][x]=='@'){
					c++;
					DFSA(y,x);
				}
				if(F[y][x]=='#'){
					c++;
					DFSP(y,x);
				}
				if(F[y][x]=='*'){
					c++;
					DFSO(y,x);
				}
			}
		}
	cout<<c<<endl;
	}
	return 0;

}

Measured memory_bytes: 3524
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
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; }
//#define int long long

void solve() {
	int n, x; cin >> n >> x;
    int s[220]; rep(i, n) cin >> s[i];
    sort(s, s + n);

    ll dp[220][100100];
    rep(i, x + 1) {
        dp[0][i] = i;
    }
    rep(i, n) {
        rep(j, x + 1) {
            dp[i + 1][j] = (dp[i][j] * i % mod + dp[i][j % s[i]]) % mod;
        }
    }

    cout << dp[n][x] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 158848
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <utility>
#include <numeric>
#include <iomanip>
#include <locale>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>
#include <cmath>

using namespace std;

vector<int> read();
int think(vector<int>);
void write(int);

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

  auto input = read();
  auto output = think(input);
  write(output);

  return 0;
}

vector<int> read() {
  int k, s;

  cin >> k >> s;
  return vector<int> {k, s};
}

int think(vector<int> input) {
  auto k = input.at(0);
  auto s = input.at(1);

  int count = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      if (x + y > s) {
        continue;
      }
      auto remain = s - x - y;
      if (remain >= 0 && remain <= k) {
        count++;
      }
    }
  }
  return count;
}

void write(int output) {
  cout << output << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long lint;
typedef pair<int, int> P;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int x[1010], y[1010], z[1010];

signed main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }

  int ans = 0;
  for (int bit = 0; bit < (1 << 3); bit++) {
    vector<int> v;
    for (int i = 0; i < N; i++) {
      int temp = 0;
      if (bit & 1) {
        temp += x[i];
      } else {
        temp -= x[i];
      }
      if (bit & 2) {
        temp += y[i];
      } else {
        temp -= y[i];
      }
      if (bit & 4) {
        temp += z[i];
      } else {
        temp -= z[i];
      }
      v.push_back(temp);
    }

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

    int sum = 0;
    for (int i = 0; i < M; i++) {
      sum += v[i];
    }

    ans = max(ans, sum);
  }

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


Measured memory_bytes: 256
N,M = map(int,input().split())
a = [int(input()) for i in range(M)]
Mod = 1000000007
dp = [1]*(N+1) #dp[i]...i番目にいる時の移動方法の数

count = 0
for i in a:
    if i+1 in a:
        print(0)
        exit()

for i in a:
    dp[i] = 0
if dp[1] == 0:
    for i in range(1,N-1):
        if dp[i+2] != 0:
            dp[i+2] = dp[i+1] + dp[i]
            dp[i+2] %= Mod
else:
    dp[1] = 1
    for i in range(N-1):
        if dp[i+2] != 0:
            dp[i+2] = dp[i+1] + dp[i]
            dp[i+2] %= Mod

print(dp[N])

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

using namespace std;

int main(){
  int N;
  cin >> N;
  double ans=0;
  for(int i=1;i<=N;i++){
    if(i%2==1){
      ans++;
    }
  }
  ans=ans/N;
  cout << ans << endl;
  return 0;
}


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

const int N = 2e5 + 10, mod = 1e9 + 7;



int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
   // scanf("%d", &tc);
    while(tc--) {
        long long n, m; scanf("%lld%lld", &n, &m);
        long long ans = (n - (n / 2)) * ((m / 2) + (m % 2));
        ans += (n / 2) * (m / 2);
        if(n == 1 || m == 1) ans = 1;
        printf("%lld\n", ans);
    }    
    return 0;
}

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

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

Measured memory_bytes: 256
//1908-1930 22m
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000
#define FIND 0
#define END 1

int TimeStump[100][2] = {};//find,end
vector<int> V[100];
stack<int> S;
int time_ = 1;

void DFS(int i){
    if (TimeStump[i][FIND] != 0) return;
    S.push(i);
    TimeStump[i][0] = time_;
    time_++;
    
    REP1(k,V[i].size()){
        if (TimeStump[V[i][k]][FIND] == 0){DFS(V[i][k]);}
    }
    
    S.pop();
    TimeStump[i][1] = time_;
    time_++;
}

int main(){
    INT(N);
    REP1(i,N){
        int from,n;
        scanf("%d %d",&from,&n);
        REP1(j,n){
            INT(to);
            V[i].push_back(to - 1);
        }
    }
    
    REP1(i,N) DFS(i);
    
    REP1(i,N) printf("%d %d %d\n",i+1,TimeStump[i][0],TimeStump[i][1]);
    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define ll long long 
#define all(v) v.begin() , v.end()
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define tr(con) for(auto it = con.begin(); it!= con.end() ; it++)
#define INF 1e9+7   
#define rep(i,l,r) for( i=l;i<=r;i++)
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;
ll gcd(ll a ,ll b){
	if(b==0) return a;
	else return gcd(b ,a%b);
}

int main(){
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
   
      int a, b ;  cin >> a>> b ;
      int add = a+b , sub = a-b ,mul =a*b ;
      cout << max(add , max(sub , mul)) ;
      return 0;
   
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repi(i, j, n) for(int i = j;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 998244353
#define F first
#define S second

int main() {

// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);

 char ch;
 cin>>ch;
 if(ch <= 'Z' && ch >= 'A') cout << "A";
 else cout<<"a";

  return 0;
}


Measured memory_bytes: 3588
//
//AtCoder Beginner Contest 137
//A - +-x
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int a, b;
    cin >> a >> b;

    int ans = max(max(a+b,a-b), a*b);
    cout << ans << endl;

    return 0;
}


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

using namespace std;
using ll=long long;
using pl=pair<ll,ll>;
void solve() {
    int n; ll D, A;
    cin >> n >> D >> A;

    priority_queue<pl,vector<pl>, greater<>> pq;
    for (int _ = 0; _ < n; _++) {
        ll x,h;
        cin >> x >> h;
        pq.emplace(x, h);
    }
    D = 2*D + 1;
    ll res = 0;
    ll E = 0;
    while (!pq.empty()) {
        ll x,h;
        tie(x,h) = pq.top(); pq.pop();
        if (h < 0) E += h;
        else if (E < h){
            ll k = (h - E + A-1)/A;
            res += k;
            E += k*A;
            pq.emplace(x + D, -k*A);
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 6512
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, k; cin >> n >> k;
	if (n % 2 == 0) {
		if (k <= n / 2) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	else {
		if (k <= n / 2 + 1) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	cin >> n;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n,k;cin >> n >> k;
    vector<int> x(n);rep(i,n)cin >> x[i];
    ll ans = INF;
    for(int i=0;i<n;i++){
        int l = i;
        int r = i+k-1;
        if(r >= n)break;
        ll res = -1;
        if(x[l] <= 0 && x[r] <= 0){
            res = abs(x[l]);
        }else if(x[l] <= 0 && x[r] >= 0){
            res = min(abs(x[r]) + abs(x[l]-x[r]),abs(x[l]) + abs(x[r]-x[l]));
        }else if(x[l] >= 0 && x[r] >= 0){
            res = abs(x[r]);
        }
        chmin(ans,res);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
s = int(input())
f = [0 for _ in range(1000005)]
f[s] = 1
n = s
for i in range(1000005):
  if(n%2==0):
    n = int(n/2)
  else:
    n = int(3*n + 1)
  if(f[n] == 1):
    print(i+2)
    sys.exit()
  else:
    f[n] = 1

Measured memory_bytes: 17016
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}

int main() {
  int n;
  cin >> n;
  vl a(n);
  rep(i,n) cin >> a[i];
  vl l(n),r(n+1);
  rep(i,n-1) l[i+1] = gcd(l[i], a[i]);
  for (int i = n-1; i >= 1; --i) r[i-1] = gcd(r[i], a[i]);
  ll ans = 1;
  rep(i,n){
    maxs(ans,gcd(l[i],r[i]));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5536
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


signed main(void) 
{
    ll w, a;
    cin >>w >>a;
    if (w <= a*2) {
        mes(0);
        re0;
    }
    mes(w - a*2);
    
   
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long)1000000007

int main() {
    int n,k;
    cin >> n >> k;
    long long ans = 0;
    long long mx,mn;
    for(long long i = k;i <= n + 1;i++){
        mn =i * (i - 1)/2;
        mx =i * (n + (n - i + 1))/2;
        ans += (mx - mn + 1)%MOD;
        ans %= MOD;
    }
    cout << ans;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			String S = scn.next();
			String T = scn.next();

			if(S.equals(T.substring(0, S.length()))) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}

		}
	}
}

Measured memory_bytes: 26944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC100
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] AB = Console.ReadLine().Split().Select(int.Parse).ToArray();
            string ans = "Yay!";
            if (AB[0] > 8||AB[1] > 8) { ans = ":("; }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    int counter = 0;
    for (int i = a; i <= b; i++)
    {
        string y = to_string(i);
        string x = to_string(i);
        reverse(x.begin(), x.end());
        if(x == y) counter ++;
    }
    cout << counter << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    l_n = [True] * n
    for i in range(m):
        a, b = map(int, input().split())
        if h[a-1] == h[b-1]:
            l_n[b-1] = False
            l_n[a-1] = False
        elif h[a-1] <= h[b-1]:
            l_n[a-1] = False
        elif h[a-1] >= h[b-1]:
            l_n[b-1] = False
    print(sum(l_n)) 

if __name__ == '__main__':
    main()

Measured memory_bytes: 20340
n = int(input())
card_list = [ int(v) for v in input().split() ]


s = sum(card_list) 
a = card_list[0]
b = s - a
ans = n*10**9

for i in range(n-1):
	ans = min(ans,abs(a-b))
	c = card_list[i+1]
	a += c
	b -= c

print(ans)

Measured memory_bytes: 24824
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) a.begin(),a.end()

typedef complex<double> Point;
typedef vector<Point> VP;
#define X real()
#define Y imag()
const double INF = 1e9;

bool compX(const Point a, const Point b) {
    return a.X<b.X;
}

bool compY(const Point a, const Point b) {
    return a.Y<b.Y;
}

double closestPair(VP &a,int l,int r) {
    if(r-l<=1) return INF;
    int m = (l+r)/2;
    double x = a[m].X;
    double d = min(closestPair(a,l,m),closestPair(a,m,r));
    inplace_merge(a.begin()+l,a.begin()+m,a.begin()+r,compY);
    
    VP b;
    for(int i=l;i<r;i++){
        if(abs(a[i].X - x)>=d)continue;
        for(int j=b.size()-1;j>=0;j--){
            if((a[i]-b[j]).Y>=d)break;
            d = min(d,abs(a[i]-b[j]));
        }
        b.push_back(a[i]);
    }
    return d;
}

double closestPair(VP ps){
    sort(ps.begin(),ps.end(),compX);
    return closestPair(ps,0,ps.size());
}

int main(void){
    int n;
    cin>>n;
    VP ps(n);
    rep(i,n){
        double x,y;
        cin>>x>>y;
        ps[i] = Point(x,y);
    }
    printf("%.9f\n",closestPair(ps));
    return 0;
}

Measured memory_bytes: 9064
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// -----------------------------------------------------------------------------
// main
// -----------------------------------------------------------------------------
fn main(){
    input!{
        n: usize
    }
    let mut ans = "No";
    for i in 0..(100/4+1){
        for j in 0..(100/4+1){
            if 4*i + 7*j == n{
                ans = "Yes";
            }
        }
    }
    println!("{}", ans);
}



Measured memory_bytes: 4352
#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;
ll n,k,v[2000001],ans,suma,sm[2000001];
map<ll,ll> f;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    f[0]=1;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        suma+=v[i];
        ll s=(suma-i)%k;
        sm[i]=s;
        if(i>=k)
        {
            f[sm[i-k]]--;
        }
        ans+=f[s];
        f[s]++;
    }
    cout<<ans;
    return 0;
}


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


int main() {
  int D,G;
  cin >> D >> G;
  vector<vector<int>> v(D,vector<int>(3));
  for (int i=0;i<D;i++){
    cin >> v.at(i).at(0) >> v.at(i).at(1);
    v.at(i).at(2)=100*(i+1)*v.at(i).at(0)+v.at(i).at(1);
  }
  int ans=1000;
  for (int bit=0;bit<(1<<D);bit++){
    int sum=0,count=0,rest_max=-1;
    for (int i=0;i<D;i++){
      if (bit&(1<<i)){
        sum+=v.at(i).at(2);
        count+=v.at(i).at(0);
      }
      else {
        rest_max=i;
      }
    }
    if (sum<G){
      int s=100*(rest_max+1);
      int need=(G-sum+s-1)/s;
      if (need<v.at(rest_max).at(0)){
        count+=need;
      }
      else {
        continue;
      }
    }
    ans=min(ans,count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256