akhauriyash/Code-Regression huggingface dataset:
#define comment Em_di_chep_code_:(

#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define mset(x, i) memset(x,i,sizeof(x))
#define elif else if
#define heap priority_queue
#define fi first
#define se second
#define pb push_back
#define ld long double
#define ll long long
#define ull unsigned long long
#define task ""
using namespace std;

int typetest;
template<class T>
void read(T &x){
    register int c;
    T neg = 1;
    x = (T)0;
    while ((c = getchar()) <= 47 || c >= 58)
		if(c == '-') neg = -1;
    for (; (c > 47 && c < 58); c = getchar()){
        x = (x << 3) + (x << 1) + (T)(c - 48);
    }
	x *= neg;
}
inline void fastIOfileinput(){
	ios_base:: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen(task".INP", "r", stdin);
//	freopen(task".OUT", "w", stdout);
//	freopen(task".in", "r", stdin);
//	freopen(task".out", "w", stdout);
	typetest = 0;
}
struct quan{
	int l, r;
	ll v;
};

const int N = 2e3 + 2;
int n, m = 0, id[N];
ll a[N], dp[N][N];

bool lef(int x, int y){
	return a[x] > a[y];
}

void Enter(){
	mset(dp, -1);
	read(n);
	for(int i = 1; i <= n; ++i)
		read(a[i]), id[i] = i;
	sort(id + 1, id + n + 1, lef);
}

ll f(int l, int r){
	if(r < l)
		return 0;
	if(dp[l][r] != -1)
		return dp[l][r];
	int i = n - r + l;
	return dp[l][r] = max(a[id[i]] * abs(id[i] - l) + f(l + 1, r),
						  a[id[i]] * abs(id[i] - r) + f(l, r - 1));
}

void Solve(){
	cout << f(1, n);
}

signed main(){
	fastIOfileinput();
	if(typetest){
		int t;
		cin >> t;
		while(t--){
			Enter();
			Solve();
		}
	}
	else{
		Enter();
		Solve();
	}
}


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

int main(){
  int N, M;  
  cin >> N >> M;
  
  vector<int> A(M); 

  for(int i = 0; i < M; i++){
    cin >> A.at(i);
  }
  
  int sum = 0;
  for(int i = 0; i < M; i++){
    sum += A.at(i);
  }
  
  int ans = N - sum;
  if(ans < 0){
    ans = -1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3640
# YouTube
from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)

def dfs(i, oi=-1, d=0):
    dep[d] += [i]
    oya[i] = oi
    for ki in to[i]:
        if ki == oi: continue
        if oya[ki] > -2:
            if i < ki:
                print(i + 1, ki + 1)
                ne[i] += 1
            continue
        dfs(ki, i, d + 1)

to = defaultdict(list)
dep = defaultdict(list)
n, m = map(int, input().split())
if m % 2:
    print(-1)
    exit()
oya = [-2] * n
ne = [0] * n
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a] += [b]
    to[b] += [a]
dfs(0)
for k, v in sorted(dep.items(), reverse=True):
    for i in v:
        if ne[i] % 2:
            print(i + 1, oya[i] + 1)
        else:
            print(oya[i] + 1, i + 1)
            ne[oya[i]] += 1
    if k == 1: break


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

#define task "A"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
string s, t, u;
int a, b;
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> s >> t >> a >> b >> u;
	if (s == u) a--;
	else if (t == u) b--;
	cout << a << ' ' << b;
}


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

class UnionFind {
public:
    UnionFind(int n) : par(n), rnk(n, 1) {
        rep(i, 0, n) par[i] = i;
    }

    int root(int a) {
        if (par[a] == a) return a;
        return par[a] = root(par[a]);
    }

    void unite(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rnk[a] > rnk[b]) swap(a, b);
        par[a] = b;
        rnk[b] += rnk[a];
    }

    bool same(int a, int b) {
        return root(a) == root(b);
    }

private:
    vector<int> par, rnk;
};

