akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
#include <stdlib.h>

using namespace std;


long long int N = 1000000007;

int main()
{
  int n;  cin >> n;
  long long int ans = 1;
  string s,t; cin >> s >> t;

  bool b;
  int pos;

  if(s[0] == t[0]){
    pos = 1;
    b = 0;
    ans = 3;
  }
  else{
    pos = 2;
    b = 1;
    ans = 6;
  }
  for(int i = pos;i<n;i++){
    if(s[i] == t[i]){
      if(b == false){
        ans = ( ans * 2 ) % N;
        b = 0;
      }
      else{
//        ans = ( ans * 2 ) % N;
        b = 0;
      }
    }
    else{
      if(b == false){
        ans = ( ans * 2 ) % N;
        b = 1;
        i++;
      }
      else{
        ans = ( ans * 3 ) % N;
        b = 1;
        i++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define int long long
signed main(){
    string s[100];
    int n,l;
    cin>>n>>l;
    for(int k=0;k<n;k++)cin>>s[k];
    sort(s,s+n);
    for(int k=0;k<n;k++)cout<<s[k];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int aa=a+b;
	int bb=a-b;
	int cc=a*b;
	int maxn=max(aa,bb);
	maxn=max(maxn,cc);
	printf("%d",maxn);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string S, T;
string ans = "No";
int main(void) {
	cin >> S >> T;
	sort(S.begin(), S.end());
	sort(T.begin(), T.end());
	reverse(T.begin(), T.end());
	for (int s = 0; s < S.size(); ++s) {
		if (S[s] > T[s]) break;
		if (S[s] < T[s]) {
			ans = "Yes";
			break;
		}
		if (s == S.size() - 1 && S.size() < T.size()) {
			ans = "Yes";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

string toUpper(string s){
    string t=s;
    for (int i=0; i<s.size(); i++){
        t[i] = toupper(s[i]);
    }
    return t;
}

int main(){
    string target,source;
    
    cin >> target;
    target = toUpper(target);
    
    int cnt = 0;
    while(1){
        cin >> source;
        if (source == "END_OF_TEXT") break;
        source = toUpper(source);
        if (target == source) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1){
    for(int u : to[v]){
        if(u == p) continue;
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main(){
    int N, Q; cin >> N >> Q;
    for(int i = 0; i < N - 1; i++){
        int a, b; cin >> a >> b; a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);        
    }

    ans.resize(N);
    for(int i = 0; i < Q; i++){
        int p, x; cin >> p >> x; p--;
        ans[p] += x;
    }

    dfs(0);
    for(int i = 0; i < N; i++){
        cout << ans[i] << endl;
    }
}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  rep(i,n) cin >> p[i];
  
  double kmax;
  double kari = 0;
  rep(j,k){
    kari += (1 + p[j]);
  }
  kmax = kari;
  rep(j,n-k){
    kari = kari + p[j+k] - p[j];
    kmax = max(kari,kmax);
  }

  printf("%f\n", kmax / 2.0);
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9

int main(){
	int x,y,h,w,t,n;
	scanf("%d",&t);
	while(t--){
		int ans = 0;
		scanf("%d%d%d%d%d",&x,&y,&w,&h,&n);
		rep(i,n){
			int tx,ty; scanf("%d%d",&tx,&ty);
			if( x<=tx && tx<=x+w && y<=ty && ty<=y+h ){
				ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        double po=0;
        for(int i=0;i<n;i++){
            po+=1.0/sc.nextInt();
        }
        System.out.println(1.0/po);
    }
}


Measured memory_bytes: 22740
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
 
  int z[1000] = {0},n,a,b,c,d,x[1000] = {0},tmp,count = 0;
  cin >> n;
 
  for(int i=0;i<n*(n-1)/2;i++){
    cin >> a >> b >> c >> d;
 
    if(c > d) z[a-1] += 3;
    else if(d > c) z[b-1] += 3;
    else if(c == d){
 
      z[a-1]++;
      z[b-1]++;
 
    }
  }
 
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(z[i] < z[j]) count++;
    }
      x[i] = count;
      count = 0;
    }
  
  for(int i=0;i<n;i++) cout << x[i]+1 << endl;

}

Measured memory_bytes: 1168
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(int[] a, int[] b, int[] c) {
    a.sort();
    b.sort();
    c.sort();

    long ans = 0;
    int n = cast(int)a.length;
    for (int i = 0; i < n; i++) {
        int lo = 0;
        int hi = n - 1;
        long na = 0;
        while (lo <= hi) {
            int m = (lo + hi) / 2;
            if (a[m] < b[i]) {
                na = m + 1;
                lo = m + 1;
            }
            else hi = m - 1;
        }

        lo = 0;
        hi = n - 1;
        long nc = 0;
        while (lo <= hi) {
            int m = (lo + hi) / 2;
            if (b[i] < c[m]) {
                nc = n - m;
                hi = m - 1;
            }
            else lo = m + 1;
        }

        ans += na * nc;
    }
    return ans;
}

void main() {
    readint;
    auto a = readints;
    auto b = readints;
    auto c = readints;
    writeln(calc(a, b, c));
}


Measured memory_bytes: 11592
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
    {
        int jump = abs(h[i] - h[i - 2]) + dp[i - 2];
        int step = abs(h[i] - h[i - 1]) + dp[i - 1];
        dp[i] = min(jump, step);
    }
    for (int i = 0; i < n; i++)
    {
        //    cout << dp[1];
    }

    cout << dp[n - 1];
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<complex>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph=vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;


int main(void)

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

	string s;
	cin >> s;

	string ss = s;
	reverse(ss.begin(), ss.end());

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == ss[i])
			continue;
		else
		{
			cout << "No" << endl;
			ret;
		}
	}
	for (int i = 0; i < (s.size() - 1) / 2; i++)
	{
		if (s[i] == ss[(s.size()-1)/2+i+1])
			continue;
		else
		{
			cout << "No" << endl;
			ret;
		}
	}
	for (int i = 0; i < s.size()-(s.size()+3)/2; i++)
	{
		if (s[i+(s.size()+3)/2-1] == s[s.size()-1-i])
			continue;
		else
		{
			cout << "No" << endl;
			ret;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, T; cin >> N >> T;
    vi c(N), t(N); REP(i, N) cin >> c[i] >> t[i];

    vi a;
    REP(i,N) {
        if (t[i] <= T) a.push_back(c[i]);
    }
    if (a.size() <= 0) {
        cout << "TLE" << endl;
        return 0;
    }
    sort(a.begin(), a.end());
    
    int ans = a[0];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<long> vl;
typedef vector<vector<long> > vvl;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

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

    if (N < 3) {
        cout << 0 << endl;
    } else {
        cout << N / 3 << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;

int main() {

    int n;
    cin >> n;

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

    vector<int> divisor;
    for ( int i=1; i<=max_t>>1; ++i ) {
	if ( max_t%i == 0 ) divisor.push_back( i );
    }
    divisor.push_back( max_t );

    int adj = 0;
    for ( int t : timing ) {
	for ( int d : divisor ) {
	    if ( d >= t ) {
		adj += d - t;
		break;
	    }
	}
    }

    cout << adj << endl;
    
    return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	char s;
	int N,r=0,b=0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> s;
		if (s == 'R')r++;
		else b ++;
	}
	cout << (r > b ? "Yes" : "No");
}


Measured memory_bytes: 256
n, m = map(int, input().split())

l = [list(map(int, input().split()))[1:] for _ in range(n)]

c = 0
for i in range(1, m+1):
    g = True
    for j in range(n):
        if i not in l[j][0:]:
            g = False
    if g:
        c = c + 1

print(c)

Measured memory_bytes: 3060
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#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 int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
int dp[5000];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n;
  cout << (n^1) << endl;

return 0;
}
///....


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
long long arr[1000];
int main()
{
	long long n,i,j;
	cin>>n;
	for(i=1;i<=9;i++)
	{
		for(j=1;j<=9;j++)
		{
			arr[i*j]=1;
		}
	}
	if (arr[n]==1)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

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

#define F first
#define S second

using namespace std;
typedef long double ld;
typedef long long ll;

const int max_n = 100011, inf = 1000111222;
const ll inff = 1000111222333444;

int n, a[max_n];
ll b[max_n];

int get_val(int i) {
    if (i >= 0 && i < n) return a[i];
    if (i < 0) return a[i + n];
    return a[i - n];
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0 && i + 1 < n) b[0] += a[i];
        else if (i % 2 == 1) b[1] += a[i];
    }
    for (int i = 2; i < n; ++i) {
        b[i] = b[i - 2] - a[i - 2] + get_val(i - 3);
    }
    for (int i = 0; i < n; ++i) {
        printf("%d ", int(sum - 2 * b[(i + 1) % n]));
    }
    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

long long lcm(long long a, long long b)
{
   return a * b / gcd(a, b);
}
int main() {
    long long a,b;cin>>a>>b;
    cout<<lcm(a,b)<<endl;
}

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

c = [500,100,50,10,5,1]

while True:
    n = int(input())
    if n == 0:
        break

    ch = 1000 - n
    ans = 0
    for i in range(6):
        num = int(ch / c[i])
        ans += num
        ch -= num * c[i]
    print(ans)



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

using namespace std;

#define int long long

using ll = long long;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)

#define rep(i,n) for_(i,0,n)
#define rrep(i,n) rfor_(i,0,n)

#define pb push_back
//#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

int H, W;

char c;

int a[26];
int t, u;

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

	cin>>H>>W;
	
	rep(i, H) {
		rep(j, W) {
			cin>>c;
			a[c-'a']++;
		}
	}

	if(H%2==0 && W%2==0) {
		rep(i, 26) {
			if(a[i]%4!=0) {
				cout<<"No"<<endl;
				return 0;
			}
		}
		cout<<"Yes"<<endl;
	}else if(H%2==0 || W%2==0) {
		rep(i, 26) {
			if(a[i]%2==1) {
				cout<<"No"<<endl;
				return 0;
			}else if(a[i]%4==2)u++;
		}
		if((H%2==0 && 2*u<=H) && (H-2*u)%4==0)cout<<"Yes"<<endl;
		else if((W%2==0 && 2*u<=W) && (W-2*u)%4==0)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}else {
		rep(i, 26) {
			if(a[i]%2==1) {
				if(t==0) {
					t++;
					if(a[i]%4==3)u++;
				}else {
					cout<<"No"<<endl;
					return 0;
				}
			}else if(a[i]%4==2)u++;
		}
		if(2*u<=(H+W-2) && (H+W-2-2*u)%4==0)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

		return 0;
	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;

int f(long long N)
{
  long long d = 2;
  long long ans = 0;
  while (1)
  {
    if (N % d <= d / 2 - 1)
    {
      ans += d / 2;
    }
  }
  return ans;
}
int main()
{
  int N;
  cin >> N;
  cout << N * 800 - (N / 15) * 200 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();


int main() {
  string S, T;
  cin >> S >> T;
  int last = -1;
  REP(i, S.size() - T.size() + 1) {
    bool flag = true;
    REP(j, T.size()) {
      if (S[i + j] != T[j] && S[i + j] != '?') flag = false;
    }
    if (flag) last = i;
  }
  if (last >= 0) {
    REP(j, T.size()) {
      S[last + j] = T[j];
    }
    REP(i, S.size()) {
      if (S[i] == '?') {
        S[i] = 'a';
      }
    }
    cout << S << endl;
  }
  else cout << "UNRESTORABLE" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long N, std::vector<long long> A, std::vector<long long> B){
    ll diff = 0;
    for(ll i=N-1; i>=0; i--){
        ll tmp = (A[i]+diff+B[i]-1)/B[i] * B[i];
        diff = tmp - A[i];
        A[i] = tmp;
    }
    cout << diff<<endl;
}

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


Measured memory_bytes: 1792
//108 correct B - Ruined Square 2018/09/01
#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;

int main(){
    int x1,x2,x3,x4,y1,y2,y3,y4;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx=x2-x1;
    int dy=y2-y1;
    x3=x2-dy; y3=y2+dx; x4=x1-dy; y4=y1+dx;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>

struct Node{
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node *find(Node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node * treeSuccessor(Node *x){
  if(x->right != NIL) return treeMinimum(x->right);
  Node *y = x->parent;
  while(y != NIL && x == y-> right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node *z){
  Node *y;
  Node *x;

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL){
    x = y->left;
  }else{
    x = y->right;
  }

  if(x != NIL){
    x->parent = y->parent;
  }

  if(y->parent == NIL){
    root = x;
  }else{
    if(y == y->parent->left){
      y->parent->left = x;
    }else{
      y->parent->right = x;
    }
  }

  if(y != z){
    z->key = y->key;
  }

  free(y);
}

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;
  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}

void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node *u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n, i, x;
  std::string com;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    std::cin >> com;
    if(com[0] == 'f'){
    scanf("%d",&x);
    Node *t = find(root, x);
    if(t != NIL) printf("yes\n");
    else printf("no\n");
  }else if(com == "insert"){
    scanf("%d",&x);
    insert(x);
  }else if(com == "print"){
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
  }else if(com == "delete"){
    scanf("%d",&x);
    treeDelete(find(root,x));
  }
}

return 0;
}



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

int main(int argc, char const *argv[])
{
	string in;
	while(cin>>in){
		bool flag=true;
		int sz=in.length();
		for (int i = 0; i < sz; i+=2)
		{
			if (in[i]=='L'||(in[i+1]=='R'))
			{
				printf("No\n");
				flag=false;
				break;
			}
		}
		if (flag)
		{
			printf("Yes\n");
		}
		
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main(void){
    // Your code here!
    int n,m;
    std::cin >> n >>m;
    std::priority_queue<int> que;
    for (int i = 0; i < n; i++) {
        int t;
        std::cin >> t;
        que.push(t);
    }
    
    
    for (int i = 0; i < m; i++) {
        int tmp=que.top()/2;
        que.pop();
        que.push(tmp);
        
    }
    
    long long int sum=0;
    while (!que.empty()) {
        sum+=que.top();
        que.pop();
    }
    std::cout << sum << std::endl;
}


Measured memory_bytes: 892
module DirectedGraph
  (* 道の表現 *)
  (Path : sig
    type t
    (* 辺の名前 *)
    type edge
    (* 長さ0の道 *)
    val nil : t
    (* 道の後ろに辺を付け足した道 *)
    val snoc : t -> edge -> t
  end) :
sig
  (* BFSにより，重みのないグラフの最短経路を求める *)
  val bfs :
    (* 頂点数（Hashtblを用いるので目安程度） *)
    int ->
    (* 辺の名前が付いた隣接リスト *)
    ('v -> ('v * Path.edge) list) ->
    (* 始点 *)
    'v ->
    (* 最短経路を返す関数 辿り着けなければNoneを返す） *)
    ('v -> Path.t option)
end = struct
  let rec bfs_aux es d frontier t =
    try Some (Hashtbl.find d t) with
    | Not_found ->
        match !frontier with
        | [] -> None
        | _ :: _ ->
            frontier := List.fold_right (fun u ->
              List.fold_right (fun (v, e) frontier ->
                if Hashtbl.mem d v
                then frontier
                else (Hashtbl.add d v (Path.snoc (Hashtbl.find d u) e); v :: frontier))
              (es u)) !frontier [];
            bfs_aux es d frontier t

  (*
   * 終点に辿り着いた時点で探索を切り上げるが，
   * 戻り値の関数を覚えておくと，途中まで探索した結果が再利用される
   * （#trace bfs_aux すると分かりやすい）
   *)
  let bfs n es s =
    let d = Hashtbl.create n in
    Hashtbl.add d s Path.nil;
    let frontier = ref [s] in
    bfs_aux es d frontier
end

(* 距離だけ欲しい場合 *)
module G = DirectedGraph (struct
  type t = int
  type edge = unit
  let nil = 0
  let snoc t _ = t + 1
end)

let () = Scanf.scanf "%d %d\n" @@ fun h w ->
  let ss = Array.init h @@ fun _ -> Scanf.scanf "%s\n" @@ fun s -> s in
  Printf.printf "%d\n" @@
  Array.fold_left (Array.fold_left max) min_int @@
  Array.init h @@ fun i ->
    Array.init w @@ fun j ->
      if ss.(i).[j] = '#' then min_int else
      let d =
        G.bfs (h * w) (fun (i, j) ->
          [(i - 1, j); (i + 1, j); (i, j - 1); (i, j + 1)]
          |> List.filter (fun (i, j) -> try ss.(i).[j] = '.' with _ -> false)
          |> List.map (fun v -> (v, ()))) (i, j) in
      Array.fold_left (Array.fold_left max) min_int @@
      Array.init h @@ fun i ->
        Array.init w @@ fun j ->
          match d (i, j) with
          | Some x -> x
          | None -> min_int


Measured memory_bytes: 6400
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

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

int p[1024];
int main(){
	int n,m;
	while(cin>>n>>m,n|m){
		int ret = 0;
		vector<int> v;
		rep(i,n)scanf("%d",&p[i]);
		p[n++] = 0;
		rep(i,n){
			for(int j=i; j<n; j++)if( p[i]+p[j]<=m ){
				v.push_back(p[i]+p[j]);
			}
		}
		sort(v.begin(),v.end());
		/*
		rep(i,v.size()){
			printf("%d\n",v[i]);
		}
		*/
		
		rep(i,n){
			for(int j=i; j<n; j++)if( p[i]+p[j]<=m ){
				int k = p[i]+p[j];
				int l = 0;
				int r = v.size()-1;
				while( l<r ){
					int mid = (l+r)/2 + 1;
					if( v[mid]+k > m ){
						r = mid - 1;
					}else{
						l = mid;
					}
				}
				ret = max(ret, k+v[l]);
			}
		}
		printf("%d\n",ret);
	}
	return 0;
}

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

int main(){
  int N,D,X;
  cin >>N>>D>>X;
  
  int ans = X;
  rep(i,0,N){
    int A;
    cin >>A;
    for(int j=1;j<D+1;j+=A) ans++;
  }
  
  cout <<ans<< endl;
}

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

#define fastIO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0);
#define endl '\n'
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MP make_pair
#define inf INT_MAX
#define minf INT_MIN

typedef long long int lli;

ofstream outfile;
ifstream infile;

int main()
{
	infile.open("input.txt");
	outfile.open("output.txt");

	lli a ;
	cin >> a;

	lli moves = (a/11)*2;
	a = a%11;
	if(!a)
		cout <<moves << "\n";
	else if(a <= 6)
		cout << moves+1 << "\n";
	else
		cout << moves+2 << "\n";
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
stepsum = 0
for i in range(n):
  if i and a[i-1] > a[i]:
    stepsum += a[i-1] - a[i]
    a[i] = a[i] + (a[i-1] - a[i])
print(stepsum)

Measured memory_bytes: 32232
#include<bits/stdc++.h>
using namespace std;
 int main(){
string str,ans;
int n;
cin >> n;
cin >> str;
if(n<str.size()){
for(int i=0;i<n;i++){
ans.push_back(str[i]);
}
for(int i=0;i<3;i++)ans.push_back('.');
}
else{
ans=str;
}
cout << ans;
}


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

int main(void){
    long n, m;
    cin >> n >> m;
    if(n<m){
        long t=m;
        m=n;
        n=t;
    }
    if(m>=2){
        cout << (n-2)*(m-2) << endl;
    }else if(n==1 && m==1){
        cout << 1 << endl;
    }else if(m==1){
        cout << n-2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a;
	cin >> a;
	cout << a + a * a + a * a*a << "\n";

	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
#define __int64 long long
const int M=1000000007;
ll ans,n;

map<P,ll>dp;

ll dfs(ll s,ll x){
	
	//cout<<s<<" "<<x<<endl;
	//if(x<=1&&s<=1)return 1;
	if(dp[mp(s,x)]>0)return dp[mp(s,x)];
	if(x==0&&s==0)return dp[mp(s,x)]=1;

	ll ret=0;
	ret+=dfs(s/2,x/2);
	if(s>=1&&x>=1)ret+=dfs((s-1)/2,(x-1)/2)%M;
	if(s>=2)ret+=dfs((s-2)/2,x/2)%M;

	return dp[mp(s,x)]=ret%M;
}
int main(){
	cin>>n;
	

	cout<<dfs(n,n)<<endl;

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


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

using namespace std;

const int maxn = 1e5;
int n, h[maxn], a[maxn];

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    a[0] = 0; a[1] = abs(h[1]-h[0]);
    for (int i = 2; i < n; i++) {
        a[i] = min(abs(h[i]-h[i-1])+a[i-1],abs(h[i]-h[i-2])+a[i-2]);
    }
    cout << a[n-1] << '\n';
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//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) LL((a).size())
#define EACH(i,c) for(auto 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,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

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

    int r;
    cin>>r;
    printf("%.9f", 2 * PI * r);
}

Measured memory_bytes: 3780
#include <cstdio>

long long int abs(long long int x) {
    return ((x > 0) ? x : -x);
}

int main() {
    long long int n, t, planned = 0;
    scanf("%lld", &n);
    int *a = new int[n+2];
    a[0] = 0;
    a[n+1] = 0;
    for (long long int i = 1; i <= n; i++) {
        scanf("%lld", &t);
        a[i] = t;
        planned += abs(a[i] - a[i-1]);
    }
    planned += abs(a[n]);

    for (long long int i = 1; i <= n; i++) {
        printf("%lld\n", (planned - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i-1] - a[i+1])));
    }

    delete[] a;

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  int coin = 0;
  cin >> a;
  cin >> b;
  if (a > b) {
    coin += a;
    a--;
  } else {
    coin += b;
    b--;
  }
  if (a > b) {
    coin += a;
    a--;
  } else {
    coin += b;
    b--;
  }
  cout << coin << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
  int N,D;
  scanf("%d %d",&N,&D);
  int s=N/(2*D+1);
  int t=N%(2*D+1);
  if(t==0){
    printf("%d",s);
  }
  else{
    printf("%d",s+1);
  }
  return 0;
}

Measured memory_bytes: 1724
#include<cstring>
#include<cstdio>
#include<cmath>
#include<memory.h>
#include<algorithm>
#include<map>
#define ll long long
#define ld long double
#define maxn 310
#define For(i,j,k)  for(ll i=j;i<=k;++i)
#define FOr(i,j,k)  for(ll i=j;i>=k;--i)
const ll inf=1e9;
const ld eps=1e-7;
using namespace std;
inline ll read(){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; }
inline void wrote(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) wrote(x/10);   putchar(x%10+'0');  }
void writeln(ll x){ wrote(x);   puts("");   }
const ll N=100100,mod=1e9+7;
ll mark[N];
int main(){
	ll answ=1,n=read();
	For(i,2,n)	if (!mark[i]){
		ll ans=0;
		for(ll j=i;j<=n;j+=i){
			for(ll t=j;t%i==0;t/=i)	ans++;
			mark[j]=1;
		}
		answ=answ*(ans+1)%mod;
	}writeln(answ);
}

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

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    int l, r, d;
    cin >> l >> r >> d;
    cout << r / d - (l - 1) / d << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    int n = 0;
    if(b<=9){
        n = 10*a+b;
    }else if(b<=99){
        n = 100*a+b;
    }else{
        n = 1000*a+b;
    }
    bool flag = false;
    for(int i=1; i<=sqrt(n); i++){
        if(i*i==n){
            flag = true;
            break;
        }
    }
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ll long long int
#define F first
#define S second
#define MAX(x,y) (x)>(y)?(x):(y)
#define MIN(x,y) (x)<(y)?(x):(y)
#define REP(i,n) for(i=0;i<(n);i+=1)
#define REPr(i,n) for(i=n-1;i>=0;i-=1)
#define REP1(i,n) for(i=1;i<=n;i+=1)

typedef vector<ll> vll;
typedef set<int>::iterator sit;
typedef unordered_set<int>::iterator usit;
typedef multiset<int>::iterator msit;
typedef unordered_multiset<int>::iterator umsit;
typedef vector<ll>::iterator vllit;

//cin.ignore(numeric_limits<streamsize>::max(),'\n');

const int N = 100001;

ll dp[N];
int h[N],n,i;

void solve(){
    dp[2] = dp[1] + abs(h[2]-h[1]);
    for(i=3;i<=n;i+=1){
        dp[i] = min(dp[i-1]+ abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp, 0, sizeof(dp));
    dp[0] = -10000000;
    dp[1] = 0;
    cin>>n;
    REP(i,n){
        cin>>h[i+1];
    }
    solve();
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1408
K=int(input())
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[K-1])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n)+1) : 1)
#define mem(x, val)    memset(x, val, sizeof(x))
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string str;
typedef pair<int, int> pii;


int main()
{
    THINK_TWICE_CODE_ONCE
    //freopen("test cases\\.txt", "r", stdin) ;
    string a, b, c; cin>>a>>b>>c;
    int x = a.size(), y = b.size(), z = c.size();
    bool b1 = 1, b2 = 0, b3 = 0;
    int i =0, j = 0, k = 0;
      for( ; ; ){
        if(b1){
            if(i==x) return cout<<"A", 0;
            if(a[i]=='b') b1 = 0, b2 = 1;
            else if(a[i]=='c') b1 = 0, b3 = 1;
            i++;
        }else if(b2){
            if(j==y) return cout<<"B", 0;
            if(b[j]=='a')b1 = 1, b2 = 0;
            else if(b[j]=='c') b2 = 0, b3 = 1;
            j++;
        }else{
            if(k==z) return cout<<"C", 0;
            if(c[k]=='a')b1 = 1, b3 = 0;
            else if(c[k]=='b')b2 = 1, b3 = 0;
            k++;
        }
    }

	return 0;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#include<iostream>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
#define VI vector<int>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=2050005;
const int MAXV=12;
int bin[15];
int n,m,ans[MAXN];
struct Trie
{
	int son[MAXN][3],tot,root;
	int val[MAXN];
	bool rev[MAXN];
	void insert(int v)
	{
		int p=root;
		for(int i=0;i<=n-1;i++)
		{
			int c=v/bin[i];c%=3;
			if(!son[p][c])son[p][c]=++tot;
			p=son[p][c];
		}val[p]=v;
	}
	void down(int p)
	{
		if(!rev[p])return ;
		swap(son[p][1],son[p][2]);
		rev[son[p][0]]^=1;rev[son[p][1]]^=1;rev[son[p][2]]^=1;rev[p]=0;
	}
	void addone(int p,int dep)
	{
		if(dep==0)return ;
		down(p);int a=son[p][0],b=son[p][1],c=son[p][2];
		son[p][0]=c;son[p][1]=a;son[p][2]=b;
		addone(son[p][0],dep-1);
	}
	void getans(int p,int dep,int nowp)
	{
		if(dep==n){ans[val[p]]=nowp;return ;}
		down(p);
		getans(son[p][0],dep+1,nowp);
		getans(son[p][1],dep+1,nowp+bin[dep]);
		getans(son[p][2],dep+1,nowp+2*bin[dep]);
	}
}tr;
char ch[MAXN];
int main()
{
	#ifdef Rose
		double BeginJudgeTime=clock();
	#endif
	bin[0]=1;for(int i=1;i<15;i++)bin[i]=bin[i-1]*3;
	n=read();
	scanf("%s",ch+1);m=strlen(ch+1);
	tr.tot=tr.root=1;
	for(int i=0;i<bin[n];i++)
		tr.insert(i);
	for(int i=1;i<=m;i++)
	{
		if(ch[i]=='S')tr.rev[1]^=1;
		else tr.addone(1,n);
	}
	tr.getans(1,0,0);
	for(int i=0;i<bin[n];i++)pr1(ans[i]);
	puts("");
	#ifdef Rose
		double EndJudgeTime=clock();
		cerr<<"JudgeTime is"<<" ";
		cerr<<(EndJudgeTime-BeginJudgeTime)/CLOCKS_PER_SEC<<endl;
	#endif
	return 0;
}


Measured memory_bytes: 15376
#include <bits/stdc++.h>
using namespace std;
int dp[100001];
vector<int> edges[100001];
int path(int s){
    if(dp[s] != -1)
    return dp[s];
    int temp=0;
    for(int a : edges[s]){
        temp=max(temp, path(a));
    }
    dp[s] = temp + 1;
    return dp[s];
    
}


int main() {
    int n,m;
    cin>>n>>m;
    int a,b;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        edges[a].push_back(b);
    }
    // dp[i] longest path till i node;
    memset(dp, -1 ,sizeof(dp));
    int ans =0;
    for(int i=1;i<=n;i++){
        ans = max(ans, path(i));
    }
	cout<<ans-1;
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<string> S(N);
    rep(i, N) cin >> S[i];
    map<string, ll> cnt;
    rep(i, N) {
        string s = S[i];
        cnt[s]++;
    }
    vector<pair<ll, string>> items;
    for (auto x: cnt) {
        items.push_back({-x.second, x.first});
    }
    sort(items.begin(), items.end());
    ll last = -1;
    for (auto x: items) {
        if (last == -1) {
            cout << x.second << '\n';
        }else{
            if (last == x.first) {
                cout << x.second << '\n';
            }else{
                break;
            }
        }
        last = x.first;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 29552
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String length = String.valueOf(s.length() -2);
        System.out.println(s.charAt(0) + length + s.charAt(Integer.parseInt(length) + 1));
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long H,W;
    cin>>H>>W;
    long long ans = H*W;
    if(H==1 || W==1) cout<<1;
    else if(ans%2 == 1) cout<<ans/2 +1;
    else cout<<ans/2;

}


Measured memory_bytes: 256
#N = int(input())
S = str(input())
#A, B = map(int, input().split())
#C = list(map(int, input().split()))

if S == "SSS":
  print(0)
elif S == "RRR":
  print(3)
elif S in ["RSS", "SRS", "SSR", "RSR"]:
  print(1)
else:
  print(2)







Measured memory_bytes: 61608
#include <iostream>

using namespace std;
typedef long long ll;
const int MAXN = 510;

int n;
int s[MAXN], c[MAXN], f[MAXN];

ll getTime(int x) {
  if (x == n - 1) {
    return 0;
  }
  ll cur = 0;
  for (int i=x;i<n-1;i++) {
    ll next = s[i];
    while (next < cur) {
      next += f[i];
    }
    cur = next + c[i];
  }
  return cur;
}

void solve() {
  for (int i=0;i<n;i++) {
    cout << getTime(i) << endl;
  }
}

int main() {
  cin >> n;
  for (int i=0;i<n-1;i++) {
    cin >> c[i] >> s[i] >> f[i];
  }
  solve();
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace
import qualified Data.Set as S

getInts :: IO [Integer]
getInts = map (fst . fromJust . B.readInteger) . B.words <$> B.getLine

inf = 10000000000
solve n as = snd $ foldl f zero as
  where
    dr = snd $ foldl (\(mn,d) x -> (min mn x, max d (x-mn))) (inf,0) as
    zero = (S.empty, 0)
    f (s,a) x = (S.insert x s, a + if (x-dr) `S.member` s then 1 else 0)


main = do
  [n,t] <- getInts
  as <- getInts
  print $ solve n as


Measured memory_bytes: 161148
import Control.Monad

solve :: [String] -> (Int, Int)
solve xs = foldl (\a ws -> f ws a) (0, 0) $ map words xs
    where
        f [s, t] (x, y)
            | s < t     = (x,     y + 3)
            | t < s     = (x + 3, y    )
            | otherwise = (x + 1, y + 1)

main :: IO ()
main = do
    n  <- readLn
    ss <- replicateM n getLine
    let (x, y) = solve ss
    putStrLn (show x ++ " " ++ show y)

Measured memory_bytes: 4536
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

void solve(int D, double E){
  double res = 1000;
  for(int i=0;i<=D;i++){
    res = min(res, abs(sqrt(i*i+(D-i)*(D-i))-E));
  }
  cout << res << endl;
}

int main(){
  int D;  double E;
  while(cin >> D >> E, D && E)
    solve(D, E);
  return 0;
}

Measured memory_bytes: 3236
ll = [list(map(int,input().split())) for _ in range(int(input()))]
ll.sort(key=lambda k:k[2],reverse=1)
x,y,h = ll[0]
for cx in range(101):
  for cy in range(101):
    ch = h+abs(x-cx)+abs(y-cy)
    for x,y,h in ll:
      if max(ch-abs(x-cx)-abs(y-cy),0) != h:
        break
    else:
      print(cx,cy,ch)
      break
  else:
    continue
  break

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

int main(){
    int iN,iM;
    std::string s;
    std::map<std::string,int> dM;
    std::cin >> iN;
    for(int i=0;i<iN;i++){
        std::cin >> s;
        dM[s]++;
    }
    std::cin >> iM;
    for(int i=0;i<iM;i++){
        std::cin >> s;
        dM[s]--;
    }
    int iMax = 0;
    for(std::pair<std::string,int> o : dM){
        iMax = std::max(iMax,o.second);
    }
    std::cout << iMax << std::endl;
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n;
    cin>>n;
    vi p(n);
    rep(i,n){
        cin>>p[i];
    }
    lli ans=0;
    for(lli i=1;i<n-1;i++){ 
        if (p[i]!=max(p[i], max(p[i+1], p[i-1]))&&p[i]!=min(p[i], min(p[i+1], p[i-1]))){ 
            ans++;
        }
    }
    out(ans);
}

Measured memory_bytes: 3568