akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int H,W; cin >>H >>W;
  string check[H];
  rep(i,0,H) cin >>check[i];

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

  rep(i,0,H) {
    rep(j,0,W) {
      if (check[i][j]=='#') continue;
      int sum=0;
      rep(d,0,8) {
        int check_y=i+dy[d];
        int check_x=j+dx[d];
        if (check_y<0 or H<=check_y) continue;
        if (check_x<0 or W<=check_x) continue;
        if (check[check_y][check_x]=='#') sum++;
      }
      check[i][j]=char(sum+'0');
    }
  }
  rep(i,0,H) cout <<check[i] <<endl;
  return 0;
}


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

using namespace std;

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  if (A.back() == B.front() && B.back() == C.front()) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin

mod = 1000000007

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m, k = na()

def invl(a, mod):
    b = mod
    p = 1; q = 0
    while b > 0:
        c = a // b
        a, b = b, a%b
        p, q = q, p-c*q
    return p + mod if p < 0 else p

num = 1
den = 1
for u in range(k-2):
    num = num * (n*m-2-u) % mod
for u in range(k-2):
    den = den * (1+u) % mod
C = num * invl(den, mod) % mod

# 10 7 6 7 10
# i i-1 .. 0 .. n-1-i
# sum_i (i*(i+1)//2 + (n-1-i)*(n-i)//2)*m
# n*(n+1)*(n+2)//6*2*m

v = n*(n+1)*(n-1)//3*m*m + m*(m+1)*(m-1)//3*n*n
v *= C
print(v*invl(2,mod)%mod)


Measured memory_bytes: 38768
import sys
readline = sys.stdin.readline

N,A,B = map(int,readline().split())
V = list(map(int,readline().split()))

# 大きいほうからA個選んだときの平均値が求める平均値
# 大きいほうからA位の数字をPとすると、
# ・A位までの数字がすべてPのとき：Pの個数から、A～B個選ぶ場合の数
# ・そうでないとき：Pの個数から、A位までに必要なPの個数を選ぶ場合の数

V = sorted(V, reverse = True)

print(sum(V[:A]) / A)

from scipy.special import comb

P = V[A - 1]
pcnt = V.count(P)

if V[0] == P:
  ans = 0
  for i in range(A, B + 1):
    ans += comb(pcnt, i, exact = True)
  print(ans)
else:
  pneed = (V[:A]).count(P)
  print(comb(pcnt, pneed, exact = True))


Measured memory_bytes: 42368
#include<stdio.h>

int main(void)
{
  int m;
  short dice;
  short west;
  short east;
  short north;
  short south;
  short back;
  short dice2;
  char b[5];
  char n = 'n';
  char s = 's';
  char w = 'w';
  char e = 'e';

  while(1){
    dice = 1;
    west = 3;
    east = 4;
    north = 2;
    south = 5;
    back = 6;
    scanf("%d",&m);
    if(m == 0){
      break;
    }

    while(m-- > 0){
      scanf("%s",b);

      if(b[0] == n){
        dice2 = south;
        south = back;
        back = north;
        north = dice;
        dice = dice2;
      }
      else if(b[0] == s){
        dice2 = north;
        north = back;
        back = south;
        south = dice;
        dice = dice2;
      }
      else if(b[0] == w){
        dice2 = east;
        east = back;
        back = west;
        west = dice;
        dice = dice2;
      }
      else if(b[0] == e){
        dice2 = west;
        west = back;
        back = east;
        east = dice;
        dice = dice2;
      }

    }
    printf("%d\n",dice);
  }
  return 0;
}

Measured memory_bytes: 604
#include <stdio.h>
#include <stdlib.h>

int main(){
	int d = 0;
	int l[100];
	int n,x;
	int i;
	int count = 1;

	scanf("%d %d", &n, &x);
	for(i = 0; i < n; i++){	
		scanf("%d", &l[i]);
	}

	for(i = 0; i < n; i++){
		d += l[i];
		if(d <= x) count++;
	}
	printf("%d", count);

}

Measured memory_bytes: 128
N = int(input())
time = [int(input()) for _ in range(5)]

cnt = 0
neck = float("inf")
for t in time:
  times = int(N / t)
  if N % t != 0:
    times += 1
  times_n = int(N / neck)
  if N % neck != 0:
    times_n += 1
  if times > times_n:
    cnt += times - times_n + 1
    neck = t
  else:
    cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define ll long long
#define sz(x) (int)(x.size())
#define pb push_back
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (long long)(1e9) + 123;
const int mod = 1000000007;
const double eps = 1e-9;


