akhauriyash/Code-Regression huggingface dataset:
def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs

def main():
    n,k=map(int, input().split())
    A=[int(i) for i in input().split()]
    MOD = 10**9 + 7
    fac, invs = prepare(n,MOD)
    ans = 0
    A.sort()

    for i in range(n):
        tmp=0
        tmp2=0
        if i<n-k+1:
            tmp = (fac[n-(i+1)]%MOD * invs[k-1]%MOD * invs[n-(i+1) - (k-1)]%MOD)%MOD
        if i>=k-1:
            tmp2 = (fac[i]%MOD * invs[k-1]%MOD * invs[i-(k-1)]%MOD)%MOD
        #print("最大になる回数", tmp2, " 最小になる回数", tmp, "A[i]", A[i])
        ans = ans%MOD + (tmp2*A[i]%MOD - tmp*A[i]%MOD)%MOD
        ans%=MOD

    if k==1:
        ans = 0
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15572
# https://atcoder.jp/contests/abc054/tasks/abc054_b
n, m = map(int, input().split())

A = []
for _ in range(n):
    row = list(input())
    A.append(row)

B = []
for _ in range(m):
    row = list(input())
    B.append(row)

def check(A, B, x, y):
    for i in range(m):
        for j in range(m):
            if B[i][j] == A[x + i][y + j]:
                continue
            else:
                return False
    return True

def main():
    for i in range(n):
        for j in range(n):
            if A[i][j] == B[0][0] and i + m <= n and j + m <= n:
                if check(A, B, i, j):
                    print('Yes')
                    return
    print('No')

if __name__ == "__main__":
    main()




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

int main()
{
  int n, m;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0)break;

    vector<int> tarou(n);
    vector<int> hanako(m);

    int a, tarou_s = 0, hanako_s = 0;
    for(int i = 0;i < n; i++)
    {
      cin >> tarou[i];
      tarou_s += tarou[i];
    }
    for(int i = 0;i < m; i++)
    {
      cin >> hanako[i];
      hanako_s += hanako[i];
    }

    sort(tarou.begin(), tarou.end());
    sort(hanako.begin(), hanako.end());

    bool frag = true;
        for(int i = 0; i < n; i++)
        {
          for(int j = 0; j < m; j++)
          {
            if((tarou_s - tarou[i] + hanako[j]) == (hanako_s - hanako[j] + tarou[i]))
            {
              if(frag){
                cout << tarou[i] << ' ' << hanako[j] << endl;
                frag = false;
              }
              
            }
          }
        }
    if(frag)cout << -1 << endl;

  }

  return 0;
}


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

