akhauriyash/Code-Regression huggingface dataset:
#
# abc046 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
2 3
1 1
3 2"""
        output = """10"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 1
1 1
1 5
1 100"""
        output = """101"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5
3 10
48 17
31 199
231 23
3 2"""
        output = """6930"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    R = [list(map(int, input().split())) for _ in range(N)]

    t = R[0][0]
    a = R[0][1]
    for i in range(1, N):
        n = max((t+R[i][0]-1)//R[i][0], (a+R[i][1]-1)//R[i][1])
        t = n*R[i][0]
        a = n*R[i][1]

    print(t+a)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16280
#include <iostream>
 #include <string>
 using namespace std;
 int N;
 void dfs(string s, char mx){
 	if(s.length() == N){
 		printf("%s\n", s.c_str());
 						}
    else {
 	for(char c='a';c<=mx;c++){
 	dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
 							 }
 		 }
 }
 int main(void){
 cin >> N;
 dfs("", 'a');
 return 0;
 }


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

vector<int> topologicalsort(const vector<vector<int> > &G) {
  const int V = G.size();      // V…頂点の数
  vector<int> indegree(V, 0);  // それぞれの頂点の入次数
  stack<int> S;                // 入次数0を突っ込むstack

  for (auto &edges : G)  // 全ての頂点の入次数を計算する
    for (auto &v : edges)
      indegree[v]++;

  for (int i = 0; i < V; i++)  // もし入次数0なら、Sに追加
    if (!indegree[i])
      S.push(i);

  vector<int> res;  // トポロジカル順に頂点を並べる
  while (S.size()) {
    int r = S.top();  // 根の番号をrに突っ込む
    res.push_back(r);
    S.pop();
    for (auto &v : G[r]) {  // rからの矢印を無かったことにする
      indegree[v]--;
      if (indegree[v] == 0)  // 入次数が0なら追加
        S.push(v);
    }
  }
  return res;
}

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

  vector<vector<int> > v(N);    // 隣接リスト
  vector<vector<int> > inv(N);  // 隣接リスト(入力)

  int from, to;
  for (int i = 0; i < N - 1 + M; i++) {  // N-1+M 辺の数
    cin >> from >> to;
    v[from - 1].push_back(to - 1);  //一つずらしている
    inv[to - 1].push_back(from - 1);
  }

  vector<int> t = topologicalsort(v);  //トポ順n番目は頂点x
  vector<int> topo(N);                 // 頂点i はトポ順で何番目か
  for (int i = 0; i < N; i++)
    topo[t[i]] = i;

  for (int i = 0; i < N; i++) {
    int parent = -1;
    for (int j = 0; j < inv[i].size(); j++)
      if (parent == -1 || topo[parent] < topo[inv[i][j]])
        parent = inv[i][j];
    cout << (parent == -1 ? 0 : parent + 1) << endl;  // ずらして出力
  }
}


Measured memory_bytes: 12532
#include <stdio.h>
#include <algorithm>

#define BUF 200002
#define LIM_N 100001

char str[BUF];

int R, D, x;

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d %d %d", &R, &D, &x);
}

void solve() {
	for (size_t i = 0; i < 10; i++) {
		x = R*x - D;
		printf("%d\n", x);
	}
}

int main(void) {
	receive_input();

	solve();
	// printf("%d\n", solve());

	return 0;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  cin >> n;
  int a = 0, b = 0;
  rep(i, 0, n) {
    int c;
    cin >> c;
    if(c % 4 == 0) a++;
    else if(c % 2 == 0) b++;
  }
  if(b) b--;
  if(n <= a * 2 + 1 + b) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
import qualified Data.Char as Char

main = putStrLn . toggleCases =<< getLine

toggleCases :: String -> String
toggleCases [] = []
toggleCases (x:xs)
    | x `elem` ['a'..'z'] = Char.toUpper x : toggleCases xs
    | x `elem` ['A'..'Z'] = Char.toLower x : toggleCases xs
    | otherwise           = x : toggleCases xs

Measured memory_bytes: 3948
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

class UnionFind {
public:
    //頂点の親の番号。
    vector<int>Parent;

    //コンストラクタ
    UnionFind(int N) { Parent = vector<int>(N+1, -1); }

    //親を調べる
    int root(int A) {
        if (Parent[A] < 0)return A;
        return Parent[A]=root(Parent[A]);//根を辿ると同時に根を更新
    }

    //グループの頂点数
    int size(int A) {
        return -Parent[root(A)];
    }

    //くっつける
    bool connect(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B)return false;

        //大きい方に小さい方をくっつけたい
        if (size(A) < size(B))swap(A, B);

        //サイズ更新
        Parent[A] += Parent[B];

        //Bの親をAに変更
        Parent[B] = A;

        return true;
    }

};



