akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int dp[3001][3000];

int main()
{
	int N, T;
	cin >> N >> T;
	vector<pair<int, int>>p(N);	//Time , Deli
	for (int i = 0; i < N; i++) {
		cin >> p[i].first >> p[i].second;
	}
	// dp[i+1][j]  = dp[i][j] (j < Time[i])
	//               max(dp[i][j], dp[i][j-Time[i]]+ Deli[i]
	// 時間でソート
	sort(p.begin(), p.end());
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < T; j++) {
			if (j < p[i].first) dp[i + 1][j] = dp[i][j];
			else dp[i + 1][j] = max(dp[i][j], dp[i][j-p[i].first] + p[i].second);
		}
		//必ずi番目を食べるなら、最後に注文するのが有利
		ans = max(ans, dp[i][T - 1] + p[i].second);
	}
	cout << ans << endl;
}


Measured memory_bytes: 35456
import math

n = int(input())

MOD = 10 ** 9 + 7
prime = [0] * (n+1)
yaku = list(range(n+1))

for i in range(n):
    num = i + 1
    # 素因数分解チェック
    for j in range(num+1):
        if j <= 1:
            continue
        else:
            if num % j == 0:
                p = j
                yaku[num] = p
                while num > 1:
                    n_num = num // p
                    prime[p] += 1
                    p = yaku[n_num]
                    num = n_num

ans = 1
for p in prime:
    ans *= (p+1)
    ans %= MOD

print(ans)


Measured memory_bytes: 9204
using System;
using System.Collections.Generic;
using System.Linq;

public static class Combination
{
    public static IEnumerable<IEnumerable<T>> GetCombinations<T>(this IEnumerable<T> elements, int k)
    {
        return k == 0 ? new[] { new T[0] } :
          elements.SelectMany((e, i) =>
            elements.Skip(i + 1).GetCombinations(k - 1).Select(c => (new[] { e }).Concat(c)));
    }
}

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var K = vals[1];
        var max = (N - 1) * (N - 2) / 2;

        if (K > max)
        {
            Console.WriteLine(-1);
            return;
        }

        var graph = new List<string>();
        var center = 1;
        for (int i = 2; i <= N; i++)
        {
            graph.Add($"{center} {i}");
        }
        var curK = max;
        foreach (var edge in Combination.GetCombinations(Enumerable.Range(2, N - 1), 2))
        {
            if (curK == K)
            {
                break;
            }

            graph.Add(string.Join(" ", edge));
            curK--;
        }
        Console.WriteLine(graph.Count);
        Console.WriteLine(string.Join(Environment.NewLine, graph));
    }
}

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

public class Main{


	int h,w;
	void solve(){

		Scanner cin = new Scanner(System.in);
		while(true)
		{
			w = cin.nextInt();
			h = cin.nextInt();
			if(w==0) break;
			String[] board = new String[h];
			for(int i=0;i<h;i++) board[i] = cin.next();
			boolean[][] white = new boolean[h][w];
			boolean[][] black = new boolean[h][w];

			int[] vx = new int[]{0,1,0,-1};
			int[] vy = new int[]{1,0,-1,0};

			for(int turn = 0; turn< h*w ;turn++){
				for(int i=0;i<h;i++){
					for(int j=0;j<w;j++){
						int y = i; int x = j;
						if(board[i].charAt(j)!='.') continue;
						for(int k=0;k<4;k++){
							int ny = y + vy[k];
							int nx = x + vx[k];
							if(!ok(ny,nx)) continue;
							if(board[ny].charAt(nx)=='B') black[y][x] = true;
							if(board[ny].charAt(nx)=='W') white[y][x] = true;
							if(black[ny][nx]) black[y][x] = true;
							if(white[ny][nx]) white[y][x] = true;
						}
					}
				}
			}

			int bnum = 0;
			int wnum = 0;
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					if(board[i].charAt(j)!='.') continue;
					if(white[i][j] && !black[i][j]) wnum++;
					if(!white[i][j] && black[i][j]) bnum++;
				}
			}
			System.out.println(bnum + " " + wnum);
		}
	}

	boolean ok(int y, int x){
		return y>=0 && x>=0 && y<h && x<w;
	}


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

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