int main(){
    int n;
    cin >> n;
    long long ans=0, ans_save;
    long num=0;
    for(int i=1;i<n+1;i++){
        num = n/i;
        // cout << num << endl;
        ans_save = i*(num)*(num+1)/2;
        ans += ans_save;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
l=gets.to_i-1
if l==0
  puts "20 1", "1 20 0"
elsif l==1
  puts "20 2", "1 20 0", "1 20 1"
else
  v=1
  E=[[1,20,0]]
  until l.zero?
    if l.odd?
      E<<[v,20,l]
      l-=1
    end
    if l<=2
      l=0
      E<<[v,20,1]<<[v,20,2]
    else
      l/=2
      E<<[v,v+1,0]<<[v,v+1,l]
    end
    v+=1
  end
  puts "20 #{E.size}"
  puts E.map{|s|s*" "}
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define EPS 0.0000000001
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n;
    cin>>n;
    double x[n];
    double count=EPS;
    rep(i,n){
        string s;
        cin>>x[i]>>s;
        if(s=="JPY"){
            count+=x[i];
        }
        else{
            count+=380000*x[i];
        }
    }
    cout<<count<<endl;

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    var a = mutableMapOf<String,Int>()
    var b = mutableMapOf<String,Int>()

    a["TTTT"]=1

    repeat(N){ i ->
        a.forEach{
            "ACGT".forEach { c ->
                val s = it.key.drop(1) + c
                if(ok4(s)) b[s] = ( (b[s]?:0) + it.value) % 1000000007
            }
        }
        a = b
        b = mutableMapOf()
    }

    val ans = a.map { it.value }.reduce { a,b -> (a+b)%1000000007 }
    println(ans)
}

fun ok4(s:String):Boolean = listOf(
        s.matches(Regex("[ATGC]AGC")),
        s.matches(Regex("A[ATGC]GC")),
        s.matches(Regex("AG[ATGC]C")),
        s.matches(Regex("[ATGC]ACG")),
        s.matches(Regex("[ATGC]GAC")) ).none{ it }

Measured memory_bytes: 127516
//=====================================================
// 
// (setq backup-inhibited t)
// (setq auto-save-default nil)
// 
// (column-number-mode t)
// (setq-default tab-width 2 indent-tabs-mode nil)
// 
// (global-set-key "\C-h" 'delete-backward-char)
// 
// (setq indent-line-function 'indent-relative-maybe)
// (global-set-key "\C-m" 'newline-and-indent)
// 
//=====================================================

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  vector<vector<int>> factors(300000);
  for(int i = 0;; ++i) {
    int i1 = i*7+1;
    int i2 = i*7+6;
    if (i1 >= 300000) break;
    if (i != 0 && factors[i1].empty()) {
      for (int j = i1; j < 300000; j += i1) {
        factors[j].push_back(i1);
      }
    }
    if (i2 >= 300000) break;
    if (factors[i2].empty()) {
      for (int j = i2; j < 300000; j += i2) {
        factors[j].push_back(i2);
      }
    }
  }
  while(1){
    int n;
    cin >> n;
    if(n==1) break;
    cout << n << ':';
    for (int k : factors[n]) {
      cout << ' ' << k;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 16636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

int main(){
  double a,b,x;
  cin>>a>>b>>x;
  double s=(2*a*a*b-2*x)/(a*a*a);
  double t=a*b*b/(2*x);

  if(x>=a*a*b/2){
    printf("%.10f\n",atan(s)*180/M_PI);
  }
  else{
    printf("%.10f\n",atan(t)*180/M_PI);
  }

  return(0);
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

		int b;

		int c;

		b = a / 1;
		c = a % 1;

		if (Anser(b, c)) {

			System.out.println("Yes");
			System.exit(0);
		}

		b = a / 2;
		c = a % 2;

		if (Anser(b, c)) {

			System.out.println("Yes");
			System.exit(0);
		}

		b = a / 3;
		c = a % 3;

		if (Anser(b, c)) {

			System.out.println("Yes");
			System.exit(0);
		}

		b = a / 4;
		c = a % 4;

		if (Anser(b, c)) {

			System.out.println("Yes");
			System.exit(0);
		}

		b = a / 5;
		c = a % 5;

		if (Anser(b, c)) {

			System.out.println("Yes");
			System.exit(0);
		}

		b = a / 6;
		c = a % 6;

		if (Anser(b, c)) {

			System.out.println("Yes");
			System.exit(0);
		}

		b = a / 7;
		c = a % 7;

		if (Anser(b, c)) {

			System.out.println("Yes");
			System.exit(0);
		}

		b = a / 8;
		c = a % 8;

		if (Anser(b, c)) {

			System.out.println("Yes");
			System.exit(0);
		}

		b = a / 9;
		c = a % 9;

		if (Anser(b, c)) {

			System.out.println("Yes");
			System.exit(0);
		}

		System.out.println("No");

	}

	public static Boolean Anser(int val01, int val02) {

		boolean flg = true;

		if (val01 >= 10) {

			return flg = false;

		}

		if (val02 != 0) {

			return flg = false;

		}

		return flg;

	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
    lint k;
    cin >> k;

    lint ans = 0;
    for(lint a=1; a<=k; a++)
    for(lint b=1; b<=k; b++)
    for(lint c=1; c<=k; c++) {
        ans += __gcd(__gcd(a,b), c);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
# 深さ優先探索（行きがけ、帰りがけ）
import sys
input = sys.stdin.readline
from collections import deque

# グラフの作成(無向グラフでは#を消す)
N = int(input())
graph = [deque([]) for _ in range(N + 1)]
for _ in range(N):
    u, k, * v = [int(x) for x in input().split()] # uは頂点番号、kは隣接頂点の個数
    v.sort()
    for i in v:
        graph[u].append(i)
        # graph[i].append(u) # 無向グラフ

time = 0
arrive_time = [-1] * (N + 1) # 到着時刻
finish_time = [-1] * (N + 1) # 探索終了時刻

# 深さ優先探索
def dfs(v):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w) 
        else:
            time += 1
            finish_time[v] = time
            stack.pop()          
    return [arrive_time, finish_time]

# 孤立している頂点対策
for i in range(N):
    if arrive_time[i + 1] < 0:
        ans = dfs(i + 1)

# 頂点番号、到着時刻、終了時刻
for j in range(N):
    temp = [j + 1, ans[0][j + 1], ans[1][j + 1]]
    print(* temp)


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

struct Edge{
	int to;
	ll D;
};

vector<Edge> G[100000];
ll X[100000];
int vis[100000];
bool ok = 1;

void dfs(int v){
	vis[v] = 1;
	for(auto e : G[v]){
		if(vis[e.to]){
			if(X[v] + e.D != X[e.to]) ok = 0;
		}
		else{
			X[e.to] = X[v] + e.D;
			dfs(e.to);
		}
	}
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N, M;
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		int L, R, D;
		cin >> L >> R >> D;
		L--, R--;
		G[L].push_back({ R, D });
		G[R].push_back({ L, -D });
	}

	for(int i = 0; i < N; i++){
		if(vis[i]) continue;
		X[i] = 0;
		dfs(i);
	}

	if(ok){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 16000
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.annotation.tailrec
import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map(converter)
  }

  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val s = get[String]

    @tailrec
    def count(l: Int, r: Int, c: Int): Int = {
      if (r <= l) {
        c
      } else {
        if (s(l) == s(r)) {
          count(l + 1, r - 1, c)
        } else if (s(l) == 'x') {
          count(l + 1, r, c + 1)
        } else if (s(r) == 'x') {
          count(l, r - 1, c + 1)
        } else {
          -1
        }
      }
    }

    out.println(count(0, s.length - 1, 0))

    out.flush()
  }
}

Measured memory_bytes: 29148
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        while(true) {
            int H = scn.nextInt();
            int W = scn.nextInt();
            if(H == 0 && W == 0) {
                break;
            }
            char[] buf = new char[W];
            Arrays.fill(buf, '#');
            String lin = new String(buf);
            for(int i = 0; i < H; i++) {
                System.out.println(lin);
            }
            System.out.println();
        }
    }
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define F first
#define S second

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

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

  vector<int> v(n, -1);
  vector<vector<int>> edge(n);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  queue<int> q;
  v[0] = 0;
  q.push(0);
  while(!q.empty()) {
    int now = q.front(); q.pop();
    rep(i, edge[now].size()) {
      int next = edge[now][i];
      if(v[next] != -1) continue;

      v[next] = now;
      q.push(next);
    }
  }

  bool f = true;
  rep(i, v.size()) {
    if(v[i] == -1) {
      f = false;
      break;
    }
  }
  if (f == false) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for(int i = 1; i < n; i++) {
      cout << v[i] + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 10332
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque
from collections import defaultdict

def bfs(graph:list, start:int) -> list:
    # 未探索のノードは距離null
    node = len(graph)
    dist = [None]*node
    
    # 始点ノードの距離を0とし、bfsのためのqueueを作成
    dist[start] = 0
    que = deque([(0,start)])
    
    # 未探索のノードをqueueに入れる
    # kより大きいの距離のものを数える
    while que:
        cost, cur_node = que.popleft()

        for nex_cost, nex_node in graph[cur_node]:
            if dist[nex_node] is not None:
                continue
            else:
                dist[nex_node] = dist[cur_node] + nex_cost
                que.append((dist[nex_node], nex_node))
                
    return dist
  
# 入力, グラフ作成
n,k = li()
adj_list = [[] for _ in range(n)]
edges = []
for _ in range(n-1):
    a,b = li_()
    adj_list[a].append((1,b))
    adj_list[b].append((1,a))
    edges.append((a,b))

ans = n
# kが奇数の時
if k%2:
    for a,b in edges:
        dist1 = bfs(adj_list, a)
        dist2 = bfs(adj_list, b)
        ans = min(ans, sum([min(d1,d2) > (k-1)//2 for d1,d2 in zip(dist1, dist2)]))
    
# kが偶数の時
else:
    for st in range(n):
        dist = bfs(adj_list, st)
        ans = min(ans, sum([d > k//2 for d in dist]))

print(ans)

Measured memory_bytes: 72848
from collections import defaultdict
N, K = map(int,input().split())
A = list(map(int,input().split()))
D = defaultdict(int)
for a in A:
  D[a]+=1
D = sorted(D.values())
ans = 0
if len(D)<=K:
  print(ans)
else:
    print(sum(D[:len(D)-K]))

Measured memory_bytes: 35220
#include <iostream>

using namespace std;

int n;
int t[100005];

int dp[100005];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> t[i];
	}
	dp[1] = 0;
	dp[2] = abs(t[1]-t[2]);
	for (int i = 3; i <= n; ++i) {
		dp[i] = min(dp[i-1]+abs(t[i]-t[i-1]), dp[i-2]+abs(t[i]-t[i-2]));
	}
	cout << dp[n] << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, M, X;
    cin >> N >> M >> X;
    int left = 0, right = 0;
    for(int i = 0; i < M; i++) {
        int A;
        cin >> A;
        if(A<X) left++;
        else right++;
    }
    cout << min(left, right) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 200005
#define INF 1001001001

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

int main(){
  int d, g;
  cin >> d >> g;
  vector<int> p(d);
  vector<int> c(d);
  rep(i, d){
    cin >> p[i] >> c[i];
  }


  priority_queue<ll> PQ;
  for(int bit=0; bit< (1<<d); bit++){
    vector<bool> uncomplete(d);
    ll sum=0;
    ll ans=0;
    rep(i, d){
      if(bit&(1<<i)){
        sum+=c[i]+p[i]*100*(i+1);
        ans+=p[i];
      } else {
        uncomplete[i]=true;
      }
    }
    int j=d-1;
    for(int j=d-1; j>=0 && sum<g; j--){
      if(uncomplete[j]){
        int num=(g-sum-100)/(100*(j+1))+1;
        if(num<=p[j]-1){
          ans+=num;
          sum+=100*(j+1)*num;
          break;
        } else {
          ans+=p[j]-1;
          sum+=100*(j+1)*(p[j]-1);
        }
      }
    }
    if(sum<g)continue;
    PQ.push(-ans);
  }
  cout << -PQ.top() << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
#dp[i][four] =: i + 1番目まで見たとき,照合したケツがfourとなるものの総数
dp = [[0 for _ in range(4)] for _ in range(len(S)+1 )]
dp[0][0] = 1
mod = 10**9 + 7
for i in range(len(S)):
    if S[i] == '?':
        dp[i+1][1] += dp[i][0] 
        dp[i+1][1] %= mod
        dp[i+1][2] += dp[i][1] 
        dp[i+1][2] %= mod
        dp[i+1][3] += dp[i][2] 
        dp[i+1][3] %= mod
    if S[i] == 'A':
        dp[i+1][1] += dp[i][0] 
        dp[i+1][1] %= mod
    if S[i] == 'B':
        dp[i+1][2] += dp[i][1]
        dp[i+1][2] %= mod
    if S[i] == 'C':
        dp[i+1][3] += dp[i][2]
        dp[i+1][3] %= mod
    for f in range(4):
        if S[i] != '?':
            dp[i+1][f] += dp[i][f]
        else:
            dp[i+1][f] += dp[i][f] * 3
        dp[i+1][f] %= mod
print(dp[len(S)][3]%mod)


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

def call(n):
    i = 0
    while True:
        i += 1
        if i > n:
            break
        x = i
        if x % 3 == 0:
            print(' ' + str(i), end = '')
            continue

        while True:
            if int(x) % 10 == 3:
                print(' ' + str(i), end = '')
                break
            x /= 10
            if x == 0:
                break
            
    print()
    
call(n)

Measured memory_bytes: 8016
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;

int main(){
    long long n;
    cin >> n;

    long long ans = 1;
    for(long long i = 1; i <= n; ++i){
        ans = i * ans % 1000000007;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
    int a;
    int b;
    int c;
    
    cin>>a>>b>>c;
    
    if(a>b){
        swap(a,b);
    }
    bool A = a < c;
    bool B = c < b;
    
    if ( A && B ){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
    return 0;
    }


Measured memory_bytes: 384
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf = 2147483647;
const long long int My_LInf = 9223372036854775807;

struct plant {
	double fertrate;

	double lovewater;
	double vital;
};
double pw;
vector<plant>plants;

double getmon(const double water) {
	double ans = water*pw;
	for (auto p:plants) {
		double rest = p.vital - water*p.lovewater;
		if (rest < 0) {
			ans += 0;
		}
		else {
			ans += rest / p.fertrate;
		}
	}
	return ans;
}

int main() {
	while (1) {
		plants.clear();
		int N; cin >> N; if (!N)break;
		cin >> pw;
		for (int i = 0; i < N; ++i) {
			double vw, pf, vf, t; cin >> vw >> pf >> vf >> t;
			double fertrate = vf / pf;
			double water= vw;
			plants.push_back(plant{ fertrate,water,t });

		}
		double amin = 0;
		double amax = 100;
		while (amin < amax - 1e-11) {
			double amid1 = (amin * 2 + amax) / 3;
			double amid2 = (amin + amax * 2) / 3;
			double mon1 = getmon(amid1);
			double mon2 = getmon(amid2);
			if (mon1 < mon2) {
				amax = amid2;
			}
			else {
				amin = amid1;
			}
		}
		double ans = getmon((amin+amax)/2);
		cout <<setprecision(22)<<fixed<< ans << endl;
	}
	return 0;
}

Measured memory_bytes: 6072
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using ll = long long;

const int AMAX = 100000;

vector<ll> cnt(AMAX + 1, 0);

int main(void) {
    int n;
    ll k;

    cin >> n >> k;

    for (int i = 0; i < n; ++i) {
        int a, b;

        cin >> a >> b;
        cnt[a] += b;
    }

    for (int ans = 1; ans <= AMAX; ++ans) {
        if (k <= cnt.at(ans)) {
            cout << ans << endl;
            break;
        }

        k -= cnt[ans];
    }

    return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_V 202
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cap, cost, rev;
	edge(int to_, int cap_, int cost_, int rev_)
		: to(to_), cap(cap_), cost(cost_), rev(rev_) {}
};

int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];

void AddEdge(int from, int to, int cap, int cost) {
	G[from].push_back(edge(to, cap, cost, G[to].size()));
	G[to].push_back(edge(from, 0, -cost, G[from].size() - 1));
}

int MinimumCostFlow(int s, int t, int f) {
	int res = 0;
	fill(h, h + V, 0);
	while (f > 0) {
		priority_queue<P, vector<P>, greater<P>> que;
		fill(dist, dist + V, INF);
		dist[s] = 0;
		que.push(P(0, s));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			int v = p.second;
			if (dist[v] < p.first) continue;
			for (size_t i = 0; i < G[v].size(); i++) {
				edge &e = G[v][i];
				if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
					prevv[e.to] = v;
					preve[e.to] = i;
					que.push(P(dist[e.to], e.to));
				}
			}
		}
		if (dist[t] == INF) return -1;
		for (int v = 0; v < V; v++)
			h[v] += dist[v];
		int d = f;
		for (int v = t; v != s; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * h[t];
		for (int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int main()
{
	int n;
	cin >> n;
	V = n * 2 + 2;
	vector<vector<int>> W(n, vector<int>(n)), E(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> W[i][j];
		}
		AddEdge(n * 2, i, 1, 0);
		AddEdge(n + i, n * 2 + 1, 1, 0);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> E[i][j];
		}
	}
	vector<string> s(n);
	int def = 0;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = 0; j < n; j++) {
			if (s[i][j] == '.') {
				AddEdge(i, n + j, 1, W[i][j]);
			}
			else {
				AddEdge(i, n + j, 1, -E[i][j]);
				def += E[i][j];
			}
		}
	}
	cout << MinimumCostFlow(n * 2, n * 2 + 1, n) + def << endl;
	int res = 0;
	for (int i = 0; i < n; i++) {
		for (auto & e : G[i]) {
			if (e.cap == 1 && e.to - n < n && s[i][e.to - n] != '.') {
				res++;
			}
			else if (e.cap == 0 && e.to - n < n && s[i][e.to - n] != 'o') {
				res++;
			}
		}
	}
	cout << res << endl;
	for (int i = 0; i < n; i++) {
		for (auto & e : G[i]) {
			if (e.cap == 1 && e.to - n < n && s[i][e.to - n] != '.') {
				cout << i + 1 << ' ' << e.to - n + 1 << " erase" << endl;
			}
			else if (e.cap == 0 && e.to - n < n && s[i][e.to - n] != 'o') {
				cout << i + 1 << ' ' << e.to - n + 1 << " write" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a); 
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}	
};


map<int,int> h;
int dp[2007];
vector <int> arraySort(vector <int> v) {
	vector<int> ans;
	for(int i = 1; i <= (int)v.size(); i++){
		dp[i] = 1;
	}
	
	for(int i = 1; i <= (int)v.size(); i++){
		for(int j = 1; j < i; j++){
			if(v[j-1] <= v[i-1]){ 
				if(dp[i] < dp[j] + 1){
					dp[i] = dp[j] + 1;
					h[i] = j;
				}
				else if(dp[i] == dp[j] + 1){					
					int index = h[i];
					int val = v[index-1];
					if(v[j-1] < val){
						h[i] = j;
					}
				}
			}
		}
	}
	int index, maxi = 0, minval = inf;
	for(int i = 1; i <= (int)v.size(); i++){
		if(maxi <= dp[i] ){
			maxi = dp[i];
		}
	} 
	
	for(int i = 1; i<= (int)v.size(); i++){
		if(maxi == dp[i]){
			if(minval > v[i-1]){
				minval = v[i-1];
				index = i;
			}
		}
	}
	
	cout<<minval<<" "<<index<<endl;
	
	int next = index;
	
	while(next){
		cout<<next<<" ";
		next = h[next];
	}
	return ans;
}


int main(){
	int n, r; cin>> n >> r;
	if(n >= 10){
		cout<< r;
	}
	else{
		
		cout<<r+1*100*(10-n);
	}
	return 0;
}













Measured memory_bytes: 256
#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++)
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;

string S[10100];
int main(){
    int N;
    cin >> N;
    ll ans = 0;
    int first = 0;
    int last = 0;
    int both = 0;
    REP(i,N){
        string s;
        cin >> s;
        S[i] = s;
        char x = s[0];
        for(int k = 1; k < s.length(); k++){
            char x2 = s[k];
            if(s[k-1] == 'A' && s[k] == 'B'){
                ans++;
            }
            x = x2;
        }

        if(s[0] == 'B' && s[s.length()-1] == 'A'){
            both++;
        }
        else{
            if(s[0] == 'B') first++;
            if(s[s.length()-1] == 'A') last++;
        }
    }

    //int tmp = min(first, last) ;
    //ans += min(tmp, N-1);

    //int ma = max(first, last);
    //int mi = min(first, last);
    //int rem = ma - mi;

    //ans += min(mi, N-1);

    //if(both >= rem){
    //    ans += rem;
    //    if(both != 0) 
    //        ans += both-1;
    //}
    //else{
    //    ans += both;
    //}

    //int x = min(both, min(first, last));
    //both -= x;
    //first -= x;
    //last -= x;

    if(both > 0){
        ans += both-1;
        if(first > 0){
            ans++;
            first--;
        }
        if(last > 0){
            ans++;
            last--;
        }
    }


    ans += min(first, last);

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


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 998244353;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    int n, s;
    cin >> n >> s;
    vector<int> v(n);
    for(int& x : v) cin >> x;
    vector<long long> ans(3001, 0);
    ans[0] = 1ll;
    long long total = 0; 
    
    for(const int& val : v)
    {
        vector<ll> cpy = ans;
        // nao usar val dobra a contribuicao de cada subconjunto
        for(int i = 0; i < 3001; ++i)
        {
            ans[i] = (ans[i] * 2ll) % MOD;
        }
        for(int i = 0; i < 3001; ++i)
        {
            if(i >= val) ans[i] = (ans[i] + cpy[i - val]) % MOD;
        }
    }
    cout << ans[s] << '\n';
    return 0;
}



Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    ll n,m;
    cin >> n >> m;
    ll ans = 1;
    for(int i=1;i*i<=m && n*i<=m;i++){
        if(m%i==0){
            if(i>=n) chmax(ans,m/i);
            chmax(ans,i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 + 7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};
 

vector<pii>g[100007];
vector<int>ans(100006);

 int cnt;

 void dfs(int x,int p,int c)
 {
   int col=1;
   for(auto i : g[x])
   {
     if(i.first!=p)
     {
       if(col==c)col++;
        ans[i.second]=col;
        dfs(i.first,x,col);
        col++;
     }
   }
 }



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


  int n;
  cin>>n;

  for(int i=1;i<=n-1;i++)
  {
    int x,y;
    cin>>x>>y;
    g[x].push_back({y,i});
    g[y].push_back({x,i});

  }
  for(int i=1;i<=n;i++)
  cnt=max(cnt,(int)g[i].size());

  dfs(1,0,0);

  cout<<cnt<<"\n";

  for(int i=1;i<n;i++)
  cout<<ans[i]<<"\n";

  
 




}

Measured memory_bytes: 11136
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

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

  int n,x;
  string s;
  cin >> n >> x;

  if(n < x) cout << 0 << endl;
  else cout << 10 << endl;  
  
  return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		sc.close();

		//3人グループを作りまくると最大になる
		int ans = N / 3;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23380
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long int llint;

llint N, K;

int main() {
	cin >> N >> K;
	vector<llint> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	sort(H.begin(), H.end());

	llint ans = 0;
	for (int i = 0; i < N - K; i++) {
		ans += H[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
if a1 < b1:
    a1, b1 = b1, a1
    a2, b2 = b2, a2
a1 *= t1
b1 *= t1
a2 *= t2
b2 *= t2
a = a1 + a2
b = b1 + b2
if a == b:
    print("infinity")
elif a > b:
    print(0)
else:
    d1 = a1 - b1
    d2 = b2 - a2
    if d1 % (d2 - d1) == 0:
        ans = d1 // (d2 - d1) * 2
    else:
        ans = d1 // (d2 - d1) * 2 + 1
    print(ans)
        
        

Measured memory_bytes: 9096
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll h,w,n;
  cin >> h >> w >> n;
  vector<P> p(n);
  rep(i,n){
    cin >> p[i].second;
    p[i].first=i+1;
  }
  vl a(h*w);
  ll cnt=0;
  ll j=0;
  rep(i,h*w){
    if(cnt<p[j].second){
      a[i]=p[j].first;
      cnt++;
    }
    else if(cnt==p[j].second){
      j++;
      a[i]=p[j].first;
      cnt=1;
    }
  }
  ll G=h*w;
  j=0;
  while(j<G){
    if((j/w)%2==0){
      FOR(i,j,j+w){
        cout << a[i] << " ";
        if(i==w-1){
          cout << endl;
        }
      }
    }
    else if((j/w)%2==1){
      for(ll i=j+w-1;i>=j;i--){
        cout << a[i] << " ";
        if(i==j){
          cout << endl;
        }
      }
    }
    j +=w;
  }
}

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

using namespace std;

const string vs = "^v<>";

int main()
{

  int N, X[3000], Y[3000], Z[3000];
  cin >> N;
  map< pair< int, int >, int > xx, yy;
  for(int i = 0; i < N; i++) {
    char zz;
    cin >> X[i] >> Y[i] >> zz;
    Z[i] = vs.find(zz);
    xx[{X[i], Y[i]}] = i;
    yy[{Y[i], X[i]}] = i;
  }

  xx[{-1145141919, -1145141919}] = -1;
  xx[{1145141919, 1145141919}] = -1;
  yy[{-1145141919, -1145141919}] = -1;
  yy[{1145141919, 1145141919}] = -1;


  int ret = 0;

  for(int i = 0; i < N; i++) {
    auto aa = xx, bb = yy;
    aa.erase({X[i], Y[i]});
    bb.erase({Y[i], X[i]});

    int now = i, sum = 1;
    bool latte = true;
    for(;; sum++) {
      latte = false;
      if(Z[now] >= 2) {
        auto pp = bb.lower_bound({Y[now], X[now]});
        if(Z[now] % 2 == 0) --pp;
        if(pp->first.first != Y[now]) break;
        now = pp->second;
      } else {
        auto pp = aa.lower_bound({X[now], Y[now]});
        if(Z[now] % 2 == 0) --pp;
        if(pp->first.first != X[now]) break;
        now = pp->second;
      }
      aa.erase({X[now], Y[now]});
      bb.erase({Y[now], X[now]});
    }

    ret = max(ret, sum);
  }

  cout << ret << endl;
}

Measured memory_bytes: 3948
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    ll a[n];
    ll s, maxa, mina;
    s = 0, maxa = -10e11, mina = 10e11;
    for (int i = 0; i < n; i++){
        cin >> a[i];
      	s += a[i];
        mina = min(a[i], mina);
    	maxa = max(a[i], maxa);
    }
    cout << mina << " " << maxa << " " << s << endl;
    return 0;
}


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

int main(){
    int N;
    string C;
    cin >> N >> C;
    int c[N+1];
    int ans;
    int count_r=0; //白石の数
    int count=0;
    //1=白石、0=赤石
    for(int i=1;i<=N;i++){
      if(C.substr(i-1,1)=="R"){
      c[i] = 0;
      count_r += 1;
      }else{
          c[i]=1;
      }
    }
  for(int i=1;i<=count_r;i++){
    if(c[i]==1){
      count += 1;
    }
  }
  
  ans = count;
  cout << ans << endl;
}


Measured memory_bytes: 4488
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int n, i;
	cin >> n;
	++n;
	int arr[n], b[n - 1];
	fo(i, 0, n)
	cin >> arr[i];
	fo(i, 0, n - 1)
	cin >> b[i];
	
	ll ans = 0;
	for(i = 0; i < n - 1; i++){
		int red = min(arr[i], b[i]);
		ans += red;
		arr[i] -= red;
		b[i] -= red;
		
		red = min(arr[i + 1], b[i]);
		arr[i + 1] -= red;
		ans += red;
		b[i] -= red;
	}
	cout << ans;
}

Measured memory_bytes: 1024
#include<stdio.h>
int m,data[100][51],sum[100][51];

void tansaku();

main(){
  int i,j,p;
  char a;

  //while(1){
    p=0;
    for(i=0;i<100;i++){
      for(j=0;j<50;j++){
	scanf("%d", &data[i][j]);
	scanf("%c", &a);
	if(a=='\n'){
	  if(i!=0){
	    if(j==0){
	      p=1;
	    }
	  }
	  data[i][j+1]=-1;
	  break;
	}
      }
      if(p==1) break;
    }

    m=(i+1)/2;

    tansaku();

    /*for(i=0;i<100;i++){
      for(j=0;j<50;j++){
	if(data[i][j]==-1) break;
	printf("%d ", data[i][j]);
      }
      printf("\n");
      if(j==1 && i!=0) break;
      }*/
    printf("%d\n", data[(2*m)][0]);
  return 0;
}



void tansaku(){
  int i,j;
  for(i=1;i<100;i++){
    if(i>m) break;
    for(j=0;j<50;j++){
      if(data[i][j]==-1) break;
      if(j==0){
	data[i][j]+=data[i-1][j];
      }
      else{
	if(data[i-1][j-1]>=data[i-1][j]){
	  data[i][j]+=data[i-1][j-1];
	}
	else data[i][j]+=data[i-1][j];
      }
    }
  }

  for(i=m+1;i<100;i++){
    if(i>(2*m)) break;
    for(j=0;j<50;j++){
      if(data[i][j]==-1) break;
      if(data[i-1][j]>=data[i-1][j+1]){
	data[i][j]+=data[i-1][j];
      }
      else data[i][j]+=data[i-1][j+1];
    }
  }
}

Measured memory_bytes: 0
while True:
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        break
    else:
        for j in range(h):
            for i in range(w):
                if j == 0 or j == h - 1 or i == 0 or i == w - 1:
                    print("#", end="")
                else:
                    print(".", end="")
            print()
        print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
using namespace std;
map <int,int> mp;
typedef pair<int, int> P;
typedef long long ll;
static const int MAX=100000;
static const int NMAX=50;
static const int MMAX=50;
int N,K;

void solve(){
    if(N!=K)
        cout<< ((N-1)%(K-1) ? (N-1)/(K-1)+1 : (N-1)/(K-1)) <<"\n";
    else
        cout<<1<<"\n";
}

int main(){
    cin>>N>>K;
    int a[N];
    for(int i=0;i<N;i++)cin>>a[i];
    solve();
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

typedef struct test
{
  int n1;
  int n2;
  char op;
}test;


int main()
{
  test a[1000];
  int count=0;
  scanf("%d %c %d", &a[count].n1, &a[count].op, &a[count].n2);
  while(a[count].op!='?')
    {
      count++;
      scanf("%d %c %d", &a[count].n1, &a[count].op, &a[count].n2);
    }
  for(int i = 0; i<count; i++)
    {
      if(a[i].op == '+')
	{
	  printf("%d\n", a[i].n1+a[i].n2); 
	}
      else  if(a[i].op == '-')
	{
	  printf("%d\n", a[i].n1-a[i].n2); 
	}
      else if(a[i].op == '*')
	{
	  printf("%d\n", a[i].n1*a[i].n2); 
	}
      else if(a[i].op == '/')
	{
	  printf("%d\n", a[i].n1/a[i].n2); 
	}
    }
  return 0;
}



Measured memory_bytes: 2140
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
  int n,a[100],sa=0,i,j;
  cin>>n;
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n,greater<int>());
  for(j=0;j<n;j++){
    if(j%2!=0)sa-=a[j];
    else sa+=a[j];
  }
  cout<<sa<<endl;
  return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
   int n,i;
   scanf("%d",&n);
   for(i=0;i<n;i++)
   {
        int base=0,score=0,outcount=0;
        while(1)
        {
            int res1,res2;
            char event[10],*hit="HIT",*homerun="HOMERUN";
            scanf("%s",event);
            res1=strcmp(hit,event);
            res2=strcmp(homerun,event);
            if(res1==0)
            {
                if(base<3)
                {
                    base++;
                }
                else
                {
                    score++;
                }
            }
            else if(res2==0)
            {
                score+=base+1;
                base=0;
            }
            else
            {
               outcount++;
               if(outcount==3)
               {
                   printf("%d\n",score);
                   break;
               }
            }
        }
   }
    return 0;
}

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

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int k, x;
    cin >> k >> x;
    bool first = true;
    for (int i = x - k + 1; i < x + k; i++)
    {
        if (first)
        {
            cout << i;
            first = false;
        }
        else
        {
            cout << " " << i;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n;cin>>n;
    vector<P> v(n);
    rep(i,n){
        ll a,b;cin>>a>>b;
        v[i]=P(a+b,a-b);
    }
    sort(all(v));
    ll ans=0;
    ll end=-inf;
    rep(i,n){
        if(end<=v[i].se){
            ans++;
            end=v[i].fi;
        }
    }
    out(ans);
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(){
    string s;
    int g = 0, p = 0;
    cin >> s;
    for(string::iterator i = s.begin(); i != s.end(); i++){
        if(*i == 'g') g++;
        if(*i == 'p') p++;
    }
    printf("%d\n", (g - p) / 2);
    return 0;
}


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

int main(){
int A,B,C;
  cin>>A>>B>>C;
  
 int m=max(max(A, B), C);
  if(m==A){cout<<A*10+B+C<<endl;}
  else if(m==B){cout<<B*10+A+C<<endl;}
  else{cout<<C*10+B+A<<endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORP(i, m, n) for(int i = m; i < n+1; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
using UnweightedGraph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
const int INF = 2000000000ll;
const long double PI = acosl(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int power(int a, int b) {return b?power(a*a,b/2)*(b%2?a:1):1;}
int perm(int N, int K){
    int x=1;
    for(int i=1;i<=K;i++)
    {
        x=x*(N-i+1);
    }
    return x;
}
int factorial(int N) {return perm(N,N);}
int comb(int N,int K) {return factorial(N)/factorial(K)/factorial(N-K);}
int hcomb(int N, int K) {return comb(N+K-1, N-1);}

int dtoi(double d) {return round(d);}

int isprime(int n) {
    if (n < 2) return 0;
    for (int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return 0;
    }
    return 1;
}

int mystoll(string S){
    int num = 0;
    for (int i = (int) S.length()-1; i >= 0; i--){
        num += (S[i]-'0') * power(10,S.length()-1-i);
    }
    return num;
}

template<class T>
int SUM(T a) {
    int sum = 0;
    for(auto iter : a) sum += iter;
    return sum;
}

void solve(int A, int B, int N);

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int A, B, N;
    cin >> A >> B >> N;
    solve(A, B, N);
    return 0;
}

void solve(int A, int B, int N) {
    int ans = 0;
    int x = min(B-1,N);
    p(A*x/B-x/B*A);
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_d && sh test.sh
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_d && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_d && sh submit.sh
*/


Measured memory_bytes: 3668