akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF pow(10,15)

int main(void){
    int n,k;
    cin >> n >> k;
    vector<ll>pos;
    vector<ll>neg;
    for(int i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        if(0 <= tmp){
            pos.push_back(tmp);
        }else{
            neg.push_back(abs(tmp));
        }
    }
    pos.push_back(0);
    neg.push_back(0);    
    sort(pos.begin(),pos.end());
    sort(neg.begin(),neg.end());


    ll init = (pos.size() < k+1)?pos.size()-1 :k;
    ll end = k-init;

    ll ans=INF;
    while(end < neg.size() and 0 <= init){
        ll tmp=pos[init] + neg[end] + min(pos[init], neg[end]);
        if(tmp < ans){
            ans = tmp;
        }
        init--;end++;
    }
    cout << ans << endl;

    // for(int i=0;i<pos.size();i++){
    //     cout << pos[i]<<' ';
    // }
    // cout << endl << endl;
    // for(int i=0;i<neg.size();i++){
    //     cout << neg[i]<<' ';
    // }


    return 0;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void solution(){
    ll n,r;
    cin>>n>>r;
    if(n < 10)
        cout<<r+(100*(10-n))<<'\n';
    else
        cout<<r<<'\n';
}
int main(){
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cerr.tie(0);
        /*ll t;
        cin>>t;
        while(t--)*/
        solution();
        return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>

int main(){

     int S, h, m, s;

     scanf("%d", &S);

     h=S/3600;
     S=S-3600*h;
     m=S/60;
     s=S-m*60;

     printf("%d:%d:%d\n", h, m, s);

     return 0;

}

Measured memory_bytes: 592
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int gcd(int a, int b){
	while( b!=0 ){
		int c = b;
		b = a%b;
		a = c;
	}
	return a;
}

int main (int argc, char * const argv[]) {
    // insert code here...
    int a, b, c;
	while(cin >> a >> b){
		if(a<b){
			swap(a, b);
		}
		c = gcd(a, b);
		cout << c << " " << a/c*b << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;


void func()
{
	int a1, a2, a3;
	cin>> a1 >> a2 >> a3;

	vector<uint16_t> costs(3);
	costs[0] = abs(a1 - a2);
	costs[1] = abs(a1 - a3);
	costs[2] = abs(a2 - a3);

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

	cout << costs[0] + costs[1] << endl;

}

int main() {

//	while(1)
		func();
	return 0;
}


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

#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)

using namespace std;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

inline void File() {
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
}

const int N = 100 + 10;
int mn = INT_MAX, mx = INT_MIN, n, a[N], ans = INT_MAX;

inline int cos(int x) {
	int res = 0;
	For(i, 1, n) res += (x - a[i]) * (x - a[i]);
	return res;
}

int main() {

	n = read();
	For(i, 1, n) a[i] = read(), mn = min(mn, a[i]), mx = max(mx, a[i]);

	For(i, mn, mx) ans = min(ans, cos(i));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
int main(void)
{
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    double maxv = -1.0;
    int sugar, water;

    for (int i = 0; i * 100 <= f; i += a)
    {
        for (int j = 0; i * 100 + j * 100 <= f; j += b)
        {
            if (i == 0 and j == 0)
                continue;
            for (int k = 0; i * 100 + j * 100 + k <= f; k += c)
            {
                for (int l = 0; i * 100 + j * 100 + k + l <= f; l += d)
                {
                    int tmpSugar = k + l;
                    int tmpWater = i + j;
                    double noudo = 100.0 * tmpSugar / (tmpSugar + 100.0 * tmpWater);
                    if (noudo > maxv and tmpWater * e >= tmpSugar)
                    {
                        maxv = noudo;
                        sugar = tmpSugar;
                        water = tmpWater;
                        // cout << noudo << " " << 100 * water + sugar << " " << sugar << " " << endl;
                    }
                }
            }
        }
    }
    cout << water * 100 + sugar << " " << sugar << endl;
}

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

int main() {
	string s,t;
	cin>>s;
	cin>>t;
	bool flag = false;
	for(int i=0;i<s.size();i++)
    {
       if(s==t)
           {
            flag=true;
            break;}
           s = s . back () + s . substr (0 , s. size () -1);
    }
	if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main()
{
	int D;
    scanf("%d",&D);
    int C[26];
    for(int a = 0; a < 26; a++)
    {
        scanf("%d",&(C[a]));
    }
    int SCORE[365][26];
    for(int a = 0; a < 365; a++)
    {
        for(int b = 0; b <26; b++)
        {
        	scanf("%d",&(SCORE[a][b]));
        }
    }
    int HUMANABC[26] = {0};
    int KEKKA[365] = {0};
    for(int a = 0; a < 365; a++)
    {
    	for(int b = 0; b <26; b++)
        {
        	HUMANABC[b] += C[b];
        }
        int GOUKEI[26] = {0};
        for(int c = 0; c <26; c++)
        {
            GOUKEI[c] = SCORE[a][c] + ((365 - a) * (HUMANABC[c]));
        }
        int n = 0;
        for(int c = 0; c < 26; c++)
        {
            if(n < GOUKEI[c])
            {
                n = GOUKEI[c];
                KEKKA[a] = (c + 1);
            }
        }
        HUMANABC[KEKKA[a] - 1] = 0;
    }
	for(int a = 0; a < 365; a++)
    {
    	printf("%d\n",KEKKA[a]);
    }
}


Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    ll n,x;
    cin >> n >> x;
    vector<ll>a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    int cnt = 0;
    int m = 0;
    rep(i,n){
        cnt += a[i];
        m++;
        if(cnt > x)break;

    }
    if(cnt != x)m--;
    cout <<  m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
  string s;cin>>s;
  int zero=0,one=0;
  rep(i,s.length()){
    if(s.at(i)=='0')zero++;
    else one++;
  }
  cout<<min(zero,one)*2;
  return 0;
}


Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] t = new int[N];
		for (int i = 0; i < N; i++)
			t[i] = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			if (t[i + 1] - t[i] >= T)
				ans += T;
			else
				ans += t[i + 1] - t[i];
		}
		System.out.println(ans+T);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define step(i,s,n,c) for(int i=(s);i<(n);i+=(c))
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define each(i,vec) for(auto i:vec)
#define cinv(n,vec) VL vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  int n;
  cin>>n;
  VP job(n);
  rep(i,n)cin>>job[i].se>>job[i].fi;
  SORT(job);
  int t=0;
  rep(i,n){
    if(job[i].fi-job[i].se<t){out("No");return 0;}
    else t+=job[i].se;
  }
  out("Yes");

  
  
  
  return 0;
}

Measured memory_bytes: 3456
N = int(input())
S = list(map(int, input().split()))

d = {0:1}
temp = 0

for i in range(N):
    temp += S[i]
    if temp in d:
        d[temp] += 1
    else:
        d.setdefault(temp, 1)

ans = 0
for num in d.values():
    ans += num*(num-1)//2

print(ans)


Measured memory_bytes: 39844
import sys
input = sys.stdin.readline
def print_ans(A, B):
    """Test Case
    >>> print_ans(2, 16)
    9
    >>> print_ans(0, 3)
    IMPOSSIBLE
    >>> print_ans(998244353, 99824435)
    549034394
    """
    if (A + B) % 2 == 0:
        print((A + B) // 2)
    else:
        print("IMPOSSIBLE")

if __name__ == '__main__':
    A, B= map(int,input().rstrip().split())
    print_ans(A, B)


Measured memory_bytes: 3060
def main():
	S = input()
	K = int(input())
	# day = 5*(10**15)
	pos = 1
	for c in S:
		c_int = int(c)
		if c_int > 1:
			print(c)
			break
		if pos == K:
			print(c)
			break
		pos += 1


if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
#include <iostream>

using namespace std;

const int MAXN = 100 + 10;
const int MAXW = 1e5 + 10;
long long v[MAXN];
int w[MAXW];
long long dp[2][MAXW];

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

    for (int i = 1; i <= N; i++)
        cin >> w[i] >> v[i];

    int now = 1, pre = 0;
    for (int i = 1; i <= N; i++) {
        swap(now, pre);
        for (int j = 0; j <= W; j++) {
            if (j >= w[i])
                dp[now][j] = max(dp[pre][j], dp[pre][j-w[i]] + v[i]);
            else
                dp[now][j] = dp[pre][j];
        }
    }

    cout << dp[now][W];
    return 0;
}

Measured memory_bytes: 1792
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        int K = scan.nextInt();
        Integer H[] = new Integer[N];
        for(int i = 0; i < N ; i++) {
            H[i] = new Integer(scan.nextInt());
        }

        Arrays.sort(H, Collections.reverseOrder());

        if(N <= K){
            os.println(0);
            return;
        }

        long ans = 0;
        for(int i = K; i < N; i++)
            ans += H[i];

        os.println(ans);

    }
}