int main()
{
    vector <int> ac(100001, 0);
    vector <int> penalties(100001, 0);
    int n, m;
    cin >> n >> m;

    int i;
    int problem;
    int penaltyCount = 0;
    int AcCount = 0;
    string s;
    for(i = 0; i < m; i ++)
    {
    	cin >> problem >> s;
    	if(problem > n)
    		continue;
    	if(ac[problem] == 0 && s == "AC")
    	{
    		AcCount ++;
    		penaltyCount = penaltyCount + penalties[problem];
    		ac[problem] = 1;
    	}
    	else if(ac[problem] == 0 && s == "WA")
    	{
    			penalties[problem] ++;
    	}
    }
    cout << AcCount << " " << penaltyCount << endl;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {
	int a;
	char s[10];
	scanf("%d", &a);
	scanf("%s",s);
	if (a >= 3200) {
		printf("%s", s);
	}
	else {
		printf("red");
	}



	
	return 0;

}

Measured memory_bytes: 128
from collections import Counter
import sys
MOD = 998244353
n, m = map(int, input().split())
d = Counter()
ans = 1
d_num = 0
def kaijou(a, n):
	x = 1
	while n > 0:
		if n & 1 == 1:
			x = (x * a) % MOD
		a = (a ** 2) % MOD
		n >>= 1
	return x
for _ in range(m):
	a, b, c = map(int, input().split())
	d[(a-1) * n + b - 1] = c
	if abs(a-b) >= 3:
		if (b-1) * n + a - 1 not in d:
			d_num += 1
			d[(b-1) * n + a - 1] = c
		elif d[(b-1) * n + a - 1] != d[(a-1) * n + b - 1]:
			print(0)
			sys.exit()
ans = (ans * kaijou(2, ((n-2) * (n-3) // 2) - d_num)) % MOD
e = 0
if 0 not in d:
	e += 1
if 1 not in d:
	e += 1
if n not in d:
	e += 1
if n+1 not in d:
	e += 1
if e == 0 and n*0+0 in d:
	if (d[n*0+0] + d[n+1]) % 2 != (d[1] + d[n]) % 2:
		ans *= 0
if e == 1 and n+1 not in d and n*0+0 in d:
	d[n+1] = (d[1] + d[n]) % 2 - d[n*0+0]
ans = (ans * (2 ** max(0, e-1))) % MOD
for i in range(n-2):
	e = 0
	if n*i+i+2 not in d:
		e += 1
	if n*i+i+2*n not in d:
		e += 1
	if e == 0 and n*i+i+n+1 in d:
		if (d[n*i+i+2] + d[n*i+i+n+1] + d[n*i+i+2*n]) % 2 != 0:
			ans *= 0
	if e == 0 and n*i+i+n+1 not in d:
		d[n*i+i+n+1] = (d[n*i+i+2] + d[n*i+i+n*2]) % 2
		ans = (ans * 499122177) % MOD
	ans = (ans * (2 ** max(0, e-1))) % MOD
	e = 0
	if n*(i+1)+i+2 not in d:
		e += 1
	if n*(i+1)+i+1+n not in d:
		e += 1
	if n*(i+1)+i+n+2 not in d:
		e += 1
	if e == 0 and n*(i+1)+i+1 in d:
		if (d[n*(i+1)+i+1] + d[n*(i+1)+i+n+2]) % 2 != (d[n*(i+1)+i+2] + d[n*(i+1)+i+1+n]) % 2:
			ans *= 0
	if e == 0 and n*(i+1)+i+1 not in d:
		ans = (ans * 499122177) % MOD
	if e == 1 and n*(i+1)+i+2+n not in d and n*(i+1)+i+1 in d:
		d[n*(i+1)+i+2+n] = (d[n*(i+1)+i+2] + d[n*(i+1)+i+1+n]) % 2 - d[n*(i+1)+i+1]
	ans = (ans * (2 ** max(0, e-1))) % MOD
print(ans)

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

using i64 = int64_t;

constexpr int INF = 1e9;

int main(){
    int n;
    cin >> n;
    vector<vector<int>> v(2, vector<int>());
    for(int i=0;i<2;++i){
        for(int j=0;j<n;++j){
            int tmp;
            cin >> tmp;
            v[i].push_back(tmp);
        }
    }

    int ans = INF;
    for(int i=0;i<(1<<n);++i){
        vector<int> c;
        for(int j=0;j<n;++j){
            c.push_back(v[(i>>j)&1][j]);
        }
        sort(c.begin(), c.end());

        vector<int> indices;
        deque<bool> used(n);
        for(int j=0;j<n;++j){
            for(int k=0;k<n;++k){
                if(used[k])continue;
                int d = (i>>k)&1;
                if(abs(j-k)%2 == d && c[j] == v[d][k]){
                    indices.push_back(k);
                    used[k] = true;
                    break;
                }
            }
        }

        if(indices.size() != n)continue;

        int inversion = 0;
        for(int j=0;j<n;++j){
            for(int k=j+1;k<n;++k){
                if(indices[j] > indices[k])inversion++;
            }
        }

        ans = min(ans, inversion);
    }

    cout << (ans != INF ? ans : -1) << endl;

    return 0;
}

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

typedef long long int ll;
ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

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

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

    ll ans = 0;
    bool f = true;
    for(ll i = 0;i < n - 1;i++){
        if(a[i] == a[i + 1]){
            f = !f;
        }
        else{
            if(f){
                ans++;
            }
            f = true;
        }
    }

    if(f){
        ans++;
    }

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a = 0, b = 0; cin >> n;
	for (int h = 1; h <= sqrt(n) + 1; h++) {
		if (n%h == 0) {
			a = h;
		}
	}
	b = n / a;
	if (b <= 9) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	cin >> n;
}

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

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

#define pb push_back
#define in ,
#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 1e9+7

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

int main() {
  ll dp[1001][1001] = {};
  string a, b;
  cin >> a >> b;

  rep(i, 0, a.length()) {
    rep(j, 0, b.length()) {
      dp[i][j] %= (ll)mod;
      dp[i + 1][j] += dp[i][j];
      if(a[i] == b[j]) {
        if(j == 0) dp[i + 1][j + 1] += 1;
        else dp[i + 1][j + 1] += dp[i][j];
      }
    }
  }

  ll ans = 0;
  rep(i, 0, a.length() + 1) {
    ans += dp[i][b.length()];
    ans %= (ll)mod;
  }

  cout << ans << endl;
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> list(M, vector<int>());
    int p, q;
    for (int i = 0; i < M; i++)
    {
        cin >> p;
        list[i].push_back(p);
        for (int j = 0; j < p; j++)
        {
            cin >> q;
            q--;
            list[i].push_back(q);
        }
    }

    vector<int> amari(M);
    for (int i = 0; i < M; i++)
        cin >> amari[i];
    int ans = 0;
    for (int tmp = 0; tmp < (1 << N); tmp++)
    {
        bitset<10> s(tmp);
        vector<int> on(M);
        for (int i = 0; i < M; i++)
        {
            for (int j = 1; j <= list[i][0]; j++)
            {
                if (s[list[i][j]])
                    on[i]++;
            }    
        }
        bool x = true;
        for (int i = 0; i < M; i++)
        {
            if (on[i] % 2 != amari[i])
                x = false;
        }
        if(x)
            ans++;
    }
    cout << ans;
}

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

int main() {
	int a = 0;
	int x,y;
	while (a == 0) {
		cin >> x >> y;
		if ((x == 0) && (y == 0)) {
			a = 1;
		}else{
			if (x == y) {
				cout << x << " " << y << endl;
			} else if (x < y) {
				cout << x << " " << y << endl;
			} else if (x > y) {
				cout << y << " " << x << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3088
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	int n;
	cin >> n;
	vector<ll> x(n), y(n);
	vector<P> p(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		p[i] = P(x[i], y[i]);
	}
	set<P> s;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			s.insert(P(x[j] - x[i], y[j] - y[i]));
		}
	}
	sort(p.begin(), p.end());
	ll ans = n;
	for (auto it = s.begin(); it != s.end(); it++) {
		ll a = (*it).first, b = (*it).second;
		ll cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < i; j++) {
				if (p[i].first == p[j].first + a && p[i].second == p[j].second + b) cnt++;
			}
		}
		//dump(cnt);
		ans = min(ans, max(0ll, n - cnt));
	}
	dump(ans);

	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int X;
string S;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	X=S.size();
	
	int R=0;
	int NS=0;
	FORR(c,S) {
		if(c=='S') NS++;
		else {
			if(NS) NS--;
			else R++;
		}
	}
	cout<<R+NS<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

const long long int M = 1000000007;
const long long int NIL = -1;

vector<long long int> memo;

long long int functional(long long int n) {
    if(n <= 1) return 1;
    if(memo[n] != NIL) return memo[n];
    return memo[n] = (n * functional(n - 1)) % M;
}

class SlidingSum {
    int size;
    std::vector<int> node;
public:
    SlidingSum(int s) :size(s), node(std::vector<int>(s + 1, 0)) {}
    long long int sum(int index) const {
        int result = 0;
        for(int i = index + 1; i > 0; i -= i & -i) result += node[i];
        return result;
    }
    long long int sum(int left, int right) const {
        return sum(right) - sum(left - 1);
    }
    void update(int index, int value) {
        for(int i = index + 1; i <= size; i += i & -i) node[i] += value;
    }
};

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> word(n);
        for(int i = 0; i < n; ++i) word[i] = i;

        int r;
        for(cin >> r; r > 0; --r) {
            int s, t;
            cin >> s >> t;
            swap(word[s - 1], word[t - 1]);
        }

        long long int answer = 0;
        memo = vector<long long int>(n, NIL);
        SlidingSum ss(n);
        for(int i = 0; i < n - 1; ++i) {
            answer += functional(n - i - 1) * (word[i] - ss.sum(0, word[i]));
            answer %= M;
            ss.update(word[i], 1);
        }
        cout << answer << endl;
    }
}

Measured memory_bytes: 6916
s = input()
 
s = s[::-1]
 
dp = [[0 for _ in range(13)] for __ in range(len(s)+1)]
 
l = len(s)
 
 
if s[0] == '?':
    for j in range(10):
        dp[0][j] = 1
else:
    dp[0][int(s[0])] = 1
 
m = 1
MOD = 10**9 +7
 
for i in range(1,len(s)):
    m = m*10 % 13
 
    if s[i] == '?':
        for k in range(13):
            for j in range(10):
                dp[i][(j*m+k)%13] += dp[i-1][k]
                dp[i][k] %= MOD
    else:
        for k in range(13):
            dp[i][(int(s[i])*m + k) %13] += dp[i-1][k]
            dp[i][k] %= MOD
 
print(dp[len(s)-1][5] % MOD )


Measured memory_bytes: 67208
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int w;
    int[] fd = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
    boolean[] use;

    void run(){
	while(sc.hasNext()){
	    w = sc.nextInt();
	    use = new boolean[10];
	    solve();
	    show(use);
	}
    }

    void solve(){
	for(int i=fd.length-1; i>=0; i--)
	    if(w>=fd[i]){
		w -= fd[i];
		use[i] = true;
	    }
    }

    void show(boolean[] a){
	StringBuffer sb = new StringBuffer();
	int i=0;
	while(!use[i]) i++;
	sb.append(fd[i]);
	i++;
	for(; i<a.length; i++)
	    if(a[i]) sb.append(" "+fd[i]);
	System.out.println(sb.toString());
    }
}

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

