akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
using namespace std;

vector< pair<int, int> > p;
vector<int> c;

vector< vector<int> > xx;

bool dfs(int v, int a){
  c[v] = a;
  // for(int i=0; i<p.size(); i++){
  //   if( p[i].first == v ){
  //     if( c[p[i].second] == a ) return false;
  //     if( c[p[i].second] == 0 && !dfs(p[i].second, -a) ) return false;
  //   }else if( p[i].second == v ){
  //     if( c[p[i].first] == a ) return false;
  //     if( c[p[i].first] == 0 && !dfs(p[i].first, -a) ) return false;
  //   }
  // }

  for(int i=0; i<xx[v].size(); i++){
    if( c[ xx[v][i] ] == a ) return false;
    if( c[ xx[v][i] ] == 0 && !dfs(xx[v][i], -a) ) return false;
  }

  return true;
}

int main(void) {

  long long int n, m;
  cin >> n >> m;
  p.resize(m);
  c.resize(n, 0);
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    p[i].first = min(a, b);
    p[i].second = max(a, b);
  }

  xx.resize(n);
  for(int i=0; i<m; i++){
    xx[ p[i].first ].push_back(p[i].second);
    xx[ p[i].second ].push_back(p[i].first);
  }

  long long int comp = n * (n-1) / 2;
  bool f = true;
  for(int i=0; i<n; i++){
    if( c[i] == 0 ){
      if( !dfs(i, 1) ){
        f = false;
      }
    }
  }
  // if( !dfs(0, 1) ) f = false;

  if(!f) cout << comp - m << endl;
  else{
    long long int x = 0, y = 0;
    for(int i=0; i<n; i++){
      if( c[i] == 1 ) x++;
      else if( c[i] == -1 ) y++;
    }
    cout << x * y - m << endl;
  }

  return 0;
}









// EOF


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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

const int MOD = 1000000007;

int h,w,K;

int dp[102][9];

int main(){
    INIT;
    cin >> h >> w >> K;
    dp[0][0] = 1;
    FOR(i,1,h+2) {
        FOR(j,0,w) {
            for(int k = 0; k < 1 << (w-1); k++) {
                bool yes = true;
                FOR(l,0,w-1) if(((k >> l) & 1) && (k >> (l+1)) &1) yes = false;
                if(!yes) continue;
                if(0 <= j-1 && (k >> (j-1) & 1))
                    dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MOD;
                else if(j+1 < w && ((k >> j) & 1))
                    dp[i][j] = (dp[i][j] + dp[i-1][j+1]) % MOD;
                else
                    dp[i][j] += dp[i-1][j];
                    dp[i][j] %= MOD;
            }
        }
    }
    int ans = dp[h][K-1] % MOD;
    cout << ans << "\n";
}

Measured memory_bytes: 256
N, K, Q = map(int, input().split())
A = []
for _ in range(Q):
    A.append(int(input()))
    
a = 1 - (K - Q)
score = [0] * N

for i in range(len(A)):
  b = A[i]
  score[b-1] += 1

for j in range(len(score)):
  if score[j] >= a:
    print('Yes')
  else:
    print('No')


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 2e5 + 1;
const ll LINF = 1e18 + 1;

int N;
ll sum[MAX_N];

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

  cin >> N;
  vector< ll > a(N);
  REP(i, N) {
    cin >> a[i];
  }

  memset(sum, 0, sizeof(sum));
  REP(i, N) {
    if (i > 0) sum[i] = sum[i - 1] + a[i];
    else sum[i] = a[i];
    //  debug(sum[i]);
  }

  ll ans = LINF ;
  REP(i, N - 1) {
    ans = min(ans, abs((sum[N - 1] - sum[i]) - sum[i]));
  }

  cout << ans << endl;

  return 0;
}



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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string s;
  cin >> s;
  ll l_cnt = 0, r_cnt = 0;
  ll ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '<')
      l_cnt++;
    else
      r_cnt++;
    if (i < s.size() - 1 && s[i] == '>' && s[i + 1] == '<') {
      ll mx = max(l_cnt, r_cnt);
      ll mn = min(l_cnt, r_cnt);
      ans += (mx * (mx + 1) / 2) + (mn * (mn - 1) / 2);
      l_cnt = r_cnt = 0;
    }
  }
  ll mx = max(l_cnt, r_cnt);
  ll mn = min(l_cnt, r_cnt);
  ans += (mx * (mx + 1) / 2) + (mn * (mn - 1) / 2);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back

int main()
{

   int n;
   cin >> n; n--;
   int arr[n];
   ll sum = 0;

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

   }
   sum = arr[n-1] + arr[0];
   for(int i = n-1; i >= 1; i--)
   {
       sum += min(arr[i], arr[i-1]);
   }


   cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int h = scanner.nextInt();
        final int w = scanner.nextInt();
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();

        for (int i = 0; i < b; i++) {
            print(0, a);
            print(1, w - a);
            System.out.println();
        }

        for (int i = 0; i < h - b; i++) {
            print(1, a);
            print(0, w - a);
            System.out.println();
        }
    }

    private static void print(final int a, final int count) {
        for (int i = 0; i < count; i++) {
            System.out.print(a);
        }
    }
}


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