signed main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    string s; cin >> s;
    string a = s.substr(0, n / 2);
    string b = s.substr(n / 2);
    if (n & 1 || a != b) {
        cout << "No";
        return 0;
    }
        cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }


int main(){
    ll s,w; cin>>s>>w;
    if(s<=w) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
AC=0
WA=0
TLE=0
RE=0
for i in range(N):
  d = input()
  if d=="AC":
    AC+=1
  elif d=="WA":
    WA+=1
  elif d=="TLE":
    TLE+=1
  elif d=="RE":
    RE+=1
    
print("AC x", AC)
print("WA x", WA)
print("TLE x", TLE)
print("RE x", RE)


Measured memory_bytes: 9084
#include <iostream>

using namespace std;

int calcg(int A, int K) {
    if (A < K) return 0;
    if (A % K == 0) return A / K;

    int dec = A / K + 1;
    A -= ((A % K - 1) / dec + 1) * dec;
    return calcg(A, K);
}

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

    int x = 0;
    for (int i = 0; i < N; ++i) {
        int A, K;
        cin >> A >> K;
        x ^= calcg(A, K);
    }
    cout << (x == 0 ? "Aoki" : "Takahashi") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  for(;;){
    int n;
    cin >> n;
    if(n==0) break;
    bool bminus = false;
    if(n < 0){
      bminus = true;
      n *= -1;
    }
    vector<int> v;
    while(n != 0){
      int d = n % 10;
      if(d == 0){
      }else if(bminus){
        d = 10 - d;
        n += d;
      }else{
        n -= d;
      }
      v.push_back(d);
      n /= 10;
      bminus = !bminus;
    }
    for(int i=v.size()-1; i>=0; i--){
      cout << v[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<string>
#include<string.h>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<deque>
#include<queue>
#include<math.h>
#include<chrono>
#include<list>
#include<random>
#include<bitset>
#include<assert.h>
#include<ctime>
#include<cstdio>
#include <unordered_map>
using namespace std;
ifstream fi("input.txt");
ofstream fo("output.txt");
#define fast_input() {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
#define ll long long
#define For(i,n) for (int(i) = 0; (i)<(n); (i)++)
#define For1(i,n) for (int(i) = 1; (i) <= (n); (i)++)
#define Forlr(i,l,r) for (int(i) = (l); (i) <= (r); (i)++)
#define Forrl(i,r,l) for (int(i) = (r); (i) >= (l); (i)--)
#define all(a) a.begin(), a.end() 
#define pb push_back
#define pp pop_back
#define mp make_pair
#define PI 3.14159265
#define putno return cout <<"NO", 0;
#define putyes return cout <<"YES", 0;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef map<int, int> mii;
//const ll MOD = 1e9 + 7;
const int N = 1e5 + 5;
//DSU
/*
int p[ N], r[N];
void init(int n) {
	For(i, n) {
		p[i] = i;
	}
}
int get(int x) {
	if (p[x] != x) {
		p[x] = get(p[x]);
	}
	return p[x];
}
bool uni(int x, int y) {
	x = get(x); y = get(y);
	if (x == y) {
		return false;
	}
	if (r[x] >= r[y]) {
		p[y] = x;
	}
	else {
		p[x] = y;
	}
	if (r[x] == r[y]) {
		r[x]++;
	}
	return true;
}
*/

// So mu
/*
int power(int x, unsigned int y, int p)
{
	int res = 1; // Initialize result

	x = x % p; // Update x if it is more than or
	// equal to p

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res*x) % p;

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x*x) % p;
	}
	return res;
}
*/

// ReadHexa
/*
bitset<16400> b[4101];
void readHexa()
{
	For(i, n)
	{
		string st;
		cin>> st;
		For(j, m/4)
		{
			int x;
			if (st[j] >= 'A' && st[j] <= 'F')
				x = st[j] - 'A' + 10;
			else x = st[j] - '0';
			for (int k = 4; k; --k, x >>= 1)
				b[i][j * 4 + k] = x & 1;
		}
	}
}
*/

// nChoosek
/*
ll nChoosek(ll n, ll k)
{
	if (k > n) return 0;
	if (k * 2 > n) k = n - k;
	if (k == 0) return 1;

	ll result = n;
	for (ll i = 2; i <= k; ++i) {
		result *= (n - i + 1);
		result /= i;
	}
	return result;
}
*/

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
MIKUNO - 15/02/1999
*/
int n, m, k, cnt, rs1;
//	priority_queue <ll, vector<ll>, greater<ll> > q;
//ll n, m, q, k, pos, t, cnt, rs1, check;
ll maxx = -1e9, minn = 1e9;
const int maxn = 1005;
const ll MOD = 1e9 + 7;
int rs;
string t = "ACGT";
int main()
{
	fast_input();
	char s;
	cin >> s;
	if (s == 'A') cout << "T";
	if (s == 'T') cout << "A";
	if (s == 'C') cout << "G";
	if (s == 'G') cout << "C";
}

Measured memory_bytes: 256
n = int(input())
L = list(map(int,input().split()))
total = sum(L)
ans = [0]*n
k = 0
for i in range(0,n-1,2):
  k += L[i]*2
ans[n-1] = total-k
ans[0] = L[n-1]*2-ans[n-1]
for i in range(1,n-1):
  ans[i] = L[i-1]*2-ans[i-1]
print(' '.join(map(str,ans)))

Measured memory_bytes: 19092
#include<bits/stdc++.h>
using namespace std;
int i,j,n;
char a,b,c;
string s,t,u;
int main(){
  for(cin>>n>>s;i<1000;i++){
    a=char(i/100+'0');b=char((i%100)/10+'0');c=char(i%10+'0');
    if(s.find(a)!=string::npos){
      t=s.substr(s.find(a)+1,n-s.find(a)+1);
      if(t.find(b)!=string::npos){
        u=t.substr(t.find(b)+1,t.size()-t.find(b)+1);
        if(u.find(c)!=string::npos)j++;
      }
    }
  }
  cout<<j;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



string s;
void solve(){
	cin >> s;
	int n = s.size();
	
	int ans = 0;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'S'){
			cnt++;
		}
		else{
			if(cnt) cnt--;
			else ans++;
		}
	}
	cnt = 0;
	for(int i = n-1; i >= 0; i--){
		if(s[i] == 'T'){
			cnt++;
		}
		else{
			if(cnt) cnt--;
			else ans++;
		}
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 720
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int[] s = new int[4];
		int[] t = new int[2];
		
		t[0] = sc.nextInt();
		s[0] = sc.nextInt();
		s[3] = sc.nextInt();
		s[1] = sc.nextInt();
		s[2] = sc.nextInt();
		t[1] = sc.nextInt();
		
		String command = sc.next();
		
		for(int i = 0; i < command.length(); i++) {
			char c = command.charAt(i);
			
			if(c == 'N') {
				int x = t[0];
				t[0] = s[0];
				s[0] = t[1];
				t[1] = s[2];
				s[2] = x;
			}else if(c == 'S') {
				int x = t[0];
				t[0] = s[2];
				s[2] = t[1];
				t[1] = s[0];
				s[0] = x;
			}else if(c == 'E') {
				int x = t[0];
				t[0] = s[1];
				s[1] = t[1];
				t[1] = s[3];
				s[3] = x;
			}else {
				int x = t[0];
				t[0] = s[3];
				s[3] = t[1];
				t[1] = s[1];
				s[1] = x;
			}
		}
		
		System.out.println(t[0]);
	}
}


Measured memory_bytes: 26184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

const ll INF = 1LL << 60;

vector<vector<int>> dp(100010, vector<int>(3, 0));

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1);
    vector<int> B(N + 1);
    vector<int> C(N + 1);
    for (int i = 1; i <= N; i++) {
        scanf("%d %d %d", &A[i], &B[i], &C[i]);
    }

    for (int i = 1; i <= N; i++) {
        chmax(dp[i][0], dp[i - 1][1] + A[i]);
        chmax(dp[i][0], dp[i - 1][2] + A[i]);

        chmax(dp[i][1], dp[i - 1][0] + B[i]);
        chmax(dp[i][1], dp[i - 1][2] + B[i]);

        chmax(dp[i][2], dp[i - 1][0] + C[i]);
        chmax(dp[i][2], dp[i - 1][1] + C[i]);
    }
    
    int ans = 0;
    chmax(ans, dp[N][0]);
    chmax(ans, dp[N][1]);
    chmax(ans, dp[N][2]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
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;
}
int main(){
    ll N;cin>>N;
    vector<ll>A(N);
    vector<ll>B(N);
    rep(i,N){
        cin>>A[i]>>B[i];
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    ll MA,MB;
    if(N%2==1){
        MA=A[(N-1)/2];
        MB=B[(N-1)/2];
        cout<<MB-MA+1<<endl;
    }
    else{
        MA=A[N/2-1]+A[N/2];
        MB=B[N/2-1]+B[N/2];
        cout<<MB-MA+1<<endl;
    }
}

Measured memory_bytes: 6428
import java.util.Scanner;

public class Main{ 
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            if(a>b){
                System.out.println("a > b");
            }else if(a<b){
                System.out.println("a < b");
            }else if(a==b){
                System.out.println("a == b");
            }
        }
}


Measured memory_bytes: 26400
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 1e9

int N;

bool isH(vector<int> h){
    bool flag=true;
    for (int i=0;i<N;i++){
        if (h[i]!=0) flag=false;
    }
    return flag;
}



int main(void){

    cin>>N;
    vector<int> h(N+1,0);
    for (int i=0;i<N;i++) cin>>h[i];

    ll ans=0;

    while(!isH(h)){
        int start=0;
        int end=N-1;
        for (int i=0;i<N;i++){
            if (h[i]!=0) {
                start=i;
                break;
            }
        }
        for (int i=start+1;i<=N;i++){
            if (h[i]==0){
                end=i;
                break;
            }
        }

        for (int i=start;i<end;i++){
            h[i]--;
        }
        ans++;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<functional>
#include<map>
using namespace std;

int main() {
	int a, b, c;
	while (cin >> a >> b >> c, a || b || c) {
		int s = 0;
		for (int d = 1; d < (1 << a); d++) {
			int g = 0, h = 0;
			for (int e = 1, f = 1; e <= a; e++, f <<= 1) {
				if (d&f) {
					g++;
					h += e;
				}
			}
			if (g == b&&c == h)s++;
		}
		cout <<s<< endl;
	}
}

Measured memory_bytes: 2936
N, Y = map(int, input().split())

for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - x - y
        if z >= 0 and 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()

print('-1 -1 -1')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  int sum=s.size();
  for(int i=0;i<sum-8;i++){
    cout<<s[i];
  }
  cout<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
using pis = pair<int,string>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  long n,k;
  cin >> n >> k;
  vector<long> a(n);
  rep(i,n){
    cin >> a.at(i);
    a.at(i)--;
    if(a.at(i) < 0) a.at(i) += k;
    a.at(i) %= k;
  }
  vector<long> sum(n+1,0);
  rep(i,n){
    sum.at(i+1) = sum.at(i) + a.at(i);
    sum.at(i+1) %= k;
  }
  map<long,long> mp;
  rep(i,n+1){
    long tmp = sum.at(i);
    mp[tmp] = 0;
  }
  int id = 0;
  vvi data(mp.size());
  for(auto P : mp){
    mp.at(P.first) = id;
    id++;
  }
  rep(i,n+1){
    int num = mp.at(sum.at(i));
    data.at(num).push_back(i);
  }
  
  long ans = 0;
  rep(i,mp.size()){
    rep(j,data.at(i).size()){
      int iter = lower_bound(data.at(i).begin(),data.at(i).end(),data.at(i).at(j)+k) - data.at(i).begin();
      int comb = iter - 1 - j;
      ans += comb;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 26752
s = list(input())
l2r = [0]
r2l = [0]
n = len(s)
for i in range(n):
  if s[i] == '<':
    l = l2r[i]
    l2r.append(l+1)
  else:
    l2r.append(0)

for j in range(n):
  if s[n-1-j] == '>':
    r2l.append(r2l[j]+1)
  else:
    r2l.append(0)
invr2l = r2l[::-1]
ans = []
for i in range(n+1):
  m = max(l2r[i],invr2l[i])
  ans.append(m)

print(sum(ans))


Measured memory_bytes: 44704
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
vector <int> g[N];
vector <int> y[N];
ll h1[N],h2[N];
ll par[N];
void dfsg(ll v,ll p,ll h){
    h1[v]=h;
    for (auto u : g[v]){
        if (u==p) continue;
        dfsg(u,v,h+1);
    }
}
void dfsy(ll v,ll p,ll h){
    h2[v]=h;
    par[v]=p;
    for (auto u : y[v]){
        if (u==p) continue;
        dfsy(u,v,h+1);
    }
}
ll check(ll u,ll v){
    if (par[u]==par[v] || u==par[v] || v==par[u] || v==par[par[u]] || u==par[par[v]]) return 0;
    return 1;
}
ll dp[N];
void dfs(ll v,ll p){
    if (h1[v]>=h2[v]) return ;
    dp[v]=h2[v]-h1[v];
    dp[v]*=2;
    for (auto u : g[v]){
        if (p==u) continue;
        dfs(u,v);
        dp[v]=max(dp[v],dp[u]+2);
        if (check(u,v)) dp[v]=1e9;
    }
}
int32_t main(){
    ll n,x,y1;
    cin >> n >> x >> y1;
    for (int i=0;i<n-1;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    for (int i=0;i<n-1;i++){
        ll u,v;
        cin >> u >> v;
        y[u].pb(v);
        y[v].pb(u);
    }
    dfsg(x,x,1);
    dfsy(y1,y1,1);
    dfs(x,x);
    if (dp[x]>=1e9) kill(-1);
    kill(dp[x]);

}


Measured memory_bytes: 43184
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
int main() {
  string s;
  cin >> s;
  long long num = atoi(s.c_str()), sum = 0;
  rep(i,s.size())
  {
    sum += s[i] - '0';
  }
  cout <<(num % sum ? "No" : "Yes");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a; i < b; ++i)

int main()
{
    ll A, B; string op;
    cin >> A >> op >> B;
    if(op[0] == '+') cout << A + B << endl;
    else cout << A - B << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

	if (a == b) {
		if (b == c) {
			cout << "1";
		}
		else {
			cout << "2";
		}
	}
	else if (a == c || b == c) {
		cout << "2";
	}
	else {
		cout << "3";
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
//#include <fstream>

int count_course(const u_int a, const u_int b, const std::map<u_int, std::vector<u_int>> &point)
{
    auto it = point.find(a);
    if(it != point.end()){
        std::vector<u_int> vec = it -> second;
        if((std::find(vec.begin(), vec.end(), b)) != vec.end()){
            return 0;
        }
    }
    if(a == 1 && b == 1){
        return 1;
    }
    else if(a == 1){
        return count_course(a, b - 1, point);
    }
    else if(b == 1){
        return count_course(a - 1, b, point);
    }
    else{
        return count_course(a - 1, b, point) + count_course(a, b - 1, point);
    }
}

int main()
{
    u_int a, b, n, x, y;
    //std::ifstream ifs("--.txt");
    while(1){
        u_int m = 0;
        std::cin /*ifs*/ >> a >> b;
        if(a == 0 && b == 0)
            break;
        
        std::map<u_int, std::vector<u_int>> point;
        std::cin /*ifs*/ >> n;
        for(u_int i = 0; i < n; ++i){
            std::cin /*ifs*/ >> x >> y;
            point[x].push_back(y);
        }
  
        m += count_course(a, b, point);
        std::cout << m << std::endl;    
    }
    //ifs.close();

    return 0;
}

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

using namespace std;

#define endl "\n"
#define lln long long int
#define IOS ios::sync_with_stdio(0);cin.tie(0);

vector<int> hm(100003);

int main(){
    IOS;

    int n;
    cin >> n;
    for(int i=0,val;i<n;i++){
        cin >> val;
        if(val-1<0) hm[100002]++;
        else hm[val - 1]++;
        hm[val+1]++;
        hm[val]++;
    }
    int ma = 0;
    for(int i=0;i<100003;i++){
        ma = max(ma,hm[i]);
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 3616
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      amount = 500*i + 100*j + 50*k
      if amount ==x:
        ans +=1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    int p[20];
    for(int i = 0; i < n; i++) cin >> p[i];

    int max = -1;
    for(int i = 0; i < n; i++){
        if(p[i] > max) max = p[i];
    }

    int total = 0;
    for(int i = 0; i < n; i++)  total += p[i];

    cout << total - max + max/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 100005
#define M 10000007
#define O 1000000009
#define vl vector<long>
#define vll vector<long long>
#define disp(n) cout<<n<<endl
#define fo(i,N) for(int i=0; i<N; ++i)
#define fos(i,b,N) for(int i=b; i<N; ++i)
#define forr(i,N) for(i=N; i>=0; --i)

using namespace std;
 
int main()
{
    long n, i;
    cin >> n;
    long a[n][3];
    long dp[n + 1][3] = {0};
    for(i = 0; i < n; ++i)
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    
    dp[1][0] = a[0][0];
    dp[1][1] = a[0][1];
    dp[1][2] = a[0][2];

    for(i = 2; i <= n; ++i) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i - 1][0];
        dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + a[i - 1][1];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + a[i - 1][2];
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]});
    return 0;
}

Measured memory_bytes: 8284
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const ll Mod = 1e9+7;
const int maxn = 2100;

int n,m;
ll c[maxn][maxn],pc[maxn][maxn];
ll f[maxn][maxn],g[maxn][maxn];

int main()
{
	scanf("%d%d",&n,&m);
	c[0][0]=1ll; pc[0][0]=1ll;
	for(int i=1;i<maxn;i++)
	{
		c[i][0]=1ll; pc[i][0]=1ll;
		for(int j=1;j<=i;j++) 
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%Mod,
			pc[i][j]=(pc[i][j-1]+c[i][j])%Mod;
	}
	for(int i=0;i<=n;i++) f[i][0]=g[i][0]=1ll;
	for(int i=0;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			f[i][j]=pc[j-1][min(i,j-1)];
	}
	for(int j=1;j<=m;j++)
	{
		g[0][j]=f[0][j];
		for(int i=1;i<=n;i++) g[i][j]=(g[i-1][j]+f[i][j])%Mod;
	}
	ll ans=1;
	for(int i=n;i>=1;i--)
	{
		for(int y=0,u=min(m-1,i);y<=u;y++)
		{
			int x=i-y; //(i,m-1) -> (x,y)
			ans+=g[x][y]*c[i+m-1-x-y][i-x]%Mod;
		}
	}
	ans%=Mod;
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 138112
using System;
using System.Linq;
using System.Collections.Generic;

namespace Aojx
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                double x = double.Parse(Console.ReadLine());
                double h = double.Parse(Console.ReadLine());

                if (x == 0 && h == 0)
                {
                    break;
                }

                double answer =
                    Math.Pow(x, 2) + 2 * x *
                    Math.Sqrt(Math.Pow(h, 2) + Math.Pow(x / 2, 2));

                Console.WriteLine("{0:F6}", answer);
            }
        }
    }
}

Measured memory_bytes: 5732
use std::cmp::max;

// ref. https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        w: usize,
        v: [[usize;2];n]
    }

    let mut dp: Vec<Vec<usize>> = vec![vec![0;w+1];n+1];

    for n_ in 0..n{
        for sum_weight in 0..w+1{
            dp[n_+1][sum_weight] = if v[n_][0] <= sum_weight {
                max(dp[n_][sum_weight], dp[n_][sum_weight-v[n_][0]]+v[n_][1])
            }else{
                dp[n_][sum_weight]
            }
        }
    }
    println!("{:?}", dp[n][w])
}


Measured memory_bytes: 106876
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int x, a, b;

	cin >> x >> a >> b;
	x -= a;
	while (1) {
		x -= b;
		if (x < 0) {
			cout << x + b << endl;
			break;
		}
		else if (x == 0) {
			cout << 0 << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

x = I()
if x == 7 or x == 5 or x == 3:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 63340
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 10e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  int X,A,B;
  cin >> X >> A >> B;
  cout << (X-A) % B << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int N,K;
	cin>>N>>K;
	cout<<N-K+1;
}

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

#define inp 200005
#define check exit(0)
#define nl cout<<endl;
#define mod 1000000007 
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(v) for(int i=0;i<v.size();i++) {cout<<v[i]; (i==v.size()-1) ? cout<<"\n":cout<<" "; }

using namespace std;

// Pick yourself up, 'cause...

const ll inf=1e15;

int main()
{
    jaldi

    int n;
    cin>>n;

    vector<int> v(n);
    for(int &x:v) cin>>x;

    vector<vector<ll>> dp(n+1,vector<ll>(n+1,inf));

    vector<ll> pre(n,0);
    pre[0]=v[0];
    for(int i=1;i<n;i++) pre[i]=pre[i-1]+v[i];

    for(int i=n-1;i>=0;i--)
    {
        for(int j=i;j<n;j++)
        {
            if(i==j) { dp[i][j]=0; continue; }
            ll add=pre[j];
            if(i) add-=pre[i-1];
            for(int k=i;k<=j-1;k++)
            {
                dp[i][j]=min(dp[i][j] , dp[i][k]+dp[k+1][j]+add);
            }
        }
    }
    cout<<dp[0][n-1];
    
    return 0;
}

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

struct Line {
    long long m, c;

    long long eval(int x) {
        return m * x + c;
    }

    double intersect(Line &l) {
        return (double) (c - l.c) / (l.m - m);
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    long long c;
    cin >> n >> c;

    int h;
    cin >> h;

    long long ret = 0;
    deque<Line> dq;
    dq.push_back({-2 * h, (long long) h * h});
    for (int i=1; i<n; i++) {
        cin >> h;

        while (dq.size() >= 2 && dq.front().eval(h) >= dq[1].eval(h))
            dq.pop_front();
        ret = dq.front().eval(h) + (long long) h * h + c;

        Line cur = {-2 * h, ret + (long long) h * h};
        while (dq.size() >= 2 && cur.intersect(dq.back()) <= dq.back().intersect(dq[dq.size()-2]))
            dq.pop_back();
        dq.push_back(cur);
    }

    cout << ret << "\n";

    return 0;
}


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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
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; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	ll k , n;
	cin >> k  >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	a.push_back(k+a[0]);
	ll sum = 0;
	ll my_M = 0 ;
	rep(i,n){
		ll tmp = abs(a[i+1] - a[i]);
		chmax(my_M,tmp);
		sum += tmp;
	}
	sum -= my_M;
	cout << sum << endl;

}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

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

  int n, m; cin >> n >> m;
  vi a(n);
  int su = 0;
  for(int i=0;i<n;++i) {
    cin >> a[i];
    su += a[i];
  }

  ld tmp = (ld)su / (4*m);

  int cnt = 0;
  for(int i=0;i<n;++i) {
    if(a[i] > tmp - eps) cnt++;
  }
  cout << (cnt >= m ? "Yes" : "No") << endl;
  
}


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

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n), v(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> q[i];
        v[i] = i + 1;
    }
    int a, b, cnt = 0;
    do {
        if (p == v) a = cnt;
        if (q == v) b = cnt;
        cnt++;
    } while (next_permutation(v.begin(), v.end()));
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let stdin = io::stdin();
    let mut line = String::new();
    stdin.read_line(&mut line).ok();
    let txt:Vec<_> = line.trim().split(' ').collect();
    let a:i32 = txt[0].parse().unwrap();

    let mut result = "ABC";
    if a <= 999 {
        result = "ABC";
    }
    else {
        result = "ABD";
    }

    println!("{}", result);
}



Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<stack>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)