int main(){
	string s;
	cin >> s;

	int c=0;
	int ans=0;
	for(int i=0; i<s.size(); i++){
		if(c==0){
			c++;
			if(s[i]=='p') ans -=1;
		}
		else{
			if(s[i]=='g'){
				ans +=1;
				c--;
			}
			else{
				c--;
			}
		}
	}

	cout << ans << endl;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    string s ;
    cin >> s ;
    if (s[2] == s[3] and s[4] == s[5])  cout << "Yes" ;
    else    cout << "No" ;
    return 0 ;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <random>
#define MOD 1000000007LL

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

long long int powmod(long long int a, long long int k, long long int m){
    if(a==0) return 0;
    long long int ap=a, ans=1;
    while(k>0){
        if(k%2==1){
            ans*=ap;
			ans%=m;
        }
        ap=ap*ap;
		ap%=m;
        k/=2;
    }
    return ans;
}

ll inv(ll a, ll p){
	return powmod(a, p-2, p);
}

int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	int m=s.size();

	ll f[5001];
	f[0]=1;
	for(ll i=1; i<=n; i++){
		f[i]=f[i-1]*i%MOD;
	}
	ll invf[5001];
	invf[n]=inv(f[n], MOD);
	for(ll i=n-1; i>=0; i--){
		invf[i]=invf[i+1]*(i+1)%MOD;
	}
	ll p2[5001];
	p2[0]=1;
	for(int i=1; i<=n; i++){
		p2[i]=p2[i-1]*2%MOD;
	}

	ll dp[5001]={};
	dp[0]=1;
	for(int i=0; i<n; i++){
		dp[i+1]+=dp[i];
		dp[i+1]%=MOD;
		for(int j=1; i+2*j<=n; j++){
			ll x;
			if(j==1) x=2;
			else x=(f[2*j-2]*invf[j-1]%MOD*invf[j-1]%MOD-f[2*j-2]*invf[j]%MOD*invf[j-2]%MOD+MOD)*p2[j]%MOD;
			dp[i+2*j]+=(dp[i]*x);
			dp[i+2*j]%=MOD;
		}
	}
	ll ans=0;
	for(int i=0; 2*i+m<=n; i++){
		ll x;
		if(i==0) x=1;
		else x=(f[2*i+m-1]*invf[i+m-1]%MOD*invf[i]%MOD-f[2*i+m-1]*invf[i-1]%MOD*invf[i+m]%MOD+MOD)*p2[i]%MOD;
      ans+=(dp[n-2*i-m]*x);
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

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

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

const double EPS = 1e-9;
const double PI = acos(-1.0);

const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

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

LL H, W;

int main() {
    cin >> H >> W;
    LL ans = H / 2 * W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (H % 2 == 1) {
        ans += (W + 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    vector<string> s(n); cin >> s;

    function<bool(int, int)> check = [&](int dy, int dx) {
        FOR(i, 0, n)FOR(j, 0, n) {
            if (s[(i - dy + n) % n][(j - dx + n) % n]
                != s[(j - dy + n) % n][(i - dx + n) % n])
                return false;
        }
        return true;
    };

    int ans = 0;
    FOR(i, 0, n)if (check(0, i))ans += n;
    cout << ans << "\n";
}

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

long long int n,i,k,a[200010],ans[200010],x,y,t;
bool vis[200010];

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>k;
	for (i=1;i<n+1;i++) cin>>a[i];
	if (a[1]==1)
	{
		cout<<1;return 0;
	}
	ans[0]=1;x=0;
	for (i=1;i<n;i++) ans[i]=a[ans[i-1]];
	for (i=1;i<n+1;i++) vis[i]=false;vis[1]=true;
	for (i=1;i<n;i++)
	{
		if (vis[ans[i]] && x==0) x=i,y=ans[i];
		vis[ans[i]]=true;
	}
	for (i=0;i<x;i++) if (ans[i]==y) t=i;
	if (k<t) cout<<ans[k];else
	{
		k=(k-t)%(x-t);
		cout<<ans[t+k];
	}
}


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

int main(void) {
	string S;
	int ans = 0;
	cin >> S;
	int l = S.length();
	for (int i = 0; i <= l / 2 - 1; i++) {
		if (S[i] != S[l - 1 - i]) {
			ans++;
		}
	}
	printf("%d", ans);

	return 0;
}


Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]

matrix = [[int(i) for i in input().split()] for gyo in range(n)]
vector = [[int(i) for i in input().split()] for gyo in range(m)]

ans = [0 for i in range(n)]


for i in range(n):
    seki = 0
    for j in range(m):
        seki += int(matrix[i][j]) * int(vector[j][0])
    ans[i] = seki


for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 8036
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

using namespace std;

int main()
{
    int r;
    cin >> r;
    string ans = "AGC";
    if (r < 1200)
    {
        ans = "ABC";
    }
    else if (r < 2800)
    {
        ans = "ARC";
    }
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n, c, k;
int t[100000 + 5];
bool go[100000 + 5];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> c >> k;
    rep(i, n) cin >> t[i];
    sort(t, t + n);
    int ans = 0;
    rep(i, n) {
        if (go[i]) continue;
        ans++;
        int now = i;
        int nowt = 0;
        int cnt = 0;
        while (now < n && cnt < c && t[now] <= t[i] + k) {
            cnt++;
            go[now] = true;
            now++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1152
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
H, W = ri_()
a = ['#' * (W + 2)]
for _ in range(H):
    a.append('#' + rs() + '#')
a.append('#' * (W + 2))
for i in range(H + 2):
    print(a[i])

Measured memory_bytes: 63468
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	max := 0
	if max < a + b {
		max = a + b
	}
	if max < a + (a-1) {
		max = a + (a-1)
	}
	if max < b + (b-1) {
		max = b + (b-1)
	}
	fmt.Println(max)
}

Measured memory_bytes: 512
N,M = map(int, input().split())
AtN,Bf1 = set(),set()
for i in range(M):
    a,b = map(int, input().split())
    if a == 1:
        Bf1.add(b)
    elif b == N:
        AtN.add(a)

if (any((b in AtN) for b in Bf1)):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

check = [0] * (n+1)
res = []

for i in range(n,0,-1):
    if sum(check[2*i::i])%2 == a[i]:
        continue
    else:
        check[i] = 1
        res.append(i)
print(len(res))
print(*res)

Measured memory_bytes: 78812
#include <cstdio>
#include <vector>
using namespace std;

int main (int argc, char const* argv[])
{
	vector<int> Card,Tmp;
	int n,m,k;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=2*n;i++) {
		Card.push_back(i);
	}
	for(int i=0;i<m;i++) {
		scanf("%d",&k);
		Tmp.clear();
		if(k==0) {
			for(int i=0;i<n;i++)Tmp.push_back(Card[i]),Tmp.push_back(Card[i+n]);
		}else {
			for(int j=k;j<2*n;j++)Tmp.push_back(Card[j]);
			for(int j=0;j<k;j++)Tmp.push_back(Card[j]);
		}
		Card=Tmp;
	}
	for(int i=0;i<2*n;i++) {
		printf("%d\n",Card[i]);
	}
	return 0;
}

Measured memory_bytes: 1052
N,Q = map(int, input().split())
S = input()
T = [0]*N
for i in range(1, N):
    T[i] += T[i-1]
    if S[i -1: i +1] == "AC":
        T[i] += 1
for j in range(Q):
    l, r = map(int, input().split())
    print(int(T[r-1] - T[l-1]))
    

Measured memory_bytes: 7700
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int n;
    int ans=0;
    cin >> n;
    vector<int> a(n);
    vector<int> new_a;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        if(a[i]-1!=new_a.size()){
            ans++;
        }else{
            new_a.push_back(a[i]);
        }
    }
    if(new_a.size()==0){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 2296
#include"stdio.h"
#include"algorithm"
using namespace std;
int main(){
int n;scanf("%d",&n);int a[n];for(int i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);int ans=0;for(int i=0;i<n;i++)ans+=a[i]*(i%2?1:-1);if(ans<0)ans*=-1;printf("%d",ans);return 0;}



Measured memory_bytes: 128
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(x) begin(x),end(x)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const ll inf = 1e9+9;
const ll mod = 1e97;
ll n,m,k;
ll psum[19][1009];
string s[19];
ll cnt(ll num){
    ll ret = 0;
    while(num){
        ll u = num%2;
        num /= 2;
        ret += u;
    }
    return ret-1;
}
ll solve(ll mask){
    ll ret = 0,last = -1;
    for(int j=0;j<m;j++){
        ll curr = 0;
        for(int i=0;i<n;i++){
            curr += psum[i][j];
            if(last != -1) curr -= psum[i][last];
            if(curr > k){
                if(last == j-1) return inf;
                last = --j,ret++; break;
            }
            if(mask&(1ll<<i)) curr = 0;
        }
    }
    return ret;
}
int main(){
    ll mn = inf;
    fast,cin>>n>>m>>k;
    for(int i=0;i<n;i++) cin>>s[i];
    for(int i=0;i<n;i++){
        psum[i][0] = s[i][0]-'0';
        for(int j=1;j<m;j++){
            psum[i][j] = psum[i][j-1];
            psum[i][j] += s[i][j] - '0';
        }
    }
    for(ll mask=(1ll<<(n-1));mask<(1ll<<n);mask++){
        mn = min(mn,cnt(mask)+solve(mask));
    }
    cout<<mn<<endl;
}


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

using ull = unsigned long long;

int main() {
  ull n;
  cin >> n;
  vector<ull> a(n), b(n, 0);

  for (ull i = 0; i < n; i++) {
    ull x;
    cin >> x;

    a[i] = --x;
    b[a[i]]++;
  }

  ull ans = 0;
  for (ull i = 0; i < n; i++) {
    ans += b[i] * (b[i]-1) / 2;
  }
  // ull ans = accumulate(b.begin(), b.end(), 0ll, [](ull x, ull y) {return x+y*(y-1)/2;});
  for (ull x: a) {
    cout << ans - (b[x]-1) << endl;
  }
}

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

int main() {
        int n;
        scanf("%d", &n);
        map<pair<int, int>, int> idx;
        vector<vector<int>> g(n);
        rep(i, n - 1) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
                idx[make_pair(min(a, b), max(a, b))] = i;
        }
        int ans = 0;
        rep(i, n) {
                ans = max(ans, (int) g[i].size());
        }
        int l = ans;
        vector<int> res(n - 1);
        function<void (int, int, int)> dfs = [&](int u, int prev, int col) {
                int c = col;
                for (auto v : g[u]) if (v != prev) {
                        c ++;
                        c %= l;
                        res[idx[make_pair(min(u, v), max(u, v))]] = c;
                        dfs(v, u, c);
                }
        };
        dfs(0, -1, 0);
        printf("%d\n", ans);
        rep(i, res.size()) printf("%d\n", res[i] + 1);
        return 0;
}


Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

ll w[101];
ll v[101];
ll n,W;

ll dp[101][100001];

ll knapsack(ll idx ,ll curr_weight){
	if(curr_weight< 0) return INT_MIN;
	if(idx==n)return 0;
	ll &ans = dp[idx][curr_weight];
	if(ans!=-1)return ans;
	ans = max(v[idx] + knapsack(idx+1 , curr_weight-w[idx]), knapsack(idx+1,curr_weight));
	return ans;
}

int main(){
	IOS;
	memset(dp,-1,sizeof(dp));
	cin >> n >> W;
	for(int i=0 ;i <n ; ++i){
		cin >> w[i] >> v[i];
	}
	cout << knapsack(0,W) << endl;

}

Measured memory_bytes: 79232
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();
  long H = sc.nextLong();
  long[] a = new long[N];
  long[] b = new long[N];
  long amax = 0;
  for(int i = 0;i < N;i++){
    a[i] = sc.nextInt();
    b[i] = sc.nextInt();
    amax = Math.max(a[i],amax);
  }
  long[] au = new long[N];
  long[] bu = new long[N];
  int counter = 0;
  for(int i = 0;i < N;i++){
    if(b[i] >= amax){
      au[counter] = a[i];
      bu[counter] = b[i];
      counter++;
    }
  }
  Arrays.sort(bu);
  long sum = 0;
  int counterb = 0;
  boolean beat = false;
  for(int i = N-1;i >= N-counter;i--){
    sum += bu[i];
    counterb++;
    if(sum >= H){
      System.out.println(counterb);
      beat = true;
      break;
    }
  }
  if(beat == false){
    System.out.println((H-sum)%amax == 0 ? counter + (H-sum)/amax : counter+1 + (H-sum)/amax);
  }
}}


