akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
#include <ctype.h> // isdigit
#include <cassert>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(u) begin(u),end(u)
#define PB push_back
#define LE(n,m) ((n) < (m) + EPS * (abs(n) + abs(m)))
#define GE(n,m) ((n) + EPS * (abs(n) + abs(m)) > (m))
#define LT(n,m) ((n) + EPS * (abs(n) + abs(m)) < (m))
#define GT(n,m) ((n) > (m) + EPS * (abs(n) + abs(m)))
#define EQ(n,m) (abs((n)-(m)) < EPS * (abs(n) + abs(m)))

typedef long long int ll;
const int INF = (1<<30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

typedef complex<double> P;

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    int N, W, D;
    cin >> N >> W >> D;
    int L = 2 * (W + D);
    //end, start
    vector<pair<int, int>> lines;
    
    for(int i=0; i<N; i++){
        int x, y; string f;
        cin >> x >> y >> f;
        P p = P(x, y);
        P p1 = P(W, 0);
        P p2 = P(W, D);
        P p3 = P(0, D);
        P C = P(0, -1);
        
        switch (f[0]) {
            case 'W':
                p = (p - p3) * C + p3;
            case 'N':
                p = (p - p2) * C + p2;
            case 'E':
                p = (p - p1) * C + p1;
            default:
                break;
        }
        
        lines.emplace_back(p.real()+p.imag(), p.real()-p.imag());
    }
    sort(lines.begin(), lines.end());
    
    int ans = INF;
    for(int s=0; s<N; s++){
        int tans = 0;
        int p = lines[0].first;
        for(int i=0; i<N; i++){
            while(i<N && lines[i%N].second <= p) i++;
            p = lines[i--%N].first;
            tans++;
        }
        ans = min(ans, tans);
        
        lines[0].first += L;
        lines[0].second += L;
        sort(lines.begin(), lines.end());
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3224
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		String[] Ws = W.split(" ");
		Arrays.sort(Ws);

		String ans = "Yes";
		if(Ws[0].equals(Ws[1])){
			if(Ws[1].equals(Ws[2])){
				ans = "No";
			}
		}else if(Ws[2].equals(Ws[1])){

		}else{
			ans="No";
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 21076
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int x,y,w,h,n,nx,ny,m;
	cin>>m;
	rep(j,m){
		cin>>x>>y>>w>>h>>n;
		int ans=0;
		rep(i,n){
			cin>>nx>>ny;
			if(nx>=x && nx<=(x+w) && ny>=y && ny<=(y+h))ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main(){
  double x1,x2,y1,y2;
  
  cin >> x1 >> y1 >> x2 >> y2;
  cout << fixed
       << setprecision(8)
       << sqrt( pow((x2-x1),2) + pow((y2-y1),2) ) 
       << endl;
  
  return 0;
}

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

long long ans;
string S;
void dfs(long long a,long long b,long long c)
    {
     if(a==S.size()) {
                      ans+=b+c;
                      return;
                     }
     int d=S[a]-'0';
     if(c) dfs(a+1,b+c,d);
     dfs(a+1,b,c*10+d);
    }
int main()
{

cin>>S;
dfs(0,0,0);
cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 256
def main():
    while True:
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            break
        dp = [[0] * a for _ in range(b)]
        n = int(input())
        for i in range(n):
            x, y = map(int, input().split())
            dp[y - 1][x - 1] = -1
        dp[0][0] = 1
        for i in range(a):
            for j in range(b):
                if dp[j][i] == -1:
                    continue
                if dp[j - 1][i] != -1:
                    dp[j][i] += dp[j - 1][i]
                if dp[j][i - 1] != -1:
                    dp[j][i] += dp[j][i - 1]
        print(dp[b - 1][a - 1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 5612
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
bitset<26> t[2000009];
string s;
void build(int v , int l , int r)
{
    if(l == r)
    {
        bitset<26> b(0);
        b[s[l]-97] = 1;
        t[v] = b;
    }
    else
    {
        int tm = (l + r)/2;
        build(2*v , l , tm);
        build(2*v+1 , tm+1 , r);
        t[v] = (t[2*v] | t[2*v + 1]);
    }
}
void update(int v , int tl , int tr , int pos , char c)
{
    if(tl == pos && tr == pos)
    {
        bitset<26> b(0);
        b[c-97] = 1;
        t[v] = b;
    }
    else
    {
        int tm = (tl + tr)/2;
        if(pos <= tm)
            update(2*v , tl , tm , pos , c);
        else update(2*v + 1 , tm+1 , tr ,pos , c);
        t[v] = (t[2*v] | t[2*v+1]);
    }
}
bitset<26> query(int v , int tl , int tr , int l , int r)
{
    if(l > r)
    {
        bitset<26> b(0);
        return b;
    }
    if(tl == l && tr == r)
    {
        return t[v];
    }
    int tm = (tl + tr)/2;
    return (query(2*v , tl , tm , l , min(r , tm)) | query(2*v+  1 , tm+1 , tr , max(l , tm+1) , r));
}
int main()
{
    int n;
    cin >> n;
    cin >> s;
    int q;
    cin >> q;
    build(1 , 0 , n-1);
    while(q--)
    {
        int num;
        cin >> num;
        if(num == 2)
        {
            int l , r;
            cin >> l >> r;
            l-- , r--;
            cout << query(1 , 0 , n-1 , l , r).count() << endl;
        }
        else
        {
            int idx;
            char c;
            cin >> idx >> c;
            update(1 , 0 , n-1 , idx-1 , c);
        }
        
    }
    return 0;
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int ans =0;
	int dp[n]={0};
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
    	if(i-1>=0 && i-2>=0)
    	{
    	
    		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    	}
    
    }
    cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<P> bc(m);
  rep(i, n){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  rep(i, m){
    int b, c;
    cin >> b >> c;
    bc[i]=P(c, b);
  }
  sort(bc.begin(), bc.end(), greater<P>());
  int num=0;
  vector<int> d;
  for(int i=0; i<m && num<n; i++){
    P p=bc[i];
    rep(j, p.second){
      d.push_back(p.first);
      num++;
      if(num==n)break;
    }
  }
  ll ans=0;
  rep(i, n){
    ans+=a[i];
  }
  int dsz=min(n, (int)d.size());
  rep(i, dsz){
    if(d[i]-a[i]>0){
      ans+=d[i]-a[i];
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++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(){
  string s;
  ll q;
  cin >> s >> q;
  
  //vector<vector<int>> a(q, vector<int>(3));
  ll t, f;
  char c;
  ll rev = 0;
  string rv;
  
  rep(i, q){
    
    cin >> t;
    
    if(t == 1){
      rev = 1 - rev;
    }
    else{
      cin >> f >> c;
      if(((f == 1)&&rev) || ((f == 2)&&!rev)){
        s.pb(c);
      }
      else{
        rv.pb(c);
      }
    }
  }

  if(!rev){
    reverse(all(rv));
    cout << rv << s << endl;
  }
  else{
    reverse(all(s));
    cout << s << rv << endl;
  }
  
  //cout << s << endl;

}





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

using namespace std;

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

typedef long long ll;

#define pb push_back

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll d, t, s;
	cin >> d >> t >> s;
	cout << (s * t >= d ? "Yes" : "No");
   return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

int main()
{
    fsscan();
    ll n,m;
    cin>>n>>m;
    
    for(ll i=m/n;i>=1;i--)
    {
        if((m%i==0)&&(m/i>=n))
        {
            cout<<i;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var X = int.Parse(ReadLine());

        var ans = Range(1, 1000).SelectMany(b => Range(2, 1000).Select(p => (int)Pow(b, p)).TakeWhile(x => x <= X)).TakeWhile(x => x <= X).Max();
        
        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28956
#include <stdio.h>

int main(void){
	int n, h = 0, m = 0, c = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int old = h;
		scanf("%d", &h);
		if(old >= h)c++;
		else c = 0;
		if(c > m) m = c;
	}
	printf("%d\n", m);
	return 0;
}


Measured memory_bytes: 2156
N, M = map(int, input().split())
adj = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
seen = [0] * (N+1)


def move(start):
    ret = []
    v = start
    seen[v] = 1
    while True:
        finish = 1
        for u in adj[v]:
            if seen[u] == 0:
                ret.append(u)
                seen[u] = 1
                v = u
                finish = 0
                break
        if finish:
            break
    return ret


fwd = move(1)
bwd = move(1)
bwd.reverse()
ans = bwd
ans.append(1)
ans.extend(fwd)
print(len(ans))
print(*ans)


Measured memory_bytes: 64160
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();

		long sum = 0;
		long SQRT = (long)Math.sqrt(N);
		for (long i = 1; i < SQRT; i++) {
			if ((N - i) % i == 0) {
				long v = (N - i) / i;
				// System.out.println(i + ":" + v);
				sum += v;
			}
		}
		long limit = (N - SQRT) / SQRT + 1;
		// System.out.println("-");
		for (long i = 1; i <= limit; i++) {
			if (N / i == N % i) {
				// System.out.println(i);
				sum += i;
			}
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 25172
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(n); ++i)

int main()
{
	int N; cin >> N;
	//連結数 = 頂点 - 辺
	ll v = 0;
	rep(i, N) v += (ll)(i + 1) * (N - i);	//N個からi個選ぶ選び方
	ll e = 0;
	rep(i, N - 1) {
		int a, b; cin >> a >> b;
		if (a > b) swap(a, b);
		e += (ll)a * (N - b + 1);	//頂点a, bが含まれる頂点の選び方
	}
	cout << v - e << endl;
	return 0;
}


Measured memory_bytes: 3144
from collections import defaultdict
from itertools import combinations

def main():
    N = int(input())

    S = defaultdict(int)

    for i in range(N):
        tmp = input()
        if tmp[0] == "M":
            S["M"] += 1
        elif tmp[0] == "A":
            S["A"] += 1
        elif tmp[0] == "R":
            S["R"] += 1
        elif tmp[0] == "C":
            S["C"] += 1
        elif tmp[0] == "H":
            S["H"] += 1

    ans = 0

    # 文字を3種類ピックアップする組み合わせごとに数を求めて
    # 足し合わせる
    for a, b, c in combinations(S.values(), 3):
        ans += a * b * c

    print(ans)
main()

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> R(n);

    for(int i = 0; i < n; i++){
        cin >> R[i];
    }
    int cnt_max = -2000000000;
    int cnt_min = R[0];

    for(int i = 1; i <n;  i++){
        cnt_max = max(cnt_max, R[i] - cnt_min);
        cnt_min = min(cnt_min, R[i]);
    }

    cout << cnt_max << endl;

    return 0;
}


Measured memory_bytes: 3548
#include <stdio.h>

int min(int a, int b){
  return 0 <= (b-a) ? a : b;
}

int nl(int a){
  return 0 <= a ? a : 0;
}

int main(){
  int a,b,c,x,
      i,j,res=0;
  
  scanf("%d%d%d%d", &a, &b, &c, &x);
  
  x /= 50;
  
  for(i=min(x/10, a); 0<=i; i--){
//    res += nl(min((x-10*i)/2, b) - (x-10*i - c + 1) / 2 + 1);
    for(j=0; j<=min((x-10*i)/2,b); j++){
      if((x - 10*i - c + 1) / 2 <= j){
        res++;
      }
    }
  }
  
  printf("%d", res);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long
#define MAX 200010

int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

int v_gcd(vector<int>& v) {
    int res = v[0];
    for(int i = 1; i < v.size(); i++) {
        res = gcd(res, v[i]);
    }
    return res;
}

signed main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

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

    int gcd = v_gcd(a);

    if(k <= a[n - 1] && k % gcd == 0) {
        cout << "POSSIBLE" << endl;
        return 0;
    }

    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include <limits.h>
#include<stdlib.h>
#include<string.h>

int main() {
	long long int x, k, d;

	long long int  absx, b, ans;

	unsigned long long int c;

	scanf("%lld %lld %lld", &x, &k, &d);
	absx = llabs(x);
	c = d * k;
	if (c <= absx) {
		ans = absx - d * k;
	}
	else {
		ans = absx % d;
		b = k - (absx / d);
		if (b % 2 == 1) {
			ans = llabs(ans - d);
		}
	}



	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1728
import java.io.PrintWriter
import java.util.ArrayDeque

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

/** edge info */
data class Edge(val to: Int)

fun solve(out: PrintWriter) {
    val (n, m) = readIntegerList()
    val hList = readIntegerList()
    /** graph[fromNodeIndex]: edges to other node */
    val graph = Array(n) { mutableListOf<Edge>() }
    repeat(m) {
        val (a, b) = readIntegerList().map { it - 1 }
        graph[a].add(Edge(b))
        graph[b].add(Edge(a))
    }

    val isGoodNodeArray = BooleanArray(n) { true }
    for (i in 0 until n) {
        for (e in graph[i]) {
            if (hList[i] <= hList[e.to]) {
                isGoodNodeArray[i] = false
            }
        }
    }

    println(isGoodNodeArray.count { it })
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 80824
import java.util.*;
public class Main {

	static class Edge{
		int from, to, cost;
		Edge(int from, int to, int cost){
			this.from = from;
			this.to = to;
			this.cost = cost;
		}
	}
	
	public static void main(String[] args) {
		long INF = Long.MAX_VALUE/2;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int P = sc.nextInt();
		Edge[] e = new Edge[M];
		for (int i = 0; i < M; i++)
		    e[i] = new Edge(sc.nextInt()-1, sc.nextInt()-1, -(sc.nextInt()-P));
		long[] d = new long[N];
		Arrays.fill(d, 1, N, INF);
		long ans = 0;
		for(int c = 1; c <= 2*N; c++) {
			for(int i = 0; i < M; i++) {
				if(d[e[i].from] != INF && d[e[i].to] > d[e[i].from] + e[i].cost) {
					d[e[i].to] = d[e[i].from] + e[i].cost;
					if(c > N)
						d[e[i].to] = -INF;
				}
			}
			if(c == N)
				ans = d[N-1];
		}
		System.out.println(d[N-1] == ans ? Math.max(-ans, 0) : -1);
	}

}

Measured memory_bytes: 52080
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c << endl;	
	
}





Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#include<regex>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl; }
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

LL N, Q;
vector<LL> counter(200010);
map<LL, vector<LL> > graph;

void dfs(LL parent_node, LL current_node) {
	counter[current_node] = (counter[parent_node] + counter[current_node]);
	for (LL next_node:graph[current_node]) {
		if (next_node == parent_node) continue;
		dfs(current_node, next_node);
	}
}

int main(void) {
	cin >> N >> Q;
	
	rep(i,N-1) {
		LL a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	rep(i, Q) {
		LL p, x;
		cin >> p >> x;
		counter[p] += x;
	}

	dfs(0, 1);

	for (LL i = 1; i <= N; i++) {
		cout << counter[i];
		if (i == N) cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 41472
#include <iostream>

using namespace std;

int main()
{
	int height[10];
	for (int i=0; i<10; i++) { cin >> height[i]; }
	
	int top[3] ={0};
	for (int i=0; i<10; i++) {
		for (int j=0; j<3; j++) {
			if (height[i] > top[j]) {
				for (int k=2; k>j; k--) { top[k] = top[k-1]; }
				top[j] = height[i];
				break;
			}
		}
	}
	
	for (int j=0; j<3; j++) { cout << top[j] << endl; }
	
	return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin>>a;
    int arr[a][2];
   for(int i=0;i<a;i++){
       for(int j=0;j<2;j++){
           cin>>arr[i][j];
           
       }
   }
   int s=1;
   for(int i=0;i<a;i++){
       for(int j=0;j<2;j++){
           if(arr[i][j]==arr[i][j+1] && arr[i+1][j]==arr[i+1][j+1] && arr[i+2][j]==arr[i+2][j+1]){
               s=2;
           }
       }
   }
   if(s==2){
       cout<<"Yes";
   }
   else{
       cout<<"No";
   }
}

Measured memory_bytes: 3616
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();
		int c = scanner.nextInt();
		scanner.close();
		int d = b + c - a;
		if (d < 0) {
			d = 0;
		}
		System.out.println(d);

	}

}


Measured memory_bytes: 23636
#include<stdio.h>
int main()
{
    int h,w,k=0,l,m,n=0;
    while(1)
    {
        scanf("%d %d",&h,&w);
        if(h==0 && w==0)
        {
            break;
        }
        for(l=1;l<=h;l++)
    {
        for(m=1;m<=w;m++)
        {
            printf("#");
        }
        printf("\n");
    }
    printf("\n");
    }

    return 0;
}



Measured memory_bytes: 1996
<?php
fscanf(STDIN, '%d', $N);
$s1 = ['.', '.', '#', '#'];
$s2 = ['.', '#', '.', '#'];
$resS1 = '';
$resS2 = '';
$right = true;
while ($N) {
	$idx = 0;
	while ($idx < 4) {
		if ($right) {
			echo $resS1.$s1[$idx]."\n".$resS2.$s2[$idx]."\n";
		} else {
			echo $s1[$idx].$resS1."\n".$s2[$idx].$resS2."\n";
		}
		fscanf(STDIN, '%s', $R);
		if ($R === 'T') {
			if ($right) {
				$resS1 .= $s1[$idx];
				$resS2 .= $s2[$idx];
			} else {
				$resS1 = $s1[$idx].$resS1;
				$resS2 = $s2[$idx].$resS2;
			}
			break;
		}
		$idx++;
	}
	if ($idx === 4) {
		$right = !$right;
	} else {
		$N--;
	}
}

Measured memory_bytes: 4044
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct frep {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr frep(int l_, int r_): l(std::min(l_, r_)), r(r_) {}
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct brep {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr brep(int l_, int r_): r(std::max(l_, r_) - 1), l(l_ - 1) {}
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
inline T scan() {
  T res;
  std::cin >> res;
  return res;
}

int main() {
  int N, K;
  std::cin >> N >> K;
  chmin(K, N);
  std::vector<int> A(N);
  for (int& x: A) {
    std::cin >> x;
  }
  std::sort(A.begin(), A.end());
  long long ans = 0;
  for (int i: frep(0, N - K)) {
    ans += A[i];
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();
		
		int ans = 0;
		
		for (int i = 1; i <= t; i++) {
			if (i % a == 0) {
				ans += b;
			}
		}
		
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

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

    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int flag = 0;
    int cnt = 0;
    rep(i, n) {
        if (i == 0) {
            cnt++;
            continue;
        }        
        if (flag == 0) {
            if (a[i-1] < a[i]) flag = 1;
            else if (a[i-1] > a[i]) flag = -1;
        } else if (flag == 1) {
            if (a[i-1] <= a[i]) continue;
            cnt++;
            flag = 0;
        } else {
            if (a[i-1] >= a[i]) continue;
            cnt++;
            flag = 0;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 640
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int A = sc.nextInt();
        int B = sc.nextInt();
        int c = (A + B) % 24;
        _out.println(c);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 23508
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int mod=1000000007;
const long long int INF=99999999999999999;

string str;
long long int n,h,w,m,a,b,sum=0,res=0,xxx[1002][1002];

int main() {
	cout << fixed << setprecision(10);
	cin>>h>>w>>a>>b;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i<b&&j<a||i>=b&&j>=a){
				cout<<1;
			}else{
				cout<<0;
			}
		}
		cout<<endl;
	}
} 


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll a, v, b, w;cin >> a >> v >> b >> w;
	ll t;cin >> t;
	if(abs(a - b) <= t * (v - w))cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 3648
n = gets.to_i
ta = gets.chomp.split
t = ta[0].to_i
a = ta[1].to_i
h = gets.chomp.split
n.times do |i|
    h[i] = h[i].to_i
end

temperature_diff_a = []
n.times do |i|
    temperature = t - h[i] * 0.006
    temperature_diff_a << (temperature - a).abs
end

puts temperature_diff_a.index(temperature_diff_a.min) + 1

Measured memory_bytes: 3836
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author dyominov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AApplePie solver = new AApplePie();
        solver.solve(1, in, out);
        out.close();
    }

    static class AApplePie {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            out.println((a * 3 + b) / 2);
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public void close() {
        }

    }
}


Measured memory_bytes: 23380
(let ((n (read))
      (k (read))
      (a (make-array 0 :element-type 'integer
                       :adjustable t
                       :fill-pointer t))
      (ans 0)
      kp kd)
  (dotimes (i n)
    (vector-push-extend (read) a))
  (setf kp (floor (* k (1+ k)) 2))
  (setf kd (floor (* k (1- k)) 2))
  (loop for i from 0 upto (1- n)
        do (let ((m (aref a i))
                 (cnt 0)
                 (mcnt 0))
             (loop for j from 0 upto (1- n)
                   do (cond ((and (< j i) (< (aref a j) m)) (incf mcnt))
                            ((< (aref a j) m) (incf cnt))))
             (incf ans (* cnt kp))
             (incf ans (* mcnt kd))
             (setf ans (rem ans 1000000007))))
  (princ ans))


Measured memory_bytes: 16612
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0; i<n; i++) {
			nums[i] = sc.nextInt();
		}
		
		Arrays.sort(nums);
		int min = Integer.MAX_VALUE;
		
		for(int i=0; i<=nums.length-k; i++) {
			min = Math.min(nums[i+k-1]-nums[i], min);
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 50080
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, lim = map(int, readline().split())
WV = np.array(read().split(), np.int64)

W = WV[::2]
V = WV[1::2]

# value sum -> min weight
INF = 10**18
dp = np.full(V.sum() + 1, INF, np.int64)
dp[0] = 0
for w, v in zip(W, V):
    np.minimum(dp[v:], dp[:-v] + w, out=dp[v:])

answer = np.where(dp <= lim)[0].max()
print(answer)

Measured memory_bytes: 28268
import std.stdio;
import core.stdc.stdio;
import std.algorithm.comparison;

int f(int x, int cnt) {
    return (x % 2 == 1 ? cnt : f(x / 2, cnt + 1));
}

void main() {
    int n;
    scanf("%d", &n);
    int ans = 1 << 30;
    foreach(i; 0..n) {
        int x;
        scanf("%d", &x);
        ans = min(ans, f(x, 0));
    }
    writeln(ans);
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split())) + [0]

p = 0
ans = 0
for ai, bi in zip(a, b):
    ans += min(-p, ai)
    n = max (ai + p, 0)
    ans += min(n, bi)
    p = min(n - bi, 0)
print(ans)


Measured memory_bytes: 18624
#include<bits/stdc++.h>
#define eps (1e-11)
using namespace std;

class Point3d{
public:
  double x,y,z;
  Point3d(double a=0,double b=0,double c=0):x(a),y(b),z(c){}
};

double norm(Point3d a,Point3d b){
  return pow((a.x-b.x),2)+pow((a.y-b.y),2)+pow((a.z-b.z),2);
}

double abs(Point3d a,Point3d b){ 
 return sqrt(norm(a,b));
}

int main()
{
  int n,m;
  double a,b,c,d;
    
  while(1){
    cin>>n;
    if(n==0)break;

    vector<Point3d> v;
    bool st[501]={};

    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      v.push_back(Point3d(a,b,c));
    }
    cin>>m;

    Point3d origin(0.0,0.0,0.0);
    for(int i=0;i<m;i++){
      cin>>a>>b>>c>>d;
      Point3d p3(a,b,c);
      double x,y,z,r;
      for(int j=0;j<n;j++){
        x=abs(v[j],origin);
        y=abs(p3,origin);
        z=abs(v[j],p3);
     	r=acos((x*x+y*y-z*z)/(x*y*2));
        if((r-d)<eps)st[j]=true;
      }
    }
    int ans=0;
    for(int i=0;i<n;i++)if(st[i])ans++;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1332
// Problem : C - H and V
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_c
// Memory Limit : 1024 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
char arr[7][7];
int m,n,k;
int res=0;
// map<pair<int,int>,bool>chk;
void cal(int r,int c){
	// if(chk.find({r,c})!=chk.end())return ;
	int ans=0;
	FOR(i,n){
		FOR(j,m){
			if(r&(1<<i) || c&(1<<j)) continue;
			if(arr[i][j]=='#')ans++;
		}
	}
	if(ans==k)res++;
	// chk[{r,c}]=true;
}
void go(int r,int c){
	for(int i=0;i<pow(2,n);i++){
		for(int j=0;j<pow(2,m);j++){
			cal(i,j);
		}		
	}		
}
void solve(){
	cin>>n>>m>>k;
	int black=0;
	FOR(i,n){
		FOR(j,m){
			cin>>arr[i][j];
			if(arr[i][j]=='#')black++;
		}
	}
	go(0,0);
	cout<<res;
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int sum1, sum2 = 0;
  vector<vector<int>> A(2, vector<int>(N));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A.at(i).at(j);
    }
  }
  for(int i = 0; i < N; i++) {
    sum1 = 0;
    for(int j = 0; j <= i; j++) {
      sum1 += A.at(0).at(j);
    }
    for(int j = i; j < N; j++) {
      sum1 += A.at(1).at(j);
    }
    if(i == 0) {
      sum2 = sum1;
    }
    else {
      sum2 = max(sum1,sum2);
    }
  }
  cout << sum2 << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

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


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
ll gcd(ll x,ll y){
    if (y == 0) return x;
    return gcd(y, x%y);
}
ll lcm(ll x,ll y){
    return x*y/gcd(x,y);
}
int main(void){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll l=lcm(c,d);
    ll buf1=b/c,buf2=b/d,buf3=b/l;
    ll buf4=(a-1)/c,buf5=(a-1)/d,buf6=(a-1)/l;
    ll res=(b-a+1)-((buf1+buf2-buf3)-(buf4+buf5-buf6));
    cout<<res<<endl;
}

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

const int N = 11;

bool eval(const string& expr, int tval) {
    int p = 0;
    function<bool()> ll1 = [&]() {
        if (isalpha(expr[p])) {
            switch (expr[p]) {
                case 'T': p++; return true;
                case 'F': p++; return false;
                default: return (tval >> (expr[p++] - 'a') & 1) == 1;
            }
        }
        if (expr[p] == '-' and expr[p + 1] != '>') { p++; return not ll1(); }
        if (expr[p] == '(') {
            p++;
            bool x = ll1();
            char op = expr[p++];
            if (op == '-') p++;
            bool y = ll1();
            p++;
            return op == '+' ? x or y : op == '*' ? x and y : (not x) or (x and y);
        }
        throw;
    };
    return ll1();
}

bool solve(const string& expr) {
    auto p = expr.find_first_of('=');
    string lhs = expr.substr(0, p), rhs = expr.substr(p + 1);
    rep(tval, 1 << N) if (eval(lhs, tval) != eval(rhs, tval)) return false;
    return true;
}

int main() {
    for (string expr; cin >> expr, expr != "#";) cout << (solve(expr) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3212
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
HOME- ITP1-ITP1_3-C
Discussion Solution Statistics Submit
 
Repetitive Processing - Swapping Two Numbers
????????¶??? : 1 sec, ?????¢?????¶??? : 65536 KB
2 ????????°?????????

???????????´??° x, y ?????????????????????????????????????°?????????????????????????????????°?????????????????????????????????

?????????????????????????????\?????????????????????????????????????????????????????????????????????????????¨?????¨?????????????????????
Input

??\???????????°????????????????????????????§?????????????????????????????????????????????????????????§??????????????????????????´??° x, y ??????????????????????§?????????????????????????

x ??¨ y ?????¨?????? 0 ?????¨?????\?????????????????????????????????????????????????????????????????????????????£????????????????????????
Output

??????????????????????????¨??????x ??¨ y ????°????????????????????????????????????????????????????????????????x ??¨ y ????????????????????????????????\??????????????????
Sample Input

3 2
2 2
5 3
0 0

Sample Output

2 3
2 2
3 5
=end
while s = STDIN.gets
  f = $_.chomp.split.map{|x| x.to_i}
  exit if f[0]==0 and f[1]==0
  if f[0] < f[1] then
    printf("%d %d\n",  f[0] ,  f[1])
  else
    printf("%d %d\n", f[1], f[0])
  end
end

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

if n == 0:
    print(x)
    exit(0)

nums = set([int(x) for x in input().split(" ")])

dist = 0

while True:
    if not x - dist in nums:
        print(x - dist)
        exit(0)

    if not x + dist in nums:
        print(x + dist)
        exit(0)

    dist += 1



Measured memory_bytes: 9184
// D - Water Bottle
#include <bits/stdc++.h>
using namespace std;
using dbl = double;

int main(){
	dbl a,b,x; cin>>a>>b>>x;
	dbl s = x/a;
	dbl h = b, w = a;
	if(s < a*b/2) w = s/b*2;
	else h = (b-s/a)*2;
	printf("%.10f\n", atan(h/w)*180/M_PI);
}

Measured memory_bytes: 256
// Min, Max and Sum
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_D
//
// Accepted

use std::io::{BufRead, stdin};

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();

    let _n: i32 = buf.trim().parse().unwrap();

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();

    let a: Vec<_> = buf.split_whitespace().map(|x| x.parse::<i64>().unwrap()).collect();

    println!("{} {} {}", a.iter().min().unwrap(), a.iter().max().unwrap(), a.iter().fold(0i64, |sum, x| sum + x))
}


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

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0); //cinとcoutの同期切り
    ios::sync_with_stdio(false); //iostreamとstdioの同期切り

    int A, B;
    cin >> A >> B;

    if(A <= 8 && B <= 8){
        cout << "Yay!" << endl;
    }
    else{
        cout << ":(" << endl;
    }
    

    return 0;
}

/*****************************************************************************/
/*****   1秒間で処理できるfor文ループの回数                                 *****/
/*****   → 10^8 = 100,000,000 回程度                                      *****/
/*****                                                                   *****/
/*****   sort(a, a+N, greater<int>()); // a[0:N) を大きい順にソート        *****/
/*****                                                                   *****/
/*****                                                                   *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3"                *****/
/*****   std::cout << std::fixed;                                        *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3.00"             *****/
/*****                                                                   *****/
/*****************************************************************************/

Measured memory_bytes: 256
# スペース区切りの整数の入力
N, a, b= map(int, input().split())
summation = 0

for i in range(N+1):
    num = i
    total = 0
    while num != 0:
        q, mod = divmod(num, 10)
        total += mod
        num = q
    
    if total >= a and total <= b:
        summation += i
    
print(summation)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1001001001;

template<typename T> int LIS_leq(const vector<T> &v, int l, int r, const T inf) {
	vector<T> dp(r - l, inf);
	for (int i = l; i < r; i++) {
		*upper_bound(dp.begin(), dp.end(), v[i]) = v[i];
	}
	return lower_bound(dp.begin(), dp.end(), inf) - dp.begin();
}

int main() {
	int n;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		A[i] = -A[i];
	}
	int ans = LIS_leq(A, 0, n, INF);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int T1, T2, A1, A2, B1, B2;
	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

	Int P = T1 * (A1 - B1);
	Int Q = T2 * (A2 - B2);

	if (P > 0) {
		P *= -1;
		Q *= -1;
	}

	if (P + Q == 0) {
		cout << "infinity" << endl;
		return 0;
	}
	if (P + Q < 0) { 
		cout << 0 << endl;
		return 0;
	}

	Int ans = -P / (P + Q) * 2;
	if (-P % (P + Q) != 0) { ++ans; }
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256