int main() {

    int N, M;
    cin >> N>>M;
    vector<int>A(M), B(M);
    for (int i = 0; i < M;i++) {
        cin >> A[i] >> B[i];
    }

    vector<long long>ans(M);
    ans[M - 1] = (long long)N*(N - 1) / 2;

    UnionFind U(N);

    for (int i = M - 1; i > 0; i--) {
        ans[i-1] = ans[i];
        if (U.root(A[i]) != U.root(B[i])) {
            ans[i - 1] -= (long long)U.size(A[i])*U.size(B[i]);
            U.connect(A[i], B[i]);
        }
    }

    for (int i = 0; i < M; i++) {
        cout << ans[i] << "\n";
    }



    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#define ll long long
#define MOD 1000000007
#define MAX 10000000
using namespace std;
ll dp[110][4][4][4];

int main(){
    int a,b; cin >> a >> b;
    if(b==1) cout << 0;
    else{
        int ans = 1;
        int res=a;
        while(b>res){
            res += a-1;
            ans++;
        }
        cout << ans;
    }

}

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

string s;

bool hoge(){
  int size = s.size();
  stack<char> temp;
  
  for(int i = 0; i < size; i++){//cout<<i<<" "<<temp.size<<endl;
    if(s[i] == 'm'){
      temp.push(s[i]);
    } else if(s[i] == 'e'){
      temp.push(s[i]);
    } else if(s[i] == 'w'){
      if(temp.size() < 2) return false;
      char a = temp.top(); temp.pop();
      char b = temp.top(); temp.pop();
      if(a != 'e' || b != 'm') return false;
    } else return false;
    if(temp.size() == 0 && i != size-1) return false;
  }
  return true;
}

signed main(){

  cin>>s;
  cout<<(hoge()?"Cat":"Rabbit")<<endl;
  return 0;
}



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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i += 1)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX_N 100000

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;