using namespace std;

signed main()
{
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int g[n + 1] = {0};
    int ans = 0;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        g[a] |= b == 1;
        g[b] |= a == 1;
        g[a] |= 2 * (b == n);
        g[b] |= 2 * (a == n);
        ans |= max(g[a], g[b]) == 3;
    }
    cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define ll long long int
#define MOD ((int)(1e9) + 7)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<ll> inp;
  for(int i=0; i<n; i++) {
    int tp;
    cin >> tp;
    inp.push_back(tp);
  }
  ll ans = INT64_MAX;
  for(ll j=1; j<=100; j++) {
    ll cnt = 0;
    for(ll i=0; i<n; i++) {
      cnt += ((inp[i] - j) * (inp[i] - j));
    }
    ans = min(cnt, ans);
  }
  cout << ans << '\n';
  return 0;
}


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

int main()
{
	int n;
	int kcos, scos;
	int kcal;
	int scal[100 + 10] = { 0 };

	int i;

	int scsum=0;
	int mcal;

	cin >> n;
	cin >> kcos >> scos;
	cin >> kcal;

	mcal = kcal / kcos;

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

	sort(scal, scal + n);

	/*
	for (i = 0; i < n + 5; i++)
	{
		cout << scal[i] << " ";
	}
	*/

	for (i = n - 1; i >= 0; i--)
	{
		scsum+=scal[i];

		if (mcal < (kcal + scsum) / (kcos + scos * (n - i)))
		{
			mcal = (kcal + scsum) / (kcos + scos * (n - i));
		}
	}

	cout << mcal << endl;

	return 0;
}

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

D = defaultdict(list)
for i in range(N-1):
  u, v, w = map(int, input().split())
  u -= 1
  v -= 1
  D[u].append((v, w))
  D[v].append((u, w))

ans = [-1] * (N)
ans[0] = 0
q = deque([])
q.append(0)

while len(q) > 0:
  u = q.pop()
  for v, w in D[u]:
    if ans[v] != -1:
      continue
    else:
      ans[v] = (ans[u] + w) % 2
    q.append(v)

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

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

int main() {
	int c1, c5, c10, c50, c100, c500, s;
	cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;
	s = c1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500;
	if (s < 1000) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}

	return 0;
}

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

typedef long long int ll;
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
const ll INF = 1LL << 50;

int N, M, R;
ll z[1010];
ll dl[210][210], ds[210][210], dist[1010][210];

int main() {
    while(cin >> N >> M, N || M) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                if(i == j) continue;
                dl[i][j] = ds[i][j] = INF;
            }
        }
        for(int i=0; i<M; i++) {
            ll x, y, t; string sl; cin >> x >> y >> t >> sl;
            x--; y--;
            if(sl == "L") {
                chmin(dl[x][y], t);
                chmin(dl[y][x], t);
            }
            else {
                chmin(ds[x][y], t);
                chmin(ds[y][x], t);
            }
        }

        cin >> R;
        for(int i=0; i<R; i++) cin >> z[i], z[i]--;
        for(int i=0; i<R; i++) {
            for(int j=0; j<N; j++) {
                dist[i][j] = INF;
            }
        }

        for(int k=0; k<N; k++) {
            for(int i=0; i<N; i++) {
                for(int j=0; j<N; j++) {
                    chmin(dl[i][j], dl[i][k] + dl[k][j]);
                    chmin(ds[i][j], ds[i][k] + ds[k][j]);
                }
            }
        }

        dist[0][z[0]] = 0;
        for(int i=0; i<R-1; i++) {
            int cur = z[i], to = z[i+1];
            for(int j=0; j<N; j++) {
                if(dist[i][j] == INF) continue;

                // land only
                chmin(dist[i+1][j], dist[i][j] + dl[cur][to]);

                // sea
                for(int k=0; k<N; k++) {
                    chmin(dist[i+1][k], dist[i][j] + dl[cur][j] + ds[j][k] + dl[k][to]);
                }
            }
        }

        ll ans = INF;
        for(int i=0; i<N; i++) chmin(ans, dist[R-1][i]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5444
#include <stdio.h>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, n, m, u, v, x, y, cnt, nowd, s;
  scanf("%lld%lld%lld", &n, &m, &s);
  if(s > 100 * n) s = 100 * n;
  vector< pair<ll, pair<ll, ll> > > vec[n];
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld%lld%lld", &u, &v, &x, &y);
    vec[--u].push_back(make_pair(--v, make_pair(x, y)));
    vec[v].push_back(make_pair(u, make_pair(x, y)));
  }
  ll a[n], b[n], max[n], d[n][100 * n + 1], ans[n];
  for(i = 0; i < n; ++i) scanf("%lld%lld", &a[i], &b[i]), max[i] = -1;
  for(i = 0; i < n; ++i) for(j = 0; j <= 100 * n; ++j) d[i][j] = 1e18;
  d[0][s] = 0;
  pair<ll, ll> now;
  pair<ll, pair<ll, ll> > p, pt;
  cnt = n;
  set< pair<ll, pair<ll, ll> > > se;
  se.insert(make_pair(0, make_pair(0, s)));
  for(i = s + 1; i <= 100 * n; ++i) se.insert(make_pair(1e18, make_pair(0, i)));
  for(i = 1; i < n; ++i) for(j = 0; j <= 100 * n; ++j) se.insert(make_pair(1e18, make_pair(i, j)));
  while(cnt) {
    nowd = (*se.begin()).first;
    now = (*se.begin()).second;
    se.erase(se.begin());
    if(max[now.first] == -1) --cnt, ans[now.first] = nowd;
    else if(now.second < max[now.first]) continue;
    max[now.first] = now.second;
    for(i = 1; i * a[now.first] + now.second < n * 100; ++i) {
      if(d[now.first][now.second + i * a[now.first]] > nowd + i * b[now.first]) {
        p = make_pair(d[now.first][now.second + i * a[now.first]], make_pair(now.first, now.second + i * a[now.first]));
        se.erase(p);
        d[now.first][now.second + i * a[now.first]] = nowd + i * b[now.first];
        p.first = nowd + i * b[now.first];
        se.insert(p);
      }
    }
    if(d[now.first][n * 100] > nowd + i * b[now.first]) {
      p = make_pair(d[now.first][n * 100], make_pair(now.first, n * 100));
      se.erase(p);
      d[now.first][n * 100] = nowd + i * b[now.first];
      p.first = nowd + i * b[now.first];
      se.insert(p);
    }
    for(i = 0; i < vec[now.first].size(); ++i) {
      p = vec[now.first][i];
      if(p.second.first <= now.second && d[p.first][now.second - p.second.first] > nowd + p.second.second) {
        pt = make_pair(d[p.first][now.second - p.second.first], make_pair(p.first, now.second - p.second.first));
        se.erase(pt);
        d[p.first][now.second - p.second.first] = nowd + p.second.second;
        pt.first = nowd + p.second.second;
        se.insert(pt);
      }
    }
  }
  for(i = 1; i < n; ++i) printf("%lld\n", ans[i]);
  return 0;
}