int main() {
    int n, m;
    cin >> n >> m;

    vector<int> p(n);
    rep(i, 0, n) cin >> p[i];

    UnionFind uf(n);

    rep(i, 0, m) {
        int x, y;
        cin >> x >> y;
        uf.unite(--x, --y);
    }

    int ans = 0;
    rep(i, 0, n) {
        if (uf.same(p[i] - 1, i)) ans++;
    }

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

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,D;
  scanf("%d%d",&n,&D);
  int *d=(int *)malloc(sizeof(int)*(n+1));
  int i;
  for(i=1;i<=n;i++) scanf("%d",d+i);
  int *now=(int *)malloc(sizeof(int)*(n+1));
  now[0]=D;
  for(i=1;i<=n;i++) now[i]=MIN(now[i-1],ABS(now[i-1]-d[i]));
  int *can=(int *)malloc(sizeof(int)*(n+1));
  int64 min=0;
  for(i=n;i>=1;i--){
    can[i]=!(now[i-1]<=min);
    if(d[i]<=2*min+1){
      min+=d[i];
    }
  }
  int q;
  scanf("%d",&q);
  while(q--){
    int x;
    scanf("%d",&x);
    printf("%s\n",can[x]?"YES":"NO");
  }
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 7680
import math
a, b, C = map(int,input().split())
C = C*math.pi/180.0
c = math.sqrt(a**2+b**2-2.0*a*b*math.cos(C))
h = b*math.sin(C)
S = 0.5*a*h
L = a+b+c
print(S)
print(L)
print(h)



Measured memory_bytes: 5708
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 1e3+2;
char grid[M][M];
int ans[M][M];
int h,w;
bool isValid(int x,int y)
{
	if(x<1 || x>h || y<1 || y>w)
		return 0;
	if(grid[x][y]!='.')
		return 0;
	return 1;
} 
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>h>>w;
	int ch,cw;
	cin>>ch>>cw;
	int dh,dw;
	cin>>dh>>dw;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin>>grid[i][j];
		}
	}
	memset(ans,-1,sizeof(ans));
	deque<pair<int,int>> dq;
	dq.push_back({ch,cw});
	ans[ch][cw] = 0;
	vector<int> dx = {0,0,1,-1};
	vector<int> dy = {1,-1,0,0};
	while(!dq.empty())
	{
		auto P = dq.front();
		dq.pop_front();
		int x = P.ff, y = P.ss;
		if(x == dh && y == dw)
		{
			cout<<ans[x][y]<<"\n";
			return 0;
		}
		for(int p=0;p<4;p++)
		{
			if(isValid(x+dx[p],y+dy[p]))
			{
				if(ans[x+dx[p]][y+dy[p]]==-1)
				{
					ans[x+dx[p]][y+dy[p]] = ans[x][y];
					dq.push_front({x+dx[p],y+dy[p]});
				}
				if(ans[x+dx[p]][y+dy[p]]>ans[x][y])
				{
					ans[x+dx[p]][y+dy[p]] = ans[x][y];
					dq.push_front({x+dx[p],y+dy[p]});
				}
			}
		}
		for(int p=-2;p<=2;p++)
		{
			for(int q=-2;q<=2;q++)
			{
				int a = x+p,b = y+q;
				if(isValid(a,b))
				{
					if(ans[a][b] == -1 || ans[a][b] > ans[x][y]+1)
					{
						ans[a][b] = ans[x][y] + 1;
						dq.push_back({a,b});
					}
				}
			}
		}
	}
	cout<<"-1\n";
	return 0;
}

Measured memory_bytes: 8480
#include<string>
#include<iostream>
#include<stdio.h>
#include<queue>
#include<ctime>
#include<vector>
#include<math.h>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int a[105][105], b[10010];
int main()
{
	int h, w;
	while (cin>>h>>w)
	{
		int i, j, t, m,k = 0;
		cin >> t;
		for (i = 0; i < t; i++)
			cin >> b[i];
		for (i = 0; i<h; i++)
		{
			if (i % 2 == 0)
				for (j = 0; j<w; j++)
				{
					a[i][j] = k + 1;
					b[k]--;
					if (b[k] == 0)
						k++;
				}
			if (i % 2 == 1)
				for (j = w - 1; j >= 0; j--)
				{
					a[i][j] = k + 1;
					b[k]--;
					if (b[k] == 0)
						k++;
				}
		}
		for (i = 0; i<h; i++)
		{
			for (j = 0; j < w - 1; j++)
				cout << a[i][j]<<" "; 
			cout << a[i][w - 1]<<endl;
		}
	}
}

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

typedef long long ll;

ll squared(ll x) {
  return (ll)x * x;
}

int main(void) {

  ll N, K;
  vector<pair<ll, ll>> sushi;
  set<ll> type;
  stack<ll> st;

  cin >> N >> K;

  sushi.reserve(N);
  for (int i = 0; i < N; i++) {
    ll t, d;
    cin >> t >> d;
    sushi.push_back(make_pair(d, t));
  }

  sort(sushi.begin(), sushi.end());
  reverse(sushi.begin(), sushi.end());

  ll ans = 0;

  for (int i = 0; i < K; i++) {
    ans += sushi[i].first;
    if (type.count(sushi[i].second)) st.push(sushi[i].first);
    type.insert(sushi[i].second);
  }

  ans += squared(type.size());
  ll tmp = ans;
  for (int i = K; i < N; i++) {

    if (st.empty()) break;
    if (!type.count(sushi[i].second)) {
      tmp = tmp - st.top() + sushi[i].first - squared(type.size()) + squared(type.size() + 1);
      st.pop();
      type.insert(sushi[i].second);
      ans = max(ans, tmp);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
int n, m;
ll k[33333];

int main(void) {
  for (;;) {
    scanf("%d%d", &n, &m); if (n+m == 0) break;
    for (int i = 0; i < n; i++) scanf("%lld", k+i);
    
    set<long long> t;
    t.insert(0);
    long long s = 0;
    long long res = 0;
    for (int i = 0; i < n; i++) {
      // printf("%4lld", s);
      s = (s + k[i])%m;
      res = max(res, (s-*t.begin()+m)%m);
      auto it = t.upper_bound(s);
      if (it != t.end()) res = max(res, (s-*it+m)%m);
      t.insert(s);
    }
    // puts("");
    printf("%lld\n", res);
  }
  return 0;
}

Measured memory_bytes: 4176
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		Map<String, List<Integer>> memo = new TreeMap<String, List<Integer>>();
		while (scanner.hasNext()) {
			String word = scanner.next();
			int page = scanner.nextInt();

			if (!memo.containsKey(word)) {
				memo.put(word, new ArrayList<Integer>());
			}
			memo.get(word).add(page);
		}
		for (Entry<String, List<Integer>> entry : memo.entrySet()) {
			Collections.sort(entry.getValue());
			System.out.println(entry.getKey());
			for (int i = 0; i < entry.getValue().size(); i++) {
				if (i != 0) {
					System.out.print(" ");
				}
				System.out.print(entry.getValue().get(i));
			}
			System.out.println();
		}

	}

}

Measured memory_bytes: 20296
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1);n(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3),i=n(5);t.exports=function(t){var e=new r(t);i(e)}},function(t,e,n){"use strict";var r=n(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){var e=t.in(),n=t.in(),r=t.in(),i=Math.floor(n/e),s=Math.min(i,r);console.log(s)}}]);