int main(){
    ll N;
    cin >> N;
    string S = "";
    ll M = 0;
    int cnt = 0;
    if(N == 0){
        cout << 0 << endl;
        return 0;
    }
    while(M != N){
        ll d = N % (1ll << (cnt+1));
        d -= M;
        d %= (1ll << (cnt+1));
        if(d == 0){
            S.push_back('0');
        }else{
            S.push_back('1');
            if(cnt % 2 == 0)M += (1ll << cnt);
            else M -= (1ll << cnt);
        }
        cnt++;
    }
    reverse(All(S));
    cout << S << endl;
    //cin >> N;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define Inf 1000000000
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	ll N;
	cin >> N;
	ll ans = 0;
	vector<vl> anslist(10);
	rep(i, 10) {
		anslist[i].resize(10, 0);
	}
	rep(i, N) {
		int n = i + 1;
		int b = n % 10;
		int a = n;
		while (1) {
			if (a < 10)
				break;
			a /= 10;
		}
		anslist[a][b]++;
	}
	for (int a = 1; a <= 9; a++) {
		for (int b = 1; b <= 9; b++) {
			ans += (ll)anslist[a][b] * (ll)anslist[b][a];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,minn;
    cin>>n;
    int ara[n];
    for(i=0; i<n; i++) cin>>ara[i];
    sort(ara,ara+n);
    int m=ara[0],ii=0,cnt=0,ind;
    while(1)
    {
        ind=ii,minn=m;
       for(i=0;i<n;i++)
       {
           if(i==ind) continue;
           if(ara[i])
           {
               ara[i]%=minn;
               if(ara[i]==0)
                cnt++;
               else if(ara[i]<m)
               {
                   m=ara[i];
                   ii=i;
               }
           }
       }
        if(cnt==(n-1))break;
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 3956
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final FastIn in = new FastIn();
	private static final PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		Solver sol = new Solver();
		sol.solve();
		out.close();
	}
	private static final class Solver {
		public void solve() {
			int n = in.nextInt();
			int[] a = new int[n];
			for (int i = 0; i < n; ++i)
				a[i] = in.nextInt();
			int ans = Integer.MAX_VALUE;
			for (int i = -100; i <= 100; ++i) {
				int res = 0;
				for (int val : a) {
					int calc = val - i;
					res += calc * calc;
				}
				ans = Math.min(ans, res);
			}
			out.println(ans);
		}
	}
	private static final class FastIn {
		private BufferedReader br;
		private StringTokenizer st;
		public FastIn() {
			br = new BufferedReader(new InputStreamReader(System.in), 1 << 20);
			st = null;
		}
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


Measured memory_bytes: 34916
from collections import deque
N = int(input())

alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
unvisited = deque(alphabet[0 : N])
visited = deque()
st = deque([["a", visited, unvisited]]) # stack

while len(st) > 0:
    str, visited, unvisited = st.popleft()

    if str[-1] not in visited:
        visited.append(str[-1])
        unvisited.popleft()

    if len(str) == N:
        print(str)
    else:
        # すでに使った文字を使う
        for x in visited:
            st.append([str + x, deque(visited), deque(unvisited)])
        # まだ使っていない文字を使う
        if len(unvisited) > 0:
            x = unvisited[0]
            st.append([str + x, deque(visited), deque(unvisited)])


Measured memory_bytes: 166636
//https://atcoder.jp/contests/abc124/tasks/abc124_a
#include<bits/stdc++.h>
using namespace std;
#define aakriti long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);    
    aakriti a, b ;
    cin >> a >> b ;
    if(a == b) cout << a + b << endl ;
    if (a-1 == b) cout << a + b << endl ;
    if (a - 1 > b) cout << 2 * a - 1 << endl ;
    if(b -1 > a) cout << 2*b - 1 << endl ;
    if (b -1 == a) cout << b + a << endl ;
}

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

int main() {

	int arrayNumber;
	int *ary;
	int max = 0, counter = 0;

	cin >> arrayNumber;
	ary = new int[++arrayNumber];

	ary[0] = 0;

	for (int count = 1; count != arrayNumber; count++) {
		cin >> ary[count];
	}

	for (int count = 1; count != arrayNumber; count++) {
		if (max <= ary[count]) {
			counter++;
			max = ary[count];
		}
	}

	cout << counter << endl;
	delete[] ary;

	return 0;
}
//*/

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100
#define INFTY (1<<21)

int main()
{
  int n,i,j;
  int minv;
  int k,c,u,v;
  int M[MAX][MAX];
  int d[MAX];
  int vis[MAX];

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  M[i][j]=INFTY;
	}
    }

  for(i=0;i<n;i++)
    {
      scanf("%d %d",&u,&k);
      for(j=0;j<k;j++)
	{
	  scanf("%d %d",&v,&c);
	  M[u][v]=c;
	}
    }

  for(i=0;i<n;i++)
    {
      d[i]=INFTY;
      vis[i]=0;
    }

  d[0]=0;

  while(1)
    {
      minv=INFTY;
      u=-1;
      for(i=0;i<n;i++)
	{
	  if(minv>d[i]&&!vis[i])
	    {
	      u=i;
	      minv=d[i];
	    }
	}
      if(u==-1) break;
      vis[u]=1;
      for(v=0;v<n;v++)
	{
	  if(!vis[v]&&M[u][v]!=INFTY)
	    {
	      if(d[v]>d[u]+M[u][v])
		{
		  d[v]=d[u]+M[u][v];
		}
	    }
	}
    }

  for(i=0;i<n;i++)
    {
      printf("%d %d\n",i,(d[i]==INFTY?-1:d[i]));
    }

  return 0;
}

      



Measured memory_bytes: 2104
#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 l,r;
    cin >> l >> r;
    vector<bool> cand(2019);
    rep(i,2019){
        cand[i]=false;
    }
    rep(i,2019){
        int a;
        a=(l+i)%2019;
        if(l+i>r) break;
        cand[a]=true;
    }
    int min=2019;
    for(int i=0;i<2019;++i){
        for(int j=i+1;j<2019;++j){
            if(cand[i]&cand[j]){
                int temp;
                temp = (i*j)%2019;
                if(temp<min) min=temp; 
            }
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;
#define INF 1000000007
#define MOD 1000000007
#define SEP " "

int		main(void)
{
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++)
		cin >> p[i];
	vector<int> q(n);
	for (int i = 0; i < n; i++)
		cin >> q[i];
	int c = 0;
	vector<int> a = p;
	if (p == q)
	{
		cout << 0 << endl;
		return (0);
	}
	while (next_permutation(a.begin(), a.end()))
	{
		c++;
		if (a == q)
		{
			cout << c << endl;
			return (0);
		}
	}
	a = q;
	c = 0;
	while (next_permutation(a.begin(), a.end()))
	{
		c++;
		if (a == p)
		{
			cout << c << endl;
			return (0);
		}
	}
	return (0);
}


Measured memory_bytes: 256
#include <cstdio>

int n, k, a[105];

int read() {
    int x = 0, f = 1; char s;
    while((s = getchar()) < '0' || s > '9') if(s == '-') f = -1;
    while(s >= '0' && s <= '9') {x = (x << 1) + (x << 3) + (s ^ 48); s = getchar();}
    return x * f;
}

int main() {
    int x;
    n = read(), k = read();
    for(int i = 1; i <= k; ++ i) {
        x = read();
        for(int j = 1; j <= x; ++ j) a[read()] = 1;
    }
    x = 0;
    for(int i = 1; i <= n; ++ i)
        if(! a[i]) ++ x;
    printf("%d\n", x);
    return 0;
}


Measured memory_bytes: 1604
class SegTreeMin:
    SENTINEL = (1 << 31) - 1
    output = []

    def __init__(self, n):
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [self.SENTINEL] * (n2 << 1)

    def update(self, i, x):
        i += self.n2
        self.tree[i] = x
        while i > 1:
            self.tree[i >> 1] = x = min(x, self.tree[i ^ 1])
            i >>= 1

    def get_min(self, s, t):
        self.output.append(self._get_min(s, t + 1, 1, 0, self.n2))

    def _get_min(self, a, b, k, l, r):
        if r <= a or b <= l:
            return self.SENTINEL
        if a <= l and r <= b:
            return self.tree[k]
        m = (l + r) // 2
        k <<= 1
        return min(
            self._get_min(a, b, k, l, m),
            self._get_min(a, b, k + 1, m, r))

    def print(self):
        print('\n'.join(map(str, self.output)))


n, q = map(int, input().split())
st = SegTreeMin(n)
fs = [st.update, st.get_min]
for c, x, y in (map(int, input().split()) for _ in range(q)):
    fs[c](x, y)
st.print()

Measured memory_bytes: 14872
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};


int main(){
  int n,W; cin >> n >> W;
  vl weight(n), value(n);
  rep(i,n) cin >> weight[i] >> value[i];

  int MAX = 1000*n;
  vvl dp(n+1,vl(MAX+1,INF));
  dp[0][0] = 0;

  rep(i,n) rep(v,MAX+1) {
    dp[i+1][v] = dp[i][v];
    if(v >= value[i]) chmin(dp[i+1][v], dp[i][v-value[i]] + weight[i]);
  }

  ll ans;
  rep(v,MAX+1) if(dp[n][v] <= W) ans = v;

  cout << ans << endl;
}


Measured memory_bytes: 80256
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] T = new int [N];
        int sum=0;
        for(int i=0; i<N; i++){
            T[i]=sc.nextInt();
            sum+=T[i];
        }
        int M = sc.nextInt();
        for(int i=0; i<M; i++){
            int P = sc.nextInt();
            int X = sc.nextInt();
            int ans = sum-T[P-1]+X;
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 10324
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  string S; cin>>S;
  int N=S.size();
  int count1=0,count2=0;
  int ans=0;
  rep(i,0,N){
    if(S[i]=='<'){
     if(S[i-1]=='>'||i==0){
      ans+=max(count1,count2);
  ans+=max(0LL,count1*(count1-1)/2);
  ans+=max(0LL,count2*(count2-1)/2);
       count1=0;
       count2=0;
     }
      count1++;
    }
    else{
      count2++;
    }
  }
  ans+=max(count1,count2);
  ans+=max(0LL,count1*(count1-1)/2);
  ans+=max(0LL,count2*(count2-1)/2);
  cout<<ans<<endl;
  }



