akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>  // ver1.8
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  if(n==m&&m==x) cout << "Yes" << endl;
  else cout<<"No"<<endl;
  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

pint operator+(pint a,pint b){
	return pint(a.fi+b.fi,a.se+b.se);
}
pint operator-(pint a,pint b){
	return pint(a.fi-b.fi,a.se-b.se);
}

signed main(){
	int N;cin>>N;
	vpint ps(N);
	rep(i,N)cin>>ps[i].fi>>ps[i].se;

	int ma=0;
	rep(i,N)rep(j,N){
		if(i==j)continue;
		pint d=ps[j]-ps[i];
		int cnt=0;
		rep(k,N)rep(l,N)if(ps[l]-ps[k]==d)cnt++;
		chmax(ma,cnt);
	}
	cout<<N-ma<<endl;
	return 0;
}

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

int dp[102][4];//j個持った状態でi番目の風船を取りに行く最小時間
int p[101];
int t[101];
int main()
{
	int n;
	while(1)
	{
		cin>>n;
		if(n==0)
			break;
		p[0]=0;
		t[0]=0;
		for(int i=1;i<n+1;i++)
			cin>>p[i]>>t[i];
		fill(dp[0],dp[102],1e8-1);
		dp[0][0]=0;//初期位置
		//dp start
		bool f=false;
		for(int i=1;i<n+1;i++)
		{
			for(int j=0;j<4;j++)
			{
				if(dp[i-1][j]==1e8-1)
					continue;
				int storet=0;//今持っているバルーンを返しに行く時間
				storet=(j+1)*p[i-1];
				int kaisyu=1e8-1;//返さずにそのまま回収するのにかかる時間
				if(j!=3)
					kaisyu=abs(p[i]-p[i-1])*(j+1);
				storet+=p[i];//返しに行ったあと風船の落ちる場所へ向かう
				if(storet<=t[i]-t[i-1])
					dp[i][1]=min(dp[i][1],dp[i-1][j]+p[i-1]+p[i]);
				if(j!=3 && kaisyu<=t[i]-t[i-1])
					dp[i][j+1]=min(abs(p[i]-p[i-1])+dp[i-1][j],dp[i][j+1]);
			}
			f=false;
			for(int j=0;j<4;j++)
			{
				if(dp[i][j]!=1e8-1)
					f=true;
			}
			if(!f)
			{
				cout<<"NG "<<i<<endl;
				break;
			}
		}
		//dp end
		//帰り道を計算する
		if(!f)
			continue;
		int ans=1e8-1;
		for(int i=0;i<4;i++)
			ans=min(ans,dp[n][i]+p[n]);
		cout<<"OK "<<ans<<endl;
	}
	return 0;
}


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

using namespace std;