Measured memory_bytes: 94048
import numpy as np

r,g,b,n=map(int,input().split())

x = np.arange(3001)
t = np.array([np.arange(0,3001*g,g)]*3001).T
y = np.array([x]*3001)
z = y*r+t
print(np.sum(np.logical_and((n-z)%b==0,n-z>=0)))

Measured memory_bytes: 364252
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int main(void){
    int a, b;
    cin >> a >> b;
    int w, e;
    int diff = b - a;
    for (int i = 1; i <= diff;i++){
        w += i;
        e += i;
    }
    cout << e - b << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
// *max_element(all(d))
// priority_queue<int,vector<int>,greater<int>>
int solve(){
  int n;
  cin >> n;
  vector<ll>cnt(5);
  ll ans = 0;
  rep(i,n){
    string tmp;
    cin >> tmp;
    char c = tmp[0];
    if(c == 'M')cnt[0]++;
    if(c == 'A')cnt[1]++;
    if(c == 'R')cnt[2]++;
    if(c == 'C')cnt[3]++;
    if(c == 'H')cnt[4]++;
  }
  rep(i,5)REP(j,i + 1,5)REP(k,j + 1,5)ans += (cnt[i] * cnt[j] * cnt[k]);
  cout << ans << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

Measured memory_bytes: 256
<?php
$n = intval(fgets(STDIN));
for($i = 0; $i < $n; ++$i){
  list($a, $b) = array_map('intval', explode(' ', trim(fgets(STDIN))));
  $C[] = $a + $b;
  $A[] = $a;
  $B[] = $b;
}
array_multisort($C, SORT_DESC, $A, $B);
$score = 0;
for($i = 0; $i < $n; ++$i){
  if($i%2){
    $score-=$B[$i];
  }else{
    $score+=$A[$i];
  }
}
printf("%d", $score);


Measured memory_bytes: 28272
numList1 = list(map(int, input().split()))
numList2 = list(map(int, input().split()))
add = 0
result = 1
cood = []
for i in range(0, len(numList2)):
    add += numList2[i]
    cood.append(add)
for i in cood:
    if i <= numList1[1]:
        result += 1
    else:
        continue
print(result)

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

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> rou(N);
  for (int i = 0; i < N; i++) cin >> rou.at(i);
  
  int m = 1000000007;
  for (int i = 0; i < N - K + 1; i++) {
    int b = rou.at(i + K - 1), a = rou.at(i);
    int time = b - a + min(abs(b), abs(a));
    if (m > time) m = time;
  }
  
  cout << m << endl;
  
}

Measured memory_bytes: 640
<?php
fscanf(STDIN, "%d %d", $n, $k);
$a = explode(" ", fgets(STDIN));

$cnt = 0;
for ($i = 0; $i < $n; $i++) {
    if ($a[$i] >= $k) {
        $cnt++;
    }
}
printf("%d\n", $cnt);
?>

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

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

    string s = "";
    if (a < b)
    {
        for (int i = 0; i < b; i++)
        {
            s.append(to_string(a));
        }
    }
    else
    {
        for (int i = 0; i < a; i++)
        {
            s.append(to_string(b));
        }
    }
    cout << s << endl;
}

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

