akhauriyash/Code-Regression huggingface dataset:
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

signed main(){
    string s,t;
    cin>>s>>t;
    ll ss = s.size();
    bool f = true;
    rep(i,ss){
        if(s[i]!=t[i]) f=false;
    }
    if(f) cout<<"Yes\n";
    else cout<<"No\n";
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long INF = MOD*MOD;
typedef pair<int,int> P;
typedef long long ll;
queue<P> que;

int w,h;
bool isV[501][501];
int m[501][501];
char s[501][501];
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
int ans = 0;

void bfs(){
  while( que.size() ){ //queがなくなるまで
    P p = que.front();que.pop();
    rep(i, 4){
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if(nx >= 0 and nx < w and ny >= 0 and ny < h and s[nx][ny] == '.' and isV[nx][ny] == false){
        isV[nx][ny] = true;
        que.push(P(nx,ny));
        m[nx][ny] = m[p.first][p.second] + 1;
        ans = max(ans,m[nx][ny]);
      }
    }
  }
}
 
int main(void){
  cin >> h >> w;
  cin.ignore();
  rep(i,h){
    string st; getline(cin,st);
    rep(j,w) s[j][i] = st[j];
  }
  
  rep(k,h) rep(l,w){
    if(s[l][k] == '.'){
      rep(i,w) rep(j,h) {m[i][j] = MOD;isV[i][j] = false;}
      isV[l][k] = true;
      m[l][k] = 0;
      que.push({l,k});
      bfs();
    }
  }

  cout << ans << "\n";
}

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

int main(){
    ll a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
    return 0;
}

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

using namespace std;

int main(){
	int m,d;
	cin>>m>>d;
	int x1=d/10;
	int y=d%10;
	int sum=0;
	for(int i=2;i<=9;i++){
		for(int j=2;j<=9;j++){
			if(i*j<=m&&(i*10+j)<=d)
			sum++;
		}
	}
	cout<<sum;
	
}

Measured memory_bytes: 256
#from bisect import bisect_right as right
import bisect

#import sys
#readline = sys.stdin.buffer.readline

N = int(input())
A = [int(input()) for _ in range(N)][::-1]

INF = 10**10
dp = [INF] * (N+1)

answer = 0
for a in A:
  r = bisect.bisect_right(dp, a)
  if dp[r] > a:
    if dp[r] == INF:
      answer += 1
    dp[r] = a
print(answer)

Measured memory_bytes: 52952
from collections import Counter
mod = 2019
s = list(input())
ln = len(s)

ms = [0]*(ln+1)
ms[ln] = 0
cr = 1
for i in range(ln):
  ms[ln-1-i] = (ms[ln-i] + cr*int(s[ln-1-i])) % mod
  cr = (cr*10) % mod

cnts = Counter()
for i in ms:
  cnts[i] += 1
ans = 0
for k,v in cnts.items():
  if v >= 2:
    ans += int(v*(v-1)/2)
print(ans)

Measured memory_bytes: 17980
#include<cstdio>

int n,a[100000];
int ans = 0;
int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++) scanf("%d",a+i);
  for(int i=0;i<n;i++){
    if(a[a[i]-1]-1==i) ans++;
  }
  printf("%d\n",ans/2);
  return 0;
}


Measured memory_bytes: 512
n, k = map(int, input().split())

visited = [False for _ in range(n)]

for _ in range(k):
    d = int(input())
    items = list(map(int, input().split()))
    for i in items:
        visited[i - 1] = True

ret = 0
for cur in visited:
    if cur == False:
        ret += 1

print(ret)

Measured memory_bytes: 9012
/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int         long long
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define whilet()    int t; scanf("%d",&t); while(t--)
#define vp          vector<pair<int,int>,int>
#define pb          push_back
#define mii         map<int,int>
#define pii         pair<int,int>
#define msi         map<string,int>
#define psi         pair<string,int>
#define mpi         map<pair<int,int>,int>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define ef          else if
#define MOD         1000000007
#define endl        '\n'
#define fastio       ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi          3.141592653589793238
const long long MAX_SIZE = 1000000000;
using namespace std;

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

signed main()
{
    fastio;
    int n,m,k;
    cin>>n>>m>>k;
    
    if(n%m==0)cout<<(n/m)*k<<endl;
    else
        cout<<((n/m)+1)*k<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <stack>
#include <cmath>
#include <map>
#include <cstring>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
const long long MAX=200005;
typedef long long ll;
const int INF=0x3f3f3f3f;
//int d[8][2]={-1,0,0,-1,0,1,1,0,1,1,-1,-1,-1,1,1,-1};
const int MAX_N=5000+3;
char str[MAX_N];
ll ans;
int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    if(x%y==0) printf("-1\n");
    else printf("%d\n",x);
}