Measured memory_bytes: 91504
#include <stdio.h>
#include <iostream>
#include <cstring>
const int N=500005;
const int M=30;
int n,q,f[N][M],st[N][19];
char s[N];
using namespace std;

int main()
{
	#ifdef Kay
		freopen ("mujin_pc_2017_c.in","r",stdin);
		freopen ("mujin_pc_2017_c.out","w",stdout);
	#endif
	scanf ("\n%s",s+1),n=strlen(s+1);
	int i,j;
	for (i=1;i<=n+2;i++)
	for (j=1;j<=27;j++)
	f[i][j]=n+2;
	for (i=n;i>=1;i--)
	{
		f[i][s[i]-'a'+1]=i+1;
		for (j=s[i]-'a'+2;j<=27;j++) f[i][j]=f[f[i][j-1]][j-1];
		for (j=1;j<=s[i]-'a';j++) f[i][j]=f[f[i][27]][j];
	}
	for (i=1;i<=n;i++) st[i][0]=f[i][27];
	for (j=1;j<19;j++)
	for (i=1;i<=n;i++)
	if (st[i][j-1]<=n) st[i][j]=st[st[i][j-1]][j-1];
	else st[i][j]=n+2;
	for (j=0;j<19;j++) st[n+1][j]=n+1;
	scanf ("%d",&q);
	int l,r;
	while (q--)
	{
		scanf ("%d %d",&l,&r);
		for (j=18;j>=0;j--)
		if (st[l][j]<=r+1) l=st[l][j];
		if (l==r+1) puts("Yes");
		else puts("No");
	}
	return 0;
}