Measured memory_bytes: 22964
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string s;
  cin >> s;
  int num = s.size();
  int flag=0;
  for(;;){
  string t,u;   
    for(int i=0;i<num*0.5;i++){//0~4
      t += s.at(i);      
    }
    for(int i=num*0.5; i<num; i++){//0~9
      u += s.at(i);
    }
    if(t == u){
      flag ++;
	  }
    if(flag==2){
      cout << num << endl;
      break;
    }
    num -= 2;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

#define lli long long int

using namespace std;

int main(){

	lli n;
	vector<lli> x;
	vector<lli> y;

	cin>>n;

	for(int i=0;i<n;i++){
		lli tmp;
		cin>>tmp;
		x.push_back(tmp);
		y.push_back(tmp);
	}
	sort(x.begin(),x.end());

	lli a = x.at(n/2-1);
	lli b = x.at(n/2);

	for(int i=0;i<n;i++){
		lli now = y.at(i);
		if(now<=a){
			cout<<b<<endl;
		}
		else{
			cout<<a<<endl;
		}
	}

	return 0;

}

Measured memory_bytes: 5476
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stdio.h>
#include <math.h>
using namespace std;

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

int main() {
	int N;
	cin >> N;
	vector<long long> H(N);
	long long tmp;
	for (int i = 0; i < N; ++i) {
		cin >> tmp;
		H[i] = tmp;
	}
	H[0] = H[0] - 1;
	for (int i = 1; i < N; ++i) {
		if (H[i - 1] <= H[i]) {
			if (H[i - 1] < H[i]) {
				H[i] = H[i] - 1;
			}
		}
		else {
			cout << "No" << endl;
			exit(0);
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 1024
import bisect

X, N = map(int, input().split())
p = sorted(map(int, input().split()))

if not p:
    print(X)
    exit()

pos = bisect.bisect_left(p, X)

left, right = p[pos], p[pos]
l_abs, r_abs = 0, 0
while True:
    if left in p:
        left -= 1
        l_abs += 1
    if right in p:
        right += 1
        r_abs += 1
    if left not in p and right not in p:
        break

if l_abs == r_abs:
    print(left)
elif l_abs > r_abs:
    print(right)
else:
    print(left)

Measured memory_bytes: 62060
Q = 10**9+7
def main():
    N, K = map( int, input().split())
    m = 0
    M = 0
    for i in range(K-1):
        m += i
        M += N-i
    ans = 0
    for i in range(K-1, N+1):
        m += i
        M += N-i

        ans += M-m+1
        ans %= Q
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]

links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)

result = [-1] * (N + 1)
q = deque([1])
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
print('Yes')
print('\n'.join(str(i) for i in result[2:]))

Measured memory_bytes: 106412
while 1:
    n,m,k = map(int,raw_input().split())
    if n == 0: break
    dp = [[0]*(m*n+1) for i in xrange(n)]
    dp[0][1:m+1] = [1]*m
    
    for i in xrange(1,n):
        for j in xrange(1,m*n+1):
            dp[i][j] = sum(dp[i-1][max(j-m,0):j])
    s = sum(dp[n-1])
    ans = 0
    for i in xrange(1,m*n+1):
        ans += 1.0*dp[n-1][i]/s * max(1,i-k)
    print "%.10f"%ans

Measured memory_bytes: 4496
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,X,Y,flag=0;cin>>N>>M>>X>>Y;
  vector<int> x(N);vector<int> y(M);
  for(int i=0;i<N;i++)cin>>x.at(i);
  for(int i=0;i<M;i++)cin>>y.at(i);
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  
  if(x.at(N-1)>=y.at(0))flag++;
  if(x.at(N-1)<X or y.at(0)>Y)flag++;
  if(flag==0)cout<<"No War"<<endl;
  else cout<<"War"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<complex>
#include<cmath>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
const int mod=1000000007;
long long qpow(long long a,long long b)
{
	long long ans=1;
	while(b)
	{
		if(b&1)	ans=ans*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return ans;
}
struct node
{
	int u,v,w;
}ed[2005];
bool cmp(node a,node b)
{
	return a.w<b.w;
}
int n,m;
long long X;
int fa[1005];
int getfa(int x)
{
	return fa[x]==x?x:(fa[x]=getfa(fa[x]));
}
int Fa[2005];
int getFa(int x)
{
	return Fa[x]==x?x:(Fa[x]=getFa(Fa[x]));
}
bool vis[2005];
bool nfree[2005];
void work(int x)
{
	long long sum=0;
	for(int i=1;i<=n;i++)
		fa[i]=i;
	memset(vis,0,sizeof(vis));
	vis[x]=1;
	fa[getfa(ed[x].u)]=getfa(ed[x].v);
	sum+=ed[x].w;//cout<<"ST"<<sum<<endl;
	for(int i=0;i<m;i++)
	{
		int a=getfa(ed[i].u);
		int b=getfa(ed[i].v);
		if(a!=b)
		{
			vis[i]=1;
			fa[a]=b;
			sum+=ed[i].w;
		}
	}//cout<<"AA"<<sum<<endl;
	if(sum>X)	return;
	if(sum<X)
	{
		int fir=0;
		for(int i=0;i<m;i++)
			if(vis[i])
			{
				fir=i;
				break;
			}
		for(int i=fir+1;i<m;i++)
			if(vis[i])
			{
				int a=getFa(fir);
				int b=getFa(i);
				if(a!=b)
				{
					Fa[a]=b;
					nfree[b]|=nfree[a];
				}
			}
		return;
	}
	for(int i=0;i<m;i++)
		if(vis[i])
			nfree[getFa(i)]=1;
}
int main()
{
	read(n);
	read(m);
	read(X);
	for(int i=0;i<m;i++)
	{
		read(ed[i].u);
		read(ed[i].v);
		read(ed[i].w);
	}
	sort(ed,ed+m,cmp);
	for(int i=0;i<m;i++)
		Fa[i]=i;
	for(int i=0;i<m;i++)
		work(i);
	int cntall=0;
	int cntnfree=0;
	memset(vis,0,sizeof(vis));
	for(int i=0;i<m;i++)
	{
		int x=getFa(i);
		if(vis[x])	continue;
		vis[x]=1;
		cntall++;//cout<<"GG"<<i<<' '<<x<<' '<<nfree[x]<<endl;
		if(nfree[x])	cntnfree++;
	}//cout<<cntall<<' '<<cntnfree<<endl;
	if(cntnfree==0)
	{
		printf("0\n");
		return 0;
	}
	long long ans=(mod+qpow(2,cntnfree)-2)%mod*qpow(2,cntall-cntnfree)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
"数学的問題"

#下のようにばかまじめに全探索したら終わりません
#数学的に考えましょう
# MAX_SIZE = 10000000 

# a, b, x = gets.split.map(&:to_i)
# ans = 0
# size = b - a + 1
# if size < MAX_SIZE
#   arr = (a..b).to_a.map{|e| e % x}
#   arr.each do |e|
#     e==0 ? ans = ans + 1 : nil
#   end
# #オーバーフローしそうなときは配列を分ける
# else
#   size = (size / MAX_SIZE).to_i
#   0.upto size do |i|
#     tail = (a+MAX_SIZE*(i+1) >= b) ? b-1 : a+MAX_SIZE*(i+1)-1
#     p tail
#     arr = (a+MAX_SIZE*i..tail).to_a.map{|e| e % x}
#     arr.each do |e|
#       e==0 ? ans = ans + 1 : nil
#     end
#   end
# end
# puts ans

#公式解説に則る
#f:0以上n以下の整数のうちxで割り切れる個数
def f(n, x)
  if n <= -1
    ans = 0
  else 
    ans = (n/x).to_i + 1
  end
  ans
end

a, b, x = gets.split.map(&:to_i)
puts f(b, x) - f(a-1, x)

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main()
{
    IO;

    ll N; cin >> N;
    vl a(N);
    rep(i, N) cin >> a[i];
    ll Q; cin >> Q;
    vl b(Q);
    rep(i, Q) cin >> b[i];

    ll ans = 0;

    rep(i, Q) {
        if (count(all(a), b[i])) ++ans;
    }

    cout << ans << endl;

}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
int main(){
  int64 a;
  while(1){
    cin >> a;
    if(!a)break;
    int v;
    int64 sum = 0;
    int64 g = 1;
    while(a){
      v = a % 10;
      a /= -10;
      if(v < 0){
        v += 10;
        a++;
      }
      sum += v * g;
      g *= 10;
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include<iostream>
using namespace std;
int main(){
  int n,m,i,sum1=1,sum2=1,ans=0;
  cin >> n >> m;
  for(i=n-1; i<=n; i++){
    sum1*=i;
  }
  sum1=sum1/2;
  if(n<=1){
    sum1=0;
  }
  for(i=m-1; i<=m; i++){
    sum2*=i;
  }
  sum2=sum2/2;
  if(m<=1){
    sum2=0;
  }
  ans=sum1+sum2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        char[] input = Console.ReadLine().ToCharArray();
        int ans = 0;
        int count = 0;
        for (int i = 0; i < input.Length; i++)
        {
            if (input[i] == 'R')
            {
                count++;
            }
            else
            {
                ans = Math.Max(ans, count);
                count = 0;
            }
        }
        Console.WriteLine(Math.Max(ans, count));
    }
}

Measured memory_bytes: 25856
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,res;
    res = 1;
    string s;
    cin>>n;
    cin>>s;
    for(int i=1;i<n;i++){
        if(s[i]!=s[i-1]){
            res++;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stack>
#include<iostream>
using namespace std;
int main(void)
{
	for(;;){
		stack<pair<int,int> > q;
		pair<int,int> g,s,w;
		int x,y,f[18][18],n,m,a=0;
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}
		s.first=1;
		s.second=1;
		q.push(s);
		g.first=x;
		g.second=y;
		for(n=0;n<18;n++){
			for(m=0;m<18;m++){
				if(n==0||n>x||m==0||m>y){
					f[n][m]=1;
				}
				else{
					f[n][m]=0;
				}
			}
		}

		scanf("%d",&n);
		for(m=0;m<n;m++){
			scanf("%d %d",&x,&y);
			f[x][y]=1;
		}

		while(!q.empty()){
			s=q.top();
			q.pop();
			if(f[s.first+1][s.second]==0){
				w.first=s.first+1;
				w.second=s.second;
				if(w==g){
					a++;
				}
				else{
					q.push(w);
				}
			}
			if(f[s.first][s.second+1]==0){
				w.first=s.first;
				w.second=s.second+1;
				if(w==g){
					a++;
				}
				else{
					q.push(w);
				}
			}
		}
		printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 3116
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int day = scan.nextInt();
		int take = 0;
		int howmany = scan.nextInt();
		
		for(int i = 0; i < howmany;i++) {
			take += scan.nextInt();
			
		}
		
		if(take > day){
			System.out.println(-1);
			
		}else {
			System.out.println(day - take);
			
		}
		
		
	}
}



Measured memory_bytes: 46440
a,b,c,d=map(int,input().split())
e=a//d
f=c//b
g=0
if a%d!=0:
    e=e+1
else:
    g=0
if c%b!=0:
    f=f+1
else:
    g=0
if f<=e:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9124
#include<stdio.h>
int main(){
  int c[10];
  int i,a=0;
  for(i=0; i<6; i++) scanf("%d",&c[i]);
  c[1] = c[1] * 5;
  c[2] = c[2] * 10;
  c[3] = c[3] * 50;
  c[4] = c[4] * 100;
  c[5] = c[5] * 500;
  for(i=0; i<6; i++){
    a += c[i];
    // printf("%d\n",a);
  }
  if(a<1000) printf("0\n");
  else printf("1\n");
  return 0;
}


Measured memory_bytes: 2140
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]
## math
DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    n, y = MII()
    s = y - 1000*n
    for a in range(0,n+1):
        for b in range(0,n-a+1):
            if 9000*a+4000*b == s:
                print(a,b,n-(a+b))
                return None
    print('-1 -1 -1')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <stdio.h>
#include <string.h>
int main(void){
	char s[1010];
	int len;
	scanf("%s",s);
	len=strlen(s);
	if(s[len-1]=='s'){
		s[len]='e';
		s[len+1]='s';
		s[len+2]='\0';
		printf("%s\n",s);
	}else{
		s[len]='s';
		s[len+1]='\0';
		printf("%s\n",s);
	}
	return 0;
}

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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  ll n;
  string s;
  bool ok = true;
  cin >> n >> s;
  
  if(n%2 == 0){
    rep(i, 0, n/2){
      if(s.at(i) == s.at(n/2+i)){
        continue;
      }
      else{
        ok = false;
        break;
      }
    }
  }
  else{
    ok = false;
  }
    
  cout << ((ok)? "Yes" : "No") << endl;
}

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

using namespace std;

int main(){
  int p,j,mp,mj,i;

  for(i=0;i<3;i++){
    cin>>p;
    if(i==0)mp=p;
    else{
      if(mp>p)mp=p;
    }
  }

  for(i=0;i<2;i++){
    cin>>j;
 if(i==0)mj=j;
    else{
      if(mj>j)mj=j;
    }
  }

  cout<<mp+mj-50<<endl;

  return 0;
}

Measured memory_bytes: 0
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

template <typename T>
class SegmentTree {
    using F = function<T(T, T)>;
    int n;
    F f;
    T t;
    vector <T> dat;
public:
    SegmentTree(F f, T t) : f(f), t(t) {}
    void init(int n_) {
        n = 1;
        while (n < n_) n <<= 1;
        dat.assign(n << 1, t);
    }
    void build(const vector <T> &v) {
        auto n_ = (int)v.size();
        init(n_);
        for (int i = 0; i < n_; i++) dat[n + i] = v[i];
        for (int i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
    }
    void set_val(int k, T x) {
        dat[k += n] = x;
        while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }
    T query(int a, int b) {
        T vl = t, vr = t;
        for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) vl = f(vl, dat[l++]);
            if (r & 1) vr = f(dat[--r], vr);
        }
        return f(vl, vr);
    }
};

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

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

    vector <int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];

    auto f = [](int a, int b) {
        return a + b;
    };

    vector <int> small(n);
    SegmentTree<int> seg1(f, 0);
    seg1.build(vector<int> (n + 1));
    for (int i = 0; i < n; i++) {
        if (i >= k) seg1.set_val(p[i - k], 0);
        seg1.set_val(p[i], 1);
        small[i] = seg1.query(p[i] + 1, n);
    }

    vector <int> big(n);
    SegmentTree<int> seg2(f, 0);
    seg2.build(vector<int>(n + 1));
    for (int i = n - 1; i >= 0; i--) {
        if (i < n - k) seg2.set_val(p[i + k], 0);
        seg2.set_val(p[i], 1);
        big[i] = seg2.query(0, p[i]);
    }

    int ans = 0;
    int d = 0;

    int cur = 0;
    for (int i = 0; i < k; i++) cur += small[i];
    if (cur) {
        ans++;
    } else {
        d = 1;
    }

    for (int i = k; i < n; i++) {
        bool flag = false;

        if (small[i]) {
            cur += small[i];
            flag = true;
            cur -= big[i - k];
        } else {
            if (big[i - k]) {
                cur -= big[i - k];
                if (cur) {
                    flag = true;
                }
            }
        }

        if (cur == 0) d = 1;
        if (flag) ans++;
    }

    cout << ans + d << '\n';
    return 0;
}

Measured memory_bytes: 7536
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define Left second
#define Right first
class SEGMENTS{
private:
    
    map<int,int> dat;
    
    bool isInclude(int li, int ri, int L, int R){ return (L<=li && ri<=R); }
    
public:
    
    void erase(int l, int r){
        while(true){
            auto it = dat.upper_bound(l);
            if(it==dat.end() || r<=it->Left)break;
            
            int li = it->Left;
            int ri = it->Right;
            
            if( isInclude(li,ri,l,r) ) dat.erase(it);
            else{
                int tl = li, tr = ri;
                dat.erase(it);
                if( isInclude(l,r,li,ri) ){
                    if(li!=l) dat[l] = li;
                    if(r!=ri) dat[ri] = r;
                }else{
                    if(li<=l&&l<ri) tr = l;
                    if(l<=li&&li<r) tl = r;
                    if(tl!=tr) dat[tr] = tl;
                }
            }
        }
    }
    
    void insert(int l, int r){
        while(true){
            auto it = dat.upper_bound(l);
            if(it==dat.end() || r<it->Left){
                if(dat.count(l)){
                    dat[r] = dat[l];
                    dat.erase(l);
                }
                else if(l!=r)dat[r] = l;
                break;
            }
            
            if( isInclude(it->Left,it->Right,l,r) ) dat.erase(it);
            else{
                l = min(l,it->Left);
                r = max(r,it->Right);
            }
        }
    }
    
    int size(){ return dat.size(); }
    
    void output(){ for(auto e:dat)cout<<e.Left<<" "<<e.Right<<endl;cout<<endl; }
};

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    SEGMENTS st;
    
    for(int i=0;i<n;){
        if(s[i]=='0')i++;
        else{
            int l=i;
            while(i<n && s[i]=='1') i++;
            st.insert(l,i);
        }
    }
    
    int q;
    cin>>q;
    while(q--){
        int l,r,b;
        cin>>l>>r>>b;
        l--;
        
        if(b==0)    st.erase(l,r);
        else        st.insert(l,r);
        
        cout<<st.size()<<endl;
    }
}

Measured memory_bytes: 4160
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    string S;
    cin >> S;
    ll counter = 0;
    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] != S[S.length()-1-i]){
            S[i] = S[S.length()-1-i];
            counter++;
        }
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll n,i,j;
    cin>>n;
    ll S[n][3];
    for (i=0;i<n;i++)
        cin>>S[i][0]>>S[i][1]>>S[i][2];
    ll cur_t;
    ll ans[n];
    for (i=0;i<n;i++)
    {
        cur_t=0;
        for (j=i;j<n-1;j++)
        {
            if (cur_t<=S[j][1])
                cur_t=S[j][1]+S[j][0];
            else
            {
                ll rem=(cur_t-S[j][1])%S[j][2];
                if (rem==0)
                    cur_t+=S[j][0];
                else
                    cur_t+=(S[j][2]-rem)+S[j][0];
            }
        }
        ans[i]=cur_t;
    }
    for (i=0;i<n;i++)
        cout<<ans[i]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,k;
