akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main() {
int s,a,d,c;
while(cin>>a>>d,a) {
s=a+d;c=0;
for(int i=1;i<5;i++) {
cin>>a>>d;
if(s<a+d)s=a+d,c=i;
}
cout<<(char)(c+'A')<<' '<<s<<endl;
}
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
int main(){
    string n,m;
    cin >>n>>m;
    int ans = 0;
    for(int i = 0;i< n.length();i++)
    {
        if(n[i] != m[i])
        {
            ans++;
        }
    }
    cout << ans<< endl;
}


Measured memory_bytes: 3912
#include <iostream>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

using ll = long long;

template <class T>
using grid = vector<vector<T>>;

#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 input(...) __VA_ARGS__; in(__VA_ARGS__)

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int combination(int i, int repeat, int sum, vector<int> &a, int x) {
  if (repeat == 0) {
    return sum == x;
  }
  if (i == a.size()) {
    return 0;
  }

  int result = 0;
  FOR(j, i, a.size() - 1) {
    result += combination(j + 1, repeat - 1, sum + a[j], a, x);
  }
  return result;
}

void solve(int n, int x) {
  vector<int> a(n);
  REP(i, n) a[i] = i + 1;

  cout << combination(0, 3, 0, a, x) << endl;
}

int main() {
  while (true) {
    int input(n, x);
    if (n == 0 && x == 0) break;
    solve(n, x);
  }
}


Measured memory_bytes: 3120
#include<stdio.h>
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P) {
    int i = 0;
    for ( int j = 0; j < k; j++ ) {
        llong s = 0;
        while ( s + T[i] <= P ) {
            s += T[i];
            i++;
            if ( i == n ) return n;
        }
    }
    return i;
}

int solve() {
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while ( right - left > 1 ) {
        mid = (left + right) / 2;
        int v = check(mid);
        if ( v >= n ) right = mid;
        else left = mid;
    }

    return right;
}

int main () {
    scanf("%d %d", &n, &k);
    for ( int i = 0; i < n; i++) scanf("%d", &T[i]);
    llong ans = solve();
    printf("%d\n", ans);
}


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