int main()
{
    int n;
    scanf("%d",&n);
    if(n%2)
    {
        printf("%d\n",(n-1)*(n-1)/2);
        for(int i=1;i<n;i++) printf("%d %d\n",i,n);
        for(int i=1;i<n;i++) 
        {
            for(int j=i+1;j<n;j++)
            {
                if(i+j==n) continue;
                printf("%d %d\n",i,j);
            }
        }
    }
    else
    {
        printf("%d\n",n*(n-2)/2);
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                if(i+j==n+1) continue;
                printf("%d %d\n",i,j);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3792
#include "bits/stdc++.h"

using namespace std;
using VI = vector<int>;
using VPI = vector<pair<int, int>>;
using LL = long long;

#define FOR(a,n) for(int i=a;i<n;i++)
#define rFOR(a,n) for(int i=n-1;i>=a;i--)
#define IN(n,a) for(int i=0;i<n;i++) cin>>a[i]
#define pIN(n,t) for(int i=0;i<n;i++){int a,b; cin>>a>>b; t.emplace_back(a,b);}
#define SORT(a) sort(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()

int main()
{
	int n;
	cin >> n;
	VI a(n - 1),ans(n - 1);
	FOR(0, n - 1)
	{
		cin >> a[i];
		ans[i] = 0;
	}

	FOR(0, n - 1)
	{
		ans[(a[i] - 1)] ++;
	}

	FOR(0, n - 1) cout << ans[i] << endl;
	cout << "0";
}

Measured memory_bytes: 4844
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int Apoint = 0;
        int Bpoint = 0;
        for(int i=0;i<n;i++){
            String strA = sc.next();
            String strB = sc.next();
            
            int a = strA.compareTo(strB);
            int b = strB.compareTo(strA);
            	
            	if(a > b){
                    Apoint += 3;
                }else if(a < b){
                    Bpoint += 3;
                }else{
                    Apoint++;
                    Bpoint++;
                }
        }
        System.out.println(Apoint + " " + Bpoint);
    }
}