Measured memory_bytes: 256
n,x,y=map(int,input().split())
x,y=x-1,y-1

ans=[0]*(n+1)



for i in range(n):
    for j in range(i+1,n):
        a=abs(i-j)
        b=abs(i-x)+1+abs(y-j)
        ans[min(a,b)]+=1
for i in range(1,n):
    print(ans[i])
    

Measured memory_bytes: 46428
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
  string s;
  cin >> s;
  
  ll k;
  cin >> k;
  
  ll res = 1;
  
  for (ll i = 0; i < k && i < s.size(); ++i) {
    ll l = s.at(i)-'0';
    if (l != 1) {
      res = l;
      break;
    }
  }
  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define d double
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
   
  int a,b;
  cin>>a>>b;
  int A=a;
  int B=b;
  string s1 =to_string(a);
  string s2= to_string(b);
  string f1,f2;
  
  while(a--){
  	f1=f1+s2;
  }
  
  while(b--){  	
  	f2=f2+s1;
  }
  

   
  if(A<B){
  	
  	cout<<f2<<endl;
  	
   }  
   
   else if(B<A){
   	
   	
   	cout<<f1<<endl;
   	
   }
   
   
   else if(A==B){
   	
   	cout<<f1<<endl;
   	
   }
   
  return 0;
}

Measured memory_bytes: 3716
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		int N = S.Length;
		if(N < 26){
			var h = new HashSet<char>();
			for(int i=0;i<N;i++) h.Add(S[i]);
			var c = 'a';
			while(h.Contains(c)) c++;
			Console.WriteLine("{0}{1}",S,c);
			return;
		}
		
		if(S == "zyxwvutsrqponmlkjihgfedcba"){
			Console.WriteLine(-1);
			return;
		}
		
		var ca = S.ToCharArray();
		NextPermutaion(ca);
		var ans = new List<char>();
		for(int i=0;i<N;i++){
			ans.Add(ca[i]);
			if(ca[i] != S[i]) break;
		}
		Console.WriteLine(new String(ans.ToArray()));
		
		
	}
	String S;
	public Sol(){
		S = rs();
	}
	static public bool NextPermutaion<T>(T[] A)where T:IComparable<T>{
		for(int i=A.Length-2;i>=0;i--){
			if(A[i].CompareTo(A[i+1])<0){
				int trgt=Array.FindLastIndex(A,x=>A[i].CompareTo(x)<0);
				Swap(ref A[i],ref A[trgt]);
				Array.Reverse(A,i+1,A.Length-(i+1));
				return true;
			}
		}
		Array.Reverse(A);
		return false;
	}
	static void Swap<T>(ref T x, ref T y){
		T t=x;x=y;y=t;
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <algorithm>
#include <utility> 
#include <unordered_set>
#include <vector>
#include <list> 
#include <string>
#include <iterator> 
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
#include <numeric>
using namespace std;


const long double PI = 3.14159265358979323846264338327950;
const int N = 100;

template <class T>
T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int arr[N];

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

	int n, lo, hi, ans;
	lo = INT_MAX; hi = INT_MIN;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
		lo = min(lo, arr[i]);
		hi = max(hi, arr[i]);
	}
	
	ans = INT_MAX;
	while (lo <= hi) {
		int sum = 0;
		for (int i = 0; i < n; ++i) {
			sum += (arr[i] - lo) * (arr[i] - lo);
		}
		ans = min(ans, sum);
		++lo;
	}

	cout << ans << '\n';
}


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



ll dp[101][100001] = {};
int a[101];
ll sum[100001];
int n,k;

ll rec(int idx , int left){
	if(idx<1 && left!=0) return 0;
	if(idx<1 && left==0) return 1;
	ll& ans = dp[idx][left];
	if(ans!=-1) return ans%mod;
	
	ans=0;
	for(int i=0;i<=a[idx] ; ++i){
		if(left-i>=0) ans += rec(idx-1 , left-i);
		ans%=mod;
	}
	return ans%mod; 
}