int main(){
    string s;
    cin >> s;
    int cnt1 = 0;
    int cnt2 = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] >= 'a' && s[i] <= 'z') cnt1++;
    }
    for(int i = 2; i < s.length() - 1; i++){
        if(s[i] == 'C') cnt2++;
    }
    if(s[0] == 'A' && cnt2 == 1 && cnt1 == s.length()-2){
        cout << "AC" << endl;
    } else{
        cout << "WA" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=[]
sum=0
for i in range(m):
    b.append(list(map(int,input().split())))
b.sort(key=lambda x: x[1])
B=len(b)
b1=b[B-1][0]
b2=b[B-1][1]
b3=0
for i in range(n):
    if a[i]<b2 and b3==0:
        sum+=b2
        b1-=1
    else:
        sum+=a[i]
    if b1==0:
        B-=1
        if B==0:
            b3=1
        b1=b[B-1][0]
        b2=b[B-1][1]
print(sum)


Measured memory_bytes: 32976
H, W = map(int, raw_input().split())
A = [raw_input() for _ in xrange(H)]
B = [[0 for j in xrange(W)] for i in xrange(H)]

dr = [-1, 0, 1, -1, 1, -1, 0, 1]
dc = [-1, -1, -1, 0, 0, 1, 1, 1]


for i in xrange(H):
    for j in xrange(W):
        if A[i][j] == '#':
            B[i][j] = '#'
            continue
        for k in xrange(8):
            ni = i + dr[k]
            nj = j + dc[k]
            if ni < 0 or ni >= H or nj < 0 or nj >= W:
                continue
            if A[ni][nj] == '#':
                B[i][j] += 1

for i in xrange(H):
    print ''.join(map(str, B[i]))


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

int main() {
  int N;
  cin >> N;
  
  int l, r, count = 0;
  for (int i=0; i<N; i++) {
    cin >> l >> r;
    count += r - l + 1;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3492
#include<stdio.h>
void sort(int *n){
	int i,j,t;
	for(i=0;i<10;i++)
		for(j=i;j<10;j++)
			if(n[i]<n[j]){
				t=n[i];n[i]=n[j];n[j]=t;
			}
}
int main(){
	int i,w[11],k[11];
	for(i=0;i<10;i++)scanf("%d",&w[i]);
	sort(w);
	for(i=0;i<10;i++)scanf("%d",&k[i]);
	sort(k);
	printf("%d %d\n",w[0]+w[1]+w[2],k[0]+k[1]+k[2]);
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9+7;
const int mod= 1e9 + 7;

int A[100001],B[100001];
ll ans;

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

	int N; cin >> N;
	FOR(i, 0, N+1) {
		cin >> A[i];
	}
	FOR(i, 0, N) {
		cin >> B[i];
	}

	FOR(i, 0, N + 1) {
		if (i != 0) {
			if (B[i - 1] > 0) {
				if (B[i-1] >= A[i]) {
					ans += A[i];
					B[i-1] -= A[i];
					A[i] = 0;
				}
				else {
					ans += B[i-1];
					A[i] -= B[i - 1];
					B[i - 1] = 0;
				}

			}
		}
		if (B[i] >= A[i]) {
			ans += A[i];
			B[i] -= A[i];
			A[i] = 0;
		}
		else {
			ans += B[i];
			A[i] -= B[i];
			B[i] = 0;
		}
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def myinput():
    return map(int,readline().split())

n = int(readline())
a = list(myinput())
mod = 10**9 + 7
ans = 0

for j in range(60):
    k = 2**j
    one = 0
    zero = 0
    for i in range(n):
        if (a[i]&k)!=0:
            one += 1
        else:
            zero += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**j) 
    ans %= mod   

print(ans%mod)

Measured memory_bytes: 89712
#include <stdio.h>
#include <string.h>
void f(char b[])
{
	int i,j,k;
	char c=b[0];
	for(i=0;i<strlen(b)-1;i++)
	b[i]=b[i+1];
	b[strlen(b)-1]=c;
}
int main(int argc, char *argv[])
{
	int n,i,j,k,l,bz=0;
	char a[105],b[105];
	scanf("%s",a);
	scanf("%s",b);
	l=strlen(a);
	for(i=0;i<l;i++)
	{
		if(a[i]!=b[i])
		f(b);
	}
	for(i=0;i<l;i++)
	if(a[i]!=b[i])
	{
		bz=1;
		break;
	}
	if(bz)
	printf("No\n");
	else
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

using tp=tuple<ll,ll,ll>;
map<tp,ll> memo;

ll f(ll a,ll b,ll x){
    if(memo.count(tp(a,b,x))){
        return memo[tp(a,b,x)];
    }
    // 不可能
    if(((a&1)^(b&1))!=(x&1)){
        return LINF;
    }
    if(x==0){
        if(a>=b) return (a-b)/2;
        else return LINF;
    }
    ll ret=2*f(a/2,b/2,x/2);
    chmin(ret,2*f((a-1)/2,(b+1)/2,x/2)+1);
    return memo[tp(a,b,x)]=ret;
}



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;cin>>n;
    ll a,b,x=0;
    cin>>a>>b;
    rep(i,n-2){
        ll t;cin>>t;
        x^=t;
    }
    ll res=f(a,b,x);
    if(res>=a) cout<<-1<<endl;
    else cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3664
def solve():
    s = read()
    result = think(s)
    write(result)


def read():
    h, w = read_int(2)
    s = []
    for y in range(h):
        s.append(list(read_line(w)))
    return s


def read_int(n):
    return list(map(int, read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(s):
    w, h = get_area(s)
    gx, gy = w - 1, h - 1

    invalid = w * h
    white_tile_mark = '.'

    memo = bfs(s, w, h, white_tile_mark, invalid)

    if memo[gy][gx] == invalid:
        return -1

    shortest_path = get_shortest_path(memo, w, h, gx, gy)
    white_tiles = collect_tiles(s, white_tile_mark)
    score = 0

    for w in white_tiles:
        if w not in shortest_path:
            score += 1
    return score


def get_area(s):
    w = len(s[0])
    h = len(s)
    return w, h


def bfs(s, w, h, white_tile_mark, invalid):
    sx, sy = 0, 0

    memo = [[invalid for x in range(w)] for y in range(h)]
    queue = []
    queue.append([sx, sy, 0])

    next_steps = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    while queue:
        nx, ny, nd = queue.pop(0)
        if not (0 <= nx < w and 0 <= ny < h and s[ny][nx] == white_tile_mark and memo[ny][nx] > nd):
            continue
        memo[ny][nx] = nd

        for dx, dy in next_steps:
            queue.append([nx + dx, ny + dy, nd + 1])
    return memo


def get_shortest_path(memo, w, h, gx, gy):
    next_steps = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    shortest_path = []
    cx, cy = gx, gy

    while True:
        shortest_path.append([cx, cy])
        current_distance = memo[cy][cx]
        if current_distance == 0:
            break
        for dx, dy in next_steps:
            nx, ny = cx + dx, cy + dy
            if not (0 <= nx < w and 0 <= ny < h):
                continue
            if memo[ny][nx] == current_distance - 1:
                cx, cy = nx, ny
                break

    return shortest_path


def collect_tiles(s, mark):
    w, h = get_area(s)
    tiles = []
    for y in range(h):
        for x in range(w):
            if s[y][x] == mark:
                tiles.append([x, y])
    return tiles


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

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

int coins[12] = {1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
int d[100010]; //存放0到18元组成的硬币数


//初始化
void initD(){
    for(int i=0; i<100010; i++){
        d[i] = 99999;
    }
};

//主要功能实现
void min_coins(){
    for(int i=0; i<100010; i++){
    if(i==0){
        d[0]=0;
        continue;
    }
    int MIN = 99999; //重设MIN
        for(int j=0; j<12; j++){
            if(i>=coins[j]){
                MIN = min(d[i-coins[j]]+1,MIN); //比较大小，寻找最佳
            }
            else break; //第一个不合条件就退出，优化算法
            d[i] = MIN;
        }
    }
}

int main()
{
    initD();
    int n;
    cin>>n;
    min_coins();
    cout<<d[n]<<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define cin_desync()                      \
	do {                                  \
		ios_base::sync_with_stdio(false); \
		cin.tie(0);                       \
	} while (0)                           \

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

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

const int max_N = 1e4 + 10;
int A[max_N], B[max_N];

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

	for (int i = 1; i <= N; ++i) {
		cin >> A[i];
	}

	for (int i = 1; i <= N; ++i) {
		cin >> B[i];
	}

	ll opsa = 0;
	for (int i = 1; i <= N; ++i) {
		if (A[i] < B[i]) {
			opsa += (B[i] - A[i]) / 2;
		} else {
			opsa -= (A[i] - B[i]);
		}
	}


	if (opsa >= 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


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

int main(){
  int N, A, B, x;
  cin >> N >> A >> B;
  x = N * A;
  if(x == B){
    cout << B <<endl;
  }
  else if(x > B){
    cout << B <<endl;
  }
  else{
    cout << x <<endl;
  }
}


Measured memory_bytes: 256
sx , sy , tx , ty = map(int,input().split())
print("L",end="")
for i in range(ty-sy+1):
    print("U",end="")
for i in range(tx-sx+1):
    print("R",end="")
for i in range(ty-sy+1):
    print("D",end="")
for i in range(tx-sx):
    print("L",end="")
for i in range(ty-sy):
    print("U",end="")
for i in range(tx-sx+1):
    print("R",end="")
for i in range(ty-sy+1):
    print("D",end="")
for i in range(tx-sx+1):
    print("L",end="")
print("U")

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

int N, M, Q;
vector<vector<int>> ABCD;
int ans;

void dfs (vector<int> A, int dep, int pre) {
  if (dep == N) {
    int sum = 0;
    // for (auto a : ABCD) {
    //   if (A.at(a.at(1)) - A.at(a.at(0)) == a.at(2)) {
    //     sum += a.at(3);
    //   }
    // }
    for (int i = 0; i < Q; i++) {
      if (A.at(ABCD.at(i).at(1)) - A.at(ABCD.at(i).at(0)) == ABCD.at(i).at(2)) {
        sum += ABCD.at(i).at(3);
      }
    }
    ans = max(ans, sum);
    return;
  }
  for (int i = pre; i <= M; i++) {
    vector<int> NA = A;
    NA.at(dep) = i;
    dfs(NA, dep + 1, i);
  }
}

int main() {
  cin >> N >> M >> Q;
  for (int a, b, c, d; cin >> a >> b >> c >> d;) {
    ABCD.push_back({--a, --b, c, d});
  }
  vector<int> A(N);
  dfs(A, 0, 1);
  cout << ans << "\n";
}

Measured memory_bytes: 3592
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    string S, T;
    cin >> S >> T;

    int ans = 0;
    for (int i = 0; i < 3; i++)
        if (S[i] == T[i]) ans++;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define hii cout << "hii" << endl
#define int long long
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int N = 5e5 + 5;
const int MAX = 250000 + 5;
const int M = 1e6 + 5;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 1e18 + 8;
const int LG = 21;

int arr[N];

void solve()
{
	int a, b;
	cin >> a >> b;
	int c, d;
	cin >> c >> d;
	int ans1 = b * d;
	int ans2 = a * c;
	int ans3 = -INF;
	int ans4 = b * c;
	int ans5 = a * d;
	if(b >= 0 and a <= 0) ans3 = 0;
	if(d >= 0 and c <= 0) ans3 = 0;
	cout << max({ans1, ans2, ans3, ans4, ans5}) << endl;
}


 
int32_t main() 
{	
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());
		int h = Integer.parseInt(scanner.nextLine());
		int w = Integer.parseInt(scanner.nextLine());

		System.out.println((n - h + 1) * (n - w + 1));
	}

}


Measured memory_bytes: 23124
n,k = [int(x) for x in input().split()]

ans = 0
for a in range(1,n+1,1):
    m = (k - a % k) % k
    if (m+m) % k == 0 and n >= m:
        x = (n - m) // k + 1
        if m == 0: x -= 1
        ans += x*x
print(ans)


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

#define int long long 
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define lbound lower_bound 
#define ubound upper_bound
#define pqueue priority_queue
#define umap unordered_map
#define uset unordered_set
#define len(a) (int)a.size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using namespace std ;

using vi   = vector<int> ;
using vvi  = vector<vi> ;
using pii  = pair<int,int> ;
using vpii = vector<pii>  ;
using mii  = map<int, int>;
using umii = umap<int, int>; 

template<class T> bool mini(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool maxi(T &a, T b) { return a < b ? (a = b, true) : false; }

int32_t main(){
    ios::sync_with_stdio(false); 
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("D:/Coding/in.txt", "r", stdin);
    freopen("D:/Coding/out.txt", "w", stdout);
#endif
    int n ,m , x ;
    cin >> n >> m >> x;
    vi a(n + 1 , 0);
    for (int i = 0; i < m ; ++i){
         int x;
         cin >> x;
         a[x] = 1; 
    }
    for (int i = 1; i < n ; ++i){
         a[i] += a[i - 1]; 
    }
    cout << min(a[x] - a[0], a[n - 1] - a[x - 1]); 

#ifndef ONLINE_JUDGE  
    cerr << "\n\nTime elapsed: " << 1.0 * clock() /CLOCKS_PER_SEC<< " s.\n";
#endif
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main () {
  string s;
  cin >> s;
  string w[3] = {"Sunny", "Cloudy", "Rainy"};
  if (s == w[0]) {
    cout<<w[1]<<endl;
  } else if (s == w[1]) {
    cout<<w[2]<<endl;
  } else if (s == w[2]) {
    cout<<w[0]<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define ll long long

const int MAX = 2e5+10;
ll a[MAX];

int main(){
    int n; scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
    ll ans = 0;
    for (int i = 1; i < n; i++){
        if (a[i] < a[i-1]){
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3296
#include<bits/stdc++.h>
using namespace std;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,E)> G;
  typedef function<T(E,E)> H;
  int n;
  G g;
  H h;
  T d1;
  E d0;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(){};
  SegmentTree(int n_,G g,H h,T d1,E d0,
	      vector<T> v=vector<T>()):
    g(g),h(h),d1(d1),d0(d0){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(n,d1);
    laz.clear();
    laz.resize(2*n-1,d0);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i]=v[i];
  }
  void eval(int k){
    if(k*2+1<2*n-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
      laz[k]=d0;
    }
  }
  
  void update(int a,int b,E x,int k,int l,int r){
    eval(k);
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return;
    }
    update(a,b,x,k*2+1,l,(l+r)/2);
    update(a,b,x,k*2+2,(l+r)/2,r);
  }
  void update(int a,int b,E x){
    update(a,b,x,0,0,n);
  }
  void eval2(int k){
    if(k) eval2((k-1)/2);
    eval(k);
  }
  
  T query(int k){
    T c=dat[k];
    k+=n-1;
    eval2(k);
    return g(c,laz[k]);
  }
};
//END CUT HERE
signed main(){
  int n,q;
  cin>>n>>q;
  SegmentTree<int,int> beet(n,
			    [&](int a,int b){ return b<0?a:b;},
			    [&](int a,int b){ return b<0?a:b;},
			    INT_MAX,-1);
  for(int i=0;i<q;i++){
    int c;
    cin>>c;
    if(c){
      int x;
      cin>>x;
      cout<<beet.query(x)<<endl;
    }else{
      int s,t,x;
      cin>>s>>t>>x;
      t++;
      beet.update(s,t,x);
    }
  }
  return 0;
}
/*
  verified on 2017/10/15
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_D&lang=jp
*/

Measured memory_bytes: 4432
N, M = map(int, input().split())
PY = [list(map(int, input().split() +[x])) for x in range(M)]

PY = sorted(PY)

keyP = -1
for i, (P, Y, _) in enumerate(PY):
  if keyP != P:
    keyP = P
    keyNo = 1

  PY[i].append("{:0>6}{:0>6}".format(keyP, keyNo))
  keyNo += 1

for P, Y, _, s in sorted(PY, key=lambda x:x[2]):
  print(s)


Measured memory_bytes: 39348
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		if(x < a) {
			System.out.println("0");
		} else {
			System.out.println("10");
		}
		sc.close();

	}

}


Measured memory_bytes: 22740
n, x, m = map(int, input().split())

dic = {}
a = x
s = 0
c = m
for i in range(1, n + 1):
    if a not in dic:
        s += a
        dic[a] = [i]
    elif len(dic[a]) == 1:
        s += a * (1 + (n - i) // (i - dic[a][0]))
        dic[a].append(i)
    else:
        break
    a = pow(a, 2, m)
print(s)

Measured memory_bytes: 75580
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI acos(-1)
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int MAXN = 1e7;

typedef long long int ll;

using namespace std;

int main(){
    FIN;
    //freopen("../../input.txt", "r", stdin);freopen("../../output.txt", "w", stdout);
    int n;cin>>n;
    int ans = 0;
    int vals[n];
    fore(i,0,n){cin>>vals[i];}
    sort(vals,vals+n);
    reverse(vals,vals+n);
    fore(i,0,n){
        fore(j,i+1,n){
            fore(k,j+1,n){
                if(vals[i] != vals[j] && vals[j] != vals[k] && vals[k] != vals[i] && vals[i]<vals[j]+vals[k] && vals[j]<vals[i]+vals[k] && vals[k]<vals[j]+vals[i]){
                    ans++;
                    //cout<<vals[i]<<" "<<vals[j]<<" "<<vals[k]<<" \n";
                }
            }
        }
    }
    
    cout<<ans<<"\n";
    return 0;
}

// ============== Notes =============== //
// common bugs
// - remove reader 
// - fastio
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?, is MAXN correct?)
// - special cases (n=1, graph not connected?)
// - re-initialize efficiently between test cases

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,sum=0;

    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                sum+=__gcd(k,__gcd(i,j));
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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



  ll a, b;
  cin >> a >> b;
  ans = a + b;
  ans = max(ans, a - b);
  ans = max(ans, a*b);
  cout << ans << endl;





  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

#define int ll
void solve()
{
	ll n,k;
	cin>>n>>k;
	vector<ll>p(n),c(n);
	rep(i,n){
		cin>>p[i];
		p[i]--;
	}
	rep(i,n)cin>>c[i];
	ll ans=-INF;
	rep(i,n){
		int cnt=k;
		ll res=0;
		vector<bool>used(n);
		int s=i;
		int nx=s;
		int loop=1;
		vector<ll>v(n),res_v(n);
		ll val=0;
		while(cnt>0){
			nx=p[nx];
			--cnt;
			if(used[nx]){
				loop=v[nx]-cnt;
				val=res-res_v[nx]+c[nx];
				++cnt;//移動回数として消費されない
				break;
			}
			res+=c[nx];
			chmax(ans,res);
			v[nx]=cnt;
			res_v[nx]=res;
			used[nx]=true;
		}
		//cout<<val<<"\n";
		if(val>0&&cnt>0){
			if(cnt/loop>=1)res+=(cnt/loop-1)*val,cnt=cnt%loop+loop;
			else res+=cnt/loop*val,cnt=cnt%loop;
			int pos=0;
			chmax(ans,res);
			while(cnt>0&&pos<=2*(loop+1)){
				++pos;
				res+=c[nx];
				chmax(ans,res);
				nx=p[nx];
				--cnt;
			}
		}
		else{
			int pos=0;
			while(cnt>0&&pos<=loop+1){
				++pos;
				res+=c[nx];
				chmax(ans,res);
				nx=p[nx];
				--cnt;
			}
		}
	}
	cout<<ans;
}
#undef int
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (lnog long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (lnog long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int a;
    string s;
    cin>>a>>s;
    cout<<((a>=3200)?s:"red")<<endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll H,W;

bool onBoard(ll y,ll x){
    if(y>=0&&y<H&&x>=0&&x<W){
        return true;
    }
    return false;
}

int main() {
    cin >> H >> W;
    vector<string> S(H);
    
    for(int i=0;i<H;i++){
        cin >> S[i];
    }

    int dy[] = {1,0,-1,0};
    int dx[] = {0,1,0,-1};
    ll d[H][W];
    memset(d,-1,sizeof(d));
    d[0][0] = 1;
    queue<ll> q;
    q.push(0);
    while(!q.empty()){
        ll t = q.front();q.pop();
        ll y = t/W;
        ll x = t%W;
        for(int i=0;i<4;i++){
            ll ny = y+dy[i];
            ll nx = x + dx[i];
            if(!onBoard(ny,nx)){
                continue;
            }
            if(d[ny][nx] != -1 || S[ny][nx] == '#'){
                continue;
            }
            d[ny][nx] = d[y][x] +1;
            q.push(ny*W+nx);
        }
    }
    if(d[H-1][W-1] ==-1){
        cout << -1 << endl;
        return 0;
    }

    ll ans =0;
    for(int i=0;i<H;i++)for(int j=0;j<W;j++){
        if(S[i][j] =='.'){
            ans++;
        }
    }
    cout << ans -d[H-1][W-1] << endl;
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
          
#define pb push_back
#define ll long long
#define F first
#define S second
#define ld long double
#define fa fflush(stdout); 
#define mp make_pair
using namespace std;
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);;                                                      
} 
int dx[5] = {-1, 0, 0, 1};
int dy[5] = {0, -1, 1, 0};
  
const int N = 1e6 + 100;
const ll mod = 1e6 + 3;
const ll big = 1e9;
const ll p = 27;
 
int main() 
{
	data();
   	// freopen("substr3.in","r",stdin);
   	// freopen("substr3.out","w",stdout);
	int n;
	cin >> n;
	int a[n + 1];int b[n + 1];
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= n - 3 + 1; i++)
	{
		int x = i + 1; 
		int x2 = i + 2;
		if (a[i] == b[i] && a[x] == b[x] && a[x2] == b[x2])
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}   	                                   



Measured memory_bytes: 3608
#include<stdio.h>
#define N 2000001
 
int a[N],c[N],b[N];
 
int main(){
  int i,j,n,k=0;
    
  scanf("%d",&n);
 
  for(i = 1; i < n+1; i++){
    scanf("%d",&a[i]);
    if(a[i] >k){
      k = a[i];
    }
  }
  for(i = 0; i < k+1; i++){
    c[i] = 0;
  }
  for(j = 1; j < n+1; j++){
    c[a[j]] = c[a[j]] + 1;
  }
 
  for(i = 1; i <= k; i++){
    c[i] = c[i] + c[i-1];
  }
  
  for(j = n; j > 0; j--){
    b[c[a[j]]] = a[j];
    c[a[j]] = c[a[j]] - 1;
  }
 
  for(i = 1; i < n; i++){
    printf("%d ",b[i]);
  }
  printf("%d\n",b[n]);
 
  return 0;
}

Measured memory_bytes: 17892
toInt :: (String -> Int)
toInt x = read x :: Int

-- 入力を受け取り、 [Int] にする
getInts = do
  x <- getLine
  let y = (map$toInt)$words x -- 半角スペースで分割してIntにする
  return y

compareInts :: [Int] -> String
compareInts inNums
  | a < b = "a < b"
  | a == b = "a == b"
  | otherwise = "a > b"
  where a = inNums !! 0
        b = inNums !! 1

main = do
  inNum <- getInts
  putStrLn $ compareInts inNum


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 100;
 ll n,a,b,m;
 vector<vector<ll> > G;
 vector<ll> cnt;
 const int INF = 1e9;
 ll dist[max_n];
 ll mod = 1e9 + 7;
int main(){
  cin >> n;
  ll h[n];
  for(int i=0 ; i<n ; i++){
    cin >> h[i];
  }
  ll dp[n];
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for(int i=2 ; i<n ; i++){
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1792
// Undone
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    int[] AB = ReadIntArray();
    if (AB[1] % AB[0] == 0) {
      Console.WriteLine(AB[0] + AB[1]);
    } else {
      Console.WriteLine(AB[1] - AB[0]);
    }
  }

  private static string ReadStr() { return Console.ReadLine(); }
  private static int ReadInt() { return int.Parse(Console.ReadLine()); }
  private static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  private static long ReadLong() { return long.Parse(Console.ReadLine()); }
  private static char ReadChar() { return Console.ReadLine()[0]; }
  private static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  private static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  private static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  private static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
  private static string[] ReadCharStringArray() { return Console.ReadLine().ToCharArray().Select(c => c.ToString()).ToArray(); }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18;

signed main(){
	string s,t = "keyence";
	cin >> s;
	if(s==t){
		cout << "YES" << endl;
		return 0;
	}
	string ss = s;
	reverse(ALL(ss));
	REP(i,7+1){
		string tmp = s.substr(0,i);
		string tmptmp = ss.substr(0,7-i);
		reverse(ALL(tmptmp));
		tmp += tmptmp;
		if(t==tmp){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

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

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

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;

ll p3[900005], dp[900005], sum[900005];
ll f1[900005], f2[900005];
ll pow2(ll a, ll b){
    ll res = 1;
    while(b){
        if(b%2) res = res*a%mod;
        a = a*a%mod;
        b/=2;
    }
    return res;
}
ll C(int a, int b){
    return f1[a]*1ll*f2[b]%mod*f2[a-b]%mod;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    f1[0] = f2[0] = 1;
    for(int i=1;i<=n+m+k;i++) f1[i] = f1[i-1]*1ll*i%mod;
    for(int i=1;i<=n+m+k;i++) f2[i] = pow2(f1[i], mod-2);
    p3[0] = 1;
    for(int i=1;i<=n+m+k;i++) p3[i] = p3[i-1]*3%mod;

    ll sum = 1, ans = 0;
    int l = 0, r = 0;
    for(int i=0;i<=m+k;i++){
        if(r > m){
            sum = (sum - C(i-1, m) + mod)%mod;
            r--;
        }
        if(i-l > k){
            sum = (sum - C(i-1, k) + mod)%mod;
            l++;
        }
        ll res = C(i+n-1, i)*1ll*sum%mod*p3[n+m+k-i-n]%mod;
        ans = (ans + res)%mod;
        sum = sum*2%mod;
        r++;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 24748
#include <iostream>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
    int a,b,c;
    REP(j,200){
    cin >> a >> b;
    if(!cin)
        return 0;
    c = a+b;
    REP(i,10){
        c/=10;
        if(c==0){
            cout << i+1 << "\n";
            break;
        }
    }
    }
}

Measured memory_bytes: 1156
# @author 

import sys

class COneQuadrillionAndOneDalmatians:
    def solve(self, tc=0):
        n = int(input()) - 1
        # for n in range(1000):
        sz = 1
        tot = 0
        while tot <= n:
            tot += 26 ** sz
            sz += 1
        sz -= 1

        ans = ""
        for i in range(1, sz):
            n -= 26 ** i
        for i in range(sz):
            ans += chr(ord('a') + (n // (26 ** (sz - i - 1))) % 26)

        print(ans)

solver = COneQuadrillionAndOneDalmatians()
input = sys.stdin.readline

solver.solve()


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

#define all(x) (x).begin(), (x).end()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int a, b, c;
  cin >> a >> b >> c;
  int n;
  cin >> n;
  while (a >= b && n--) {
    b *= 2;
  }

  while (b >= c && n--) {
    c *= 2;
  }

  if (a < b && b < c) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

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

using namespace std;

long long n, ans;
int b[105];

int main(){
	scanf("%lld", &n);
	for(int i=1; i<n; ++i)
	  scanf("%d", &b[i]);
	for(int i=1; i<n-1; ++i){
		if(b[i] <= b[i+1]){
			ans += b[i];
		} 
		else ans+=b[i+1];
	}
	ans += b[1];
	ans += b[n-1];
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main(int argc, char** argv)
{
	while (true)
	{
		std::string str;
		int val = 0;
		if (std::getline(std::cin, str))
		{
			if (str[0] == '0')
			{
				break;
			}

			for (auto c : str)
			{
				val += c - '0';
			}
		}
		std::cout << val << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3188
from collections import defaultdict

N, M = map(int, input().split())
*l, = [tuple(map(int, input().split())) for _ in range(M)]
ans = M

for i in range(M):
    d = defaultdict(list)
    for j in range(M):
        if j==i:continue
        a, b = l[j]
        d[a].append(b)
        d[b].append(a)
    q = [a]
    used = [False]*(N+1)
    used[0] = True
    used[a] = True
    while q:
        s = q.pop()
        for t in d[s]:
            if used[t]:continue
            used[t] = True
            q.append(t)
    if all(used):
        ans -= 1
print(ans)


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

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

    sort(v.begin(), v.end());

    for(int i = 0; i <= n - k; ++i)
    {
        res = min(res, v[i + k - 1] - v[i]);
    }

    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 3784
function Main(input) {
    input = input.trim().split(" ");
    var X = parseInt(input[0],10);
    var A = parseInt(input[1], 10);
    
    if (X < A){
        console.log(0);
    }
    else {
        console.log(10);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define N_MAX 102
#define W_MAX 100002
#define ll long long

using namespace std;

int n, W;

int w[N_MAX];
ll v[N_MAX];

ll dp[W_MAX];

int main()
{
    cin >> n >> W;
    for(int i = 1; i <= n; i++)
        cin >> w[i] >> v[i];
    for(int i = 1; i <= n; i++)
        for(int j = W - w[i]; j >= 0; j--)
            dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
    ll ans = -1;
    for(int i = 0; i <= W; i++)
        ans = max(ans, dp[i]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n=16,a,b;
  cin >> a >> b;
  if(a<=8&&b<=8) pr("Yay!");
  else pr(":(");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<fstream>
#include<queue>
#include<set>
#include<string>
using namespace std;
void fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main()
{
	fast();

	int a, b, x;
	cin >> a >> b >> x;
	if ((a+b)>x&&x>=a)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}



Measured memory_bytes: 3652
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    if(c-(a-b)<=0){
      System.out.println(0);
    }else{
      System.out.println(c-(a-b));
    }
    sc.close();
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define inf (1<<16)
 
int main(){
  int n;
  cin>>n;
  int a[12]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
  vector<int> dp(n+1,inf);
  dp[0]=0;
 
  for(int i=0;i<=n;++i){
    for(int j=0;j<12;++j){
      if(i+a[j]<=n)dp[i+a[j]]=min(dp[i+a[j]],dp[i]+1);
    }
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 640
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>power;
int main()
{
    cin>>n;
    cout<<n*n<<endl;
    return 0;
}
/*
5
4
3
2
3
4
4
3
3
4
2
3
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;
#define ll long long
#define ar array

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

	string S;
	cin >> S;
	
	if (S.size()==2) {
		cout << S << endl;
	} else {
		cout << S.at(2) << S.at(1) << S.at(0) << endl;
	}
	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
    #include<math.h>
    #include<stdlib.h>
     
    //D日目時点のスコアを計算
    int score(int D, int c[], int s[][26], int t[]){
        int pen_day[26]={1};
        for(int i=0; i<26; i++){
            pen_day[i]=1;
        }
        int score=0;
        
        for(int i=0; i<D; i++){
            int type=t[i]-1;
            pen_day[type]=0;
            //満足度増加
            score+=s[i][type];
            //満足度低下
            for(int j=0; j<26; j++){
                int dec=c[j]*pen_day[j];
                score-=dec;
            }
            //日数追加
            for(int j=0; j<26; j++){
                pen_day[j]++;
            }        
        }
        return score;
    }
     
    void Greedy(int D, int c[], int s[][26]){
        int t[D], max_type=0, max_score=0;
     
        for(int i=0; i<D; i++){
            max_score=0;
            for(int j=0; j<26; j++){
                t[i]=j+1;
                int S=score(i+1, c, s, t);
                if(max_score < S){
                    max_score = S;
                    max_type=j+1;
                }
            }
            t[i]=max_type;
        }
     
        //局所探索
        int new=0;
        int roop_num=0;
        int MAX=max_score;
        while(1){
            int a=rand()%D;
            int b=rand()%D;
     
            //a,bを入れ替え
            int tmp;
            tmp=t[a];
            t[a]=t[b];
            t[b]=tmp;
     
            //scoreを計算
            int now_score=score(D, c, s, t);
            if(MAX<now_score) MAX=now_score;
            else{
                tmp=t[a];
                t[a]=t[b];
                t[b]=tmp;  
            }
            new++;
            roop_num++;
            if(roop_num==D*100) break;
        }
     
        for(int i=0; i<D; i++){
            printf("%d\n", t[i]);
        }
    }
     
    int main(void){
        int D, c[26], s[365][26], t[365];
     
        //入力
        scanf("%d", &D);
        for(int i=0; i<26; i++){
            scanf("%d", &c[i]);
        }
        for(int i=0; i<D; i++){
            for(int j=0; j<26; j++){
                scanf("%d", &s[i][j]);
            }
        }
        /*
        for(int i=0; i<D; i++){
            scanf("%d", &t[i]);
        }
        */
     
       /*ここから処理*/
       /*
        int num=1;
        for(int i=0; i<D; i++){
            printf("%d\n", num);
            num++;
            if(num>26) num=1;
        }
        */
     
       Greedy(D, c, s);
     
     
        return 0;
    }

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

int main() {
  int n,i,x=0,ans=0;
  string s;
  cin>>n>>s;
  
  for(i=0;i<n;i++){
    if(s[i]=='I')
      x++;
    else if (s[i]=='D')
      x--;
    if(ans<x)
      ans=x;
  }
  cout<<ans;
  
}

Measured memory_bytes: 256
import sys

def solve():
    N = int(input())
    print("0" + "\n", flush = True)
    a = input()
    if a == "Vacant": return 0
    elif a == "Male": basis = 0
    else: basis = 1
    low, high = 0, N
    Fin = {0}
    while high - low > 1:
        mid = (low + high) // 2
        Fin |= {mid}
        print(str(mid) + "\n", flush = True)
        a = input()
        if a == "Vacant": break
        else:
            b = (0 if a == "Male" else 1)
            expected = (basis if mid % 2 == 0 else (basis + 1) % 2)
            if b != expected:
                high = mid
            else:
                low = mid
    else:
        if low in Fin: print(str(high) + "\n", flush = True)
        else: print(str(low) + "\n", flush = True)
        a = input()

    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3660