Measured memory_bytes: 96896
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, ans, sum, last, cnt, a[2];
struct Edge { LL to,cost; };
vector<Edge>vec[100000];
string str,ss;
bool f=0;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n;
	LL high = n, low = 0;
	cout << 0 << endl;
	cin >> str;
	while (1) {
		LL midle = (high + low) / 2;
		cout << midle << endl;
		cin >> ss;
		if (ss == "Vacant") {
			return 0;
		}
		if (midle % 2 == 0) {
			if (str == ss) 
				low = midle;
			else 
				high = midle;
		}
		else {
			if (str == ss)
				high = midle;
			else
				low = midle;
		}
		cnt++;
		if (cnt == 10000)
			return 0;
	}
	return 0;
}

Measured memory_bytes: 3176
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<string>
#include<bits/stdc++.h>

/*define*/
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
typedef pair<int, int> P;
static const int max_n = 200000, max_m = 200000;
static const int  INF = 10000000;
vector<int> G[max_n];
int Color[max_n];
int ci;
int D;
int T;
string ans = "YES";
map<int, int> m;


int main(){
    int N, M;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> D;
        ++m[D];
    }
    cin >> M;
    rep(i, M){
        cin >> T;
        if(m[T]==0){
            ans = "NO";
            break;
        }
        --m[T];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,e)for(int i=0;i<e;i++)
