akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
#include <fstream>
#include <sstream>
#include <math.h>
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <time.h>
#include <stdio.h>
#include <deque>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define POW(n) ((n)*(n))
#define ALL(a) (a).begin(),(a).end()
#define cerr if(false) cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

int N,K,X,Y;

void solve() {

}

int main() {
	cin >> N  >> K >> X >> Y;

	ll ans = min(N, K) * X + max(0, N - min(N, K)) * Y;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
<?php
error_reporting(0);
//list($x,$t) = explode(" ",trim(fgets(STDIN)));
$N = trim(fgets(STDIN));
$s = array();
for($i=0;$i<$N;$i++) {
  $A = trim(fgets(STDIN));
  if (isset($s[$A])) {
    unset($s[$A]);
  }
  else {
    $s[$A]=1;
  }
}
printf("%d\n",count($s));


Measured memory_bytes: 18036
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main() {
  int n;
  cin >> n;
  map<string, int> m;
  int max = 1;
  for (int i = 0; i < n; i++) {
    string vote;
    cin >> vote;
    if (m.count(vote) == 0) {
      m[vote] = 1;
    } else {
      m[vote] += 1;
      int v = m[vote];
      max = v > max ? v : max;
    }
  }

  for (auto i = m.begin(); i != m.end(); i++) {
    if (i->second == max) {
      cout << i->first << endl;
    }
  }
  return 0;
}


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

typedef long long lint;
typedef unsigned long long ulint;
const int MOD=1000000007;

int ksum(int A){
    int r=0;
    for(int i=0;i<6;i++){
        r+=A%10;
        A/=10;
    }
    return r;
}
int main(){
    int N;
    cin >> N;

    int m=100000;
    for(int i=1;i<N;i++){
        m=min(m,ksum(N-i)+ksum(i));
    }
    cout << m << endl;

    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cmath>

using namespace std;


int main()
{
    //string S, T;
    int A, B;
//    int count = 0;

    //double K, S;
    //double x, y, z;


    cin >> A;
    cin >> B;

   if(A + B == 3){
       cout << 3 << endl;
   }

   if(A + B == 4) {
       cout << 2 << endl;
   }

   if(A + B == 5) {
       cout << 1 << endl;
   }


     return 0;

}



Measured memory_bytes: 256
# カードを記録する二次元配列を定義。持っていない＝Falseとしてデフォルト定義
cards = [[False for i in range(13)] for j in range(4)]
pattern = ["S", "H" ,"C", "D"]

# input情報から手元にあるカードをTrueとして記録する
n = int(input())
for s in range(n):
    cd, rank = map(str, input().split())
    cards[pattern.index(cd)][int(rank)-1] = True

# 手元にない（False）のカードを出力
for j in range(4):
    for i in range(13):
        if cards[j][i] == False:
            print(pattern[j], i+1)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
vector<int> t[MAXN + 5];
int dfs(int x, int depth, int fa)
{
    int ans = 1;
    if (depth > 0)
        for (auto i : t[x])
            if (i != fa)
                ans += dfs(i, depth - 1, x);
    return ans;
}
vector<pair<int, int>> edge;
int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        t[a].push_back(b);
        t[b].push_back(a);
        edge.push_back(make_pair(a, b));
    }
    int ans = n;
    if (k % 2 == 0)
        for (int root = 1; root <= n; root++)
            ans = min(ans, n - dfs(root, k / 2, -1));
    else
        for (auto e : edge)
            ans = min(ans, n - dfs(e.first, k / 2, e.second) - dfs(e.second, k / 2, e.first));
    cout << ans;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#include <string>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
// #define mod  1000000007
#define N 100005
// #define MAX 200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"
// const int inf = (int)1e18 + 10;
const int mod = 1e9 + 7;

const int inf = 1e15;

int mx = 42;
int c[50] , a[N] , b[N][50] = {{0}};
signed main(){
  fast;
 
  int n , k;
  cin >> n >> k;
  for(int i = 1 ; i <=n ; i++){
      cin >> a[i];
     for(int j = 0 ; j <= mx ; j++){
         b[i][j] = ((a[i] & (1ll << j)) > 0);
     }
  }


  for(int j = 0 ; j<=mx ; j++)
       c[j] = ((k & (1ll << j)) > 0);
  

  bool t = 0;
  int sum = 0;
  for(int j = mx ; j>=0 ; j--){
       int d = c[j] , r = 0;
      for(int i = 1 ; i<=n ; i++)
            r+=b[i][j];
      if(d == 0 && t == 0)
        sum += (1ll << j) * r;
      else if(d == 1 && t == 0){
        if(r > n - r){
           sum += (1ll << j) * r;
           t = 1;
        }
        else{
          sum += (1ll << j) * (n - r);
          t = 0;
        }
      }
      else if(t == 1 ){
          if(r > n - r)
           sum += (1ll << j) * r;
        else
          sum += (1ll << j) * (n - r);      
      }

     

  }

  cout << sum << endl;

}


Measured memory_bytes: 40192
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int A,B,C;
    cin >> A >> B >> C;
    if((C>A&&C<B)||(C<A&&C>B)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
    string ans = "YES";
    ll n;
    ll b = 0;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    rep(i,n){
        int c = a[i];
        if(b==c){
            ans = "NO";
            break;
        }else b=c;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
 
typedef long long ll;
 
using namespace std; 
 
#define REP(inc, bgn, end) for (int inc = bgn; inc < end; inc++)

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    REP(i, 0, n) cin >> h[i];

    int cnt = 0;
    REP(i, 0, n) {
        if (h[i] >= k) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640
// https://atcoder.jp/contests/abc066/tasks/abc066_b

#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int isss(string s)
{
  int l = s.length();
  return s.substr(0, l / 2) == s.substr(l / 2)
             ? s.length()
             : isss(s.substr(0, l - 2));
}

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  string s;

  cin >> s;

  int lm = isss(s.substr(0, s.length() - 2));

  cout << lm << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> h(n), a(m), b(m);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    vector<bool> flag(n, true);
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        if(h[a[i]-1] > h[b[i]-1]){
            flag[b[i]-1] = false;
        }else if (h[a[i]-1] < h[b[i]-1]){
            flag[a[i]-1] = false;
        }else if(h[a[i]-1] == h[b[i]-1]){
            flag[a[i]-1] = false;
            flag[b[i]-1] = false;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(flag[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4580
// {{{ Boilerplate Code <--------------------------------------------------
// vim:filetype=cpp:foldmethod=marker:foldmarker={{{,}}}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define ALL(A)     (A).begin(), (A).end()

using namespace std;

// }}}

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

        int judge=0;
        int zorocount=0;

        FOR(i,0,N){
                int a,b;
                cin>>a>>b;

                if (a==b) {
                        ++zorocount;
                        if (zorocount == 3) {
                                judge=1;
                        }
                }else{
                        zorocount=0;
                }

        }
        cout<<(judge?"Yes":"No")<<endl;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;


int main(void) {
	ll n, m, ans = 0;
	cin >> n >> m;
	vector<ll>a(n), sum(n + 1);
	for (ll i = 0;i < n;i++)cin >> a[i];
	for (ll i = 0;i < n;i++)sum[i + 1] = sum[i] + a[i];
	for (ll i = 0;i <= n;i++)sum[i] = sum[i] % m;
	sort(sum.begin(), sum.end());
	for (ll i = 0;i < n;) {
		ll num = sum[i];
		ll j = i;
		while (j<=n&&num == sum[j]) {
			j++;
		}
		ans += (j - i) * (j - i - 1) / 2;
		i = j;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC116A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, n;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            n = a * b / 2;
            Console.WriteLine(n);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;


class Main{
 public static void main(String[] args){
 Scanner stdIn = new Scanner(System.in);
 //数値の入力
 int K = stdIn.nextInt(); //倍数
 int A = stdIn.nextInt();
 int B = stdIn.nextInt();
 
 //計算
 int num = 0;
 
 for (int i = 0; i <= (B / K); i++){
   if( i * K >= A)
    num = num +1;
 }
 
 if(num > 0)
  System.out.println("OK");
 else
  System.out.println("NG");
 }
}


Measured memory_bytes: 35784
#include <array>
#include <iostream>

int main()
{
    char S[4];
    for (int i = 0; i < 4; ++i) {
        std::cin >> S[i];
    }

    if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
        std::cout << " Yes " << std::endl;
    } else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
        std::cout << " Yes " << std::endl;
    } else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
        std::cout << " Yes " << std::endl;
    } else {
        std::cout << " No " << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<50
#define fst first
#define sec second
#define pb push_back
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(int itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(int itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<ll,ll> P;

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

  int n,k,x,y;
  cin >> n >> k >> x >> y;
  
  cout << (n<k?x*n:x*k+y*(n-k)) << endl;

  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

N,A,B = map(int,input().split())
C = A-B
health = [int(input()) for i in range(N)]
health.sort()

def check(Bx):
	Ax = 0
	for h in health:
		if h > Bx*B:
			Ax += math.ceil((h-Bx*B)/C)
	return Ax <= Bx

low = 0
high = health[N-1]//B+1

while True:
	mid = (low+high)//2
	if check(mid):
		high = mid
	else:
		low = mid
	if high - low <= 1:
		break

print(high)

Measured memory_bytes: 8128
// Created by sz
//test2
#include <bits/stdc++.h>
using namespace std;

const int N = 1e3 + 5;

typedef pair<int, int> pii;

char g[N][N];
int vis[N][N], d[N][N];
int h,w;

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

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>h>>w;
    queue<pii> q;
    
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin>>g[i][j];
            if(g[i][j]=='#'){
                vis[i][j] = 1;
                d[i][j] = 0;
                q.push({i,j});
            }
        }
    }
    
    int mxd = 0;
    while (!q.empty()) {
        pii u = q.front();
        q.pop();
        
        for (int i = 0; i < 4; i++){
            int nx = u.first + dx[i];
            int ny = u.second + dy[i];
            if(nx<0||nx>=h)continue;
            if(ny<0||ny>=w)continue;
            if(!vis[nx][ny]){
                d[nx][ny] = d[u.first][u.second] + 1;
                vis[nx][ny] = 1;
                q.push({nx,ny});
                mxd = max(mxd, d[nx][ny]);
            }
        }
        
    }
    
    
    cout<<mxd<<endl;
    
    return 0;
}



Measured memory_bytes: 17296
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, X = getlist()
	B = [0] * 51
	P = [0] * 51
	Size = [0] * 51
	P[0] = 1
	for i in range(50):
		B[i + 1] = 2 * B[i] + 2
		P[i + 1] = 2 * P[i] + 1
	for i in range(51):
		Size[i] = B[i] + P[i]

	def solve(N, X):
		if N == 0:
			return 1
		elif X == 1:
			return 0
		elif X <= 1 + Size[N - 1]:
			return solve(N - 1, X - 1)
		elif X == 2 + Size[N - 1]:
			return P[N - 1] + 1
		elif 2 + Size[N - 1] < X and X <= 2 + 2 * Size[N - 1]:
			return (P[N - 1] + 1 + solve(N - 1, X - 2 - Size[N - 1]))
		else:
			return 2 * P[N - 1] + 1

	ans = solve(N, X)
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3444
#include <iostream>

int main() {
	if (int N = 1) {
		if (int K = 1) {
			if (int X = 1) {
				if (int Y = 1) {
					if (int ans = 0) {}
					else {
						if (std::cin >> N) {}
						if (std::cin >> K) {}
						if (std::cin >> X) {}
						if (std::cin >> Y) {}
						while (N > K) {
							if (ans += Y) {}
							if (N--) {}
						}
						while (N > 0) {
							if (ans += X) {}
							if (N--) {}
						}
						if (std::cout << ans << std::endl) {}
					}
				}
			}
		}
	}
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	int n, a[100];
	scanf("%d", &n);
	rep(i, n)scanf("%d", &a[i]);
	sort(a, a + n);
	printf("%d\n", a[n - 1] - a[0]);

	return 0;
}


Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b){
  if(a % b == 0) return b;
  return gcd(b, a % b);
}
int main(){
  ll a,b;
  cin >> a >> b;
  ll num = a;
  map<ll, int> cnt;
  for(int i = 2; i <= sqrt(a); i++){
    if(num % i == 0){
      num /= i;
      cnt[i]++;
    }
    while(num % i == 0) num /= i;
  }
  if(num > 1) cnt[num]++;
  num = b;
  for(int i = 2; i <= sqrt(b); i++){
    if(num % i == 0){
      num /= i;
      cnt[i]++;
    }
    while(num % i == 0) num /= i;
  }
  if(num > 1) cnt[num]++;
  int ans = 1;
  for(auto x : cnt){
    if(x.second == 2) ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

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

bool d[20][20];
int P[20];

ll ans;
int N, M;

void dfs(int m, int bit){
    if(m == N){
        vector<int> K(M);
        for(int b = 0; b < N; b++){
            bool high = (bit >> b) & 1;
            if(!high) continue;

            for(int i = 0; i < M; i++){
                if(d[i][b]) K[i]++;
            }
        }

        for(int i = 0; i < M; i++){
            int t = K[i] % 2;
            if(t != P[i]){
                return;
            }
        }

        ans++;
        return;
    }

    dfs(m+1, bit);
    dfs(m+1, bit | (1 << m));
}

int main(){
    cin >> N >> M;
    REP(i,M){
        int k;
        cin >> k;
        REP(j,k){
            int s;
            cin >> s;
            s--;
            d[i][s] = true;
        }
    }

    REP(i,M){
        int p;
        cin >> p;
        P[i] = p;
    }

    dfs(0, 0);

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


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    final static int  MAX_N = 1500;
    static int[][] memorry = new int[MAX_N][MAX_N];

    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n;

	n = scan.nextInt();
	for(int i=0; i<n; i++){
	    char[] str1 = scan.next().toCharArray();
	    char[] str2 = scan.next().toCharArray();
	    solve(str1, str2);
	}
    }

    static void solve(char[] str1, char[] str2){
	for(int i=0; i<str1.length; i++){
	    for(int j=0; j<str2.length; j++){
		if(str1[i]==str2[j])memorry[i+1][j+1]=memorry[i][j]+1;
		else memorry[i+1][j+1]=Math.max(memorry[i][j+1], memorry[i+1][j]);
	    }
	}
	System.out.println(memorry[str1.length][str2.length]);
    }
}

Measured memory_bytes: 21000
N, M = map(int, input().split())
a = []
counter = 0
total = [0 for i in range(M + 1)]
tmp = []
for i in range(N):
  tmp.append(list(map(int, input().split()))[1 :])
for i in tmp:
  for j in i:
    total[j] += 1
for i in range(len(total)):
  if total[i] == N:
    counter += 1
    
print(counter)



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

int main() {
  while (true) {
    int n, w;
    cin >> n >> w;
    if (n == 0 && w == 0) return 0;
    int v[n];
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }

    int max_v = v[0];
    for (int i = 1; i < n; i++) {
      max_v = max(max_v, v[i]);
    }

    int number = max_v / w + 1;
    int count[number];
    for (int i = 0; i < number; i++) {
      count[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      count[v[i] / w]++;
    }

    int max_h = count[0];
    for (int i = 0; i < number; i++) {
      max_h = max(max_h, count[i]);
    }

    double res = 0.0;
    for (int i = 0; i < number; i++) {
      double temp
	= ((double)(number - 1 - i) * count[i])/ ((double)(number - 1) * max_h);
      res += temp;
    }
    printf("%.6f\n", res + 0.01);
  }
}

Measured memory_bytes: 3080
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define		vii 			vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
ll NcR(ll n, int r)
{
	if(n<=1)return 0;
    ll res = 1;
    if ( r > n - r )
        r = n - r;
    loop(r,i,0){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}
int main() {
	ll n,m;cin>>n>>m;
	cout<<NcR(n,2)+NcR(m,2)<<endl;
}


Measured memory_bytes: 256
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7

x, y = multi_int_input()

if y < x*2 or y > x * 4 or y % 2 != 0:
    print("No")
else:
    print("Yes")



Measured memory_bytes: 9616
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<string>s(n);
    set<string>se;
    rep(i,n){
        cin>>s[i];
        se.insert(s[i]);
    }
    cout<<se.size()<<endl;
}

Measured memory_bytes: 25008
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

map<ll, ll> prime_factorization(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while(n >= a*a){
    if(n % a == 0){
      ans[a]++;
      n /= a;
    }else{
      a++;
    }
  }
  ans[n]++;

  return ans;
}

// map<ll, ll> prime_factorization(ll n, set<int> &ps){
//   map<ll, ll> ans;
//   if(ps.find(n) != ps.end()){
//     ans[n]++;
//     return ans;
//   }
//   auto itr = ps.begin();
//   while(n >= (*itr)*(*itr)){
//     if(n % (*itr) == 0){
//       ans[(*itr)]++;
//       n /= (*itr);
//       if(ps.find(n) != ps.end()){
//         ans[n]++;
//         return ans;
//       }
//     }else{
//       itr++;
//     }
//   }
//   ans[n]++;
//   return ans;
// }

set<int> make_prime_set(int lim){
  set<int> ps;
  vector<bool> chk(lim+1, true);
  chk.at(0) = chk.at(1) = false;
  rep2(i, 2, chk.size()){
    if(chk.at(i) == false) continue;
    ps.insert(i);
    for(int j = i+i; j < chk.size(); j +=i) chk.at(j) = false;
  }
  return ps;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  // auto ps = make_prime_set(1e6+5);
  set<int> ups;
  bool f = false;
  for(auto now : a){
    // auto rs = prime_factorization(now, ps);
    auto rs = prime_factorization(now);
    for(auto p : rs){
      if(p.first != 1 && ups.find(p.first) != ups.end()){
        f = true;
        break;
      }else{
        ups.insert(p.first);
      }
    }
    if(f == true) break;
  }
  if(f == false){
    cout << "pairwise coprime" << endl;
    return 0;
  }

  int g = a.front();
  rep2(i, 1, a.size()){
    g = __gcd(g, a.at(i));
  }
  if(g == 1) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;
  return 0;
}

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

int main(){
    long long ans=0,sum=0;
    int n,a,b;
    cin >>n>>a>>b;


    //cout <<fixed<<setprecision(16)<< << endl;
    cout << min(b,n*a) << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int n;
void dfs(std::string s,char mx) {
  if (s.size() == n) {
    std::cout << s << std::endl;
    return;
  }
  for (char c = 'a'; c <= mx + 1; ++c) {
    std::string t = s;
    t += c;
    dfs(t, std::max(mx, c));
  }
}

int main() {
  std::cin >> n;
  dfs("", 'a'-1);
  return 0;
}

Measured memory_bytes: 3588
import sys
def 解():
    input = sys.stdin.readline
    N,K = [int(_) for _ in input().split()]
    aP = sorted([[int(_) for _ in input().split()] for _ in range(N)],key=lambda x:x[1],reverse=True)
    dS = set()
    aPK = aP[:K]
    for t,d in aPK:
        dS.add(t)
    dSall = dS.copy()
    for t,d in aP[K:]:
        dSall.add(t)
    iSall = len(dSall)

    iSum = sum(x[1] for x in aPK)
    i種類 = len(dS)
    iTotal = iSum + i種類**2
    if iSall == len(dS): #種類を増やす余地がない
        print(iTotal)
        exit()
    else: #種類を増やす余地があるとき
        #とりあえず地図を作る
        dPK = {}
        for t,d in aPK:
            if t in dPK :
                dPK[t].append(d)
            else:
                dPK[t] = [d]
        vT = set()
        j = K - 1
        for nt,nd in aP[K:]:
            if i種類 == iSall:
                break
            if nt not in dS:
                #for i in range(K-1,-1,-1):
                for i in range(j,-1,-1):
                    t,d = aPK[i]
                    if t not in vT:
                        dPK[t].sort()
                        vT.add(t)
                    aT = dPK[t]
                    if 1 < len(aT):
                        iNewTotal = iSum - d + nd  + (i種類+1)**2
                        if iTotal < iNewTotal:
                            iTotal = iNewTotal
                        del dPK[t][0]
                        dPK[nt]=[nd]
                        aPK[i]=[nt,nd]
                        i種類 += 1
                        iSum = iSum -d +nd
                        dS.add(nt)
                        break
                j=i-1
        print(iTotal)
解()


Measured memory_bytes: 38648
import collections

if __name__ == "__main__":
    N = int(input()) 
    # int型のリスト
    A = list(map(int, input().rstrip().split(' ')))
    #print(A)
    
    # #TLE
    # ans = 0
    # for i, a in enumerate(A):
    #     target = A[i+a:]
    #     #print(target)
    #     for j, b in enumerate(target):
    #         if j  == b:
    #             #print(a, b)
    #             ans += 1
    # print(ans)
    
    L = [i+A[i] for i in range(N)]
    R = [i-A[i] for i in range(N)]
    c_l = collections.Counter(L)
    c_r = collections.Counter(R)
    #print(L)
    #print(c_l)
    #print(R)
    #print(c_r)
    ans = 0
    for k, v in c_l.items():
        v_ = c_r.get(k, 0)
        ans += v * v_
    print(ans)

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

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

  int ans = INT_MAX;
  rep(i, S.size() - 2) { ans = min(ans, abs(stoi(S.substr(i, 3)) - 753)); }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
from collections import Counter
N = int(input())
Dlist = list(map(int, input().split()))
DCounter = Counter(Dlist)
if DCounter[0] == 1 and Dlist[0] == 0:
    num = 1
    for i in range(1, max(Dlist) + 1):
        num *= DCounter[i - 1] ** DCounter[i]

    print(num % 998244353)
else:
    print(0)


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

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

    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll	long long 
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
int gcd(int a, int b) 
{ 
	if (a == 0) 
		return b; 
	return gcd(b % a, a); 
} 
int invertBits(int num) 
{  
    int x = log2(num) + 1; 
    for (int i = 0; i < x; i++)  
       num = (num ^ (1 << i));  
   
    return num; 
} 
///////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
	int n,l,i;
	cin>>n>>l;
	int fl[n],sum=0;
	for(i=0;i<n;i++)
	{
		fl[i]=l+i;
		sum+=fl[i];
	}
	//cout<<sum<<endl;
	int mi=INT_MAX;
	int ans;
	for(i=0;i<n;i++)
	{
		//cout<<sum-fl[i]<<endl;
		if(abs(sum-(sum-fl[i]))<mi)
		{
			ans=sum-fl[i];
			mi=abs(sum-(sum-fl[i]));
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
ans=1000000000000
for i in range(N):
    temp=T-H[i]*0.006
    if abs(temp-A)<ans:
        ans=abs(temp-A)
        p=i+1
print(p)


Measured memory_bytes: 9072
def main():
    import sys
    input = sys.stdin.readline
    n,m,l = map(int,input().split())
    E = [[float("INF")]*n for i in range(n)]
    for i in range(m):
        a,b,c = map(int,input().split())
        E[a-1][b-1] = c
        E[b-1][a-1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                E[i][j] = min(E[i][j],E[i][k]+E[k][j])
    wa = [[float("INF")]*n for i in range(n)]
    for i in range(n):
        for j in range(n):
            if E[i][j] <= l:
                wa[i][j] = 1
    for k in range(n):
        for i in range(n):
            for j in range(n):
                wa[i][j] = min(wa[i][j],wa[i][k]+wa[k][j])
    
    x = int(input())
    for i in range(x):
        s,g = map(int,input().split())
        if wa[s-1][g-1] == float("INF"):
            print(-1)
        else:
            print(wa[s-1][g-1]-1)

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 126428
S = gets
cnt = 0
cnt += 1 if S[0] == S[1]
cnt += 1 if S[0] == S[2]
cnt += 1 if S[0] == S[3]
cnt += 1 if S[1] == S[2]
cnt += 1 if S[1] == S[3]
cnt += 1 if S[2] == S[3]
puts 'Yes' if cnt == 2
puts 'No' if cnt != 2

Measured memory_bytes: 3836
s = input()

ans1 = 0
ans2 = 0

for i in range(len(s)):
    if (i % 2 == 0 and s[i] == '0') or (i % 2 == 1 and s[i] == '1'):
        ans1 += 1
    elif (i % 2 == 1 and s[i] == '0') or (i % 2 == 0 and s[i] == '1'):
        ans2 += 1

print(min(ans1, ans2))

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int main(){
  int n;
  int cs=1;
  while(cin >> n, n){
    int field[10][10];
    
    int cnt = 1;
    field[0][0] = cnt++;
    
    int x = 0, y = 0;
    
    while(cnt < n*n){   
      if(x < n-1){
	x++;
	field[y][x] = cnt++;
      } 
      while(0 < x && y < n-1){
	x--, y++;
	field[y][x] = cnt++;
      }
      if(y == n-1){
	x++;
	field[y][x] = cnt++;
      }
      else{
	y++;
	field[y][x] = cnt++;
      }
      while(0 < y && x < n-1){
	x++, y--;
	field[y][x] = cnt++;
      }
      
      if(x == n-1){
	y++;
	field[y][x] = cnt++;
      }
    }
    
    printf("Case %d:\n", cs++);
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
	printf("%3d", field[i][j]);
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;


/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/


int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
       int a,b;
       cin>>a>>b;
       if(a<=9&&b<=9)cout<<a*b<<endl;
       else cout<<-1<<endl;
    }
}












Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

itn N, a[400];
int n[10];
double dp[400][400][400];
bool check[400][400][400];

double f(itn i, int j, int k) {
    if (check[i][j][k])
        return dp[i][j][k];
    check[i][j][k] = 1;
    double ret = 0;
    if (i > 0)
        ret += i * f(i - 1, j, k);
    if (j > 0)
        ret += j * f(i + 1, j - 1, k);
    if (k > 0)
        ret += k * f(i, j + 1, k - 1);
    ret += N;
    ret /= (double)(i + j + k);
    return dp[i][j][k] = ret;
}

void solve() {
    FOR(N)
    n[a[i]]++;
    dp[0][0][0] = 0;
    check[0][0][0] = 1;
    cout << f(n[1], n[2], n[3]) << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
    cin >> N;
    FOR(N)
    cin >> a[i];


    solve();
    return 0;
}


Measured memory_bytes: 423808
#include <stdio.h>
int main(){
	
	int n, m;
	
	scanf("%d", &n);
	scanf("%d", &m);
	
	int matriz[n][m];
	int vetor[m];
	int c[n];
	
	for(int i = 0; i < n; i++)
	    c[i] = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			scanf("%d", &matriz[i][j]);
		}
	}
	
	for(int i = 0; i < m; i++)
		scanf("%d", &vetor[i]);
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			c[i] += matriz[i][j]*vetor[j];
			//printf("c[%d] = %d matriz[i][j] = %d vetor[j] = %d\n",i, c[i], matriz[i][j], vetor[j]);
		}
	}
	
	for(int i = 0; i < n; i++)
		printf("%d\n", c[i]);

  return 0;
}

Measured memory_bytes: 1068
N,M=map(int,input().split())
results=[]
for i in range(M):
   p,S=input().split()
   p=int(p)
   p_S=[p,S]
   results.append(p_S)

WA=[]
solved=[]
for i in range(1,N+1):
   a=[i,0]
   WA.append(a)
   b=[i,False]
   solved.append(b)

AC_count=0
WA_count=0
for i in range(M):
   if results[i][1]=="WA":
      if solved[results[i][0]-1][1]==False:
         WA[results[i][0]-1][1]+=1

   elif results[i][1]=="AC":
      if solved[results[i][0]-1][1]==False:
         AC_count+=1
         solved[results[i][0]-1][1]=True

for i in range(N):
   if solved[i][1]==True:
      WA_count+=WA[i][1]

print(AC_count,WA_count)

Measured memory_bytes: 45684
import sys
s=list(input())
r=list(reversed(s))
n=len(s)

for i in range(n):
    if s[i]!=r[i]:
        print('No')
        sys.exit()

s1=s[:]

del s1[(n-1)//2:]
r1=list(reversed(s1))

for i in range(len(s1)):
    if s1[i]!=r1[i]:
        print('No')
        sys.exit()

s2=s[:]

del s2[:(n+3)//2-1]
r2=list(reversed(s2))

for i in range(len(s2)):
    if s2[i]!=r2[i]:
        print('No')
        sys.exit()
print('Yes')

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e9;

int N, M;
int A[3];
VI G[51];
VI G_[51][3];
void calc(){
  for(int u=1;u<=N;++u){
	REP(i,3){
	  int crt = 0, nxt = 1;
	  set<int> s[2];
	  s[crt].insert(u);
	  REP(turn,A[i]){
		s[nxt].clear();
		for(int v: s[crt])
		  for(int to: G[v])
			s[nxt].insert(to);
		swap(crt, nxt);
	  }
	  for(int v: s[crt])
		G_[u][i].PB(v);
	}
  }
}

int dp[51];
/*
int solve(int u){
  if(u == N) return dp[u] = 0;
  if(dp[u] >= 0) return dp[u];
  int res = 0;
  dp[u] = INF;
  REP(i,3){
	int tmp = INF;
	for(int to: G_[u][i])
	  tmp = min(tmp, solve(to)+1);
	res = max(res, tmp);
  }
  return dp[u] = res;
}
*/

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

  cin >> N >> M >> A[0] >> A[1] >> A[2];
  REP(i,M){
	int u, v; cin >> u >> v;
	G[u].PB(v);
  }
  calc();
  fill((int*)dp, (int*)dp+51, INF);

  dp[N] = 0;
  REP(j,N){
	FOR(u,1,N+1){
	  int res = 0;
	  REP(i,3){
		int tmp = INF;
		for(int to: G_[u][i])
		  tmp = min(tmp, dp[to]+1);
		res = max(res, tmp);
	  }
	  dp[u] = min(dp[u], res);
	}
  }
  int ans = dp[1];
  if(ans >= INF)
	cout << "IMPOSSIBLE" << endl;
  else
	cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3264
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
int C[100000];

signed main(){
    cin >> N;
    rep(i, N){
        int A;
        cin >> A;
        C[A-1]++;
    }
    int cnt = 0;
    rep(i, 100000){
        if(C[i] > 1) cnt += C[i]-1;
    }
    cout << N - (cnt+1)/2*2 << endl;
}

Measured memory_bytes: 4020
#include<cstdio>
int n, a[10];
int b[11] = { }, c[11] = { };

bool
dfs (int l, int r)
{
  if (l + r == 10)
    return true;
  if (b[l] < a[l + r])
    {
      b[l + 1] = a[l + r];
      return dfs (l + 1, r);
    }
  else if (c[r] < a[l + r])
    {
      c[r + 1] = a[l + r];
      return dfs (l, r + 1);
    }
  return false;
}

int
main (void)
{
  scanf ("%d", &n);
  for (int i = 0; i < n; i++)
    {
      for (int j = 0; j < 10; j++)
	scanf ("%d", &a[j]);
      if (dfs (0, 0))
	puts ("YES");
      else
	puts ("NO");
    }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

int main(void){
  int n, x;
  cin >> n >> x;

  vector<int> l(n);
  int now = 0;
  int cnt = 1;

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

  for (int i = 0; i < n; i++) {
    now += l[i];
    if (now <= x) cnt ++;
    else break;
  }


  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  cout << setprecision(10) << fixed;
  for(;;){
    int n,m,s,g;
    cin >> n >> m;
    if(!n) return 0;
    cin >> s >> g;
    vector<tuple<int,int,int> > e[32];
    REP(i,m){
      int x,y,d,c;
      cin >> x >> y >> d >> c;
      e[x].push_back(make_tuple(y,d,c));
      e[y].push_back(make_tuple(x,d,c));
    }
    vector<pair<double,int> > cost[32][32];
    REP(i,32) REP(j,32) cost[i][j].clear();
    // pos,vel
    priority_queue<tuple<double,int,int,int> > dijk;
    // (negcost,from),pos,vel
    dijk.push(make_tuple(0.0,-1,s,0));
    while(!dijk.empty()){
      double negcos;
      int from,pos,vel;
      tie(negcos,from,pos,vel)=dijk.top();
      dijk.pop();
      if(cost[pos][vel].empty()){
	cost[pos][vel].push_back(make_pair(-negcos,from));
	for(auto x:e[pos]){
	  int to,d,c;
	  tie(to,d,c)=x;
	  if(from==to) continue;
	  FOR(dv,-1,2){
	    int nvel=vel+dv;
	    if(nvel<=0 || c<nvel) continue;
	    dijk.push(make_tuple(negcos-1.0*d/nvel,pos,to,nvel));
	  }
	}
      }else if(cost[pos][vel].size()<2 && from!=cost[pos][vel][0].second){
	cost[pos][vel].push_back(make_pair(-negcos,from));
	for(auto x:e[pos]){
	  int to,d,c;
	  tie(to,d,c)=x;
	  if(cost[pos][vel][0].second!=to) continue;
	  FOR(dv,-1,2){
	    int nvel=vel+dv;
	    if(nvel==0 || nvel>c) continue;
	    dijk.push(make_tuple(negcos-1.0*d/nvel,pos,to,nvel));
	  }
	}
      }
    }
    if(cost[g][1].size()) cout << cost[g][1][0].first << endl;
    else cout << "unreachable" << endl;
  }
}

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

#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

using namespace std;

ll dp[109][100010];
int main()
{
    fastio;

    string s, t;
    cin >> s >> t;
    int a = s.length(), b = t.length();
    int dp[a + 1][b + 1];
    pair<int, int> cc[a + 1][b + 1];
    for (int i = 0; i <= a; i++)
    {
    	for (int j = 0; j <= b; j++)
    	{
    		if (i == 0 or j == 0)
    		{
    			dp[i][j] = 0;
    			cc[i][j] = {-1, -1};
    		}
    		else if (s[i - 1] == t[j - 1])
    		{
    			dp[i][j] = dp[i - 1][j - 1] + 1;
    			cc[i][j] = {i - 1, j - 1};
    		}
    		else
    		{
    			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    			if (dp[i][j] == dp[i - 1][j])
    				cc[i][j] = {i - 1, j};
    			else cc[i][j] = {i, j - 1};
    		}
    		//cout << dp[i][j] << " ";
    	}
    	//cout << endl;
    }
    int i = a, j = b;
    string ans = "";
    while (true)
    {
    	pair <int, int> p = cc[i][j];
    	if (p.first == -1)
    		break;
    	else if (s[i - 1] == t[j - 1])
    		ans = s[i - 1] + ans;
    	i = p.first;
    	j = p.second;

    }
    cout << ans;
    return 0;
}




Measured memory_bytes: 105856
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)

typedef unsigned long long ull;

int main(){
	const int n = 3,m = 8;
	vector<pair<double,int> > v;
	FOR(i,n){
		pair<double,int> x[m];
		FOR(i,m) cin>>x[i].second >> x[i].first;
		sort(x,x+m);
		FOR(i,2) printf("%d %.2lf\n",x[i].second,x[i].first);
		v.insert(v.end(),x+2,x+m);
	}

	sort(v.begin(),v.end());
	FOR(i,2) printf("%d %.2lf\n",v[i].second,v[i].first);

	return 0;
}

Measured memory_bytes: 1252
N = int(input())
a = list(map(int, input().split()))

x = a[0]
y = sum(a[1:])

ans = abs(x-y)

for i in range(1,N-1):
    x += a[i]
    y -= a[i]
    score = abs(x-y)
    if score < ans:
        ans = score

print(ans)

Measured memory_bytes: 23800
#include <iostream>
#include <iomanip>
#include <algorithm>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a < 6) {
        cout << 0 << endl;
    } else if (a < 13) {
        cout << (b / 2) << endl;
    } else {
        cout << b << endl;
    }
}


Measured memory_bytes: 256