akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
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; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  int c[3][3]; rep(i,3) rep(j,3) cin >> c[i][j];
  vector<pair<int,int>> x(3), y(3);
  rep(i,3){
    x[i].first = c[i][0] - c[i][1];
    x[i].second = c[i][1] - c[i][2];
    y[i].first = c[0][i] - c[1][i];
    y[i].second = c[1][i] - c[2][i];
  }
  int flg=0;
  rep(i,2){
    if(x[i].first != x[i+1].first) flg=1;
    if(x[i].second != x[i+1].second) flg=1;
    if(y[i].first != y[i+1].first) flg=1;
    if(y[i].second != y[i+1].second) flg=1;
  }
  if(flg) cout << "No";
  else cout << "Yes";
  
  return 0;
}


Measured memory_bytes: 256
using System;

namespace aoj8a
{
    class Program
    {
        static void Main(string[] args)
        {
            /*1?????????????????????????????????char???????????????????????????*/
            char[] line = (Console.ReadLine()).ToCharArray();

            for (int i = 0; i < line.Length; i++)
            {
                line[i] = changeCtype(line[i]);     //??§??????????°??????????????°????????????§?????????????????????????????????
            }

            string str = new string(line);
            Console.WriteLine(str);
        }

        private static char changeCtype(char ch)
        {
            if (char.IsUpper(ch))       //??§????????§????????°
            {
                ch = char.ToLower(ch);
                return ch;              //?°??????????????????????
            }
            else if (char.IsLower(ch))  //?°?????????§????????°
            {
                ch = char.ToUpper(ch);
                return ch;              //??§?????????????????????
            }
            else
            {
                /*nop*/
                return ch;              //???????????§??????????????°??????????????????
            }
           
        }
    }
}

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