#define PI acos(-1)
using namespace std;
#define toLower(str)transform(str.begin(),str.end(),str.begin(),::tolower)

int main(){
    int i, j;
    int n;
    cin >> n;
    cout << n << ":";
    int n1 = n;
    while(n%2==0){
        cout << " 2";
        n/=2; 
    }
    for(i=3;i*i<n1;i+=2){
        while(n%i==0){
            cout << " " << i;
            n/=i;
        }
    }
    if(n!=1)cout << " " << n;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3128
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    ll X,Y;cin>>X>>Y;
    int ans=1;
    while(true){
        X*=2;
        if(X<=Y)ans++;
        else {
            cout<<ans<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m;
  cin >> m;
  vector<p> v(m);
  ll keta = 0, sum = 0;
  rep(i, m){
    cin >> v[i].first >> v[i].second;
    keta += v[i].second;
    sum += v[i].first * v[i].second;
  }
  ll res = (keta - 1) + (sum - 1) / 9;
  cout << res << endl;

}


Measured memory_bytes: 3456
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>
#include <algorithm>
#include<iomanip>
#define INF 1000000000
#define LM 55555
using namespace::std;


long long mc,pc,p[100001],m[100001],n, bc, now, C, H, W, X[100000],K, Y, ans, r, l, numcon, N, M;
string S,s,a[101],b[101],c[101];
bool h,k[101];
int main() {
	cin >> S>>K;
	now = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != '1') {
			now = i;
			break;
		}
	}
	if (K - now > 0) {
		cout << S[now] << endl;
	}
	else {
		cout << '1' << endl;
	}

	return 0;

}