int main(){
	//memset(dp,1,sizeof(dp));
	IOS;
	cin >> n >> k;
	for(int i=1;i<=n ;++i){
		cin >> a[i];
	}

	for(int i=0;i<=a[1] ; ++i){
		dp[1][i] = 1;
	}
	
	for(int i=2; i <=n ; ++i){
		sum[0] = dp[i-1][0];
		for(int c=1;c<=k ; ++c){
			sum[c] = (sum[c-1] + dp[i-1][c] + mod) % mod;
		}
		for(int j = 0;j<=k ; ++j){
			dp[i][j] = sum[j] - sum[j-min(j,a[i])-1];
		}
	}
	cout << (dp[n][k] + mod)%mod << endl;
}

Measured memory_bytes: 79232
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;


class StdType
{
public:
    string s;
    char max_c;
    
    StdType(string s, char max_c) : s(s), max_c(max_c) {}
};


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

    queue<StdType> wq( { StdType("a", 'a') } );
    while (!wq.empty())
    {
        StdType w = wq.front();
        wq.pop();

        if (w.s.length() == n)
        {
            cout << w.s << endl;
        }
        else
        {
            for (char c = 'a'; c <= w.max_c + 1; c++)
            {
                wq.push(StdType(w.s + c, max(c, w.max_c)));
            }
        }   
    }
}


Measured memory_bytes: 8832
x = int(input())
ans = 0
while(x > 5):
  if x >= 500:
    ans += (x // 500) * 1000
    x = x % 500
    continue
  if x >= 5:
    ans += (x // 5) * 5
    x = x % 5
    continue    

    
print(ans)

Measured memory_bytes: 8988
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int X, Y;
	cin >> X >> Y;
	int ans = 0;
	ans += max(0, 4 - X) * 100000;
	ans += max(0, 4 - Y) * 100000;
	if (X == 1 && Y == 1) ans += 400000;
	cout << ans << endl;
}


Measured memory_bytes: 256
// atcoder/abc139/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  while (cin >> a >> b) {
    int x = 0;
    for (int i = 0; ; ++i) {
      x = i;
      if (b <= i * (a - 1) + 1) {
        break;
      }
    }
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int x = sc.nextInt();
			if(n==0 && a==0 && b==0 && c==0 && x==0) break;
			
			int[] y = new int[n];
			for(int i=0;i<n;i++) y[i] = sc.nextInt();
			
			int count=0;
			boolean flag = false;
			for(int i=0;i<=10000;i++){
				if(x==y[count]) count++;
				if(count==n){
					System.out.println(i);
					flag = true;
					break;
				}
				x = (a*x+b)%c;
			}
			if(flag==false) System.out.println(-1);
		}	
	}	
}

Measured memory_bytes: 31648
N = int(input())
f = 0
A = []
for i in range(N):
  if i == 0:
    A.append(input())
  else:
    A.append(input())
    if A[-2][-1] != A[-1][0]:
      f = 1
      break
    if len(set(A)) < i + 1:
      f = 1
      break
if f == 0:
  print("Yes")
else:
  print("No")

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

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0); //cinとcoutの同期切り
    ios::sync_with_stdio(false); //iostreamとstdioの同期切り

    int N;
    string S;
    cin >> N >> S;

    int ans = N;
    int mukikaeru_mae;
    for(int leader = 0; leader < N; ++leader){  //リーダーを一人ずつ変える
        int mukikaeru = 0;
        if(leader == 0){
            for(int i = 1; i < N; ++i){
                if(S[i] == 'E') ++mukikaeru;
            }
            ans = min(ans, mukikaeru);
        }
        else{
            mukikaeru = mukikaeru_mae;
            if(S[leader] == 'E'){
                mukikaeru -= 1;
            }
            if(S[leader - 1] == 'W'){
                mukikaeru += + 1;
            }
            ans = min(ans, mukikaeru);
        }
        mukikaeru_mae = mukikaeru;
    }
    
    cout << ans << endl;

    return 0;
}

/*****************************************************************************/
/*****   1秒間で処理できるfor文ループの回数                                 *****/
/*****   → 10^8 = 100,000,000 回程度                                      *****/
/*****                                                                   *****/
/*****   sort(a, a+N, greater<int>()); // a[0:N) を大きい順にソート        *****/
/*****                                                                   *****/
/*****                                                                   *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3"                *****/
/*****   std::cout << std::fixed;                                        *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3.00"             *****/
/*****                                                                   *****/
/*****************************************************************************/