Measured memory_bytes: 900
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll a[n];
    ll ans=0;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++)
    {
        if(a[i-1]>a[i])
        {
            ll k=(a[i-1]-a[i]);
            ans+=k;
            a[i]+=k;
        }
    }
    cout<<ans;    
    return 0;
}

Measured memory_bytes: 5176
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll K,N;
map<ll,ll> a,b;
ll ans;


int main(){
    cin >> K >> N;
    if(K*500>=N){
        cout << "Yes" << endl;
    }else{
        cout << "No" <<endl;
    }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll a[110000];
pair<ll,ll> x[110000];
vector<ll> y;
int main(){
  ll n,m,b,c,ans=0;
  cin>>n>>m;
  rep(i,0,n)cin>>a[i];
  rep(i,0,m){
    cin>>b>>c;
    x[i]=mp(c,b);
  }
  sort(a,a+n,greater<ll>());
  sort(x,x+m,greater<pair<ll,ll>>());
  rep(i,0,m){
    rep(j,0,x[i].second)y.pb(x[i].first);
    if(y.size()>n)break;
  }
  ll cnt1=0,cnt2=0;
  while(cnt1+cnt2<n){
    if(cnt2>=y.size()){
      ans+=a[cnt1];
      cnt1++;
    }
    else if(a[cnt1]>=y[cnt2]){ans+=a[cnt1];cnt1++;}
    else {ans+=y[cnt2];cnt2++;}
  }
  cout<<ans;
}


Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n; i++)
#define all(a) (a).begin(),(a).end()