Measured memory_bytes: 30100
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<vector<int>> G(N + 1);
	for (auto i = 0; i < N - 1; ++i)
	{
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	vector<int> c(N);
	auto sum = 0ll;
	for (auto i = 0; i < N; ++i)
	{
		cin >> c[i];
		sum += c[i];
	}
	sort(c.begin(), c.end(), greater<int>());
	sum -= c[0];

	bool used[10001];
	memset(used, 0, sizeof(used));
	queue<int> q;
	q.push(1);
	vector<int> result(N);
	auto index = 0;
	while (!q.empty())
	{
		auto x = q.front();
		q.pop();
		if (used[x])
		{
			continue;
		}

		result[x - 1] = c[index];
		++index;
		used[x] = true;

		for (auto n : G[x])
		{
			if (used[n])
			{
				continue;
			}

			q.push(n);
		}
	}

	cout << sum << endl;
	for (auto i = 0; i < N; ++i)
	{
		cout << result[i];
		if (i < N - 1)
		{
			cout << " ";
		}
		else
		{
			cout << endl;
		}
	}

	return 0;
}

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

struct dsu {
  const int n;
  vector<int> p, sz;
  dsu(int _n) : n(_n), p(n, -1), sz(n, 1) {}
  int root(int v) { return p[v] == -1 ? v : v = root(p[v]); }
  void unite(int u, int v) {
    u = root(u), v = root(v);
    if (u == v) return;
    if (sz[u] < sz[v]) swap(u, v);
    p[v] = u;
    sz[u] += sz[v];
  }
  int size(int v) { return sz[root(v)]; }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w;
  while (cin >> w >> h, w) {
    vector<string> s(h);
    for (auto&& e : s) {
      cin >> e;
    }
    dsu d(h * w);
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (s[i][j] != '#') {
          if (i + 1 < h and s[i + 1][j] != '#') {
            d.unite(i * w + j, (i + 1) * w + j);
          }
          if (j + 1 < w and s[i][j + 1] != '#') {
            d.unite(i * w + j, i * w + (j + 1));
          }
        }
      }
    }
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (s[i][j] == '@') {
          cout << d.size(i * w + j) << '\n';
        }
      }
    }
  }
}



Measured memory_bytes: 3036
n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
for i in range(n):
    for j in range(i+1,n):
        k=2*j-i
        if k>=n:
            continue
        if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
            ans-=1
print(ans)


Measured memory_bytes: 67892
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

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

    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a;
        cin >> a;
        n -= a;
    }
    cout << max(-1, n) << endl;

    return 0;
}

Measured memory_bytes: 3652
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    a = list(int(_) for _ in input().split())
    a.sort()
    ans = 0
    for i in range(1,N):
        if(a[i]!=a[i-1]):
            ans += a[i] - a[i-1]
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
using System;

namespace abc165_b
{
    class Program
    {
        static void Main(string[] args)
        {
            long x = long.Parse(Console.ReadLine());
            double money = 100;
            int year = 0;
            while (money < x)
            {
                money = Math.Floor(money * 1.01);
                year++;
            }
            Console.WriteLine(year);
        }
    }
}


Measured memory_bytes: 27564
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main() {
    int n,k;cin>>n>>k;
    ll co=k;
    for(int i=1;i<n;i++){
        co*=k-1;
    }
    cout<<co<<endl;
}

Measured memory_bytes: 256
var
  n,i,j,k,t:longint;
  s:int64;
  a:array[1..10000]of longint;
begin
  readln(n,k);
  for i:=1 to n do read(a[i]);
  for i:=1 to n-1 do
    for j:=i+1 to n do
    if a[i]<a[j] then
    begin
      t:=a[i];
      a[i]:=a[j];
      a[j]:=t;
    end;
  for i:=1 to k do s:=s+a[i];
  writeln(s);
end.

Measured memory_bytes: 128
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static final MyScanner in = new MyScanner();

	public static final Map<Integer, Integer> map = new HashMap<>();
	public static final Integer ZERO = Integer.valueOf(0);
	public static int N;
	public static int X;
	public static int Y;
	public static int s;

	public static void main(String[] args) {

		N = in.nextInt();
		X = in.nextInt();
		Y = in.nextInt();
		s = (Y + X) / 2;

		for(int i=1;i<N;i++) {
			for(int j=i+1;j<N+1;j++) {


				if(i <= X) {
					beforeX(i, j);
					continue;
				}

				if(i > X && i < s) {
					middle(i,j);
					continue;
				}

				countUp(j-i);

			}
		}

		for(int i=1;i<N;i++) print(i);

	}

	public static void beforeX(int i, int j) {
		if(j <= s) {
			countUp(j-i);
		} else if(j>s) {
			int toY = Math.abs(X - i)+1;
			int fromY = Math.abs(Y-j);
			countUp(toY+fromY);
		}
	}

	public static void middle(int i, int j) {
		int x_route = i-X+1 + Math.abs(Y-j);
		int simple = j - i;
		countUp(Math.min(x_route, simple));
	}


	public static void countUp(int len) {
		int cnt = map.getOrDefault(len, ZERO);
		map.put(len, cnt+1);
	}

	public static void print(int k) {
		System.out.println(map.getOrDefault(k, ZERO));
	}

	public static class MyScanner {
		Scanner sc = new Scanner(System.in);
		String next() { return sc.next();}
		int nextInt() { return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next()); }
	}
}