vector<int> card[10];
map<stack<int> ,int> check;
int visit[10];

stack<int> ub;
int cont;

void saiki(int dep,int k,int n){
	if(dep==k){
		if(check[ub]==0){
			check[ub]=1;
			cont++;
		}
		return;
	}
	
	rep(i,n){
		if(visit[i]==0){
			visit[i]=1;
			rep(j,card[i].size()){
				ub.push(card[i][j]);
			}
			
			saiki(dep+1,k,n);
			
			rep(j,card[i].size()){
				ub.pop();
			}
			visit[i]=0;
		}
	}
}

int main(){
	while(1){
		int n;
		int k;
		
		scanf("%d%d",&n,&k);
		if(n==0)break;
		
		rep(i,10){
			card[i].clear();
			visit[i]=0;
		}
		
		check.clear();
		cont=0;
		
		rep(i,n){
			int a;
			scanf("%d",&a);
			
			if(a<10){
				card[i].push_back(a);
			}else{
				card[i].push_back(a/10);
				card[i].push_back(a%10);
			}
		}
		
		saiki(0,k,n);
		
		printf("%d\n",cont);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define whatis(x) cerr << #x << " is " << (x) << endl;
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
#define umap unordered_map
#define uset unordered_set
using namespace std;
using namespace __gnu_pbds;

#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> P) { for(auto const &vv: P)os<<"("<<vv.first<<","<<vv.second<<")"; return os; }
template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 1000001

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a,b;
    sc(a,b);
    if(abs(a-b)&1) REE("IMPOSSIBLE")
    cout << (a+b)/2 << '\n';
}



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

using namespace std;

int main()
{
    string s; cin >> s;
    int r = 0;
    for (int i = 1; i < s.size(); ++i)
        if (s[i] != s[i-1])
            ++r;
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 512
//状态:
//题号:
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <iomanip>
#include <cassert>
#include <complex>
#include <functional>
#include <list>
using namespace std;
typedef pair<int,int> pii;
const int INF=1e9+7;
int dp[100005];
int n,m;
vector<pii> nei[100005];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		a--;
		b--;
		nei[a].push_back(make_pair(b,c));
		nei[b].push_back(make_pair(a,-c));
	}
	fill(dp,dp+100005,INF);
	for(int i=0;i<n;i++){
		if(dp[i]==INF){
			//f/or(int i=0;i<n;i++){
				//c/out<<dp[i]<<" ";
			//}
			//cout<<endl;
			queue<int> q;
			q.push(i);
			dp[i]=0;
			for(;q.size();){
				int t=q.front();q.pop();
				for(int j=0;j<nei[t].size();j++){
					pii p=nei[t][j];
					int pp=p.first,c=p.second;
					if(dp[pp]==INF){
						dp[pp]=dp[t]+c;
						q.push(pp);
					}
					else if(dp[pp]!=dp[t]+c){
						puts("No");
						return 0;
					}
				}
			}
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 9344
import java.util.Deque;
import java.util.LinkedList;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {

	public static void main(String[] args) {

		InputOutput stdIO = new InputOutput();

		int n = stdIO.getValue();
		Deque<Integer> dll = new LinkedList<>();

		int value;
		String[] inputline;

		long t1 = System.nanoTime();

		for (int i = 0; i < n; i++) {
			inputline = stdIO.getLineStringArray();
			switch (inputline[0]) {
			case "insert":
				insert(dll, Integer.parseInt(inputline[1]));
				break;
			case "delete":
				delete(dll, Integer.parseInt(inputline[1]));
				break;
			case "deleteFirst":
				deleteFirst(dll);
				break;
			case "deleteLast":
				deleteLast(dll);
				break;
			}
		}
		long t2 = System.nanoTime();

                StringBuilder sb = new StringBuilder();
		int size = dll.size();
		for (int i = 0; i < size; i++) {
			sb.append(dll.pop() + " ");
		}
		sb.delete(sb.length() - 1, sb.length());
		System.out.println(sb);
		stdIO.close();
	}

	private static void insert(Deque<Integer> dll, int value) {
		dll.push(value);
	}

	private static void delete(Deque<Integer> dll, int value) {
		dll.remove((Integer) value);
	}

	private static void deleteFirst(Deque<Integer> dll) {
		dll.removeFirst();
	}

	private static void deleteLast(Deque<Integer> dll) {
		dll.removeLast();
	}
}
class InputOutput {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public int getValue() {
		int n = 0;
		try {
			n = Integer.parseInt(br.readLine());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return n;
	}
	public String[] getLineStringArray() {
		try {
			return br.readLine().trim().split(" ");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}


	public void close() {
		try {
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

const int MAX_W = 50;
const int MAX_H = 20;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int H, W;
bool ok[MAX_H][MAX_W];
char maze[MAX_H][MAX_W+1];
int sx, sy;

inline bool check(int hx, int hy){ return 0 <= hx && hx < H && 0 <= hy && hy < W; }

int main()
{
  while((cin >> W >> H) && W){
    rep(i, H) cin >> maze[i];

    rep(i, H) rep(j, W) ok[i][j] = false;
    rep(i, H) rep(j, W) if(maze[i][j] == '@') sx = i,  sy = j;

    stack<pii> st;
    st.push(mp(sx, sy));
    maze[sx][sy] = '.';
    ok[sx][sy] = true;
    while(!st.empty()){
      pii here = st.top();  st.pop();
      int hx = here.first;
      int hy = here.second;
      rep(k, 4){
        int nx = hx + dx[k];
        int ny = hy + dy[k];
        if(!check(nx, ny) || maze[nx][ny] == '#') continue;
        if(ok[nx][ny]) continue;
        ok[nx][ny] = true;
        st.push(mp(nx, ny));
      }
    }

    int res = 0;
    rep(i, H) rep(j, W) if(ok[i][j]) res += 1;
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1204
import java.util.*;

public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  
// 整数の入力
int days = sc.nextInt();
int homeworks = sc.nextInt();
int sum = 0;
int temp =0;
  for (int i=0;i<homeworks;i++){
  temp = sc.nextInt();
    sum += temp;
  }
  
  int result = days- sum;
  if (result < 0){
  result = -1;
  }
System.out.println(result);
}
}

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

int main()
{
    int $=1;
    //cin>>$;
    while($--)
    {
        long long n,a=0;
        cin>>n;
        a+=(n/500)*1000;
        n%=500;
        a+=(n/5)*5;
        cout<<a<<endl;
    }
}


/*
8888888888888888888888888888
    Md. Masud Mazumder
    University of Chittagong
    Department of CSE
8888888888888888888888888888
*/


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

using namespace std;

const int INF=1<<29;//十分大きな値にする

//入力
int n,A;
int h[100010];

//DPテーブル
int dp[100010];
//dp[i+1][j]:=i番目までの整数のなかから総和がjとする方法そ全て考えたときのコストの最小値
int main(){
cin >>n;
for(int i=1;i<=n;++i)cin >>h[i];//初期条件
//一旦全てINFに
for(int i=0;i<10010;++i)dp[i]=INF;
dp[1]=0;//dp[1]だけ0に=1番目の足場にたどり着くコスト=0
dp[2]=abs(h[1]-h[2]);
for(int i=1;i<=n-2;i++){
    dp[i+2]=min(dp[i+1]+abs(h[i+1]-h[i+2]),dp[i]+abs(h[i]-h[i+2]));
    
}

cout <<dp[n]<<endl;

}

Measured memory_bytes: 1024