int main()
{
    int n, m;
    int vc[100001];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> vc[i];
    }

    for(int i = n - 1; i > 0; i--) {
        if(vc[i] < vc[i-1]) vc[i - 1] -= 1;
    }

    for(int i = 1; i < n; i++) {
        if(vc[i-1] > vc[i]) return cout << "No" << endl, 0;
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
from collections import deque
import bisect


def solve(N: int, A: "List[int]"):
    Q = deque([])
    c = 0
    for a in A:
        if len(Q) == 0:
            c += 1
            Q.append(a)
            continue
        i = bisect.bisect_left(Q, a)
        if i == 0:
            c += 1
            Q.appendleft(a)
        else:
            Q[i-1] = a
    print(c)
        
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

#define M_PI 3.14159265358979323846

using namespace std;

//typedef
//-------------------------#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}
inline int readInt()
{
    int x;
    scanf("%d", &x);
    return x;
}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#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())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const int INF = 2147483647;

int a[110];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int ans = 0;
    for (int i = 0; i <= A; i++)
    {
        for (int j = 0; j <= B; j++)
        {
            for (int k = 0; k <= C; k++)
            {
                if (500 * i + 100 * j + 50 * k == X)
                    ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<*it.F<<' '<<*it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
vi nc,nmc;

ll power(ll x, unsigned ll y, unsigned ll m=MOD) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 
  

ll modInverse(ll a, ll m=MOD) 
{ 
    return power(a, m-2, m);
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,k;
    cin>>n>>k;
    nc.resize(n+5);
    nmc.resize(n+5);
    nc[0] = 1;
    nmc[0] = 1;
    for(ll i=1;i<=n+4;i++){
        nc[i] = (((nc[i-1]*(n-i+1))%MOD)*modInverse(i));
        nmc[i] = (((nmc[i-1]*(n-i))%MOD)*modInverse(i));
        nc[i]%=MOD;
        nmc[i]%=MOD;
    }
    ll ans = 1;
    ll i;
    for(i=1;i<=min(n-1,k);i++){
        ans = ans + (nc[i]*nmc[n-i-1])%MOD;
        ans%=MOD;
    }
    if(ans<0){
    	ans+=MOD;
    }
    cout<<ans;

    return 0;
}






Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }



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

  ll n;
  cin >> n;

  vector<ll> a;
  ll sum = 0;
  rep(i, 1, n+2){
    sum += i;
    a.pb(i);
    if(sum > n){
      break;
    }
  }

  ll sub = 0;
  rep(i, 0, sz(a)){
    if(sum - a[i] == n) sub = max(sub, a[i]);
  }

  rep(i, 0, sz(a)){
    if(a[i] == sub) continue;
    cout << a[i] << endl;
  }

  return 0;
}

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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  
  char old = s.at(0);
  int cnt = 1;
  for(char c: s){
    if(c != old){
      cnt++;
    }
    old = c;
  }
  
  cout << cnt << endl;
}





Measured memory_bytes: 512
#include <stdio.h>

int main(void){
	int a[4];
	int i;
	for(i=0;i<4;i++){
		scanf("%d",&a[i]);
	}
	printf("%d\n%d\n",(a[0]+a[1]+a[2]+a[3])/60,(a[0]+a[1]+a[2]+a[3])%60);
	return 0;
}

Measured memory_bytes: 596
<?php

$q = array();
while($line = fgets(STDIN)){
	$q[] = explode(",", $line);
}

$a = array();
$arr_len = count($q);
$old_len = 0;
for($i = 0; $i < $arr_len; $i++){
	$len = count($q[$i]);
	$a[$i] = array();
	
	if($i == 0){
		$a[$i][0] = $q[$i][0];
	}else{
		for($j = 0; $j < $len; $j++){
			if($len > $old_len){
				// ?????????
				if($j <= 0){
					$o1 = 0;
				}else{
					$o1 = $a[$i - 1][$j - 1] + $q[$i][$j];
				}
				if($j >= $len - 1){
					$o2 = 0;
				}else{
					$o2 = $a[$i - 1][$j] + $q[$i][$j];
				}
			}else{
				// ?????????
				$o1 = $a[$i - 1][$j] + $q[$i][$j];
				$o2 = $a[$i - 1][$j + 1] + $q[$i][$j];
			}
			if($o1 > $o2){
				$a[$i][$j] = $o1;
			}else{
				$a[$i][$j] = $o2;
			}
		}
	}
	
	$old_len = $len;
}

echo $a[$arr_len - 1][0] . "\n";

Measured memory_bytes: 16064
/**
 *    author:  morato
 *    created: 29.08.2020 17:19:01
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, n;
  cin >> x >> n;
  set<int> st;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    st.insert(k);
  }
  int l = x, r = x;
  while (true) {
    if (!st.count(l)) {
      cout << l << '\n';
      return 0;
    }
    if (!st.count(r)) {
      cout << r << '\n';
      return 0;
    }
    l--, r++;
  }
  return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
string str1,str2;
int main () {
    ios_base::sync_with_stdio(false);
    cin>>str1>>str2;
    if(str1 == str2.substr(0,str1.size())) {
        cout<<"Yes"<<"\n";
    }
    else {
        cout<<"No"<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3608
N = int(input())

AB = 0
Bxxx = 0
xxxA = 0
BxxA = 0
for i in range(N):
    s = input()
    AB += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        BxxA += 1
    elif s[0] == 'B':
        Bxxx += 1
    elif s[-1] == 'A':
        xxxA += 1

if Bxxx == 0 and xxxA == 0:
    print(AB + max(BxxA - 1, 0))
else:
    print(AB + min(Bxxx, xxxA) + BxxA)

Measured memory_bytes: 3188
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    println(problem090b(a, b))
}

fun problem090b(a: Int, b: Int): Int {
    var count = 0
    for (i in a..b) {
        val str = i.toString()
        if (str[0] == str[4] && str[1] == str[3]) count++
    }
    return count
}

Measured memory_bytes: 34184
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

@mt
def slv(N, A, B):
    AB = list(zip(A, B))


    ans = INF
    for f in product(range(2), repeat=N):
        o = []
        e = []
        for i, (c, ab) in enumerate(zip(f, AB)):
            v = ab[c]
            if i % 2 == 0:
                if c == 0:
                    e.append((v, i))
                else:
                    o.append((v, i))
            else:
                if f[i] == 0:
                    o.append((v, i))
                else:
                    e.append((v, i))
        if 0 <= len(e) - len(o) <= 1:
            bit = Bit(50)
            e.sort()
            o.sort()
            eo = [e, o]
            cand = 0
            p = -1
            for i in range(N):
                if p > eo[i%2][i//2][0]:
                    break
                p = eo[i % 2][i//2][0]
                bit.add(eo[i%2][i//2][1]+1, 1)
                cand += i + 1 - bit.sum(eo[i%2][i//2][1]+1)
            else:
                ans = min(ans, cand)
    if ans == INF:
        ans = -1
    return ans


def main():
    N = read_int()
    A = read_int_n()
    B = read_int_n()
    print(slv(N, A, B))

if __name__ == '__main__':
    main()


Measured memory_bytes: 70360
#!/usr/bin/env python
# coding: utf-8

# In[24]:


# N = int(input())
# a = list(map(int, input().split()))


# In[28]:


# color_list = [rate//400 for rate in a]
# # print(color_list)
# filtered = [x for x in color_list if x < 8]
# # print(filtered)
# free = len(color_list) - len(filtered)

# if free == len(color_list):
#     print(1, min(free, 8))
# else:
#     print(len(set(filtered)), min(len(set(filtered)) + free, 8))


# In[ ]:


n=int(input())
list=list(map(int,input().split()))
ans=set()
temp=0
for i in list:
    if i>=3200:temp+=1
    else:ans.add(i//400)
print(max(1,len(ans)),len(ans)+temp)



Measured memory_bytes: 3316
#![allow(unused_macros, unused_imports, dead_code)]
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty), +) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn main() {
    from_line!(a: u32, b: u32, c: u32);
    let mut cnt = 0;
    for i in a..(b+1) {
        if c % i == 0 {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}



Measured memory_bytes: 5024
<?php
    $input_line = fgets(STDIN);
    $input_line = str_replace(array("\r\n","\r","\n"), '', $input_line);
    $array = explode(" ", $input_line);
    $N = $array[0];
    $W = $array[1];
    $array_v = array(-1);
    $array_w = array(-1);
    for($i = 0; $i < $N; $i++){
        $input_line = fgets(STDIN);
        $input_line = str_replace(array("\r\n","\r","\n"), '', $input_line);
        $array = explode(" ", $input_line);
        array_push($array_v, $array[0]);
        array_push($array_w, $array[1]);
    }
    //var_dump($array_v);
    //var_dump($array_w);
    for($i = 0; $i <= $N; $i++){
        for($j = 0; $j <= $W; $j++){
            $x = 0;
            $y = 0;
            if($i == 0){
                $data[$i][$j] = 0;
            } else{
                $x = $data[$i - 1][$j];
                if($array_w[$i] <= $j) $y = $data[$i - 1][$j - $array_w[$i]] + $array_v[$i]; 
                $data[$i][$j] = ($x > $y) ? $x : $y;
            }
        }
        if ($i >= 2) {
          unset($data[$i-2]);
        }
    }
    /*
    for($i = 0; $i <= $N; $i++){
        echo $i."| ";
        for($j = 0; $j <= $W; $j++){
            echo $data[$i][$j]." ";
        }
        echo "\n";
    }
    */
    echo $data[$N][$W];
?>



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

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

typedef int64_t ll;

int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	int n;
	string s1,s2;
	cin >> n >> s1 >> s2;
	ll sum = s1[0] == s2[0] ? 3 : 6;
	bool ren = s1[0] == s2[0];
	int i = s1[0] == s2[0] ? 1 : 2;
	while(i < n){
		//cerr << "i : sum " << i << ':' << sum << endl;
		if(s1[i] == s2[i]){
			i++;
			if(ren){
				sum *= 2ll;
				sum %= MODULO;
			}
			ren = true;
		}
		else {
			i += 2;

			if(!ren)
				sum *= 3ll;
			else
				sum *= 2ll;
			sum %= MODULO;
			ren = false;
		}
	}

	cout << sum << '\n';


}



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