Measured memory_bytes: 60428
#include"bits/stdc++.h"
using namespace std;

int main() {
	int D, G;
	cin >> D >> G;
	vector<int> p(D), c(D);
	for (int i = 0; i < D; i++)
	{
		cin >> p.at(i) >> c.at(i);
	}

	int min_cnt = 1<<30;
	for (int bit = 0; bit < (1<<D); bit++)
	{
		int pnt = 0;
		int cnt = 0;
		for (int i = 0; i < D; i++)
		{
			if ((bit >> i) & 1)
			{
				pnt += p.at(i) * 100 * (i + 1) + c.at(i);
				cnt += p.at(i);
			}
		}
		if (pnt >= G) { min_cnt = min(cnt, min_cnt); continue; }
		else
		{
			for (int i = D-1; i >= 0; i--) {
				if ((bit >> i) & 1) continue;
				for (int j = 0; j < p.at(i)-1; j++)
				{
					if (pnt >= G) { min_cnt = min(cnt, min_cnt); continue; }
					pnt += 100 * (i + 1);
					cnt++;
				}
			}
			if (pnt >= G) min_cnt = min(cnt, min_cnt);
		}
	}
	cout << min_cnt << endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    while(N != 0){
        vector<int> virus(N,false);
        virus[0] = true;
        vector<pair<int,pair<int,int>>> G(M);
        for(int i=0; i<M; i++){
            cin >> G[i].first >> G[i].second.first >> G[i].second.second;
            G[i].second.first--;
            G[i].second.second--;
        }
        sort(G.begin(),G.end());
        for(int i=0; i<M; i++){
            virus[G[i].second.second] |= virus[G[i].second.first];
        }
        int ans = 0;
        for(int i=0; i<N; i++){
            ans += virus[i];
        }
        cout << ans << endl;
        cin >> N >> M;
    }
    return 0;
}


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

#define   Pi     2*acos(0.0)
#define   LINF   1LL<<63
#define   ll     long long
#define   ull    unsigned long long
#define   pb     push_back
#define   mp     make_pair
#define   MAX    500006
#define   MAX1   10000008
#define   mem(a,v)   memset(a,v,sizeof(a))
#define   all(x) x.begin(),x.end()
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define yes   cout<<"YES"<<endl
#define no   cout<<"NO"<<endl
#define buga  cout<<1<<endl
#define bugb  cout<<2<<endl
#define bugc  cout<<3<<endl
#define bugd  cout<<4<<endl
#define buge  cout<<5<<endl


void fastIO (){ios_base::sync_with_stdio(false);cin.tie(0); cout.precision(20);}
void pr(ll n){ cout<<n<<endl;}

ll A[MAX];
ll B[MAX];
ll C[MAX];
vector< ll >V;
vector< ll >Ans;
vector< pair<ll,ll> >VP;
map< ll,ll >M;
vector<ll>prime;
bool mark[MAX1];
ll N=1e7;
void seive (){int limit = sqrt(N*1.0)+2;mark[1]=1;for (int i=4;i<=N;i+=2)mark[i]=1;prime.push_back(2);for (int i=3;i<=N;i+=2){if(!mark[i]){prime.push_back(i);if(i<=limit){for (int j=i*i;j<=N;j+=i*2)mark[j]=1;}}}}