LL t[60], p[60];
LL ans;

void rec(LL now, LL rem){
  if(now == 0){
    ans++;
    return;
  }
  if(--rem <= 0) return;
  if(rem < t[now-1]){
    rec(now-1, rem);
  }else{
    rem -= t[now-1];
    ans += p[now-1];
    if(rem == 0) return;
    rem--; ans++;
    if(rem == 0) return;
    if(rem < t[now-1]){
      rec(now-1, rem);
    }else{
      rem -= t[now-1];
      ans += p[now-1];
      assert(rem <= 1);
    }
  }
}

int main(){
  LL n, x;
  cin >> n >> x;
  t[0] = 1;
  p[0] = 1;
  rep(i, n){
    t[i+1] = 2*t[i]+3;
    p[i+1] = 2*p[i]+1;
  }
  rec(n, x);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;
    a--; b--; c--; d--;
    for(int i = a; i < max(c,d); i++){
        if(s[i+1]=='#' && s[i]=='#'){
            cout << "No" << endl;
            return 0;
        }
    }
    if(c < d){
        cout << "Yes" << endl;
        return 0;
    }else{
        for(int i = b-1; i <= d-1 ; i++){
            if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 640
while(1):
    N, M = map(int, input().split())
    if N == 0 and M == 0:
        break
    H = [int(input()) for i in range(N)]
    HD = [0] * 1500 ** 2
    for i in range(N):
        tmp = 0
        for j in range(i, N):
            tmp += H[j]
            HD[tmp] += 1
    ans = 0
    W = [int(input()) for i in range(M)]
    for i in range(M):
        tmp = 0
        for j in range(i, M):
            tmp += W[j]
            ans += HD[tmp]
    print(ans)


Measured memory_bytes: 58320
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int a,b,c;
  cin >> a >> b >> c;

  if(a==b) cout << c << endl;
  if(a == c) cout << b << endl;
  if(b == c) cout << a << endl;

  return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using pll = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vl>; using vb = vector<bool>; using vvb = vector<vb>;
#define rep0(TMS) for (int CNT = 0; CNT < (int)(TMS); CNT++)
#define rep(CNT, GOAL) for (int CNT = 0; CNT < (int)(GOAL); CNT++)
#define rep2(CNT, START, GOAL) for (int CNT = (int)(START); CNT < (int)(GOAL); CNT++)
#define rep3(CNT, START, GOAL) for (int CNT = (int)(START); CNT > (int)(GOAL); CNT--)
#define all(CONT) begin(CONT), end(CONT)
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void prec(const int &DIG) { cout << fixed << setprecision(DIG); cerr << fixed << setprecision(DIG); }
template <typename T> void CERR(const T &ELEM) { cerr << ELEM; }
#define dbl(OBJ) cerr << #OBJ << ": "; CERR(OBJ); cerr << "\n"
template <typename T, typename ...Ts> void CERR(const T &FIRST, const Ts &...REST) { CERR(FIRST); cerr << ", "; CERR(REST...); }
#define dbs(...) cerr << "(" << #__VA_ARGS__ << "): ("; CERR(__VA_ARGS__); cerr << ")\n"
#define itrep(ITR, CONT) for (auto ITR = begin(CONT); ITR != end(CONT); ITR++)
template <typename T> void CERR(const vector<T> &VEC) { cerr << "{ "; itrep(ITR, VEC) { CERR(*ITR); cerr << ", "; } cerr << "}"; }
#define YN(FLG) cout << (FLG ? "YES" : "NO") << "\n"
#define Yn(FLG) cout << (FLG ? "Yes" : "No") << "\n"
#define yn(FLG) cout << (FLG ? "yes" : "no") << "\n"

// #include <atcoder/all>

// using namespace atcoder;

// const ll INF = LONG_LONG_MAX;
const int INF = INT_MAX;
// const ll MOD = 1000000007; // 998244353;

vector<pii> pf(int x) {
	vector<pii> res;
	int p = 2;
	while (p * p <= x) {
		int d = 0;
		while (x % p == 0) {
			x /= p;
			d++;
		}
		res.push_back(pii(p++, d));
	}
	if (x > 1) res.push_back(pii(x, 1));
	return res;
}

ll solve(int K) {
	vector<pii> v = pf(K);
	ll res = 1;
	for (pii p : v) {
		res *= (1 + p.second);
	}
	return res;
}

int main() {
	int N; cin >> N;
	ll ans = 0;
	rep2(K, 1, N) ans += solve(K);
	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 500'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  int a, b;
  cin >> a >> b;
  for (int i = 1; i < 4; ++i) {
    if (i != a && i != b) {
      cout << i << '\n';
    }
  }
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int d,t,s,r;
    cin>>d>>t>>s;
    r=t*s;
    if(r>=d)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

 return 0;
}


Measured memory_bytes: 3632
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var n = Number(lines[0]);
 var ans = "No";
 
 for(i=1; i<=9; i++){
   for(j=1; j<=9; j++){
     if(i * j == n){
       ans = "Yes";
     }
   }
 }
 
console.log(ans);


});

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

const ll M[6] = {100, 101, 102, 103, 104, 105};

ll memo[100100];

bool dfs(ll x){

    if(x == 0) return memo[x] = true;
    if(x < 100) return false;
    if(memo[x] >= 0) return memo[x];

    bool ret = false;
    REP(i,6){
        bool valid = dfs(x-M[i]);
        if(valid) {
            ret = true;
            break;
        }
    }
    return memo[x] = ret;
}

int main(){
    ll X;
    cin >> X;

    fill(memo, memo+X+1, -1);
    bool ans = dfs(X);

    if(ans)
        cout << 1 << endl;
    else
        cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 1024
def binary_search_loop(li,n):
    arry = li
    target = n
    result = None
    left = 0
    right = len(arry) - 1

    while left <= right:
        mid = (left + right) // 2
        if arry[mid] == target:
            result = mid
            break               
        elif arry[mid] > target:
            right = mid - 1
        else:
            left = mid + 1

    if result == None:
        return False
    else:
        return True

        
def era(n):
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(2*i, n + 1, i):
                table[j] = 1
    
    return prime_list

Q = int(input())
s = [list(map(int,input().split())) for i in range(Q)]



N = 10**5
prime_list = era(N)
#2M-1(Mは素数)と表される素数の累積和
ruiseki = [0]*(N+1)

for i in prime_list:
    if 2*i - 1 <= N:
        if binary_search_loop(prime_list,2*i - 1):
            ruiseki[2*i - 1] = 1   

for i in range(N):
    ruiseki[i+1] += ruiseki[i]


for i in s:
    print(ruiseki[i[1]] - ruiseki[i[0]-1])



Measured memory_bytes: 31644
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
        
        while(true){
            int sum=0;
        	double ave;
        	int count=0;
        	int n=sc.nextInt();
            int[] a=new int[n];
            if(n==0)
                break;
        	for(int i=0;i<n;i++){
            	a[i]=sc.nextInt();
           		sum+=a[i];
        	}
        	ave=sum/n;
        
        	for(int i=0;i<n;i++){
            	if(ave>=a[i])
                count++;
        	}
        	System.out.println(count);
        
        
        
        }
        
    }
}