int main()
{
	cin>>n>>k; int ans=0;
	for(int i=1;i<=n;i++){
		double x,y;
		cin>>x>>y;
		double dis=sqrt(x*x+y*y);
		if(dis<=k)++ans;
	} cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3732
use std::str::FromStr;
use std::io::stdin;

fn read<T: FromStr>() -> T{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
                    .map(|e| e.parse().ok().unwrap())
                    .collect()
}

fn main() {
    let hw = read_vec::<i32>();
    let h = hw[0];
    let w = hw[1];
    let mut field = vec![];
    for _y in 0..h {
        let s = read::<String>().chars().collect::<Vec<_>>();
        field.push(s);
    }

    for y in 0..h {
        for x in 0..w {
            if field[y as usize][x as usize] == '#' {
                continue;
            }
            let mut sum = 0;
            for dy in [-1, 0, 1].iter() {
                for dx in [-1, 0, 1].iter() {
                    let ny = y+dy;
                    let nx = x+dx;

                    if ny<0 || ny>=h || nx<0 || nx>=w
                        || field[ny as usize][nx as usize] != '#'{
                            continue;
                    }

                    sum += 1;
                        
                }
            }

            field[y as usize][x as usize] = ('0' as u8 + sum as u8) as char;
        }
    }

    for y in 0..h {
        for x in 0..w {
            print!("{}", field[y as usize][x as usize]);
        }
        println!("");
    }
}

Measured memory_bytes: 4352
import java.util.*;

public class Main {
    private static final Scanner sc = new Scanner(System.in);

    private void run() {
        String s = sc.next();
        if (s.equals("ABC")) {
            System.out.println("ARC");
        } else {
            System.out.println("ABC");
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

int main(){
    int W,H,N;
    cin >> W >> H >> N;
    int x[110],y[110],a[110];
    int x1=0,x2=W,y1=0,y2=H;
    for(int i=0;i<N;++i) {
        cin >> x[i] >> y[i] >> a[i];
        if(a[i]==1) {
            if(x[i]>x1) x1 = x[i];
        } else if (a[i]==2) {
            if(x[i]<x2) x2 = x[i];
        } else if (a[i]==3) {
            if(y[i]>y1) y1 = y[i];
        } else {
            if(y[i]<y2) y2 = y[i];
        }
    }
    if (x1>x2||y1>y2) {
        cout << 0 << endl;
    } else {
        cout << (x2-x1)*(y2-y1) << endl;
    }
}

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

int N;
int A[2][110];

int main()
{
    cin >> N;

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

    int ma = 0;
    for (int k = 0; k < N; k++)
    {
        int sum = 0;
        for (int j = 0; j <= k; j++)
        {
            sum += A[0][j];
        }
        for (int j = k; j < N; j++) {
            sum += A[1][j];
        }
        ma = max(ma,sum);
    }

    cout << ma << endl;

    return 0;
}


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

int main()
{
    //入力を受け取る
    char w;
    cin >> w;
    switch (w)
    {
        case 'A':
            cout << 'T' << endl;
            break;
        case 'G':
            cout << 'C' << endl;
            break;

        case 'C':
            cout << 'G' << endl;
            break;
        default:
            cout << 'A' << endl;
            break;
        }
}

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

int main(){
    int cards[4][14]={},j,n,i;
    char m;
    cin >> n;

    for ( int c = 0; c < n; c++){
        cin >> m >> j;
        if ( m == 'S'){
            i = 0;
            cards[i][j] = 1;
        }
        else if ( m == 'H'){
            i = 1;
            cards[i][j] = 1;
        }
        else if( m == 'C'){
            i = 2;
            cards[i][j] = 1;
        }
        else if ( m == 'D'){
            i = 3;
            cards[i][j] = 1;
        }
    }
    for ( int i = 0; i < 4; i++ ){
        for ( j = 0; j < 14; j++ ){
            if ( cards[i][j] == 0 && j != 0 ){
                if ( i == 0 ){
                    cout << "S" << " " << j << '\n';
                }
                else if ( i == 1 ){
                    cout << "H" << " " << j << '\n';
                }
                else if ( i == 2 ){
                    cout << "C" << " " << j << '\n';
                }
                else if ( i == 3 ){
                    cout << "D" << " " << j << '\n';
                }
            }
        }
    }
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  a[0] = 0;
  rep(i, 0, N) {
    cin >> a[i];
    a[i]--;
  }

  int now = a[0], cnt = 1;
  rep(i, 1, N) {
    if (now == 1) {
      cout << cnt << endl;
      return 0;
    }
    now = a[now];
    cnt++;
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int INF = 1e9;

int c[3], n[3], d, e;

int solve(){
  int res = c[0] * n[0] + c[1] * n[1] + c[2] * n[2];
  if(n[2] >= d) res = min(res, c[0] * n[0] + c[1] * n[1] + e * n[2]);
  else if(n[1] + n[2] >= d) res = min(res, c[0] * n[0] + c[1] * (n[1] - (d - n[2])) + e * d);
  else if(n[0] + n[1] + n[2] >= d) res = min(res, c[0] * (n[0] - (d - n[1] - n[2])) + e * d);
  else res = min(res, e * d);
  return res;
}

int main() {
  while(cin >>c[0] >>c[1] >>c[2] >>d >>e && c[0]){
    REP(i, 3) cin >>n[i];
    cout <<solve() <<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
s = list(input())
diff = 999

for i in range(len(s)-2):
    a = int(s[i])
    b = int(s[i+1])
    c = int(s[i+2])
    p = ('{}{}{}'.format(a,b,c))
    p = int(p)
    if abs(753 - p) < diff:
        diff = abs(753 - p)

print(diff)

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  cout<<(A+B>=C?"Yes":"No")<<endl;
  return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1777777777ll
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li a[111];

int main() {
    li n;
    cin >> n;
    rin{
        cin >> a[i];
    }
    sort(a, a + n);
    reverse(a, a + n);
    li sum[2] = {0};
    rin{
        sum[i % 2] += a[i];
    }
    cout << sum[0] - sum[1] << endl;

    return 0;
}


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

int top, s[100];
void push(int);
int pop(void);
int main(){
  int a,b;
  top = 0;
  char s[100];
  while(scanf("%s",s) != EOF){
    if( (*s < 48) || (*s > 57)){
      s[0] = *s;
    }
    if(s[0]=='+'){
      a = pop();
      b = pop();
      push(a+b);
    }
    else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a-b);
    }
    else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a*b);
    }
    else{
      push(atoi(s));
    }
    
  }
     
  printf("%d\n",pop());
  return 0;
}

void push (int a){
  s[++top] = a;
}

int pop(){
  top--;
  return s[top+1];
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
void _(ll&a , ll b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;cin >> n >> m;
    cout << n*(n-1)/2+m*(m-1)/2;
    }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, Q;
	cin >> N >> Q;
	int B = 300;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	vector<int> L;
	int cur = -1;
	vector<int> X(N);
	int n = B;
	for (int i = 0; i < N; i++) {
		if (n == B) {
			n = 0;
			L.push_back(i);
			cur++;
		}
		n++;
		X[i] = cur;

	}
	L.push_back(N);
	cur++;
	vector<int> sum(cur);
	vector<int> mx(cur);
	vector<int> mn(cur);
	vector<int> ans(cur);

	for (int i = 0; i < cur; i++) {
		sum[i] = 0;
		mx[i] = 0;
		mn[i] = 0;
		ans[i] = 0;
		for (int j = L[i]; j < L[i + 1]; j++) {
			sum[i] += A[j];
			mx[i] = max(mx[i], sum[i]);
			mn[i] = min(mn[i], sum[i]);
			ans[i] = max(ans[i], sum[i] - mn[i]);
		}
	}
	vector<int> res;
	int sm = 0;
	int mnn = 0;
	int t = 0;
	for (int i = 0; i < cur; i++) {
		t = max(t, ans[i]);
		t = max(t, sm + mx[i] - mnn);
		mnn = min(mnn, sm + mn[i]);
		sm += sum[i];
	}

	res.push_back(t);

	for (int q = 0; q < Q; q++) {
		int k, x;
		cin >> k >> x;
		k--;
		{
			int i = X[k];
			A[k] = x;
			sum[i] = 0;
			mx[i] = 0;
			mn[i] = 0;
			ans[i] = 0;
			for (int j = L[i]; j < L[i + 1]; j++) {
				sum[i] += A[j];
				mx[i] = max(mx[i], sum[i]);
				mn[i] = min(mn[i], sum[i]);
				ans[i] = max(ans[i], sum[i] - mn[i]);
			}
		}

		t = 0;
		sm = 0;
		mnn = 0;
		for (int i = 0; i < cur; i++) {
			t = max(t, ans[i]);
			t = max(t, sm + mx[i] - mnn);
			mnn = min(mnn, sm + mn[i]);
			sm += sum[i];
		}
		res.push_back(t);
	}

	for (int i = 0; i < res.size(); i++) {
		cout << res[i] << endl;
	}
}


Measured memory_bytes: 5524
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	ans := int(s[0]-'0') + 9*(len(s)-1)
	for i := 1; i < len(s); i++ {
		if s[i] != '9' {
			fmt.Println(ans - 1)
			return
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{

int n;
cin>>n;
int s[200200];
for(int i=0;i<n;i++)
    cin>>s[i];
int p[200200];
for(int i=0;i<n;i++)
    p[i]=s[i];
sort(p,p+n);
int mid=n/2;
for(int i=0;i<n;i++)
    {if(p[mid]>s[i]) cout<<p[mid]<<endl;
                else cout<<p[mid-1]<<endl;}     
                               
system("pause");
return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n,a,b,q,r,ans;
	cin>>n>>a>>b;
	r=n%(a+b);
	q=n/(a+b);
	ans=a*q;
	ans+=min(r,a);
	cout<<ans;
	
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int add = sc.nextInt();
		String s = sc.next();
		char[] s_chars = s.toCharArray();
		
		int nam = s.length();
		for(int i = 0;i < nam ; i++){
		    char xx = s_chars[i];
		    if((char)(xx + add ) > 'Z'){
		        System.out.print((char)((xx + add) - 26));
		    }else{
		        System.out.print((char)(xx + add));
		    }
		}
		
    }
}


Measured memory_bytes: 23764