Measured memory_bytes: 720
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++) cin >> a[i];

  /*
  vector<vector<int>> table(n);
  for(int i=0;i<n;i++){
    //各bitを掃き出す
    for(int j=0;j<60;j++){
      ll bit = a[i]>>j & 1;
      table[i].push_back(bit);
    }
  }
  */

  /*
  for(int i=0;i<n;i++){
    for(int j=0;j<60;j++){
      cout<<table[i][j];
    }
    cout << endl;
  }
  */

  ll sum = 0;
  ll bin = 1;
  for(int j=0;j<62;j++){
    int cnt_one = 0;
    for(int i=0;i<n;i++){
      //if(table[i][j] == 1) cnt_one++;
      if(a[i]>>j&1) cnt_one++;
    }
    sum += bin * cnt_one %mod * (n-cnt_one);
    sum %= mod;
    bin *= 2;
    bin %= mod;
  }

  cout << sum << endl;
}


Measured memory_bytes: 2560
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
//typedef complex<double>P;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS*(abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑

int a, b, k[1005], l[1005], ans, cnt, hi;
int main() {
	cin >> a >> b;
	vector<bool> m(b);
	for (int i = 0; i < a; ++i) {
		cin >> k[i];
	}
	for (int i = 0; i < b; ++i) {
		cin >> l[i];
		m[i] = true;
	}
	sort(l, l + b);
	reverse(l, l + b);
	for (int i = 0; i < a; ++i) {
		cnt = 0;
		for (int j = 0; j < b; ++j) {
			if (k[i] <= l[j] && m[j] == true) {
				++cnt;
				m[j] = false;
			}
		}
		if (hi < cnt) {
			hi = cnt;
			ans = i + 1;
		}
	}
	cout << ans << endl;
}


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

typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define sz(v) ll(v.size)