Measured memory_bytes: 59052
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <iomanip>
#define ll long long

using namespace std;

int main(void){
    ll n, m;
    cin >> n >> m;
    vector<ll> c(n+1, 0), s(n+1, 1);
    c[1]=1;
    ll MAX = 2;
    ll ans = 0;
    for(ll i = 0; i < m; i++){
        ll a, b;
        cin >> a >> b;
        s[a]--; s[b]++;
        if(a <= MAX && c[a] != 0){
            c[b]++;
            MAX = max(MAX, max(a, b));
            if(s[a] == 0) c[a]=0;
        }
        //if(i==0) c[1]=0;
    }
    for(ll i = 1; i <= n; i++){
    //cout << s[i] << " " << c[i] << endl;
        if(s[i]!=0 && c[i]!=0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, ss, ee) for (int i = (ss); i < (ee); ++i)

int x[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
int y[] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
int z[] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};

void solve() {
  int N;
  cin >> N;
  string s;
  map<char, ll> m;
  rep(i, 0, N) {
    cin >> s;
    m[s[0]]++;
  }

  vector<ll> v(5);
  v[0] = m['M'];
  v[1] = m['A'];
  v[2] = m['R'];
  v[3] = m['C'];
  v[4] = m['H'];

  ll ans = 0;
  rep(i, 0, 10) { ans += v[x[i]] * v[y[i]] * v[z[i]]; }
  cout << ans << endl;
}

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

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

int main() {
  char s[3];
  cin>>s[0]>>s[1]>>s[2];
  
  if((s[0]=='A'||s[1]=='A'||s[2]=='A')&&(s[0]=='B'||s[1]=='B'||s[2]=='B')){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<char> &v) {
  for(auto x : v) {
    cout << x;
  }
  cout << endl;
}

int num[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  VI dp(n+1, -INF);
  VI a(m);
  rep(i, m) {
    cin >> a[i];
    a[i]--;
  }
  sort(rall(a));
  dp[0] = 0;
  rep(i, n) {
    int q = -INF;
    rep(j, m) {
      if(i + 1 - num[a[j]] >= 0) q = max(q, dp[i + 1 -num[a[j]]] + 1);
    }
    dp[i + 1] = q;
  }
  ll d = dp[n];
  vector<char> ans;
  rep(i, d) {
    int s;
    rep(j, m) {
      if(n-num[a[j]] >= 0 && dp[n-num[a[j]]] == dp[n]-1) {
        s = a[j] + 1;
        n -= num[a[j]];
        break;
      }
    }
    ans.push_back('0' + s);
  }

  print(ans);


  return 0;
}


Measured memory_bytes: 384
h, w = map(int, input().split())
ss = [[0] * w for _ in range(h)]
s = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            for k in range(max(0, i - 1), min(h, i + 2)):
                for l in range(max(0, j - 1), min(w, j + 2)):
                    ss[k][l] += 1
for i in range(h):
    ans = ""
    for j in range(w):
        if s[i][j] == "#":
            ans += s[i][j]
        else:
            ans += str(ss[i][j])
    print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);    
    
    int N, M; cin >> N >> M;
    vpl data;
    F0R(i, N) {
		ll A, B; cin >> A >> B;
		//sort by increasing date
		data.pb(mp(A, B));
	}
	sort(all(data));
	ll ans = 0;
	
	int nxt = 0;
	priority_queue<ll> pq;
 
	FOR(i, 1, M+1) {
		while (nxt < N && data[nxt].f == (ll) i) {
			pq.push(data[nxt].s); nxt++;
		}
		if (!pq.empty()) {
			ans += pq.top();
			pq.pop();
		}
	}
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3696
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>

using namespace std;

string str[101];

int main()
{
	int n;

	
	while(cin >> n && n)
	{
		bool flag = false;
		int a[2] = {0,0};
		int sum = 0; 

		for(int i = 0;i < n;i++)
		{
			cin >> str[i];
		}
		
		for(int i = 0;i < n;i++)
		{
			if(flag)
			{
				if(str[i] == "ld")
				{
					a[0] = 0;
				}else
				if(str[i] == "rd")
				{
					a[1] = 0;
				}
				if(str[i] == "lu")
				{
					a[0] = 1;
				}else
				if(str[i] == "ru")
				{
					a[1] = 1;
				}

				if(!a[0] && !a[1])
				{
					flag = false;
					sum++;
				}

			}else
			{
				if(str[i] == "ld")
				{
					a[0] = 0;
				}else
				if(str[i] == "rd")
				{
					a[1] = 0;
				}
				if(str[i] == "lu")
				{
					a[0] = 1;
				}else
				if(str[i] == "ru")
				{
					a[1] = 1;
				}

				if(a[0] && a[1])
				{
					flag = true;
					sum++;
				}
			}
		}

		cout << sum << endl;
	}


	return 0;
}

Measured memory_bytes: 1212
#include<iostream>
using namespace std;
 int main()
 {
     int a,b;
     while(cin>>a>>b)
{


     if(a>b)
        cout<<"a > b"<<endl;
     else if( a<b)
        cout<<"a < b"<<endl;
     else
        cout<<"a == b"<<endl;
}
     return 0;


 }



Measured memory_bytes: 3080
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
//typedef pair<int,int> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
	int n,m,a,b;
	cin>>n>>m;
	int ans[n+2];
  for(int i=0;i<n+1;i++) ans[i]=0;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		ans[a]++;
		ans[b]++;
	}
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int main(void) {
  ll a, b;
  cin >> a >> b;
  ll x = a + b;
  if(x % 2) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  cout << (x >> 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int W,H,x,y,r;

  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if( y+r <= H  && x+r <= W  &&  y-r >= 0  &&  x-r >= 0){

    printf("Yes\n");

  }

  else {

    printf("No\n");

  }

  return 0;

}

Measured memory_bytes: 584
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
    int N,M,p,ans=100000;
    int lis[10001]={0},lismap[100001]={0};
    cin>>N>>M>>p;
    for(int i=0;i<M;i++){
        int a;
        cin>>a;
        lis[i]=a;
        lismap[a]=1;
    }
    sort(lis,lis+M);
    int che=0;
    for(int i=0;;i++){
        if(lismap[(p+i)%N]==1)che++;
        if(che==M){
            ans=min(ans,i);
            break;
        }
    }
    che=0;
    for(int i=0;;i++){
        if(lismap[(N+(p-i))%N]==1)che++;
        if(che==M){
            ans=min(ans,i);
            break;
        }
    }
    for(int i=0;i<M;i++){
        int karians1=0,karians2=0;
        int a=lis[i]-p;
        if(a<0)a+=N;
        karians1+=a*2;
        karians2+=a;
        if(i==M-1){
            int b=p-lis[0];
            if(b<0)b+=N;
            karians1+=b;
            karians2+=b*2;
        }
        else{
            int b=p-lis[i+1];
            if(b<0)b+=N;
            karians1+=b;
            karians2+=b*2;
        }
        ans=min(ans,min(karians1,karians2));
    }
    cout<<ans*100<<endl;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    for(int i=0; i<1000; i++){
        if(s[i] == ' ')
            continue;
        if(s[i] == '\0')
           break;
        if(s[i]<='C')
            s[i] += 26;
        s[i] -= 3;
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mod (1000*1000*1000+7)
#define modd (1000*1000*1000+9)
#define flush fflush(stdout)
#define pi 3.14159265358979323846264338327950
#define read_in_arr(a, n) for(int i=0;i<n;i++){ cin>>a[i];}
#define print_arr(a, n) for(int i=0;i<n;i++){ cout<<a[i]<<" ";} cout<<endl;
// cout<<fixed<<setprecision(12)<<ans<<endl;
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	int n;
	cin>>n;
	int c = n%1000;
	if(c==0){
		cout<<"0"<<endl;
		//continue;
	}
	else{
		cout<<1000-c<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<iterator>
#include<math.h>
#include<cstring>
using namespace std;
void lets_play()

{
    int a[10],i;
   int c1=0,c2=0;
  for(i=0;i<3;i++)
  {
      cin>>a[i];
  }

    if( a[0]==5&&a[1]==5&&a[2]==7|| a[0]==5&&a[1]==7&&a[2]==5|| a[0]==7&&a[1]==5&&a[2]==5)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    }

int main()
{
        lets_play();

}


Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 1111111


struct BinaryIndexed {
  ll num;
  vll bit;

  BinaryIndexed(ll x = MAX) {
    num = x;
    bit.resize(x + 1, 0);
  }

  ll sum(ll i) {
    ll ret = 0;
    while (i > 0) {
      ret += bit[i];
      i -= i & -i;
    }
    return ret;
  }

  void add(ll i, ll x) {
    if (i == 0) cout << "access 0 index" << endl;
    while (i <= num) {
      bit[i] += x;
      i += i & -i;
    }
  }
};


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

  cin >> n;
  cin >> s;
  s = " " + s;
  ll q;
  cin >> q;
  while (q--) {
    cin >> m;
    BinaryIndexed bit;
    cnt = 0; ans = 0;
    ll a = 0, b = 0;
    FOR(i, 1, n + 1) {
      if (i > m) {
        if (s[i - m] == 'D') {
          cnt -= b; a--;
        }
        if (s[i - m] == 'M') b--;
      }

      if (s[i] == 'D') {
        a++;
      }
      if (s[i] == 'M') {
        b++;
        cnt += a;
      }
      if (s[i] == 'C') {
        ans += cnt;
      }
    }
    cout << ans << endl;
  }


  return 0;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);


    int n;
    cin >> n;
    vi x(n), y(n), h(n);
    rep(i, n)cin >> x[i] >> y[i] >> h[i];
    rep(i, 101)rep(j, 101){
        int ch;
        int ml = infi;
        for(int k=0; k < n; k++){
            int l =  abs(i-x[k])+abs(j-y[k]); 
            if(l < ml){
                ml = l;
                ch = h[k]+l;
            }
        }
        bool f = true;
        for(int k = 0; k < n; k++){
            int th = max(ch-abs(i-x[k])-abs(j-y[k]), 0);
            if(th != h[k]){
                f = false;
                break;
            }
        }
        if(f){
            cout << i << " " << j << " " << ch << "\n";
            return 0;
        }
    }


    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i=0; i<n; i++) cin >> h.at(i);
  int mh = h.at(0);
  int ans = 1;
  for (int i=1; i<n; i++) {
    if (h.at(i) >= mh) {
      ans++;
      mh = h.at(i);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256