/*
vector<int>s;
int seive[3125007],arr[100007],co[100007],n,q;
bool check(int n,int pos) {return (n& (1<<pos));}
int Set(int n,int pos) {return (n(1<<pos));}
void bitwise_seive(){
    int x=sqrt(100000000);
    for(int i=3;i<=x;i+=2){
        if(check(seive[i/32],i%32)==0)
        {
            for(int j=i*i;j<=100000000;j+=(i<<1)){
                seive[j/32]=Set(seive[j/32],j%32);
            }
        }
    }
    s.push_back(2);
    for(int i=3;i<=100000000;i+=2){
        if(check(seive[i/32],i%32)==0){
           // cout<<i<<endl;
            s.push_back(i);
        }
    }
}
*/
/*
ll bin_pow(ll o, ll s) {
    if (s == 0) return 1;
    if (s == 1) return o % mod;
    ll d = bin_pow(o, s/2);
    d = (d * 1ll * d) % mod;
    if (s % 2 == 1)
        d = (d * 1ll * o) % mod;
    return d;
}
*/
/*
vector<int> z_function (string s) {
    int n = (int) s.length();
    vector<int> z (n);
    for (int i=1, l=0, r=0; i<n; ++i) {
        if (i <= r)
            z[i] = min (r-i+1, z[i-l]);
        while (i+z[i] < n && s[z[i]] == s[i+z[i]])
            ++z[i];
        if (i+z[i]-1 > r)
            l = i,  r = i+z[i]-1;
    }
    return z;
}*/
int main ()
{
    fastIO();
    ll a,b,c,d,n,m,k,l,p,q,r,t,x,y;
    ll cnt=0,cntr=0,sum=0,ans=1,check=0;
    ll Max= 0,Max1=-1e18+1,Min=LINF;
    string s,s1,s3,s4;

    //cin>>n;
    //cin>>t;
    t=1;

    while(t--){
        cin>>s;
        cin>>s1;
        n=s.size();
        m=s1.size();
        Max=0;
        for(int i=0;i<=n-m;i++){
            cntr=0;
            for(int j=0;j<m;j++){
                if(s1[j]==s[j+i])cntr++;
            }
        Max=max(cntr,Max);
        }
        cout<<m-Max<<endl;
    }

    return 0;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int dp[1100][10100];
 
int main(){
    int h,n;
    cin>>h>>n;
    vector<int> a(n),b(n);
    rep(i,n) cin>>a[i]>>b[i];

    rep(i,1100) rep(j,10100) dp[i][j]=INF;
    dp[0][0]=0;

    rep(i,n){
        for(int j=0;j<=h;j++){
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            dp[i+1][min(h,j+a[i])]=min(dp[i+1][min(h,j+a[i])],dp[i+1][j]+b[i]);
        }
    }

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

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

#define REP(i, n) for(int i = 0; i < (int)n; ++i)

int main()
{
    int N, M; ll L;
    scanf("%d %d %lld", &N, &M, &L);
    ll graph[N][N];

    REP(i, N) REP(j, N) graph[i][j] = 1e15;
    REP(i, N) graph[i][i] = 0;

    REP(i, M) {
        int a, b; ll c;
        scanf("%d %d %lld", &a, &b, &c);
        --a, --b;
        graph[a][b] = graph[b][a] = c;
    }

    REP(k, N) REP(i, N) REP(j, N) graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
    
    int res[N][N];
    REP(i, N) REP(j, N) res[i][j] = 1e9;
    REP(i, N) res[i][i] = 0;
    REP(i, N) REP(j, N) if(graph[i][j] <= L) res[i][j] = 1;

    REP(k, N) REP(i, N) REP(j, N) res[i][j] = min(res[i][j], res[i][k] + res[k][j]);

    int Q;
    scanf("%d", &Q);
    int ans[Q];
    REP(i, Q){
        int s, t;
        scanf("%d %d", &s, &t);
        --s, --t;
        ans[i] = (res[s][t] == 1e9) ? -1 : res[s][t] - 1;
    }
    REP(i, Q) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;



int main(){
	int n, a, b;
	cin >> n >> a >> b;
	string s; cin >> s;
	int cnt = 0, cntb = 1;
	Loop(i, s.length()) {
		if (s[i] == 'a') {
			if (cnt < a + b) {
				cnt++;
				cout << "Yes" << endl;
			}
			else cout << "No" << endl;
		}
		else if (s[i] == 'b') {
			if (cnt < a + b&&cntb <= b) {
				cnt++;
				cntb++;
				cout << "Yes" << endl;
			}
			else cout << "No" << endl;
		}
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 896
N, M = map(int,input().split())

L = []
S = []
for i in range(N):
  temp = list(map(int,input().split()))
  L.append(temp)
  TL = []
  TL.append(temp[0]+temp[1]+temp[2])
  TL.append(-1*temp[0]+temp[1]+temp[2])
  TL.append(temp[0]-temp[1]+temp[2])
  TL.append(temp[0]+temp[1]-temp[2])
  TL.append(-1*temp[0]-temp[1]+temp[2])
  TL.append(-1*temp[0]+temp[1]-temp[2])
  TL.append(temp[0]-temp[1]-temp[2])
  TL.append(-1*temp[0]-temp[1]-temp[2])
  S.append(TL)

ans = -float('inf') 
for i in range(8):
  TMP = []
  for j in range(N):
    TMP.append(S[j][i])
  TMP.sort(reverse=True)
  ans = max(ans,sum(TMP[:M]))
  
print(ans)

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

int32_t main() {

	int n, d;
	cin >> n >> d;

	int count = 0;

	for(int i = 1; i <= n; i ++) {

		int x, y; scanf("%lld %lld", &x, &y);

		if(x * x + y * y <= d * d)
			count ++;
	}	
	cout << count << endl;
}

Measured memory_bytes: 3756
#include <iostream>

using namespace std;

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

    bool isFour = false;

    for (int i = 0; i < N; i++) {
        string c;
        cin >> c;
        if (c == "Y") {
            isFour = true;
        }
    }

    if (isFour) {
        cout << "Four" << endl;
    } else {
        cout << "Three" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int l2=15000;
const int l3=5000;
const int N=31000;
int n,tot;
int a[N],cnt=0;
int main()
{
  scanf("%d",&n);
  int even=n/2*2;
  if(n==3) return printf("2 5 63\n"),0;
  int c2=0,c3=0;
  for(int i=1;i<=min(l3,even-2);i++) a[++tot]=(2*i-1)*3,c3+=2*i-1;
  n-=tot;
  for(int i=1;i<=n;i++) a[++tot]=i*2,c2+=i;
  c2%=3;
  c2=(3-c2)%3;
  a[tot]+=c2*2;
  for(int i=1;i<=tot;i++) printf("%d ",a[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=1e9+7;
const double eps=1e-8;
const int INF = 0x3f3f3f3f;

char s[200005];
int main()
{
    cin>>s;
    ll ans=0;
    for(int i=0; i<strlen(s); i++)
    {
        ans+=s[i]-'0';
    }
    //cout<<ans<<endl;
    if(ans%9==0)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 3792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		int numlength = sc.nextInt();
		boolean[] numbers = new boolean[101];

		for (int i = 0; i < numlength; i++) {
			numbers[sc.nextInt()] = true;
		}

		for (int i = 0; i < numlength + 1; i++) {
			if (numbers[number - i] == false) {
				System.out.println(number - i);
				return;
			} else if(number + i == 101){
				System.out.println(101);
				return;
			}else if (numbers[number + i] == false) {
				System.out.println(number + i);
				return;
			}
		}

	}

}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;  typedef pair<int,ll> pii;
typedef vector<int> VI; typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	vector<VI> r(n);
	
	rep(i, m){
		int a,b;
		cin >>a >>b;
		r[a-1].push_back(b-1);
		r[b-1].push_back(a-1);
	}

	const int INF =1<<29;
	VI ds(n, INF); ds[0] = 0;
	queue<int> q; q.push(0);
	
	for(; !q.empty(); ){
		int v = q.front(); q.pop();
		for(auto x: r[v]){
			if(ds[x] == INF){
				ds[x] = ds[v] + 1;
				q.push(x);
			}
		}
	}
	
	cout <<(ds[n-1]<3? "POSSIBLE": "IMPOSSIBLE") <<endl;
	
	return 0;
}

Measured memory_bytes: 13168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 1e9 + 7;
const ll maxn = 200005;
const ll N = 500005;
char s[1000000],ch;
vector<char>va,vb; // va是反向存储的头部添加的串，vb是正向存储尾部添加的串 
int main(){ // 区别正反向存储是为了能够直接用 push_back操作 
	cin.tie(0); 
    ios::sync_with_stdio(false);
	scanf("%s",s);
	ll q,ti,fi,rev=0;
	scanf("%lld",&q);
	while(q--){
		scanf("%lld",&ti);
		if(ti==1) rev=!rev; // 串的翻转不影响添加方式，可以先记录状态最后再处理 
		else{
			scanf("%lld %c",&fi,&ch); // 输入格式控制可以避免繁琐的使用 getchar() 
			if(fi==1){ // insert效率太低会 TLE，因此用 push_back替代 
				if(!rev) va.push_back(ch);
				else vb.push_back(ch); 
			}
			else{
				if(!rev) vb.push_back(ch);
				else va.push_back(ch);
			}
		}
	}
	if(!rev){ // 最后处理串的翻转	
		for(ll i=va.size()-1;i>=0;i--) printf("%c",va[i]);
		printf("%s",s);
		for(ll i=0;i<vb.size();i++) printf("%c",vb[i]);
	}
	else{
		for(ll i=vb.size()-1;i>=0;i--) printf("%c",vb[i]);
		for(ll i=strlen(s)-1;i>=0;i--) printf("%c",s[i]);		
		for(ll i=0;i<va.size();i++) printf("%c",va[i]);
	}
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void) 
{
    int a, b, d,r;
    double f;

    scanf("%d %d", &a, &b);

    d = a / b;
    r = a % b;
    f = 1.0*a / b;

    printf("%d %d %lf",d,r, f);
    
    return 0;
}


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

#define pb push_back

using ll = long long;
using pii = pair<int, int>;

const int N = 1e5 + 10;
vector<pii> g[N];
int col[N];
int K;

void dfs(int u, int p, int colp) {
	int c = 1;
	for (auto v : g[u]) {
		if (v.first == p) 
			continue;
		if (c == colp) ++c;
		col[v.second] = c;
		dfs(v.first, u, c);
		++c;
	}
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n; cin >> n;
    for (int i = 1; i < n; ++i) {
    	int a, b; cin >> a >> b;
    	g[a].pb({b, i});
    	g[b].pb({a, i});
    }
    K = 0;
    for (int i = 1; i <= n; ++i) 
    	K = max(K, (int)g[i].size());
    dfs(1, 0, 0);
    cout << K << "\n";
    for (int i = 1; i < n; ++i)
    	cout << col[i] << "\n";
}

Measured memory_bytes: 9344
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
   
// g++ -std=c++11 prac.cpp
        
int main(){
    int d,n,x,y=0,z,m,k,w,sum=0,ans=0,Max=-1e9,Min=1e9+1;
    string s,t,u;
    bool count=false,ok=false;
    cin >> n >> s >> t >> u;
    rep(i,n){
        if(s[i]!=t[i] && s[i]!=u[i] && t[i]!=u[i]){
            ans += 2;
        } 
        else if (s[i]==t[i] && s[i]==u[i] && t[i]==u[i]){
            ans += 0;
        }
        else if (s[i]==t[i] || t[i]==u[i] ||s[i]==u[i]){
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static java.util.stream.Collectors.counting;

public class Main {

    public static Integer getKey(Integer val){
        int last = val % 10;
        int first = val;
        while(first >= 10){
            first /= 10;
        }
        return first * 10 + last;
    }

    public static int exchange(int k){
        return (k/10)+(k%10)*10;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<Integer, Long> mp =
                IntStream.rangeClosed(1, N).boxed()
                    .collect(
                            Collectors.groupingBy(Main::getKey, counting())
                );
        long cnt=0;
        for(Integer i:mp.keySet()){
            int j = exchange(i);
            if(mp.containsKey(j))
                cnt += mp.get(i) * mp.get(j);
        }
        System.out.println(cnt);

    }
}


Measured memory_bytes: 35532
#include<bits/stdc++.h>
using namespace std;
int n,d;
int x[15][15];
bool f[410000];
void ispf() {
	memset(f,false,sizeof(f));
	for(int i=1;i*i<=401000;i++)
		f[i*i]=true;
}
int main() {
	ispf();
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=d;j++)
			scanf("%d",&x[i][j]);
	int ans,cnt=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++) {
			ans=0;
			for(int k=1;k<=d;k++)
				ans+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			if(f[ans]) cnt++;
		}
	printf("%d",cnt);
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int n,i,c=0;
    scanf("%d",&n);
    while(n>0)
    {
        i=n%10;
        n=n/10;
        if(i==7)
        {
            printf("Yes");
            c++;
            break;
        }
    }
    if(c==0)
        printf("No");
}


Measured memory_bytes: 1728
#include<iostream>

using namespace std;

int idirs[] = {0, 0, 1, 1, 1, -1, -1, -1};
int jdirs[] = {1, -1, 0, 1, -1, 0, 1, -1};

int map[52][52];

void dfs(int i, int j) {
    if (!map[i][j]) return;
    map[i][j] = 0;
    for (int k = 0; k < 8; ++k) {
        dfs(i + idirs[k], j + jdirs[k]);
    }
}

int main() {
    while (1) {
        int w, h;

        cin >> w >> h;

        if (w == 0) break;

        for (int i = 0; i < 52; ++i)
            for (int j = 1; j < 52; ++j)
                map[i][j] = 0;

        for (int i = 1; i <= h; ++i) {
            for (int j = 1; j <= w; ++j) {
                cin >> map[i][j];
            }
        }

        int ans = 0;
        for (int i = 1; i <= h; ++i) {
            for (int j = 1; j <= w; ++j) {
                if (map[i][j] == 1) {
                    dfs(i, j);
                    ans++;
                }
            }
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 3092
A=int(input())
B=int(input())
C=int(input())
X=int(input())
ans=0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                ans+=1

print(ans)


Measured memory_bytes: 9088
// 9/19 リアルタイム参加
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

    // Aを1から10^6 - 1まで変化させる。
    ll ans = 0;

    for (int A = 1; A < N; A++) {
        ans += ((N - 1) / A);
    }

    cout << ans << endl;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> x(n);
	rep(i,n) cin >> x[i];
	int ans = 1e9;
	for(int p = 1; p <= 100; ++p){
		int cost = 0;
		rep(i,n) cost += (x[i] - p) * (x[i] - p);
		chmin(ans, cost);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b,c,x,y,i,j,xy,res=0;
    cin>>a>>b>>c>>x>>y;
    res=x*a+b*y;
    xy=min(x,y);
    res=min(res,res-(a+b)*xy+xy*2*c);
    x-=xy;y-=xy;
    while(1)
    {
        long long ans=res;
        if(x==0)
        {
            ans=ans-b+2*c;y--;
            if(y<0||ans>=res) break;
        }
        else
        {
             ans=ans-a+2*c;x--;
            if(x<0||ans>=res) break;
        }
       res=ans;
    }
    cout<<res<<endl;
}



Measured memory_bytes: 256