void solve(long long N, std::vector<std::string> S){
    vector<ll> names(5, 0);
    rep(i, N) {
        if (S[i][0] == 'M') {
            names[0]++;
        }
        if (S[i][0] == 'A') {
            names[1]++;
        }
        if (S[i][0] == 'R') {
            names[2]++;
        }
        if (S[i][0] == 'C') {
            names[3]++;
        }
        if (S[i][0] == 'H') {
            names[4]++;
        }
    }
    ll s = 0;
    rep(i, 5) {
        FOR(j, i+1, 5) {
            FOR(k, j+1, 5) {
                s += names[i] * names[j] * names[k];
            }
        }
    }
    cout << s << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


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

int main(void){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    double r = 0.0;
    pair<int,int> ans;

    for(int i=0; i*a*100<=f; i++){
        for(int j=0; i*a*100+j*b*100<=f; j++){
            if(i == 0 && j == 0){
                continue;
            }
            int w = i*a*100 + j*b*100;
            for(int k=0; w+k*c<=f; k++){
                for(int l=0; w+k*c+l*d<=f; l++){
                    int s = k*c + l*d;
                    double m = (double)s/(w+s);
                    if(m <= (double)e/(100+e) && m >= r){
                        ans.first = w+s;
                        ans.second = s;
                        r = m;
                    }
                }
            }
        }
    }

    cout << ans.first << " " << ans.second << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    ll C[n][n];
    for(int i=0;i<n;++i) for(int j=0;j<n;++j) cin >> C[i][j];

    ll ans = 0;
    for(int i=0;i<n;++i) {
        for(int j=i+1;j<n;++j) {
            if(i == j) continue;
            ans += min(C[i][j], C[j][i]);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3164
#include<set>
#include <unordered_set>
#include <unordered_map>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<math.h>
#include <string.h>
#include <strings.h>


#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define readll(x) scanf("%I64d",&x)
#define eps 1e-6
#define infi 1000000000
#define infll 1000000000000000000ll



using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef unordered_set<int> usi;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef unordered_map<ll,ll> umll;
using namespace std;
const int N = 1e5 + 6;
int ptr = 0;
pair<int,pii> arr[N];
int main(){
    int n,t,x,y,delta;
    arr[++ptr] = mp(0,mp(0,0));
    readi(n);
    lp(i,1,n){
        read3i(t,x,y);
        arr[++ptr] = mp(t,mp(x,y));
    }
    sort(arr+1,arr+1+ptr);
    lp(i,2,ptr){
        delta = abs(arr[i].second.first - arr[i-1].second.first) + abs(arr[i].second.second - arr[i-1].second.second);
        t = arr[i].first - arr[i-1].first;
        if(t < delta || ((delta-t) & 1)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
   
    return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());

		long ans = 0;
		int p = n / k;
		int q = (n + (k / 2)) / k;

		ans += (long) p * p * p;

		if (k % 2 == 0) {
			ans += (long) q * q * q;
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 22740
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 1e5 + 20;
const int inf = 1e9 + 7;

int n, m;
vi s, g[N], rev[N];
vi cur;
int was[N];
int dp[N];

void dfs(int v) {
	was[v] = 1;
	for (auto x : g[v])
		if (!was[x]) dfs(x);
	cur.pb(v);
}

int go(int v) {
	if (dp[v] != inf) re dp[v];
	int ans = 0;
	for (auto x : rev[v])
		ans = max(ans, 1 + go(x));
	re dp[v] = ans;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--; y--;
		g[x].pb(y);
		rev[y].pb(x);
	}
/*	for (int i = 0; i < n; i++)
		if (!was[i]) {
			cur.clear();
			dfs(i);
			s.pb(cur.back());
		}
*/	for (int i = 0; i < n; i++) dp[i] = inf;
//	for (auto x : s) dp[x] = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) ans = max(ans, go(i));
	cout << ans;
	return 0;
}


Measured memory_bytes: 16128
/*
  B - Comparison
  Contest 059
  Rakesh Kumar --> 24/08/2020
 */

#include <bits/stdc++.h>

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

    std::string a;
    std::string b;
    std::getline(std::cin, a);
    std::getline(std::cin, b);
    if (a.size() > b.size())
        std::cout << "GREATER" << std::endl;
    else if (a.size() < b.size())
        std::cout << "LESS" << std::endl;
    else {
        if (a == b)
            std::cout << "EQUAL" << std::endl;
        else if (a > b)
            std::cout << "GREATER" << std::endl;
        else
            std::cout << "LESS" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

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

signed main() {
  init();
  ll N, A, B;
  cin >> N >> A >> B;
  vll H(N);
  cin >> H;

  ll left = 0, right = 1000000000;
  while (right - left > 1) {
    ll center = (right + left) / 2;
    ll count = 0;
    rep(i, N) {
      ll h = H[i] - center * B;
      if (h > 0) {
        count += h / (A - B);
        if (h % (A - B) != 0) count++;
      }
    }
    if (count > center)
      left = center;
    else
      right = center;
  }
  COUT(right);
  return 0;
}

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

int main() {
  int m1,d1,m2,d2,ans=0;
  cin >> m1 >> d1 >> m2 >> d2;
  if(m1!=m2) ans=1 ;
  cout << ans << endl;
}


Measured memory_bytes: 256
import fractions

a,b = map(int,input().split())
kouyakusu = fractions.gcd(a,b)

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

print(len(set(factorize(kouyakusu)))+1)

Measured memory_bytes: 64108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner kbScanner = new Scanner(System.in);
		int input1 = kbScanner.nextInt();
		int input2 = kbScanner.nextInt();
		
		while((input1 != 0) || (input2 != 0)){
			if(input1 > input2){
				int oki = input1;
				input1 = input2;
				input2 = oki;
			}
			System.out.println(input1 + " " + input2);
			input1 = kbScanner.nextInt();
			input2 = kbScanner.nextInt();
		}
	}
}

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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  string C;
  cin >> C;
  int red = 0;
  for(int i = 0; i < N; i++){
    if(C[i] == 'R') red++;
  }
  int cnt = 0;
  for(int i = 0; i < red; i++){
    if(C[i] == 'W') cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3728
def sort(a, b)
  if a > b
    t = a
    a = b
    b = t
  end
  return a, b
end

n = gets.chomp.split(" ").map &:to_i

n[0], n[1] = sort(n[0], n[1])
n[1], n[2] = sort(n[1], n[2])
n[0], n[1] = sort(n[0], n[1])

puts "#{n[0]} #{n[1]} #{n[2]}"

Measured memory_bytes: 8600
#include "bits/stdc++.h"
using namespace std;
int main(){
    int H,W;
    cin >> H >> W;
    int i,j;
    char c;
    int B[H][W];
    int P[W],Q[H];//sum of tate/yoko
    for(i=0;i<H;i++) Q[i]=0;
    for(j=0;j<W;j++) P[j]=0;
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            cin >> c;
            if(c == '#') B[i][j] = 1;
            else B[i][j] = 0;
            P[j] += B[i][j];
            Q[i] += B[i][j];
        }
    }
    for(i=0;i<H;i++){
        if(Q[i]==0) continue;
        for(j=0;j<W;j++){
            if(P[j]==0)continue;
            if(B[i][j]==0) cout << ".";
            else cout << "#";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int l;
    int r;
    int d;
    int a=0;
    scanf("%d %d %d", &l,&r,&d);

    for (int i =l; i <= r; i++){
        if(i%d==0){
        a = a+1;
        }
    }
    printf("%d", a);
    return 0;
}

Measured memory_bytes: 1732
#include <algorithm>
#include <climits>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

// 二乗を計算する。
int sq(int x) { return x * x; }

// 領域内にいるか。
bool within(int x, int min, int max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T & container, typename T::key_type & key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
LONG modpow(LONG b, LONG e, LONG m) {
	LONG result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}

int B[300000] = { 0 };
int W[300000] = { 0 };
int main(void) {
	int N;
	string S;
	cin >> N >> S;
	int count = 0;
	for (int i = 0; i <= N; ++i) {
		W[i] = count;
		if (i < N && S[i] == '#') count++;
	}
	count = 0;
	for (int i = N; i >= 0; --i) {
		B[i] = count;
		if (i < N && S[i] == '.') count++;
	}

	int ans = INT_MAX;
	for (int i = 0; i <= N; ++i) {
		ans = min(ans, W[i] + B[i]);
	}

	cout << ans << endl;

	return 0;
}


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

int main()
{
    int n, q;
    string s;
    cin >> n >> q >> s;
    vector<int> l(q);
    vector<int> r(q);
    for (int i = 0; i < q; i++)
    {
        cin >> l.at(i) >> r.at(i);
    }
    vector<int> x(n + 1);
    s+="X";
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'A' && s[i + 1] == 'C')
        {
            x.at(i+1)++;
        }
        if (i != 0)
        {
            x.at(i) += x.at(i - 1);
        }
    }

    for (int i = 0; i < q; i++)
    {
        cout << x.at(r.at(i)-1) - x.at(l.at(i)-1) << endl;
    }
}


Measured memory_bytes: 2176
toll = [[0, 300, 500, 600, 700, 1350, 1650],
        [0, 0, 350, 450, 600, 1150, 1500],
        [0, 0, 0, 250, 400, 1000, 1350],
        [0, 0, 0, 0, 250, 850, 1300],
        [0, 0, 0, 0, 0, 600, 1150],
        [0, 0, 0, 0, 0, 0, 500]]
S, E = 17 * 60 + 30, 19 * 60 + 30

until (d = $<.gets.to_i).zero?
  h, m = $<.gets.split.map(&:to_i)
  td = h * 60 + m
  a = $<.gets.to_i
  h, m = $<.gets.split.map(&:to_i)
  ta = h * 60 + m
  
  d, a = a, d if d > a
  f = if (a == 6 and d == 1) or (a == 7 and d <= 3)
    false
  elsif td.between?(S, E) or ta.between?(S, E)
    true
  else
    false
  end
  
  result = toll[d - 1][a - 1]
  result /= 2 if f
  puts ((result / 50.0).ceil * 50).to_i
end


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q; cin>>n>>q;
    using Tup = tuple<ll,ll,ll>;
    vector<Tup> range(n);
    rep(i,n){
        ll s,t,x; cin>>s>>t>>x;
        range[i] = tie(x,s,t);
    }
    sort(all(range));
    using P = pair<ll,int>;
    set<P> qSet;
    rep(i,q){
        ll d; cin>>d;
        qSet.emplace(d,i);
    }
    vector<ll> ans(q, -1);
    rep(i,n){
        ll s,t,x;
        tie(x,s,t) = range[i];
        auto st = qSet.lower_bound(mp(s-x, 0));
        auto ed = qSet.lower_bound(mp(t-x, 0));
        for(auto itr=st; itr!=ed; itr++){
            P p = *itr;
            ll dist; int idx;
            tie(dist,idx) = p;
            ans[idx] = x;
        }
        qSet.erase(st,ed);
    }
    rep(i,q){
        cout<<ans[i]<<endl;
    }
    return 0;
}

//d+xが区間[s,t)に入ってたら通行止めに引っかかる
//∴s-x <= d < t-x


Measured memory_bytes: 20608
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int main(){
  ll ans=0;
  int N,a[100000],x;
  cin>>N>>x;
  for(int i=0;i<N;i++){
    cin>>a[i];
  }

  if(a[0]+a[1]-x<0){
    
  }else if(a[0]>x){
    ans+=a[0]+a[1]-x;
    a[1]=0;
    a[0]=x;
  }else{
    ans+=a[0]+a[1]-x;
    a[1]=x-a[0];
  }

  for(int i=1;i<N-1;i++){
    if(a[i]+a[i+1]-x>=0){
      ans+=a[i]+a[i+1]-x;
      a[i+1]=x-a[i];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
import sys
v=[0]*101
for e in sys.stdin:
 a,b=map(int,e.split())
 v[a]+=1;v[b]+=1
 if a==0:
  print(['NG','OK'][(v[1]&1)*(v[2]&1)*sum(x&1 for x in v)==2])
  v=[0]*100


Measured memory_bytes: 5608
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll r;
    cin >> r;
    cout << r * r * 3 << endl;
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] a = new int[n];
        boolean[] up = new boolean[n];

        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }

        long k = 0;
        long m = 1000;

        for(int i = 0; i < n - 1; i++){
            if(k == 0){
                if(a[i] < a[i + 1]){
                    k = m / a[i];
                    m %= a[i];
                }
            }else{
                if(a[i] > a[i + 1]){
                    m += k * a[i];
                    k = 0;
                }
            }
        }
        m += k * a[n - 1];

        System.out.println(m);
    }
}


Measured memory_bytes: 35772
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

tuple<ll, ll> func(ll n) {
    ll cnt = 1;
    n *= 2;
    if (n >= 10) {
        ++cnt;
        n = (n % 10) + (n / 10);
    }
    return mt(n, cnt);
}

ll solve_naive(vector<int>& remain) {
    ll ans = 0;
    while(SIZE(remain) >= 2) {
        int a = remain.back();
        remain.pop_back();
        int b = remain.back();
        remain.pop_back();

        ans++;
        int sum = a + b;
        while (sum >= 10) {
            sum = (sum % 10) + (sum / 10);
            ans++;
        }
        remain.push_back(sum);
    }
    return ans;
}

ll solve(vector<pair<ll, ll>>& DCs) {
    ll ans = 0;
    vector<int> remain;

    for(auto dc: DCs) {
        ll d = dc.first;
        ll c = dc.second;
        ll local_ans = 0;
        while (c >= 2) {
            if (c % 2) {
                remain.pb(d);
                c--;
            }
            ll new_d; ll cnt;
            tie(new_d, cnt) = func(d);
            // cerr << "c, new_d, cnt = " << c << "," << new_d << "," << cnt << endl;
            local_ans += cnt * (c / 2);

            d = new_d;
            c /= 2;
        }
        remain.pb(d);
        ans += local_ans;
    }

    // cerr << "remain:";
    // for(auto r: remain) cerr << " " << r;
    // cerr << endl;

    ans += solve_naive(remain);
    return ans;
}


int main(void)
{
    cin.sync_with_stdio(false);
    int M;
    cin >> M;
    vector<pair<ll, ll>> DCs;
    REP(m, M) {
        ll d, c;
        cin >> d >> c;
        DCs.pb(mp(d, c));
    }
    cout << solve(DCs) << endl;
    

    return 0;
}


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

using namespace std;
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<int> a(n);
	rep(i,n) cin >>a[i];
	
	sort(all(a));
	if(n==2){
		cout <<a[1] <<" "<<a[0] <<"\n";
		return 0;
	}
	int sn = a[n-1];
	
	int ps= lower_bound(all(a), a[n-1]/2) - a.begin();
	ll mn=1LL<<50; int ans =0;
	rep(i, 3){
		if(ps+i <n -1 && abs(a[n-1] - 2*a[ps+i]) < mn){
			mn = abs(a[n-1] - 2*a[ps+1]); ans = ps+1;
		}
		if(ps-i >=0 &&abs(a[n-1] - 2*a[ps-i]) < mn){
				mn = abs(a[n-1] - 2*a[ps-i]); ans = ps-i;
		}
	}
	
	cout << a[n-1] <<" " <<a[ans] <<"\n";
	
	return 0;
	
}


Measured memory_bytes: 640
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,mul4=0, odd=0,nm4
    integer(int32), allocatable:: a(:)

    read*, n
    allocate(a(n))
    read*, a(:)
    do i=1,n
        if (btest(a(i),0))then
            odd=odd+1
        else if (mod(a(i),4) == 0) then
            mul4=mul4+1
        end if
    end do

    nm4 = odd
    if (mul4+odd == n) nm4=nm4-1

    if (mul4 >= nm4) then
        print'(a)', 'Yes'
    else
        print'(a)', 'No'
    end if
end program name

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
int n,m,k;
int a[200000],b[200000];
int suma[200000],sumb[200000];
vector<int>t;
signed main(){
    cin>>n>>m>>k;
    rep(i,n){
        cin>>a[i];
        if(i==0)suma[0]=a[0];
        else suma[i]=suma[i-1]+a[i];
    }
    rep(i,m){
        cin>>b[i];
        if(i==0)sumb[0]=b[0];
        else sumb[i]=sumb[i-1]+b[i];
    }
    rep(i,n+1){
        int x;
        if(i==0)x=k;
        else x=k-suma[i-1];
        if(x<0)break;
        t.push_back(i+(upper_bound(sumb,sumb+m,x)-sumb));
    }
    sort(all(t));
    int l=t.size();
    cout<<t[l-1]<<endl;
    return 0;
}



Measured memory_bytes: 11576
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main(){

    int n;

    cin >> n;
    map<int,int> odd_map;
    map<int,int> even_map;
    int odd_max = 0;
    int odd_2nd = 0;
    int odd_num;
    int even_max = 0;
    int even_2nd = 0;
    int even_num;

    for(int i = 1; i <= n; i++){
        int tmp;
        cin >> tmp;
        
        if(i % 2 == 1){
            odd_map[tmp]++;
            if(odd_max <= odd_map[tmp]){
                if(odd_num != tmp) odd_2nd = odd_max;
                odd_num = tmp;
                odd_max = odd_map[tmp];
            }else{
                if(odd_2nd < odd_map[tmp]){
                    odd_2nd = odd_map[tmp];
                }
            }
        }else{
            even_map[tmp]++;
            if(even_max <= even_map[tmp]){
                if(even_num != tmp) even_2nd = even_max;
                even_num = tmp;
                even_max = even_map[tmp];
            }else{
                if(even_2nd < even_map[tmp]){
                    even_2nd = even_map[tmp];
                }
            }
        }
    }

    if(odd_num != even_num){
        cout << n - odd_max - even_max << endl;
    }else{
        if(odd_2nd < even_2nd){
            cout << n - odd_max - even_2nd << endl;
        }else{
            cout << n - odd_2nd - even_max << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(){
	while(true){
		int m,n,book[101]={},sum[101]={};
		cin >> m >> n;
		if(m==0) break;
		for(int i=1;i<=n;i++){
			cin >> book[i];
			sum[i]=sum[i-1]+book[i];
		}
		int d=0;
		int u=1500000;
		int md;
		while(d+1<u){
//			cout << u << " " << d << endl;
			bool ok=false;
			int j=0,until=0;
			md=(d+u)/2;
			for(int i=0;i<m;i++){
				while(sum[j]-sum[until]<=md){
					j++;
					if(j==n+1){
						ok=true;
						break;
					}
				}
				if(ok) break;
				until=j-1;
			}
			if(ok){
				u=md;
				if(d+1>=u){
					cout << u << endl;
					break;
				}
			}
			else{
				d=md;
				if(d+1>=u){
					cout << u << endl;
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
n,tp=gets.split.map(&:to_i)
a=gets.split.map{|i|i.to_i%2}
odd=a.count(1)
even=a.count(0)
fl=(2..odd).inject([1,1]){|s,r|s<<(s[-1]*r)}
p (2**even)*tp.step(odd,2).inject(0){|s,r|s+fl[odd]/fl[r]/fl[odd-r]}


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
ll gcd(ll a, ll b) {

    if (b == 0)return a;
    else return gcd(b, a % b);
}
ll lcm(ll a, ll  b) {
    return a*b/gcd(a, b);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll LCM = lcm(c, d);
    ll ac = (a-1) / c, ad = (a - 1) / d, acd = (a - 1) / LCM;
    ll bc = b / c, bd = b / d, bcd = b / LCM;
    ll ans = b - a - (bc - ac) - (bd - ad) + (bcd - acd) + 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import bisect

n = int(input())
l = [int(i) for i in input().split()]

l.sort(reverse=True)
ans = 0

l = list(map(lambda x: x * (-1), l))

for i in range(n-2):
    for j in range(i+1,n-1):
        need = l[i] - l[j] - 1
        idx = bisect.bisect_right(l,need)
        #print(i,j,idx,need,ans)
        ans += max(0,idx-j-1)
        
print(ans)

Measured memory_bytes: 3188