int main() {
	long long a, b = 0; cin >> a;
	long long d = 100;
	for (int i = 3; i >= 0; --i) {
		char c; cin >> c;
		if (i == 2) continue;
		b += d * (c - '0');
		d /= 10;
	}
	string ans = to_string(a * b);
	if (ans.size() < 3) cout << 0 << endl;
	else cout << ans.substr(0, ans.size() - 2) << endl;

	return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main()
{
  int N;
  cin >> N;
  vector<int> A(N), B(N), C;
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  int ans = 0;
  ll y = 0;
  rep(i, N)
  {
    int a = A[i] - B[i];
    if (a > 0)
      C.push_back(a);
    else if (a < 0)
    {
      ans++;
      y -= a;
    }
  }
  if (y == 0)
  {
    cout << 0 << endl;
    return 0;
  }
  sort(C.begin(), C.end(), greater<int>());
  rep(i, C.size())
  {
    y -= C[i];
    if (y <= 0)
    {
      cout << ans + i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
     if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int M=500000,N=M+5,mod=998244353;
ll fn[N],fm[N],fac[N],ni[N],ans;
ll ksm(ll a,int b){
	int ans=1;
	for(;b;b>>=1){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}
ll p(int a,int b){
	return fac[a]*ni[a-b]%mod;
}
ll c(int a,int b){
	return p(a,b)*ni[b]%mod;
}
int main(){
	For(i,fac[0]=1,M)fac[i]=fac[i-1]*i%mod;
	ni[M]=ksm(fac[M],mod-2); Rep(i,M,1)ni[i-1]=ni[i]*i%mod;
	int n=read(),m=read();
	For(i,fn[0]=1,m)fn[i]=fn[i-1]*(n+1)%mod;
	For(i,fm[0]=1,n)fm[i]=fm[i-1]*(m+1)%mod;
	For(i,0,min(n,m)){
		ans=(ans+((i&1)?-1:1)*c(n,i)*p(m,i)%mod*fm[n-i]%mod*fn[m-i])%mod;
	}
	cout<<(ans+mod)%mod<<endl;
}

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

int main(){
    long long int a, b;
    cin >> a >> b;
    int k1;
    k1 = a + b;
    if(k1 % 2 != 0){
        cout << "IMPOSSIBLE\n";
    }
    else{
        cout << k1/2 << "\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

ll A[200010];

int main() {
	int N;
	ll K;
	cin >> N >> K;
	for(int i=0; i<N; ++i) cin >> A[i];
	ll ng=0, ok=1000000000;
	while(ng+1<ok){
		ll mid=ng+(ok-ng)/2, res=0;
		for(int i=0; i<N; ++i){
			res += (A[i]+mid-1)/mid-1;
		}
		if(res<=K) ok=mid;
		else ng=mid;
	}
	cout << ok << endl;
	return 0;
}

Measured memory_bytes: 5152
from collections import deque
def main():
    N = int(input())
    divs = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
    dp = [0]*(10**6+1)
    def f(x):
        if x == 0:
            return 0
        if x < 0:
            return 10**6
        if dp[x]:
            return dp[x]
        else:
            res = 10**6
            for d in divs:
                res = min(res,f(x-d)+1)
            dp[x] = res
            return res
            

    print(f(N))
main()

Measured memory_bytes: 82920
n = int(input())

a = list(map(int, input().split()))

left = 0
right = 1

cur_sum = a[0]
cur_xor = a[0]

ans = 0

while right <= n:
    if cur_sum == cur_xor:
        ans += right - left
        right += 1
        if right > n:
            break
        cur_sum += a[right-1]
        cur_xor ^= a[right-1]
    else:
        cur_sum -= a[left]
        cur_xor ^= a[left]
        left += 1

print(ans)


Measured memory_bytes: 23560
#include <iostream>
#include <cmath>
using namespace std;
using ll = long long int;
int main() {
  // a + b + 2*√a*b < c
  // 2*√a*b < c - a - b;
  // 4*a*b < (c-a-b)^2
  ll a, b, c;
  cin >> a >> b >> c; 
  const ll l = 4 * a * b;
  const ll r = (c - a - b) * (c - a - b);
  if (l < r && (c-a-b) > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll a,b;
  cin >> a >> b;
  cout << (a<=5?0:a<=12?b/2:b) << endl;
}

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

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

int main(){
    int N;
    cin >> N;
    vector<int> D;
    for(int i=0;i<N;i++){
        int t;
        cin >>t;
        D.push_back(t);
    }
    vector<int> T(13,0);
    T[0]++;
    for(int i=0;i<D.size();i++){
        T[D[i]]++;
    }
    for(int i=0;i<13;i++){
        if(T[i]>2){
            cout << 0<<endl;
            return 0;
        }
    }
    if(T[0]>=2){
        cout << 0 << endl;
        return 0;
    }

    int ans=0;
    for(int bit=0;bit<(1<<12);bit++){
        vector<int> A;
        A.push_back(0);
        for(int i=0;i<12;i++){
            if(T[i+1]==2){
                A.push_back(i+1);
                A.push_back(23-i);
            }
            else if(T[i+1]==1){
                if(bit&(1<<i)){
                    A.push_back(23-i);
                }
                else{
                    A.push_back(i+1);
                }
            }
        }
        int C=100;
        for(int i=0;i<A.size();i++){
            for(int j=0;j<A.size();j++){
                if(i==j)continue;
                int dt = abs(A[i]-A[j]);
                dt = min(dt,24-dt);
                C = min(C,dt);
            }
        }
        ans = max(ans,C);
    }
    cout << ans <<endl;
}


Measured memory_bytes: 256
from sys import stdin
from collections import deque

if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    Q =     _in[1]   # type:str
    Q_arr = []
    for __in in _in[2:]:
        _ = __in.split(' ')
        if len(_) == 1:
            Q_arr.append([int(_[0])])
        else:
            Q_arr.append([int(_[0]),int(_[1]),_[2]])
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    S_arr = deque([s for s in S])
    reverse = False
    for _Q in Q_arr:
        if _Q[0] == 1:
            reverse = not reverse
        elif (_Q[1] == 1 and (not reverse)) or (_Q[1] == 2 and reverse):
            S_arr.appendleft(_Q[2])
        else:
            S_arr.append(_Q[2])
    if reverse:
        S_arr.reverse()
    S_arr = list(S_arr)
    S = ''.join(S_arr)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(S)


Measured memory_bytes: 123100
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int n,a[100000];
	cin>>n;

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

	int ans=0;
	for (int i = 0; i < n; i++){
		if(a[a[i]-1]==i+1)ans++;
	}

	cout<<ans/2<<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const double pi = 3.141592653589;
const double pih = pi / 2;

double dist2(double x1, double y1, double x2, double y2)
{
	double dx = x2 - x1, dy = y2 - y1;
	return dx * dx + dy * dy;
}

double theta(int x1, int y1, int x2, int y2, int x3, int y3)
{
	double a2 = dist2(x1, y1, x2, y2);
	double b2 = dist2(x1, y1, x3, y3);
	double c2 = dist2(x2, y2, x3, y3);
	double ab = sqrt(a2 * b2);

	return acos((a2 + b2 - c2) / (2 * ab));
}

double radius(double r1, int x1, int y1, int x2, int y2, int x3, int y3)
{
	double th1 = theta(x1, y1, x2, y2, x3, y3);
	double th2 = theta(x2, y2, x1, y1, x3, y3);
	double len = sqrt(dist2(x1, y1, x2, y2));

	double lb = 0.1, ub = 2000;

	double rx1 = len - r1 * tan(pih - th1 / 2);
	double ry1 = r1;

	for(int step = 0; step < 100; ++step) {

		double mid = (lb + ub) / 2;

		double rx2 = mid * tan(pih - th2 / 2);
		double ry2 = mid;

		if(rx1 < rx2 || dist2(rx1, ry1, rx2, ry2) < (r1 + mid) * (r1 + mid))
			ub = mid;
		else
			lb = mid;
	}

	return lb;
}

bool ok(double r1, int x1, int y1, int x2, int y2, int x3, int y3)
{
	double r2 = radius(r1, x1, y1, x2, y2, x3, y3);
	double r3 = radius(r1, x1, y1, x3, y3, x2, y2);
	double r3d = radius(r2, x2, y2, x3, y3, x1, y1);

	return r3d < r3;
}


int main()
{
	while(true) {

		int x1, x2, x3, y1, y2, y3;

		scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3);
		if(abs(x1) + abs(x2) + abs(x3) + abs(y1) + abs(y2) + abs(y3) == 0)
			break;

		double lb = 0.1, ub = 2000.0;

		for(int step = 0; step < 100; ++step) {

			double mid = (lb + ub) / 2;

			if(ok(mid, x1, y1, x2, y2, x3, y3))
				lb = mid;
			else
				ub = mid;
		}

		double r1 = lb;
		double r2 = radius(r1, x1, y1, x2, y2, x3, y3);
		double r3 = radius(r1, x1, y1, x3, y3, x2, y2);

		printf("%.9lf %.9lf %.9lf\n", r1, r2, r3);
	}

	return 0;
}

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


int main(){
    int N,X,m[1100];
    cin>>N>>X;
    for(int i=0;i<N;i++)cin>>m[i];

    int sum1_weight=0;
    int number_dounut=0;
    int min_weight=1<<30;
    for(int i=0;i<N;i++){
        sum1_weight+=m[i];
        number_dounut++;
        min_weight=(min_weight>m[i]) ? m[i] : min_weight ;
    }
    
    

    number_dounut=(X-sum1_weight)/min_weight+number_dounut;

    
    cout<<number_dounut<<endl;

    return 0;
    
}

Measured memory_bytes: 256
import numpy as np

S = np.array(list(input()))

R = np.where(S == 'R')[0] + 1
L = np.where(S == 'L')[0] + 1

if (np.prod(R) % 2 == 1) * (np.sum(L % 2) == 0):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 21144
def main():
  N=int(input())
  D=[0]*(10**6+1)
  A=sorted(map(int,input().split()))
  m=max(A)+1

  for a in A:
    if D[a]==0:
      D[a]=1
      for i in range(2*a,m,a):
        D[i]=-1
    else:
      D[a]=-1

  print(D.count(1))

main()


Measured memory_bytes: 40120
#include<stdio.h>
int main ()
{
    int flag=1,n1,n2,i,a;
    scanf("%d",&a);
    scanf("%d %d",&n1,&n2);
    for (i=n1;i<=n2;i++)
    {
        if (i%a==0)
        {
            flag=0;
            break;
        }
    }
    if (flag==1)
        printf("NG");
    else
        printf("OK");
 
 
}

Measured memory_bytes: 1692
# -*- coding: utf-8 -*-
# D

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

N = int(input())
L = list(map(int, input().split()))

L.sort(reverse=True)
acm_l = []

for i in range(1, N-1):
    acm_l.append([ -(L[i] + L[j]) for j in range(i+1, N)])

# print(L)
# print(acm_l)


ans = 0
for i, l in enumerate(L[:-2]):
    for j in range(i, N-2):
        idx = bisect.bisect_left(acm_l[j], -l)
        # print(acm_l[j], l, idx)
        ans += idx

print(int(ans))


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

int main(){
    typedef pair<int, int> P;
    int INF = 1'000'000'000;
    int h,w;
    cin >> h >> w;
    char x;
    int tmp = 0;
    vector<vector<bool>> maze(h, vector<bool>(w));
    vector<vector<int>> distance(h, vector<int>(w));
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            distance[i][j] = INF;
            cin >> x;
            if (x == '.') maze[i][j] = true;
            else maze[i][j] = false;
            if (x == '.') tmp++;
        }
    }
    distance[0][0] = 1;
    queue<P> q;
    q.push({0, 0});
    maze[0][0] = false;
    int s,t;
    vector<int> ds = {0, 0, 1, -1};
    vector<int> dt = {1, -1, 0, 0};
    while (q.size() > 0){
        s = q.front().first;
        t = q.front().second; q.pop();
        for (int i = 0; i < 4; i++){
            if (s + ds[i] < 0 || s + ds[i] >= h || t + dt[i] < 0 || t + dt[i] >= w) continue;
            if (maze[s + ds[i]][t + dt[i]]){
                maze[s + ds[i]][t + dt[i]] = false;
                q.push({s + ds[i], t + dt[i]});
                distance[s + ds[i]][t + dt[i]] = distance[s][t] + 1;
            }
        }
    }
    if (distance[h-1][w-1] != INF) cout << tmp - distance[h-1][w-1] << endl;
    else cout << -1 << endl;
}


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

int main(){
    int num[200];
    int numt[200];
    int n, n2;
    int m;
    int k;
    int i, j;
    cin >> n;
    n2 = 2*n;
    for(i=0;i<n2;i++){
        num[i] = i;
    }
    cin >> m;
    for(i=0;i<m;i++){
        cin >> k;
        if(k == 0){
            for(j=0;j<n;j++){
                numt[j*2] = num[j];
                numt[j*2+1] = num[j+n];
            }
        }else{
            for(j=0;j<k;j++){
                numt[n2-k+j] = num[j];
            }
            for(j=k;j<n2;j++){
                numt[j-k] = num[j];
            }
        }
        for(j=0;j<n2;j++){
            num[j] = numt[j];
        }
    }
    for(i=0;i<n2;i++){
        cout << num[i]+1 << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a<<" "<<b<<" "<<c*3-a-b<<" "<<endl;
    int youxia=c*3-a-c;
    int you=c*3-c*3+a+b-youxia;
    int zuo=c*3-c-you;
    cout<<zuo<<" "<<c<<" "<<you<<" "<<endl;
    cout<<c*3-zuo-a<<" "<<c*3-c-b<<" "<<youxia;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i;
  int range, anchor;

  scanf("%d %d", &range, &anchor);

  for(i=anchor-range+1; i<=anchor+range-1; i++){
    if(i == anchor+range-1)
      printf("%d", i);
    else
      printf("%d ", i);
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 + 7;
int INF = 2e18;
 
signed main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i < N; i++) ans += i;
    cout << ans << endl;
}


Measured memory_bytes: 256
// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;


int main() {
    int a, b;
    cin >> a >> b;
    if(b-a>=2019) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 1e9;
    for(int i = a; i < b; i++) {
        for(int j = i+1; j <= b; j++) {
            ans=min(ans, (i%2019)*(j%2019)%2019);
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define MOD2 1494318097
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define nl '\n'
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 55, maxm = 25;

int N,M,par[maxn],dep[maxn];
ll msks[maxm],power[maxn];
pii arr[maxm];
vector<int> g[maxn];

inline ll gm(int a, int b){
    if(dep[a] > dep[b]) swap(a,b);
    ll res = 0;
    while(dep[b] > dep[a])
        res|=(1LL<<(b-1)), b = par[b];
    while(a != b){
        res|=(1LL<<(a-1));
        res|=(1LL<<(b-1));
        a = par[a], b = par[b];
    }
    return res;
}

void dfs(int u, int p){
    for(int v:g[u]){
        if(v == p) continue;
        dep[v] = dep[u]+1;
        par[v] = u;
        dfs(v,u);
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for(int i=1; i<N; i++){
        int a,b; cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs(1,-1);
    cin >> M;
    for(int i=1; i<=M; i++){
        cin >> arr[i].f >> arr[i].s;
        msks[i] = gm(arr[i].f,arr[i].s);
    }
    ll res = 0;
    power[0] = 1;
    for(int i=1; i<=N; i++)
        power[i] = power[i-1]*2;
    for(int i=1; i<(1<<M); i++){
        ll t = 0;
        for(int k=0; k<M; k++)
            if(i&(1<<k))
                t|=msks[k+1];
        int rem = N-1-__builtin_popcountll(t);
        if(__builtin_popcount(i)%2) res+=power[rem];
        else res-=power[rem];
    }
    cout << power[N-1]-res << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  LL A, B, C, K;
  cin>>A>>B>>C>>K;
  LL ans = 0;
  LL cnt = 0;
  ans += min(A, K);
  cnt += min(A, K);
  cnt += B;
  if (cnt < K) {
    ans -= (K - cnt);
  }
  cout<<ans<<endl;

  return 0;
}


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

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int x, y ;
  cin >> x >> y ;
  
  cout << x+y/2 <<endl ;
  
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

string S;
bool check(ll m) {
  ll N = S.size();
  char before = S.at(N - m);
  bool res = true;
  for (ll i = N - m; i < m; ++i) {
    if (before != S.at(i)) {
      res = false;
      break;
    }
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> S;
  ll l = 1, r = S.size() + 1;
  while (l + 1 != r) {
    ll m = (l + r) / 2;
    if (check(m)) {
      l = m;
    }
    else {
      r = m;
    }
  }
  cout << l << "\n";
}


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

using namespace std;

int main() {

  int n, l, ans, relens = 1e9;
  cin >> n >> l;
  ans = l * n + (n * (n-1)) / 2;
  for(int i = 1;i <= n;i++){
    if(abs(relens) > abs(l + i - 1)){
      relens = l + i - 1;
    }
  }
  cout << ans - relens;
  return 0;
}


Measured memory_bytes: 3568
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
string s;int len;char a[100005],b[100005];
int main()
{
	cin>>s;
	len=s.length();
	for(int i=0;i<len;i++){a[i]=s[i];b[len-i-1]=s[i];}
	for(int i=0;i<len;i++)
	{
		if(b[i]=='b') b[i]='d';
        else if(b[i]=='d') b[i]='b';
        else if(b[i]=='p') b[i]='q';
        else if(b[i]=='q') b[i]='p';
	}
//	cout<<a<<endl<<b;
	for(int i=0;i<len;i++)if(a[i]!=b[i]){cout<<"No"<<endl;return 0;}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_map>
#include <iomanip>

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> pre(n);
    pre[0] = 0;
    for (int i = 1; i < n; i++) {
        pre[i] += pre[i - 1] + (s[i - 1] == 'A' && s[i] == 'C');
    }
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        if (l == 0) {
            cout << pre[r] << '\n';
        } else {
            cout << pre[r] - pre[l] << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 1488
import java.util.Scanner;

public class Main {

	final int[] a = { 0, 0, 1, 1, 1, -1, -1, -1 };
	final int[] b = { 1, -1, 1, 0, -1, 1, 0, -1 };

	void run() {
		try (Scanner sc = new Scanner(System.in)) {
			int m = Integer.parseInt(sc.next());
			int n = Integer.parseInt(sc.next());
			char[][] map = new char[m][];
			for (int i = 0; i < m; i++) {
				map[i] = sc.next().toCharArray();
			}

			int cnt = 0;
			for (int i = 1; i < m; i++) {
				for (int j = 0; j < n; j++) {
					if (map[i][j] == '-') {
						boolean f = false;
						for (int k = 0; k < 8; k++) {
							int ny = i + a[k];
							int nx = j + b[k];
							if (ny >= 0 && ny < m && nx >= 0 && nx < n) {
								if (k < 2 && map[ny][nx] != '-' || map[ny][nx] == 'x') {
									f = true;
									break;
								}
							}
						}
						if (!f) {
							cnt++;
						}
					}
				}
			}
			System.out.println(cnt);
		}
	}

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

Measured memory_bytes: 28036
#include <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <list>
#include <math.h>
#include <iomanip>
#include <map>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int const static Q_MAX = 1000 * 100 + 10;

int Q;
int l[Q_MAX];
int r[Q_MAX];

bool era[Q_MAX+10];
int like_2017[Q_MAX+100];

void init_era(){
  memset(era,true,sizeof(era));
  era[1] = false;
  era[2] = true;
  for(int i=2; i<Q_MAX;i++){
    if(era[i] == true){
      for(int j=2;i*j < Q_MAX; j++){
        era[i*j] = false;
      }
    }
  }
}

void init_like_2017(){

  memset(like_2017,0,sizeof(like_2017));
  like_2017[3] = 1;
  for(int i=4;i<Q_MAX;i++){
    if(i%2==1 && era[i] && era[(i+1)/2]) like_2017[i] = 1;
    like_2017[i] += like_2017[i-1];
  }
}

int main(){
  init_era();
  init_like_2017();

  //rep(i,100) cout<<"i:"<<i<<" v:" << era[i]<<endl;
  cin>>Q;
  rep(i,Q){
    int a,b;cin>>a>>b;
    //cout<< (like_2017[b]-like_2017[a]) <<endl;
    cout<< (like_2017[b] - like_2017[a-1]) <<endl;
  }


}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
ll D;
ll G;
ll dp[12][1201] = {};//iの問題まで解いた時の最大点数
int main() {
	cin >> D >> G;
	int p[11], c[11];
	for (int i = 1; i <= D; ++i) {
		cin >> p[i] >> c[i];
	}
	for (int i = 1; i <= D; ++i) {
		for (int j = 0; j < 1010; ++j) {
			for (int k = 0; k <= p[i]; ++k) {
				if (k == p[i]) {
					dp[i][j+k] = max(dp[i][j+k], dp[i-1][j] + 100 *i*k + c[i]);
				}
				else {
					dp[i][j + k] = max(dp[i][j + k], dp[i - 1][j] + 100 * i*k);
				}
			}
		}
	}
	for (int i = 0; i < 1010; ++i) {
		if (dp[D][i] >= G) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(){
	char str[22];
	char *sp,*sp2;

	scanf("%s",str);
	sp=&str[22];
	while(sp!=str){
		if(*sp=='\0')sp2=sp;
		sp--;
	}
	while(sp2!=str){
		sp2--;
		printf("%c",*sp2);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 524
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String str[];
		int card[];
		boolean op,tp,tc,fh,fc,st;

		card = new int[5];
		while (sc.hasNext()) {
			op = false;
			tp = false;
			tc = false;
			fh = false;
			fc = false;
			st = false;
			str = sc.next().split(",");
			for (int i = 0; i < 5; i++) {
				card[i] = Integer.valueOf(str[i]);
			}
			for (int i = 0; i < 5; i++) {
				int min = i;
				for (int j = i; j < 5; j++) {
					if (card[j] < card[min]) {
						min = j;
					}
				}
				int swap = card[i];
				card[i] = card[min];
				card[min] = swap;
			}
			if (card[0] == card[1] || card[1] == card[2] || card[2] == card[3] || card[3] == card[4]) {
				op = true;
			}
			if ((card[0] == card[1] && (card[2] == card[3] || card[3] == card[4])) || (card[1] == card[2] && card[3] == card[4])) {
				tp = true;
			}
			if (card[0] == card[2] || card[1] == card[3] || card[2] == card[4]) {
				tc = true;
			}
			if ((card[0] + 1 == card[1] || card[0] + 12 == card[4]) && card[1] + 1 == card[2] && card[2] + 1 == card[3] && card[3] + 1 == card[4]) {
				st = true;
			}
			if ((card[0] == card[1] && card[2] == card[4]) || (card[0] == card[2] && card[3] == card[4])) {
				fh = true;
			}
			if (card[0] == card[3] || card[1] == card[4]) {
				fc = true;
			}
			if (fc) {
				System.out.println("four card");
			} else if (fh) {
				System.out.println("full house");
			} else if (st) {
				System.out.println("straight");
			} else if (tc) {
				System.out.println("three card");
			} else if (tp) {
				System.out.println("two pair");
			} else if (op) {
				System.out.println("one pair");
			} else {
				System.out.println("null");
			}
		}
	}
}

Measured memory_bytes: 12000
import sys
sys.setrecursionlimit(700000)

n = int(input())
schd = []

for _ in range(n):
    schd.append(list(map(int, input().split())))

def travel(t, x, y, k):
    t1, x1, y1 = schd[k][0], schd[k][1], schd[k][2]
    dist = abs(x1-x) + abs(y1-y)
    time_dist = t1-t
    
    if dist <= time_dist and dist%2 == time_dist%2:
        if k+1 == n:
            return "Yes"
        else:
            return travel(t1, x1, y1, k+1)
    else:
        return "No"

print(travel(0, 0, 0, 0))


Measured memory_bytes: 116320
#include <algorithm>
#include <iostream>
#include <strings.h>

int main(void)
{
    std::string word;
    std::cin >> word;

    int count = 0;
    while (true) {
        std::string textWord;
        std::cin >> textWord;
        if (textWord == "END_OF_TEXT") {
            break;
        }

        if (strcasecmp(word.c_str(), textWord.c_str()) == 0) {
            count++;
        }
    }

    std::cout << count << std::endl;

    return 0;
}

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

int main() {
  int N,p;
  cin >>N;
  p=0;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
  for(int i=0;i<N;i++){
    cin >>A.at(i);
  }
  for(int i=0;i<N;i++){
    cin >>B.at(i);
    p+=B.at(i);
  }
  for(int i=0;i<N-1;i++){
    cin >>C.at(i);
  }
  for(int i=0;i<N-1;i++){
    if(A.at(i)+1==A.at(i+1)){
      p+=C.at(A.at(i)-1);
    }
  }
  cout <<p<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	string s;
	cin>>s;
	int n=s.size();
	int j=n-1,c=0,m=n/2;
	for(int i=0;i<m;i++)
    {
        if(s[i]!=s[j])
        {
            c++;
        }
        j--;
    }
    printf("%d",c);
	return 0;
}


Measured memory_bytes: 256
import sys
import re
import random
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def solve():
    MOD = 998244353
    n, k = getList()
    imos = [0] * (n + 10)
    imos[2] = -1
    kukan = [getList() for i in range(k)]

    ans = 1
    for i in range(1, n+1):
        ans += imos[i]
        for l, r in kukan:
            l, r = min(i+l, n+2), min(i+r, n+2)
            imos[l] += ans
            imos[r+1] -= ans
        ans %= MOD
    
    print(ans % MOD)


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 144496
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
 
int main(){
    while(1){
        int h, w;
        char f[102][102];
         
        scanf(" %d %d", &h, &w);
        if(h==0) break;
         
        for(int i=0; i<h; ++i)
        for(int j=0; j<w; ++j)
        scanf(" %c", &f[i][j]);
         
        int x=0, y=0;
        bool loop=false;
        while(!loop && f[y][x]!='.'){
            if(f[y][x]=='a') loop=true;
            else{
                int tx=x, ty=y;
                 
                if(f[y][x]=='>') ++x;
                else if(f[y][x]=='<') --x;
                else if(f[y][x]=='^') --y;
                else if(f[y][x]=='v') ++y;          
                 
                f[ty][tx]='a';
            }
        } 
        if(loop) printf("LOOP\n");
        else printf("%d %d\n", x, y);
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // Atcoder
    // template: cpp
    ll n;
    cin >> n;
    vector<ll> p(n);
    rep(i, n) cin >> p[i];
    ll cnt = 0;

    for(size_t i = 1; i < n - 1; i++) {
        if(p[i - 1] < p[i] && p[i] < p[i + 1])
            cnt++;
        else if(p[i - 1] > p[i] && p[i] > p[i + 1])
            cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define fi first
#define se second
#define inf 1000000000
#define mod 1000000007
using namespace std;
template <class T> void chmax(T &x,T y){x=x>y?x:y;return;}
template <class T> void chmin(T &x,T y){x=x<y?x:y;return;}
typedef long long ll;
typedef unsigned long long ull;

int n,a[200005],cnt[200005];
ll ans;

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

Measured memory_bytes: 5388
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

template<class T>
class Fenwick{
public:
  vector<T> data;
  int n;
  Fenwick(){};
  Fenwick(int tn){
    data.resize(tn,0);
    n = tn;
  }
  T read(int idx,int tidx,ll mod){
    T sum = 0;
    if (idx == 0){
      while(tidx > 0){
	sum=(sum+data[tidx])%mod;
	tidx-=(tidx&-tidx);
      }
      return sum;
    }else return (read(0,tidx,mod)-read(0,idx-1,mod)+mod)%mod;
  }
  void update(int idx,T val,ll mod){
    while(idx <= n){
      data[idx]=(data[idx]+val)%mod;
      idx+=(idx & -idx);
    }
  }
};

main(){
  ll a,b,p;
  while(cin>>a>>b>>p && p){
    Fenwick<ll> dp(100002);
    vector<int> num(b-a+2);
    vector<string> all;
    for(ll i=a;i<=b;i++){
      string tmp="";
      ll now = i;
      while(now)tmp=tmp+string(1,'0'+now%10),now/=10;
      reverse(tmp.begin(),tmp.end());
      all.push_back(tmp);
    }
    sort(all.begin(),all.end());
    for(int i=0;i<all.size();i++){
      ll tmp = atoi(all[i].c_str());
      num[tmp-a]=i+1;
    }

    for(ll i=a;i <= b;i++){
      int now = num[i-a];
      ll tmp = (dp.read(0,now-1,p)+1)%p;//+1 is itself
      dp.update(now,tmp,p);
    }
    cout << dp.read(0,b-a+1,p) << endl;

  }
  return false;
}

Measured memory_bytes: 5632
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

const long long int mod = 998244353;

long long int mypow(long long int a, long long int b) {
    // if (b == 1) return a;
    // long long int p = mypow(a, b / 2);
    // return (p * p % mod) * (b % 2 == 1 ? a : 1) % mod;
    long long int res = 1;
    for (long long int i = 1; i <= b; i++) 
        res = res * a % mod;
    return res;
}

int main(int argc, char *argv[]) {
    long long int n;
    cin >> n;
    unordered_map<long long int, long long int> um;
    long long int maxn = 0;
    int fail = 0;
    for (long long int i = 0; i < n; i++) {
        long long int t;
        cin >> t;
        if (i == 0 && t != 0) {
            fail = 1;
        }
        maxn = max(t, maxn);
        um[t]++;
    }
    if (um[0] != 1 || fail == 1) {
        cout << 0 << endl;
        return 0;
    }
    long long int res = 1;
    for (long long int i = 0; i < maxn; i++) {
        res *= mypow(um[i], um[i + 1]);
        res %= mod;
        // cout << um[i] << " " << um[i + 1] << " " << mypow(um[i], um[i + 1]) << endl;
    }
    cout << res % mod << endl;
}



Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


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

int main()
{
	int k[4001];
	rep(i,4001)
	{
		k[i] = i+1;
	}


	int n;
	while(cin >> n)
	{
		long long res = 0;
		rep(a,1001)
		{
			rep(b,1001)
			{
				if(a + b <= n)
				{
					int m = n - a -b;
					if(m <= 1000)
					{
						res += k[m];
					}
					else if(m <= 2000)
					{
						res += k[2000-m];
					}
				}
			}
		}

		cout << res << endl;
	}
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int mn=0x3f3f3f3f,mx=0;
int main(){
	int n;
	int x;
	scanf("%d",&n); 
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		mn=mn>x?x:mn;
		mx=mx<x?x:mx;
	}
	printf("%d\n",mx-mn);
	return 0;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  
  vector<int> road(N,0);
  vector<int> a(M);
  vector<int> b(M);
  
  for (int i=0;i<M;i++){
    cin>>a.at(i)>>b.at(i);
  }
  for(int i=0;i<M;i++){
    road.at(a.at(i)-1)++;
    road.at(b.at(i)-1)++;
  }
  for(int i=0;i<N;i++){
    cout<<road.at(i)<<endl;
  }
}
  

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) {
		BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
		try {
			int n;
			String str;
			double[] s = new double[ 1000+1 ];
			int i;
			double ave = 0, sum = 0, a = 0;
			while( true ) {
				n = Integer.parseInt( kb.readLine() );
				if( 0 == n ) { break; }
				sum = i = 0;
				for( String nums: kb.readLine().split( " ", 0 ) ) {
					s[i] = Double.parseDouble( nums );
					sum += s[i++];
				}
				ave = sum/n;
				sum = 0;
				for( i=0; i<n; i++ ) {
					sum += Math.pow( s[i]-ave, 2 );
				}
				a = Math.sqrt( sum/n );
				System.out.print( a + "\n" );
			}
			
			
		} catch( IOException e ) {
			System.err.println( e );
		}
	}
}

Measured memory_bytes: 19360
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}



int main(){
	FIO
	
	vector<int> a[1500];
	int n;cin >> n;
	int q;
	cin >> q;
	while(q--){
		int op;
		cin >> op;
		if(op == 2){
			int t;
			cin >> t;
			a[t].clear();
		}
		else if(op == 0){
			int t,x;
			cin >> t >> x;
			a[t].push_back(x);
		}else{
			int t;
			cin >> t;
			if(a[t].size()){
				cout << a[t][0];
				for(int i = 1; i < (int)a[t].size(); i++)cout << ' ' << a[t][i];
			}
			cout << '\n';
		}
	}
	return 0;
}



Measured memory_bytes: 5976
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define rev(a) a.rbegin(),a.rend()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >



void solve(){
    ll m = 0, n = 0, i = 0, j = 0, k = 0, ma = -1e9, mi = 1e9, ans = 0, cnt = 0;	
    cin>>n>>m;
    vl v;
    rep(i, n){
        ll temp;
        cin>>temp;
        v.pb(temp);
    }
    sort(all(v));
    rep(i, m){
        ans += v[i];
    }
    cout<<ans<<"\n";
}

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

    /* ll t;
    cin>>t;
    while(t--){ */
        solve();
    /* } */

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> P;
typedef long long ll;
const int MAXN = 1e5 + 50;
 
priority_queue<P, vector<P>, greater<P> > pque;
vector<int> V[MAXN];
int n, m;
int a[MAXN];
int u[MAXN];
int x,y;
 
int find(int t){
    return (u[t] == t) ? t : (u[t] = find(u[t]));
}
 
int same(int x, int y){
    return find(x) == find(y);
}
 
void uni(int x, int y){
    int ux = find(x), uy = find(y);
    u[ux] = uy;
}
 
 
int main() {
    ll res = 1e9;
    cin >> n >> m;
    for(int i = 0; i < n; i++) u[i] = i;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        uni(x, y);
    }
    for(int i = 0; i < n; i++){
        V[find(i)].push_back(i);
        pque.push(P(a[i], i));
    }
 
    if(n < 2 * (n-m-1)) return !printf("Impossible");
    if(n == m + 1) return !printf("0");
    priority_queue<P, vector<P>, greater<P> > alr;
 
    int mint = -1;
    for(int t : V[find(0)])
        if(res > (ll)a[t]) res = (ll)a[t], mint = t;
    for(int t : V[find(0)]) if(t != mint) alr.push(P(a[t], t));
 
 
    while(!pque.empty()){
        P p = pque.top(); pque.pop();
        if(same(p.second, 0)) continue;
 
        int k = find(p.second);
        uni(p.second, 0);
        //cout << "connecting " << p.second << " and " << alr.top().second << endl;
        //cout << "adding " << p.first << endl;
        res += (ll)(p.first);
        for(int t : V[k])
            if(t != p.second)
                alr.push(P(a[t], t));
 
    }
    for(int i = 0; i < 2*(n-m-1)-(n-m); i++){
        res += alr.top().first;
        //cout << "adding" << alr.top().first << endl;
        alr.pop();
    }
 
    cout << res;
 
}

Measured memory_bytes: 7284
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [input().split() for _ in range(N)]

count = 0
for i in range(N):
    result = 0
    for j in range(M):
        result += int(A[i][j]) * B[j]
    if 0 < result + C:
        count += 1
print(count)


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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll N, M;
	cin >> N >> M;
	vector<pair<ll, ll>> p(N); 
	for (int i = 0; i < N; i++)
	{
		ll a, b;
		cin >> a >> b;
		pair<ll, ll> tmp = {a, b};
		p[i] = tmp;
	}
	sort(p.begin(), p.end());
	ll ans = 0;
	for (int i = 0; i < N; i++)
	{
		if(M>p[i].second){
			M-=p[i].second;
			ans+=p[i].first*p[i].second;
		}else{
			ans+=p[i].first*M;
			break;
		}
	}
	cout << ans << endl;
}

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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int N = 3000 + 10;
int T;

const int mod = 1e9 + 7;
int dp[22][1 << 21];
int a[22][22];
int n;

//生成下个相同1的数
int nextN(int n)
{
    int x = n & (-n);
    int t = n + x;
    return ((n ^ t) / x) >> 2 | t;
}

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif

    while (cin >> n)
    {
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++) cin >> a[i][j];

        clr(dp, 0);
        int lim = (1 << n);
        for (int j = 0; j < n; j++)
        {
            if (a[0][j] == 1)
            {
                dp[0][1 << j] = 1;
            }
        }

        for (int i = 0; i < n - 1; i++)
        {
            for (int st = (1 << (i + 1)) - 1; st < lim; st = nextN(st))
            {
                // debug(i, st);
                for (int j = 0; j < n; j++)
                {
                    if (a[i + 1][j] == 0) continue;
                    if (st & (1 << j)) continue;
                    dp[i + 1][st | (1 << j)] += dp[i][st];
                    dp[i + 1][st | (1 << j)] %= mod;
                }
            }
        }

        cout << dp[n - 1][lim - 1] << endl;
    }

    return 0;
}


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

D = defaultdict(list)
N = int(input())
for i in range(N):
    s = input().strip()
    if s[0] in ('M', 'A', 'R', 'C', 'H'):
        D[s[0]].append(s)

if len(D.keys()) < 3:
    print(0)
    exit()

C = combinations(list(D.keys()), 3)

ans = 0
for c in C:
    ans += len(D[c[0]]) * len(D[c[1]]) * len(D[c[2]])

print(ans)


Measured memory_bytes: 56664
#include <functional>
#include <iostream>
#include <sys/types.h>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  int input;
  vector<int> v;
  u_int64_t  ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> input;
    v.push_back(input);
  }
  sort(v.begin(), v.end(), greater<int>());

  for (int i = 0; i < N; i++) {
    if (K > 0) {
      K--;
      continue;
    } else {
      ans += v[i];
    }
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 1400
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = sc.nextInt();
      int D = sc.nextInt();
      int m = 0;
      int n = 0;
      if(A>=B){
        m = B;
      }else{
        m = A;
      }
      if(C>=D){
        n = D;
      }else{
        n = C;
      }
      System.out.println(m+n);
    }
}
      

Measured memory_bytes: 35744
n=int(input())
s=input()
a="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
ans =""
for i in range(len(s)):
    for j in range(26):
        if s[i] == a[j]:
            ans += a[j+n]
            
print(ans)


Measured memory_bytes: 3060