Measured memory_bytes: 256
/**
 * File              : C.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 19.01.2020
 * Last Modified Date: 19.01.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

#include <bits/stdc++.h>
using namespace std;
int const INF = 2e9;


int main() {
    int n;
    cin >> n;
    int ans = 0;
    int _min = INF;
    for (int i = 0; i < n; i++) {
        int val;
        cin >> val;
        if (val < _min) {
            _min = val;
            ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
t,x,y =(0, 0, 0)
for _ in range(n):
    nt, nx, ny =map(int,input().split())
    dis=abs(nx-x)+abs(ny-y)
    tim = nt - t
    if tim >= dis and (tim - dis) % 2 ==0:
        t,x,y=nt, nx, ny
    else:
        print('No')
        break
else:
    print('Yes')


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

class DisjointSet{
public:
  vector<int> rank,p;

  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++)makeSet(i);
  }

  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }

  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }

  void unite(int x,int y){
    link(findSet(x),findSet(y));
  }

  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
    }
    else {
      p[x]=y;
      if(rank[x]==rank[y]){
	rank[y]++;
      }
    }
  }

  int findSet(int x){
    if(x!=p[x]){
      p[x]=findSet(p[x]);
    }
    return p[x];
  }
};
 int main()
{
  int n,q;
  int t,a,b;

  cin>>n>>q;

  DisjointSet ds(n);

  for(int i=0;i<q;i++){
    cin>>t>>a>>b;
    if(t==0)ds.unite(a,b);
    else {
      if(ds.same(a,b))cout<<1<<endl;
      else cout<<0<<endl;
    }
  }
  return 0;
}
 


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

int main() {
    int h, w;
    while(true) {
        cin >> h >> w;
	if(h==0 && w==0) break;

	for(int i=0; i<h; i++){
	    for(int j=0; j<w; j++){
	        if(i!=0 && i!=h-1 && j!=0 && j!=w-1) cout << '.' << flush;
		else cout << '#' << flush;

		if(j==w-1) cout << endl;
	    }
	}

	cout << endl;
    }
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <unordered_set>
#include <numeric>
using namespace std;

const int MOD = 1e9 + 7;
#define ll long long


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

int findlcm(vector<int >arr, int n)
{
	int ans = arr[0];

	for (int i = 1; i < n; i++)
		ans = (((arr[i] * ans)) /
		(gcd(arr[i], ans)));

	return ans;
}

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

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

	int lcm = findlcm(arr, n);
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		sum += lcm / arr[i];
	}

	printf("%.5f\n", (double)lcm / sum);
}

Measured memory_bytes: 256
n = int(input())
S = [int(x) for x in input().split()]
q = int(input())
T = [int(x) for x in input().split()]

def LinearSearch(S,T):
    count = 0
    for i in range(q): #T
        for j in range(n): #S
            if T[i] == S[j]:
                count += 1
                break
    return count

print(LinearSearch(S,T))



Measured memory_bytes: 6552
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=405,Mod=998244353;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,h[MAXN],F[MAXN][MAXN],G[MAXN][MAXN],C[MAXN][MAXN],Fpow[MAXN];
inline void Init(){
	C[0][0]=1;Rep(i,1,n){C[i][0]=1;Rep(j,1,i)C[i][j]=(C[i-1][j-1]+C[i-1][j])%Mod;}
	Fpow[0]=1;Rep(i,1,n)Fpow[i]=Fpow[i-1]*2%Mod;
}
void Dp(int d,int l,int r){
	static int tmp1[MAXN],tmp2[MAXN];memset(F[d],0,sizeof(F[d])),memset(G[d],0,sizeof(G[d]));
	int last=l-1,len=r-l+1,s=0;F[d][0]=G[d][0]=1;	
	Rep(i,l,r+1)if(i>r||h[i]==d){
		if(last<i-1){
			int k=i-last-1;
			memset(tmp1,0,sizeof(tmp1)),memset(tmp2,0,sizeof(tmp2)),Dp(d+1,last+1,i-1),memset(tmp1,0,sizeof(tmp1)),memset(tmp2,0,sizeof(tmp2));
			Rep(i,0,s)Rep(j,0,k)tmp1[i+j]=(tmp1[i+j]+1ll*F[d][i]*F[d+1][j])%Mod,tmp2[i+j]=(tmp2[i+j]+1ll*G[d][i]*G[d+1][j])%Mod;
			s+=k;Rep(i,0,s)F[d][i]=tmp1[i],G[d][i]=tmp2[i];
		}last=i;
	}int t=len-s;
//	cout<<d<<' '<<l<<" "<<r<<" "<<len<<" "<<s<<" "<<t<<"\n";
//	Rep(i,0,s)cout<<F[d][i]<<" ";cout<<"\n";
//	Rep(i,0,s)cout<<G[d][i]<<" ";cout<<"\n";
	memset(tmp1,0,sizeof(tmp1)),memset(tmp2,0,sizeof(tmp2));
	Rep(i,0,s){
		int tt=s-i;
		Rep(j,0,tt)tmp1[i+j+t]=(tmp1[i+j+t]+1ll*C[tt][j]*(j?Fpow[i+t]:Fpow[i+t]-1)%Mod*F[d][i])%Mod;
		tt=len-i;
		Rep(j,0,tt)tmp2[i+j]=(tmp2[i+j]+1ll*C[tt][j]*(j?Fpow[i]:Fpow[i]-1)%Mod*G[d][i])%Mod;
		tmp1[i]=(tmp1[i]+G[d][i])%Mod,tmp2[i]=(tmp2[i]+G[d][i])%Mod;
	}Rep(i,0,len)F[d][i]=tmp1[i],G[d][i]=tmp2[i];
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),Init();
	Rep(i,1,n)h[i]=read();
	Dp(1,1,n),cout<<F[1][n]<<'\n';
//	Rep(i,1,2){Rep(j,0,n)cout<<F[i][j]<<" ";cout<<"\n";Rep(j,0,n)cout<<G[i][j]<<" ";cout<<"\n";}
	return 0;
}




Measured memory_bytes: 5656
import itertools
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
import sys
sys.setrecursionlimit(10**9)

def main():
    N,K = map(int,input().split())
    p = 10**9 + 7

    ans = 1
    for i in range(K,N+1):
        ans += (i * (N*2-i+1)) // 2 - i*(i-1) // 2 + 1
        ans %= p

    print(ans)

if __name__ == "__main__":
  main()


Measured memory_bytes: 27028
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e15;
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  vector<ll> l(n);
  REP(i, n) cin >> l[i];
  sort(ALL(l));

  ll ans = 0;
  REP(i, n) FOR(j, i + 1, n) {
    ll a = l[i], b = l[j];
    auto lb = upper_bound(ALL(l), abs(a - b)) - l.begin();
    auto ub = lower_bound(ALL(l), a + b) - l.begin();
    if (lb < j) lb = j + 1;
    ll tmp = ub - lb;

    if (lb <= i && i < ub) tmp--;
    if (lb <= j && j < ub) tmp--;
    if (tmp <= 0) continue;
    ans += tmp;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
typedef long long int LL;
using namespace std;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    int K,i,j,t;
    LL sum=0;
    cin>>K;
    for(i=1;i<=K;i++)
        for(j=1;j<=K;j++)
            for(t=1;t<=K;t++)
                sum+=gcd(gcd(i,j),t);
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;cin>>n;
	int N=1e4+1;
	int arr[N];
	memset(arr,0,sizeof(arr));
	for(int i=1;i<=100;i++){
	    for(int j=1;j<=100;j++){
	        for(int k=1;k<=100;k++){
	            int h=(i+j+k)*(i+j+k);
	            h-=(i*j)+(j*k)+(k*i);
	            if(h>0 && h<N){arr[h]++;}
	        }
	    }
	}
	for(int i=1;i<=n;i++){cout<<arr[i]<<"\n";}
	return 0;
}


Measured memory_bytes: 3632