Measured memory_bytes: 20860
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a,b,flag=false;
	int res=0;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		if(a==b){
			res++;
		}
		else{
			res=0;
		}
		if(res>=3){
			flag=true;
		}
	}
	if(flag){
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
}

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

int main()
{	
    int n;
    cin >> n;
    int x =n;
    cout << x << ":";
    for(int i=2; i*i <=x;i++){
    	while(n%i == 0){
    		n/=i;
    		cout << " " << i;
    	}
    }

    if(n !=1) cout << " " << n;
    cout << endl;
	
	return 0;
}






Measured memory_bytes: 3100
import sys
a,b,c,d = map(int,input().split())
a_life = c-b
t_life = a-d
if a_life<=0:
  print('Yes')
  sys.exit()
elif t_life<=0:
  print('No')
  sys.exit()


while(a_life>0 or t_life>0):
  a_life -= b
  if a_life<=0:
    print('Yes')
    sys.exit()
  t_life -= d
  if t_life<=0:
    print('No')
    sys.exit()

Measured memory_bytes: 9200
# F - Bracket Sequencing

from itertools import chain

n = int(input())
ss = [input() for i in range(n)]

def parse(s):
    "バランスしていない閉じ括弧数, 開き括弧数"
    cl, op = 0, 0
    for c in s:
        if c == '(':
            op += 1
        elif op > 0:
            op -= 1
        else:
            cl += 1
    return (cl, op)

inc   = []  # 開き括弧が多い
dec   = []  # 閉じ括弧が多い
close = []  # 閉じ括弧のみ
for s in ss:
    cl, op = parse(s)
    if cl < op:
        inc.append((cl, op))
    elif op == 0:
        close.append((cl, op))
    else:
        dec.append((cl, op))
peak = 0
inc.sort()
dec.sort(reverse=True)
for cl, op in chain(inc, dec, close):
    if peak < cl:
        print('No')
        exit()
    peak += op - cl
print('Yes' if peak == 0 else 'No')


Measured memory_bytes: 88168
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main(void){

  int i,N,max=0,c=0;
  scanf("%d",&N);
  int p[N];
  
   for(i=0;i<N;i++){
     scanf("%d",&p[i]);
     if(max<=p[i]){
       max=p[i];
     }
     c+=p[i];
   }
     printf("%d\n",c-max/2);
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		int N = GetInt();
		int ans = 0;
		for(int i = 1; i <= N; i++)
			if(numDigits(i) % 2 == 1)
				ans++;
		Console.WriteLine(ans);
	}

	private static int numDigits(int x)
	{
		int res = 0;
		while(x > 0)
		{
			res++;
			x /= 10;
		}
		return res;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

void solve () {
	int n, k;
	cin >> n >> k;
	int a[n], mx = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mx = max(mx, a[i]);
	}
	int l = 1, r = mx, z, y = k;
	while (r - l > 1) {
		k = y;
		int md = (l + r) / 2;
		int m = 0, tmp;
		for (int i = 0; i < n; i++) {
			tmp = a[i];
			if (tmp <= md) continue;
			if (k != 0) {
				if (tmp % md == 0) z = tmp / md - 1;
				else z = tmp / md;
				if (z <= k) {
					k -= z;
					tmp = md;
				}
			}
			m = max(m, tmp);
		}
		if (m <= md) r = md;
		else l = md;
	}
	k = y;
	int ans;
	int md = (l + r) / 2;
	int m = 0, tmp;
	for (int i = 0; i < n; i++) {
		tmp = a[i];
		if (k != 0) {
			if (tmp % md == 0) z = tmp / md - 1;
			else z = tmp / md;
			if (z <= k) {
				k -= z;
				tmp = md;
			}
		}
		m = max(m, tmp);
	}
	if (m <= md) ans = md;
	else ans = md + 1;
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
  #endif
	int t = 1;
	while (t--) {
		solve();
	}
 	return 0;
}