using namespace std;

void func_A() {

    string s, t;
    cin >> s >> t;

    string temp = t.substr(0, s.size());
    if (s == temp) cout << "Yes";
    else cout << "No";
}

void func_B() {

    long long a, b, c, k;
    cin >> a >> b >> c >> k;

    long long num = 0;
    if (a >= k) {
        cout << k;
        return;
    }
    else {
        k -= a;
        num += a;
    }

    if (b >= k) {
        cout << num;
        return;
    }
    else {
        k -= b;
    }

    cout << num - k;
}


void func_C() {

}

int main() {

    //func_A();
    func_B();
    //func_C();

    return 0;

}

Measured memory_bytes: 3632
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;
int main(void)
{
	int n, a[5001];
	while (1) {
		cin >> n;
		if (n == 0)
			break;
		for (int i = 1; i <= n; i++)
			cin >> a[i];
		int goukei = 0, ryuta = -10000000;
		for (int i = 1; i <= n; i++)
		{
			goukei = 0;
			for (int j = i; j <= n; j++)
			{
				goukei = goukei + a[j];
				ryuta = max(goukei, ryuta);
			}
		}
		cout << ryuta << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

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

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int m; cin >> m;
	cout << 48 - m << endl;
	return 0;
}


Measured memory_bytes: 3624
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
if even(n):
    print(-1)
    exit()
elif n%5==0:
    print(-1)
    exit()
s = "7"
count = 1
while True:
    if int(s) < n:
        s = s+"7"
        count += 1
        continue
    else:
        res = int(s)%n
        if res == 0:
            print(count)
            exit()
        s = str(int(s)%n)


Measured memory_bytes: 67876
#include <iostream>

using namespace std;

int main() {
    long long A, B;

    // input
    cin >> A >> B;

    // process
    if ((A % 2) == 0) {
        if ((B % 2) == 0) {
            cout << (A + B) / 2;
        } else {
            cout << "IMPOSSIBLE";
        }
    } else {
        if ((B % 2) == 1) {
            cout << (A + B) / 2;
        } else {
            cout << "IMPOSSIBLE";
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

string bigger(string s1, string s2){
    if(s1.size() > s2.size()) return s1;
    else return s2;
}

int main(){
    string s, t; cin >> s >> t;
    vvs dp(s.size()+10, vs(t.size()+10, ""));
    REP(i, s.size()){
        REP(j, t.size()){
            if(s[i]==t[j]) dp[i+1][j+1] = bigger(dp[i][j] + s[i], dp[i+1][j+1]);
            dp[i+1][j+1] = bigger(dp[i+1][j+1], dp[i+1][j]);
            dp[i+1][j+1] = bigger(dp[i+1][j+1], dp[i][j+1]);
        }
        if(i >= 3) vs().swap(dp[i-2]);
    }
    cout << dp[s.size()][t.size()] << endstr;
    return 0;
}


Measured memory_bytes: 71168
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/26/20 20:17:32
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll n,m,s; cin>>n>>m>>s;
  struct Train {
    ll s, c, d;
    Train(ll s,ll c,ll d):s(s),c(c),d(d){}
    bool operator>(const Train& x) const {return d>x.d;}
  };
  vector<Train> graph[n];
  for (int i = 0; i < m; i++) {
    ll u,v,a,b; cin>>u>>v>>a>>b; u--; v--;
    graph[u].emplace_back(v,a,b);
    graph[v].emplace_back(u,a,b);
  }
  for (int i = 0; i < n; i++) {
    int c,d; cin>>c>>d;
    graph[i].emplace_back(i,-c,d);
  }
  constexpr ll MAX = 200;
  constexpr ll INF = 1e18;
  vector<array<ll, MAX+1>> dp(n);
  for (auto& arr:dp) arr.fill(INF);
  dp[0][min(s,MAX)] = 0;
  priority_queue<Train, vector<Train>, greater<>> qs;
  qs.emplace(0,s,0);
  while (not qs.empty()) {
    auto [s,c,d] = qs.top(); qs.pop();
//    if (d > dp[s][min(c,MAX)]) continue;
    for (auto t:graph[s]) {
      if (c-t.c<0) continue;
      if (d+t.d >= dp[t.s][min(c-t.c,MAX)]) continue;
      dp[t.s][min(c-t.c,MAX)] = d+t.d;
      qs.emplace(t.s, c-t.c, d+t.d);
    }
  }
  for (int i = 1; i < n; i++) {
    cout << *min_element(dp[i].begin(), dp[i].end()) << endl;
  }

  return 0;
}


Measured memory_bytes: 3880
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import deque
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = list(map(int, input().split()))

    que = deque([])

    for i in range(n):
        if i % 2 == 0:
            que.appendleft(a[i])
        else:
            que.append(a[i])

    if len(a) % 2 == 0:
        que.reverse()

    index = 0
    for i in que:
        if index == len(que) - 1:
            print("{}".format(i))
        else:
            print("{} ".format(i), end="")
        index += 1

if __name__ == '__main__':
    main()


Measured memory_bytes: 25424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll, ll> freq;
int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> vec;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        vec.push_back(x);
    }
    sort(vec.begin(), vec.end());
    for (int i = 0; i < m; i++) {
        int b, c;
        cin >> b >> c;
        freq[-c] += b;
    }
    int idx = 0;
    for (auto it: freq) {
        if (idx >= n) break;
        int tmp = it.second;
        while (idx < n && vec[idx] >= -it.first) idx++;
        while (tmp > 0 && idx < n && vec[idx] < -it.first) {
            vec[idx] = -it.first;
            idx++;
            tmp--;
        }
    }
    ll res = 0;
    for (auto x: vec) res += x;
    cout << res;
    return 0;
}

Measured memory_bytes: 10376
from math import gcd

if __name__ == '__main__':
    n = int(input())
    count = 1
    result = 0

    while count <= n:
        for i in range(1, n + 1):
            for j in range(1, n + 1):
                # print(f"gcd({count}, {i}, {j})")
                result += gcd(count, gcd(i, j))
        count += 1

    print(result)

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

int main() {
    int h, w, n;
    cin >> h >> w >> n;

    map<P, int> mp;

    rep(i, n) {
        int a, b;
        cin >> a >> b;
        rep(i, 3) rep(j, 3) {
            ll y=a-i, x=b-j;
            if (1 <= y and y <= h - 2 and 1 <= x and x <= w - 2) {
                if (mp.count({x, y}) > 0) {
                    mp[{x, y}]++;
                }
                else {
                    mp[{x, y}] = 1;
                }
            }
        }
    }

    vector<ll> ans(10);
    ll all = 0;
    for (auto & t : mp) {
        //cout << t.first.first << " " << t.first.second << "/ " << t.second << endl;
        ans[t.second]++;
        all++;
    }

    cout << (ll)(h-2)*(ll)(w-2)-all << endl;

    rep(i, 9) {
        cout << ans[i+1] << endl;
    }

}


Measured memory_bytes: 56448
program main 
 implicit  none
 integer,allocatable :: x(:)
 integer :: p,i,n,w(1:3)
  read *, n
  allocate(x(n))
  read *, x(:)
  p=int(sum(x)/n)
  w(:)=0
 do i=1,n
  w(1)=w(1)+(x(i)-p)**2
  w(2)=w(2)+(x(i)-p-1)**2
  w(3)=w(3)+(x(i)-p+1)**2
 end do
 
 write(*,'(i0)') minval(w)
 
end program main

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

int main()
{
    int x,y,z;
    cin >> x >> y >> z;
    int tmp;
    tmp=x;
    x=y;
    y=tmp;
    tmp=x;
    x=z;
    z=tmp;
    cout << x << ' '<< y << ' '<< z << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    n, m, x = map(int, input().split())
    c = list()
    a = list()

    for i in range(n):
        bi = list(map(int, input().split()))

        ci = bi[0]
        c.append(ci)

        ai = bi[1:]
        a.append(ai)

    ans = float('inf')

    # KeyInsight: bit演算を使った全探索
    # 全パターン(選ぶ/選ばないを1/0で表現)を列挙
    for i in range(1 << n):
        cost = 0
        tmp = [0 for _ in range(m)]

        for j in range(n):
            # あるビットが立っているかどうか(1かどうか)を判定
            if (i >> j & 1):
                cost += c[j]

                for index, aii in enumerate(a[j]):
                    tmp[index] += aii

        if min(tmp) >= x:
            ans = min(ans, cost)

    if ans == float('inf'):
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9216
#include<stdio.h>
#include<string.h>
int main()
{
    long int i,j,count=0;
    char a[1000000];
    i=0,j=1;
    gets(a);
    int x=strlen(a);
    while(j<x){
        if(a[i]==a[j]){
            count++;
            if(a[j]=='1')
                a[j]='0';
            else
                a[j]='1';
        }
        i++; j++;
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 1748
#include <iostream>
#include <map>

using namespace std;

int main()
{
    int n, m;
    string u, t;
    map<string, bool> ic;
    bool open = true;

    cin >> n;
    while (n--) {
        cin >> u;
        ic[u] = true;
    }

    cin >> m;
    while (m--) {
        cin >> t;
        if (ic.count(t) == 0)
            cout << "Unknown " << t << endl;
        else {
            if (open) 
                cout << "Opened by " << t << endl;
            else
                cout << "Closed by " << t << endl;

            open = !open;
        }
    }

    return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int long long
#define ll long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
 
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
bool comp1(pair<int,int> p1,pair<int,int> p2)
{
	if(p1.ff!=p2.ff)
		return p1.ff>p2.ff;
	else
		return p1.ss>p2.ss;
}
bool comp2(pair<int,int> p1,pair<int,int> p2)
{
	if(p1.ff!=p2.ff)
		return p1.ff<p2.ff;
	else
		return p1.ss<p2.ss;
}
int32_t main()
{
    IOS;
  /*  #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    int n;
    cin>>n;
    vpi v1(n);
    vpi v2(n);
    for(int i=0;i<n;i++)
    	cin>>v1[i].ff>>v1[i].ss;
    for(int i=0;i<n;i++)
    	cin>>v2[i].ff>>v2[i].ss;
    sort(v1.begin(),v1.end(),comp1);
    sort(v2.begin(),v2.end(),comp2);
    vi mark(n,0);
    int ans=0;
    for(int i=0;i<n;i++)
    {
    	int ch=0;
    	int ind;
    	for(int j=0;j<n;j++)
    	{
    		//trace5(mark[j],v1[i].ff,v1[i].ss,v2[j].ff,v2[j].ss);
    		if(!mark[j] && v1[i].ff<v2[j].ff && v1[i].ss<v2[j].ss)
    		{
    			if(ch==0)
    				ind=j;
    			else
    			{
    				if(v2[ind].ss>v2[j].ss)
    					ind=j;
    			}
    			ch=1;
    			//break;
    		}
    	}
    	if(ch)
    	{
    		mark[ind]=1;
    		ans+=1;
    	}
    	//trace2(ind,ans);
    }
    cout<<ans;
    
    return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char s[100],t[100],b[100];
    cin>>s>>t>>b;
    if((s[strlen(s)-1]==t[0]) && (t[strlen(t)-1]==b[0]))
     cout<<"YES";
    else 
     cout<<"NO";
     return 0;
}
     
   




Measured memory_bytes: 3572
#include<stdio.h>
int main(){
  int n,m,i,j,max,u[50],r,s[10],k,d[10][10]={0};
  scanf("%d",&n);
  while(n--){
    for(i=0;i<5;i++){
      for(j=r=0;j<5;j++){
	scanf(" %d",&m);
	if(m)d[i][j]=++r;
	else d[i][j]=r=0;//printf("%d ",d[i][j]);
      }//printf("\n");
    }
    for(j=0;j<5;j++)d[i][j]=0;
    for(i=max=0;i<5;i++){
      s[u[0]=0]=d[0][i];
      for(j=r=1;j<6;j++){
	u[r]=j;
	while(s[r-1]>d[j][i]){
	  if(max<s[r-1]*(j-u[r-1]))max=s[r-1]*(j-u[r-1]);
	  r--;
	}
	if(s[r-1]-d[j][i])s[r++]=d[j][i];
	//for(k=0;k<r;k++)printf("%d %d\n",s[k],u[k]);printf("\n");
      }//printf("\n");
    }
    printf("%d\n",max);
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<long long> a(N);
  vector<long long> b(N);
  vector<long long> d(N);
  long long suma=0;
  for (int i=0;i<N;i++){
    cin>>a[i];
    suma=suma+a[i];
  }
  long long sumb=0;
  for (int i=0;i<N;i++){
    cin>>b[i];
    sumb=sumb+b[i];
    d[i]=a[i]-b[i];
  }  
  if(suma<sumb){
    cout<<-1<<endl;
    return 0;
  }
  sort(d.begin(),d.end());
  long long sumd=0;
  long long count=0;
  while(d[count]<0){
    sumd=sumd+d[count];
    count++;
  }
  long long j=0;
  while(sumd<0){
    sumd=sumd+d[N-1-j];
    j++;
  }
  cout<<count+j<<endl;
  
  return 0;
}


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

const long mod = 1e9+7;

long modpow(long a, long b)
{
	long res = 1;
	while (b > 0)
	{
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b /= 2;
	}
	return res;
}

long comb(long a,long b)
{
	long x = 1, y = 1;
	for (int i = 1; i <= b; i++)
	{
		x = x * (a - i + 1) % mod;
		y = y * i % mod;
  }
  return x * modpow(y, mod - 2) % mod;
}

int main()
{
	long N, A, B;
	cin >> N >> A >> B;
	long ans = modpow(2, N);
	ans--;
	ans -= comb(N, A);
	ans -= comb(N, B);
	while (ans < 0) ans += mod;
	cout << ans << "\n";
}


Measured memory_bytes: 384
#include<stdio.h>
#define MAX 100005
#define NIL -1
 
/*
 p: parent
 l: left-child
 r: right sibling
 */
 
struct Node{
    int p, l, r;
};
struct Node T[MAX]; // Tree
int n;

void Preorder(int u){
  if(u != NIL){
  printf(" %d",u);  
  Preorder(T[u].l); 
  Preorder(T[u].r);
  }
}

void  Inorder(int u){
  if(u != NIL){
   Inorder(T[u].l); 
  printf(" %d",u);
 Inorder(T[u].r);
  }
}

void  Postorder(int u){
 if(u != NIL){
Postorder(T[u].l); 
Postorder(T[u].r); 
 printf(" %d",u);
}

}

main(){
  int i, j, d, v, c, l;
  int first;
     
    scanf("%d", &n);
     
    for ( i = 0; i < n; i++ ) {
        T[i].p = T[i].l = T[i].r = NIL;
    }
    for (i = 0; i <n ; i++){
      scanf("%d %d %d", &v, &d, &c);
      if(i==0){
	       first=v;
	     }
      //  if(i==0)tmp=v;
             T[d].p=v;
	     T[c].p=v;
             T[v].l=d;
             T[v].r=c;
	    
    }
	     /*	     if(flag==0 /*|| flag==2) && (d!=NIL && c!=NIL)){
	       flag=3;
	       first=v;
	     }
	     if(flag==0 && (d!=NIL || c!=NIL)){
	       flag=2;
	       semfirst=v;
	     }
	   
}
    if(flag==0){
      lasfirst=tmp;
      flag=1;
      }*/
    for(i=0;i<n;i++){
      //printf(" %d ",T[i].p);
      if(T[i].p == NIL){
	first=i;
      break;
      }
    }

    
    /*...*/
    printf("Preorder\n");
    Preorder(first);
    
    printf("\n");
    printf("Inorder\n");
    Inorder(first);
 
    printf("\n");
    printf("Postorder\n");
    Postorder(first);
 
    printf("\n");
    return 0;
}

Measured memory_bytes: 620
N=int(input())
if (N&-N)==N:
  print('No')
  exit()
print('Yes')
P=[[] for i in range(2*N)]
X=1
while 2*X-1<=N:
  X*=2
X-=1
for i in range(X-1):
  P[i].append(i+1)
  P[N+i].append(N+i+1)
P[X-1].append(N)
while X+2<=N:
  P[X].append(X+1)
  P[0].append(X+1)
  P[0].append(X+N)
  P[X+N].append(X+N+1)
  X+=2
if X!=N:
  X=N&(-N)
  P[X-1].append(N-1)
  if X==2:
    P[N-X].append(2*N-1)
  else:
    P[2*N-X-1].append(2*N-1)
for i in range(len(P)):
  for j in range(len(P[i])):
    print(i+1,P[i][j]+1)

Measured memory_bytes: 96496
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int n;
    scan(n);
    int a, b;
    scan(a, b);
    auto p = readln.split.to!(int[]);
    auto c = new int[](3);

    foreach (pi ; p) {
        if (pi <= a) {
            c[0]++;
        }
        else if (pi <= b) {
            c[1]++;
        }
        else {
            c[2]++;
        }
    }

    int ans = c.reduce!min;

    writeln(ans);
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg ; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg ; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

long powmod(long x, long y, long mod = 1_000_000_007L) {
    long res = 1L;

    while (y > 0) {
        if (y & 1) {
            (res *= x) %= mod;
        }
        (x *= x) %= mod;
        y >>= 1;
    }

    return res;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
        mut x: [i64;m],
    }

    if n>=m {
        println!("0");
        return;
    }

    x.sort();
    let mut l: Vec<i64> = Vec::new();
    for i in 0..m-1 {
        l.push(x[i+1]-x[i]);
    }
    l.sort();
    l.reverse();
    let mut ans = x[m-1] - x[0];
    for i in 0..n-1 {
        ans -= l[i];
    }

    println!("{}", ans);

}


Measured memory_bytes: 4484
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //_reads = new string[] { "200000", string.Join(" ", Enumerable.Repeat("1000000000", 200000)) };
            int count = int.Parse(ReadLine());
            for (int i = 0; i < count; ++i)
            {
                Console.WriteLine(Get());
            }
        }

        static long Get()
        {
            var read = ReadLine().Split(' ').Select(long.Parse).ToArray();
            var min = Math.Min(read[0], read[1]);
            var max = Math.Max(read[0], read[1]);
            long score = read[0] * read[1];
            long sq = (long)Math.Sqrt(score);
            if (sq * sq == score) --sq;
            long result = sq - (min <= sq ? 1 : 0);
            result += sq - (max <= sq ? 1 : 0);
            if (score <= sq * (sq + 1)) --result;
            return result;
        }}}

Measured memory_bytes: 13396
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  x = remain = 0
  remains = [0] * 2019
  k = 1
  for d in map(int, list(s[::-1])):
    x = d * k + remain
    remain = x % 2019
    k = (10 * k) % 2019
    remains[remain] += 1

  print(sum([(remain * (remain - 1)) // 2 for remain in remains]) + remains[0])
  
if __name__=='__main__':
  main()


Measured memory_bytes: 10700
#include<iostream>
using namespace std;
int main() {

	int n, x;
	int sum;

	while (true) {
		int ans = 0;
		cin >> n >> x;
		if (n == 0 && x == 0) break;
		for (int i = 3; i <= n; i++) {
			for (int j = 2; j < i; j++) {
				for (int k = 1; k < j; k++) {
					sum = i + j + k;
					if (sum == x)ans += 1;

				}
			}
		}
		cout << ans << endl;
	}

	return 0;

}



Measured memory_bytes: 3104
#include<queue>
#include<stdio.h>

using namespace std;

class T{
	public:
	int x1,x2,y1,y2,count;
	T(int x1,int y1,int x2,int y2,int count):x1(x1),y1(y1),x2(x2),y2(y2),count(count){}
};

char check[55][55][55][55];
int board[55][55];

int main(){
	while(1){
		for(int i=0;i<55;i++){
			for(int j=0;j<55;j++){
				board[i][j]=0;
				for(int k=0;k<55;k++){
					for(int p=0;p<55;p++){
						check[i][j][k][p]=0;
					}
				}
			}
		}
		
		int w,h;
		int sx1,sx2,sy1,sy2;
		
		scanf("%d%d",&w,&h);
		if(w==0 && h==0)break;
		
		scanf("%d%d%d%d",&sx1,&sy1,&sx2,&sy2);
		
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				scanf("%d",&board[i][j]);
			}
		}
		
		
		queue<T> que;
		que.push(T(sx1-1,sy1-1,sx2-1,sy2-1,0));
		
		while(1){
			if(que.empty())break;
			
			T u = que.front();
			que.pop();
			
			if(check[u.x1][u.y1][u.x2][u.y2]==1)continue;
			check[u.x1][u.y1][u.x2][u.y2]=1;
			
			if(u.count>=100)break;
			if(u.x1 == u.x2 && u.y1 == u.y2){
				printf("%d\n",u.count);
				goto A;
			}
			
			int dx[4] = {0,1,0,-1};
			int dy[4] = {1,0,-1,0};
			for(int i=0;i<4;i++){
				int nx1 = u.x1 + dx[i];
				int ny1 = u.y1 + dy[i];
				
				int nx2 = u.x2 - dx[i];
				int ny2 = u.y2 - dy[i];
				
				if(nx1<0 || ny1<0 || nx1>=w || ny1>=h || board[ny1][nx1]==1){
					nx1=u.x1;
					ny1=u.y1;
				}
				if(nx2<0 || ny2<0 || nx2>=w || ny2>=h || board[ny2][nx2]==1){
					nx2=u.x2;
					ny2=u.y2;
				}
				que.push(T(nx1,ny1,nx2,ny2,u.count+1));
			}
		}
		
		printf("NA\n");
		A:;
	}
}

Measured memory_bytes: 11192
h,w = map(int, raw_input().split())
cost = []
for _ in range(10): 
	cost.append(map(int,raw_input().split()))


mat = [map(int, raw_input().split()) for ii in range(h)]

h = {(u,v):cost[u][v] for u in range(10) for v in range(10)}
for t in range(10):
	for u in range(10):
		for v in range(10):
			for w in range(10):
				h[(u,v)] = min(h[(u,v)], h[(u,w)] + h[(w,v)])
cumul = 0
for e in mat:
	for el in e:
		if el != -1:
			cumul += h[(el,1)]
print cumul

Measured memory_bytes: 99368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
#define ll long long int

int main() {
	ll n, d;
	ll k=0;
	cin >> n >> d;
	d = d * d;
	ll a,b;
	rep(i,n){
		cin >> a >> b;
		if(a*a+b*b <= d) k++;
	}
	
	cout << k;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include<string.h>
using namespace std;
int main() {
	int len, coj = 0, coi = 0;
	char mozi[10005] = {};
	while (cin >> mozi){
		len = 0;
		coj = 0;
		coi = 0;
		len = strlen(mozi);
		for (int i = 0; i<len; i++){
			if (mozi[i] == 'J'){
				if (mozi[i + 1] == 'O'){
					if (mozi[i + 2] == 'I'){
						coj++;
					}

				}
			}
			if (mozi[i] == 'I'){
				if (mozi[i + 1] == 'O'){
					if (mozi[i + 2] == 'I'){
						coi++;
					}

				}
			}
		}
		cout << coj << endl << coi << endl;
	}
	return 0;
}

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

struct Item{
    int value;
    int weight;
    char type;
    int64 day;
    string name;
};

bool cmp(Item a,Item b){
    if(a.value < b.value) return true;
    else if(a.value == b.value){
        if(a.weight < b.weight ) return true;
        else if(a.weight == b.weight){
            if(a.type < b.type) return true;
            else if(a.type == b.type){
                if(a.day < b.day) return true;
                else if(a.day == b.day){
                    if(a.name < b.name) return true;
                }
            }
        }
    }
    return false;
}

int main(){
    int n; cin >> n;
    Item a[n];
    rep(i ,n) cin >> a[i].value >> a[i].weight >> a[i].type >> a[i].day >> a[i].name;
    sort(a,(a+n),cmp);
    rep(i ,n){
        cout << a[i].value << " " << a[i].weight << " " << a[i].type << " " << a[i].day << " " << a[i].name << endl;
    }
    return 0;
}


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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXN = 100;

int a[MAXN + 2];

int main() {
	int N;
	cin >> N;
	int sum = 0;
	for(int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int mdiff = INT_MAX, idx = 0;
	for(int i = 0; i < N; i++) {
		int diff = abs(N * a[i] - sum);
		if(diff < mdiff) {
			mdiff = diff;
			idx = i;
		}
	}
	cout << idx << endl;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,m,c; cin >> n >> m >> c;
  vector<int> b(m); rep(i,m) cin >> b[i];
  vector<vector<int>> a(n,vector<int>(m));
  rep(i,n)
    rep(j,m) cin >> a[i][j];

  int ans = 0;
  rep(i,n){
    int tmp = 0;
    rep(j,m) tmp+=a[i][j]*b[j];
    tmp+=c;
    if(tmp>0) ans++;
  }

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


Measured memory_bytes: 3636
#include <stdio.h>
int main(void){
  int n,i,a,min=100000,max=0,g[100003]={},s,ans=0;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d",&a);
    if (min>a+1) min=a+1;
    if (max<a+1) max=a+1;
    g[a+1]++;
  }
  s=g[min-1]+g[min]+g[min+1];
  for (i=min;i<=max;i++){
    if (ans<s) ans=s;
    s+=g[i+2]-g[i-1];
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 512
from collections import Counter
n = int(input())
s = []
for i in range(n):
  s.append(input())

S=Counter(s)
c = S.most_common()[0][1]
values, counts = zip(*S.most_common())
res = []
for va, co in zip(values, counts):
  if co == c:
    res.append(va)
res = sorted(res)

for i in res:
  print(i)

Measured memory_bytes: 59680
n, m = map(int, input().split())
a = list(map(int, input().split()))

d = {0: 1}
s = 0
ans = 0

for i in range(0, n):
    s += a[i]
    if s%m in d:
        d[s%m] += 1
    else:
        d[s%m] = 1
    ans += d[s%m]-1

print(ans)

Measured memory_bytes: 14252
#include<stdio.h>

int partition(int *,int ,int );

int main(){
  int A[100000];
  int i,n,m;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  m = partition(A,0,n-1);

  for(i = 0; i < m; i++){
    printf("%d ",A[i]);
  }

  printf("[%d] ",A[m]);

  for(i = m+1; i < n; i++){
    if(i == n-1){
      printf("%d\n",A[i]);
    }else{
    printf("%d ",A[i]);
    }
  }

  return 0;
}

  
int partition(int *A, int p, int r){

  int x,i,j,kari;

  x = A[r];
  i = p-1;

  for(j = p; j <= r-1; j++){
    if(A[j] <= x){
      i = i+1;
      kari = A[j];
      A[j] = A[i];
      A[i] = kari;
    }
  }

  kari = A[i+1];
  A[i+1] = A[r];
  A[r] = kari;

  return i+1;
}



Measured memory_bytes: 2112