Measured memory_bytes: 4428
import Control.Monad
import Data.Bool
import Data.Char
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
main=putStrLn.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve(n:ss)=bool"No""Yes"$f[v]$M.fromListWith(+)$zip vs$repeat 1 where
  (v:vs)=sortOn(0-)$ss
f vs m
  |null m=True
  |otherwise=maybe False(uncurry f)$foldM g(vs,m)vs
g(vs,m)v=case M.lookupLT v m of
  Just(u,i) -> Just$(u:vs,bool(M.delete u m)(M.insert u(i-1)m)(i>1))
  Nothing -> Nothing

Measured memory_bytes: 74224
// D - Digit Sum Replace
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int m;
	cin >> m;
	vector<long long> d(m), c(m);
	for (int i = 0; i < m; i++) cin >> d[i] >> c[i];

	vector<pair<int, int> > t(10);
	for (int i = 1; i < t.size(); i++) {
		int k = 1;
		t[i].first++;
		for ( ; ; ) {
			k += i;
			t[i].first++; t[i].second++;
			if (k >= 10) {
				k = k / 10 + k % 10;
				t[i].second++;
			}
			if (k == 1) break;
		}
	}

	// for (int i = 0; i < t.size(); i++) cout << t[i].first << ' ' << t[i].second << endl;

	long long ans = 0;
	for (int i = 0; i < m; i++)
		if (d[i] == 0) {
			ans += c[i];
			c[i] = 0;
		} else {
			while (c[i] >= t[d[i]].first) {
				ans += (c[i] / t[d[i]].first) * t[d[i]].second;
				c[i] = c[i] / t[d[i]].first + c[i] % t[d[i]].first;
			}
		}

	int k = -1;
	for (int i = 0; i < m; i++) {
		if (c[i] == 0) continue;
		while (c[i] > 0) {
			if (k < 0) {
				k = d[i];
				c[i]--;
			} else {
				ans++;
				k += d[i];
				c[i]--;
				if (k >= 10) {
					k = k / 10 + k % 10;
					ans++;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 998244353
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

ll pow_mod(ll a, ll b, ll m){
    ll ret = 1;
    while (b > 0) {
        if (b & 1) {
            ret = ret * a % m;
        }
        a = a * a % m;
        b >>= 1;
    }
    return ret;
}

ll to_num(string s) {
    ll ans = 0;
    rep(i, s.size()) {
        ans *= 2;
        ans %= mod;
        ans += (s[i] - '0');
        ans %= mod;
    }
    return ans;
}

string inverse(string s) {
    string ans = "";
    rep(i, s.size()) {
        if(s[i] == '0') ans += '1';
        else ans += '0';
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll N;
    string X;
    cin >> N >> X;
    ll xx = to_num(X) + 1;
    ll A = N;
    while(A % 2 == 0) A /= 2;
    vector<ll> B;
    for(ll n = N; n >= 3; n--) {
        if(A % n == 0) B.pb(n);
    }
    
    ll ans = 0;
    vector<ll> C(B.size());
    
    rep(i, B.size()) {
        string t = X.substr(0, N / B[i]);
        string s = "";
        rep(j, B[i]) {
            if(j % 2 == 0) s += t;
            else s += inverse(t);
        }

        if(s <= X) {
            C[i] = to_num(t) + 1;
        }
        
        else {
            C[i] = (to_num(t) + mod) % mod;
        }
        
        rep(j, 0, i) {
            if(B[j] % B[i] == 0) {
                C[i] -= C[j];
                C[i] %= mod;
                (C[i] += mod) %= mod;
            }
        }
        ans += C[i] * N / B[i] * 2;
        ans %= mod;
    }
    
    ll sum = 0;
    rep(i, C.size()) (sum += C[i]) %= mod;
    xx -= sum;
    (xx += mod) %= mod;
    
    ans += xx * N * 2;
    ans %= mod;
    output(ans);
    
    

    
    return 0;
}


Measured memory_bytes: 1016
from collections import Counter
n, m = map(int,input().split())
x = list(map(int,input().split()))
data = [[] for i in range(m)]


def mod(x):
    return x%m - 1
def insert(x):
    y = mod(x)
    data[y].append(x)
for i in x:
    insert(i)


ans = len(data[m-1])//2

#print(data)

for i in range(m//2):
    p = len(data[i])
    q = len(data[m-i-2])
    if  p == q:
        if i != m-i-2:
            ans += p
        else:
            ans += p//2
    elif p > q:
        ans += q
        r = (p-q)//2
        same = 0
        set_i = Counter(data[i])
        for keys in set_i:
            same +=set_i[keys]//2
        #print(set_i)
        ans += min(r,same)
    else:
        ans += p
        r = (q-p)//2
        set_j = Counter(data[m-i-2])
        same = 0
        for keys in set_j:
            same += set_j[keys] // 2
        #print(set_j)
        ans += min(r,same)

print(ans)

Measured memory_bytes: 72428
#include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
	int n, r;

	while(cin >> n >> r, n + r){
		int huda[51];
		REP(i, n){
			huda[i] = n - i;
		}
		
		while(r--){
			int p, c;
			int tmp[51];
			cin >> p >> c;
			
			REP(i, c){
				tmp[i] = huda[p + i - 1];
			}
			
			REPR(i, p - 2){
				huda[i + c] = huda[i];
			}

			REP(i, c){
				huda[i] = tmp[i];
			}
		}

		cout << huda[0] << endl;
	}
}

Measured memory_bytes: 3016
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b)+min(c,d) << endl;
}


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

int main() {
 int N;
  cin >> N;
  int sum=0;

  for(int i = 0; i < 8; i++) {
    int x=1;
    for(int j = 0; j < i;j++)
      x *= 10;
    sum += (N%(10*x)-N%(x))/x;
  }
  if((N%sum)==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
	long int s=0,x,y;
	scanf("%ld",&x);
	y=x;
	while(x!=0)
	{
		s=s+x%10;
		x=x/10;
	}
	if(y%s==0)
	printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
// Not for Rating """"""""""I'm in Love with Experience :)""""""""""""""""""
void solve()
{
    ll N;cin>>N;
    if(N==3 or N==5 or N==7)cout<<"YES\n";
    else cout<<"NO\n";
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int T=1;while(T--){solve();}return 0;
}/*Solved By:- RITIK AGARWAL*/

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int N, a[55], b[55], M, u[55], v[55];

vector<int> Adj[55];
int calc(long long int k) {
	int ret = 0;

	while (k > 0) {
		ret += (k % 2);
		k /= 2;
	}
	return ret;
}


int Edge[55][55];

vector<int> V[25];

int check[55];
int p[55];

void INIT(void) {
	for (int i = 1; i <= N; i++) { check[i] = 0; p[i] = -1; }
}

void visit(int K) {

	check[K] = 1;

	for (auto y : Adj[K]) {
		if (check[y] == 0) { p[y] = K; visit(y); }
	}
}

void path(int i, int u, int v) {

	int cur = v;

	while (1) {
		V[i].push_back(Edge[cur][p[cur]]);
		cur = p[cur];
		if (cur == u) { break; }
	}
}

int C[55];

long long int POW[55];

long long int ENUM(long long int k) {
	for (int i = 1; i <= N; i++) { C[i] = 0; }
	
	for (long long int i = 1; i <= M; i++) {
		if ((k >> (i - 1)) & 1) {
			for (auto y : V[i]) { C[y] = 1; }
		}
	}

	long long int cnt = 0;
	for (int j = 1; j <= N - 1; j++) {
		if (C[j] == 0) { cnt++; }
	}


	return POW[cnt];
}



int main(void) {

	cin >> N;
	for (int i = 1; i <= N - 1; i++) {
		cin >> a[i] >> b[i];
		Adj[a[i]].push_back(b[i]);
		Adj[b[i]].push_back(a[i]);
		Edge[a[i]][b[i]] = i;
		Edge[b[i]][a[i]] = i;
	}

	cin >> M;
		for (int i = 1; i <= M; i++) {
			cin >> u[i] >> v[i];
			INIT();
			visit(u[i]);
			path(i, u[i], v[i]);
		}


		POW[0] = 1;
		for (int i = 1; i <= 52; i++) {
			POW[i] = POW[i - 1] * 2;
		}

		long long int ans = 0;


		for (int k = 0; k < (1 << M); k++) {
			long long int tmp = calc(k);
			long long int sign = 1;
			if (tmp % 2 == 1) { sign = -1; }

			ans += sign*ENUM(k);
		}

		cout << ans << endl;


	return 0;
}

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


int main() {
    int a,b,n;
    while(cin>>a>>b>>n) {
        int c = (a%b) * 10;
        int ans = 0;
        for(int i=0; i<n; i++) {
            ans += c / b;
            c = (c%b) * 10;
        }
        cout << ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 1160
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	a := make([]int, n)
	k := 0
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
		if a[i] > k {
			k = a[i]
		}
	}
	
	c := make([]int, k+1)
	for i := 0; i < n; i++ {
		c[a[i]]++
	}

	for i := 0; i < k; i++ {
		c[i+1] += c[i]
	}

	b := make([]int, n)
	for i := n-1; i >= 0; i-- {
		b[c[a[i]]-1] = a[i]
		c[a[i]]--
	}

	fmt.Println(strings.Trim(fmt.Sprint(b), "[]"))
}




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

int main() {
  ll n;
  cin >> n;
  ll ten=1;
  ll nine=1;
  ll eight=1;
  ll ans = 0;

  for(int i=0;i<n;i++){
      ten *= 10;
      nine *= 9;
      eight *= 8;
      ten = ten % 1000000007;
      nine = nine % 1000000007;
      eight = eight % 1000000007;
  }
  nine = (2*nine)%1000000007;
  ans = (ten - nine)%1000000007;
  ans = (ans+eight)%1000000007;

  if(ans <0){
      ans += 1000000007;
  }

  cout << ans << endl ;



}

Measured memory_bytes: 3628
n = int(input())
ball = list(map(int,input().split()))

num = [0] * (n + 1)
data = [0] * (n + 1)

for i in ball:
    num[i] += 1

for i in range(n+1):
    data[i] = num[i] * (num[i] - 1) // 2

x = sum(data)

for i in ball:
    print(x - num[i] + 1)


Measured memory_bytes: 24748
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {

    private int n;
    private int len;
    private int ans = 0;

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

    public void answer() {
	set();
	if (len < 3) {
	    System.out.println(0);
	    System.exit(0);
	}
	StringBuilder sb = new StringBuilder();
	joint(sb);
	System.out.println(ans);
    }

    private void joint(StringBuilder sb) {
	String s = sb.toString();
	if (s.length() <= len && s.length() > 0) {
	    if (Integer.parseInt(s) <= n && s.indexOf("7") >= 0
		&& s.indexOf("5") >= 0 && s.indexOf("3") >= 0) ans++;
	} else if (s.length() > len) {
	    return;
	}
	StringBuilder sb7 = new StringBuilder(s);
	joint(sb7.append("7"));
	StringBuilder sb5 = new StringBuilder(s);
	joint(sb5.append("5"));
	StringBuilder sb3 = new StringBuilder(s);
	joint(sb3.append("3"));
    }

    private void set() {
	try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
	    String s = br.readLine();
	    n = Integer.parseInt(s);
	    len = s.length();
	} catch (IOException e) {
	    e.printStackTrace();
	}
    }   
}

Measured memory_bytes: 36052
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7, A = 2e3 + 2;
int mul(ll x, ll y) {return (x * y) % mod;}
int add(ll x, ll y) {return ((x + y) % mod + mod) % mod;}
int fp (ll x, ll y)
{
    if (!y) return 1;
    int acc = fp(x, y / 2);
    acc = mul(acc, acc);
    if (y & 1) acc = mul(acc, x);
    return acc;
}
int ncr(int n, int r)
{
    int ans = 1, fact = 1;
    for (int i = n - r + 1; i <= n; i++)
        ans = mul(ans, i);
    for (int i = 2; i <= r; i++)
        fact = mul(fact, i);
    return mul(ans, fp(fact, mod - 2));
}
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    cout << add(fp(2, n), -add(1, add(ncr(n, a), ncr(n, b))));
    return 0;
}

Measured memory_bytes: 256
n = int(input())
Alph = ['A', 'B', 'C', 'D', 'E',
        'F', 'G', 'H', 'I', 'J',
        'K', 'L', 'M', 'N', 'O',
        'P', 'Q', 'R', 'S', 'T',
        'U', 'V', 'W', 'X', 'Y', 'Z'
       ]
S = input()
for i in range(len(S)):
  print(Alph[(Alph.index(S[i]) + n) % 26], end='')

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << max(a,max(b,c))-min(a,min(b,c)) << endl;

}

Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d', $N);
fscanf(STDIN, '%d', $A);
fscanf(STDIN, '%d', $B);
fscanf(STDIN, '%d', $C);
fscanf(STDIN, '%d', $D);
fscanf(STDIN, '%d', $E);

$timer = intval(ceil($N / min($A, $B, $C, $D, $E))) + 4;

echo $timer . PHP_EOL;

Measured memory_bytes: 4604
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    c = min(a[i],b[i])
    a[i] -= c
    b[i] -= c
    ans += c
    c = min(a[i+1],b[i])
    a[i+1] -= c
    b[i] -= c
    ans += c
print(ans)

Measured memory_bytes: 24112
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

long long init = 1000000000000000LL;

vector<long long> get_yen(int n, int s, vector<vector<int> >& edge_from, vector<int>&u, vector<int>& v, vector<int>& a) {
	vector<long long> ret(n);
	priority_queue<pair<long long, int> > q;
	q.push(make_pair(init, s));
	set<int> visted;
	while (q.size()) {
		pair<long long, int> p = q.top(); q.pop();
		long long rem = p.first;
		int pos = p.second;
		if (visted.count(pos)) {
			continue;
		}
		// cerr << pos << "," << init - rem << endl;
		ret[pos] = rem;
		visted.insert(pos);
		for (int i = 0; i < edge_from[pos].size(); i++) {
			int e = edge_from[pos][i];
			int dest = u[e] == pos ? v[e] : u[e];
			q.push(make_pair(rem - a[e], dest));
		}
	}
	return ret;
}



int main() {
	int n, m, s, t; cin >> n >> m >> s >> t; s--; t--;
	vector<int> u(m), v(m), a(m), b(m);
	for (int i = 0; i < m; i++) cin >> u[i] >> v[i] >> a[i] >> b[i], u[i]--, v[i]--;
	vector<vector<int> > edge_from(n);
	for (int i = 0; i < m; i++) {
		edge_from[u[i]].push_back(i);
		edge_from[v[i]].push_back(i);
	}
	vector<long long> yen = get_yen(n, s, edge_from, u, v, a);
	vector<long long> snuke = get_yen(n, t, edge_from, u, v, b);
	vector<long long> sum(n);
	for (int i = 0; i < n; i++) sum[i] = init - (init - yen[i]) - (init - snuke[i]);
	// for (int i = 0; i < sum.size(); i++) cerr << sum[i] << " "; cerr << endl;

	vector<long long> ans(n);
	for (int i = n - 1; i >= 0; i--) {
		ans[i] = sum[i];
		if (i + 1 < n) {
			ans[i] = max(ans[i], ans[i + 1]);
		}
	}
	for (int i = 0; i < n; i++) cout << ans[i] << endl;
}

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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP				make_pair
#define X				first.first
#define Y				first.second

typedef pair<int, int> P;

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; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

int rtime[21][21];
vector<int> leaf;
int N, ANS = 0;

int dfs( int from ) {
	int dmax = 0;
	REPONE( i, N ) {
		if( rtime[from][i] < INF ) {
			rtime[i][from] = INF;
			chmax( dmax, rtime[from][i] + dfs( i ) );
		}
	}
	return dmax;
}

signed main() {
	while( cin >> N, N ) {
		fill( rtime[0], rtime[21], INF );
		ANS = 0;

		REP( i, N - 1 ) {
			int from, to, t;
			cin >> from >> to >> t;
			rtime[from][to] = t;
			rtime[to][from] = t;
			ANS += 2 * t;
		}

		
		REPONE( i, N ) {
			int cnt = 0, idx;
			REPONE( j, N ) {
				if( rtime[i][j] != INF ) {
					cnt++;
					idx = j;
				}
			}

			if( cnt == 1 && i != 1 ) {
				ANS -= 2 * rtime[i][idx];
				rtime[i][idx] = rtime[idx][i] = INF + 1;
			}
		}


		cout << ANS - dfs( 1 ) << endl;
	}
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<str> vs;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};

int main() {
    vi a(3);
    cin >> a[0]>>a[1]>>a[2];
    cout << *max_element(all(a))-*min_element(all(a)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
struct point{
	int x,y;
}a[N];
bool cmp(point a,point b){
	return a.x < b.x;
}
int main()
{
	int n;
	while(cin >> n){
		for(int i = 1; i <= n; i++){
			cin >> a[i].x;
			a[i].y = i;
		}
		sort(a+1,a+n+1,cmp);
		for(int i = 1; i <= n; i++){
			cout << a[i].y << " ";
		}
		cout << endl;
	}
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for(int i=0; i<=a; i++) {
    for(int j=0; j<=a; j++) {
      if(0 <= b-(i+j) && b-(i+j) <= a) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int mod = 1000000007;
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        long[] b = new long[n + 1];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sc.next());
            b[i + 1] = b[i] + a[i];
        }
        long result = 0;
        for (int i = 0; i < n; i++) {
            long sum = (b[n] - b[i + 1]) % mod;

            result = (result + ((long) a[i] * sum) % mod) % mod;
        }
        System.out.println(result);
    }
}

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

int main() {
  string S, T ;
  int A , B ;
  string U ; 
  
  cin >> S >> T ;
  cin >> A >> B ;
  cin >> U  ;
  
  if (U == S ){
    cout << A-1 << " "<< B <<endl ; 
    
  }
  else {
    cout << A << " " <<B-1 << endl ; 
  }
  
  
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	vector<ll> a, b;
	for(int i=0; i<n; i++){
		ll x;
		cin >> x;
		a.push_back(x);
	}
	b=a;
	sort(b.begin(), b.end());

	ll cnt=0;
	for(int i=0; i<n; i++){
		if((lower_bound(b.begin(), b.end(), a[i])-b.begin())%2!=i%2){
			cnt++;
		}
	}
	cout << cnt/2 << endl;
	return 0;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,A;
    cin >> N >> A;
    vector<int>x(N);
    for(int i = 0; i < N; i++) {
        cin >> x[i];
    }
    int dp[55][55][5000];
    for(int i = 0; i < 55; i++) {
        for(int j = 0; j < 55; j++) {
            for(int k = 0; k < 5000; k++) {
                dp[i][j][k] = 0;
            }
        }
    }
    dp[0][0][0] = 1;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            for(int k = 0; k < 5000; k++) {
                if(dp[i][j][k] == 0) {
                    continue;
                }
                dp[i+1][j][k] += dp[i][j][k];
                dp[i+1][j+1][k+x[i]] += dp[i][j][k];
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        ans += dp[N][i][i*A];
    }
    cout << ans << endl;
}



Measured memory_bytes: 121764
#include <cstdio>

int d_num(int n){
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(n % i == 0){
			ans++;
		}
	}
	return ans;
}

int main(){
	int N;
	scanf("%d",&N);

	for(int i = 1;;i++){
		if(d_num(i) == N){
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 2756
#include<bits/stdc++.h>
#define REP(i, n) for(int i=0; i<n; i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int N;
int main() {  
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    ll ans = 1000;
    ll s = 0;
    for (int i = 0; i < N; i++)
    {
        ans += a[i]*s;
        s = 0;
        if(i==N-1) break;
        if(a[i]<a[i+1]){
            s += ans/a[i];
            ans %= a[i];
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int i = 0; i <= K; ++i) {
    if (i > S) break;
    ans += max(min(K, S - i) - max(S - i - K, 0) + 1, 0);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())
cake = [input() for _ in range(H)]
memo = [[0] * W for _ in range(H)]
cake_count_row = [0] * H

for y in range(H):
    count = 0
    for x in range(W):
        if cake[y][x] == "#":
            count += 1
    cake_count_row[y] = count

count = 1
for y in range(H):
    first = True
    if cake_count_row[y] == 0:
        continue 
    for x in range(W):
        if cake[y][x] == "#":
            if first:
                first = False
            else:
                count += 1
        memo[y][x] = count
    if first == False:
        count += 1

copy_y_save = -1
for y in range(1, H):
    if cake_count_row[y] == 0:
        for x in range(W):
            memo[y][x] = memo[y - 1][x]

for y in range(H - 2, -1, -1):
    if cake_count_row[y] == 0:
        for x in range(W):
            memo[y][x] = memo[y + 1][x]

for i in range(H):
    print(" ".join(list(map(str, memo[i]))))


Measured memory_bytes: 7284
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N;
    cin >> N;
    vector<int> A(N);
    readvec(A);

    int absmax = 0, sign = 1, ind = 0;

    REP(i, N){
        if(llabs(A[i]) > absmax){
            absmax = llabs(A[i]);
            sign = absmax / A[i];
            ind = i;
        }
    }

    cout << 2 * N - 1 << endl;
    //Aの符号を全てsignにする
    REP(i, N){
        cout << ind + 1 << " " << i + 1 << endl;
    }
    if(sign == 1){
        REP(i, N - 1){
            cout << i + 1 << " " << i + 2;
            if(i != N - 2) cout << endl;
        }
    }else{
        REP(i, N - 1){
            cout << N - i << " " << N - i - 1;
            if(i != N - 2) cout << endl;
        }
    }
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>

using namespace std;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

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

	UnionFind u(N + 1);
	for (int i = 0; i < M; ++i) {
		int X, Y, Z;
		cin >> X >> Y >> Z;
		u.unionSet(X, Y);
	}

	set<int> s;
	for (int i = 1; i <= N; ++i) {
		s.insert(u.root(i));
	}
	cout << s.size() << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const int mod=1e9+7;

int main(){
  int N,K;
  cin>>N>>K;
  vector<char>D(K);
  for(int i=0;i<K;i++){
    cin>>D[i];
  }
  for(int i=N;;i++){
    string t=to_string(i);
    bool use=true;
    for(int k=0;k<t.size();k++){
      bool ok=true;
      for(int j=0;j<K;j++){
        if(t[k]==D[j]){
          ok=false;
        }
      }
      if(!ok){use=false;}
    }
    if(use){cout<<t<<endl;return 0;}
  }
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

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

  cout << ((n+m)*(n+m-1)/2)-n*m << "\n";
  return 0;
}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
if a>=0 and c>=0:
    Ans=b*d
elif b<0 and d<0:
    Ans=a*c
elif a>=0:
    if d<0:
        Ans=a*d
    else:
        Ans=b*d
elif c>=0:
    if b<0:
        Ans=b*c
    else:
        Ans=b*d
else:
    if b>0 and d>0:
        Ans=max([a*c,b*d])
    else:
        Ans=a*c
print(Ans)

Measured memory_bytes: 9192
#include<iostream>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double pi = 3.14159265358979323846264338327950288;
bool a[8][8];
bool l = 0;
char b[8][8];
int h, w, sum = 0;
void solve(int i, int j,int s) {
	if (i == h - 1 && j == w - 1) {
		if (sum == s)
			l = 1;
		return;
	}
	if (i + 1 < h&&b[i + 1][j] == '#')
		solve(i + 1, j, s + 1);
	if (j + 1 < w&&b[i][j + 1] == '#')
		solve(i, j + 1, s + 1);
}
int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> b[i][j];
			if (b[i][j] == '#')
				sum++;
		}
	}
	solve(0, 0, 1);
	if (l)
		cout << "Possible\n";
	else
		cout << "Impossible\n";
	cin >> h;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
data = [0] * (N+1)
for i in range(N):
    data[i+1] = data[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r =map(int, input().split())
    print(data[r-1] - data[l-1])


Measured memory_bytes: 7748