akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  string s;
  cin >> s;

  deque<char> d;
  REP(i, s.length()) d.push_back(s[i]);

  int ans = 0;
  while(!d.empty()){
    if(d.back() == d.front()){
      d.pop_back();
      if(!d.empty()) d.pop_front();
    }
    else{
      if(d.back() == 'x'){
        ans++;
        d.push_front('x');
      }
      else if(d.front() == 'x') {
        ans++;
        d.push_back('x');
      }
      else{
        cout << -1 << endl;
        return 0;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

typedef  int64_t llong;
llong mod(llong a, llong b) {
  llong res = a % b;
  if (res < 0) {
    return res + b;
  } else {
    return res;
  }
}

      



int main() {
  int n;
  cin >> n;
  vector<llong> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  llong s1 = 0;
  llong s2 = 0;
  llong modulus = 1000'000'000 + 7;
  for (int i = 0; i < n; ++i) {
    s1 = mod(s1 + a[i], modulus);
    s2 = mod(s2 + mod(a[i]*a[i], modulus), modulus);
  }

  llong ans = mod(s1*s1, modulus);
  ans = mod(ans - s2, modulus);

  llong half = (modulus + 1) / 2;

  ans = mod(ans*half, modulus);
    

  cout << ans << endl;
  
}


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

using namespace std;

#define PB push_back
#define SZ(a) (int)a.size()
#define MP make_pair

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;

int main() {

	ll a;
	int b1, b2;

	scanf("%lld %d.%d", &a, &b1, &b2);

	printf("%lld\n", (a*(b1*100 + b2))/100);

	return 0;
}


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

typedef pair<int, int> Data;
typedef pair<Data, Data> Pair;

int M;
int T;
int P;
int R;
int teams[114514];
int penalty[114514];
int correct[114514];
int wrong[1145][1419];
Pair ps[114514];

bool CompareScore(int a, int b) {
  if (correct[a] != correct[b]) return correct[a] > correct[b];
  if (penalty[a] != penalty[b]) return penalty[a] < penalty[b];
  return false;
}

bool Compare(int a, int b) {
  if (correct[a] != correct[b]) return correct[a] > correct[b];
  if (penalty[a] != penalty[b]) return penalty[a] < penalty[b];
  return a > b;
}

int main() {
  while (1) {
    scanf("%d%d%d%d", &M, &T, &P, &R);
    if ((M|T|P|R) == 0) return 0;

    for (int i=0; i<T; i++) teams[i] = i+1;
    fill(wrong[0], wrong[114], 0);
    fill(penalty, penalty+114, 0);
    fill(correct, correct+114, 0);

    for (int i=0; i<R; i++) {
      int m, t, p, ji;
      scanf("%d%d%d%d", &m, &t, &p, &ji);
      ps[i] = Pair(Data(m, -ji), Data(t, p));
    }
    sort(ps, ps+R);
  
    for (int i=0; i<R; i++) {
      Pair pa = ps[i];
      Data d1 = pa.first;
      Data d2 = pa.second;
      int m = d1.first;
      int ji = -d1.second;
      int t = d2.first;
      int p = d2.second;
  
      if (ji != 0) {
        wrong[t][p]++;
      } else {
        correct[t]++;
        penalty[t] += m + 20*wrong[t][p];
      }
    }
  
    sort(teams, teams+T, Compare);
    printf("%d", teams[0]);
    for (int i=1; i<T; i++) {
      if (!CompareScore(teams[i-1], teams[i])) printf("=");
      else printf(",");
      printf("%d", teams[i]);
    }
    puts("");
  }
}

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

int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	char tmp;
	int count = 0;
	bool white = false;
	cin >> tmp;
	white = tmp == 'W';
	while(cin >> tmp)
	{
		if((tmp == 'W' )^white)
		{
			count++;
		}
		white = tmp == 'W';
	}
	cout << count << '\n';
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll A, B, N;
    cin >> A >> B >> N;
    ll ans = 0;
    if (N < B) {
        ans = (A * N) / B - A * (N / B);
    }
    else {
        ans = (A * (B - 1)) / B;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3596
n = int(input())
p = list(map(int,input().split()))
p1 = sorted(p)
#print(p1)
count = 0
for i in range(len(p)):
  if p[i] != p1[i]:
    count += 1
  else:
    continue
#print(count)
if count == 2 or count == 0:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

ll MAX = LLONG_MAX;

int main()
{

  int k;
  cin >> k;

  bool judge = false;
  int ans;
  ll num = 7;
  ll rem;

  if (k % 2 != 0)
  {
    for (int i = 1; i <= 100000000; i++)
    {
      rem = num % k;

      if (rem == 0)
      {
        judge = true;
        ans = i;
        break;
      }

      num = rem * 10 + 7;
    }
  }

  if (judge)
    cout << ans << endl;
  else
    cout << -1 << endl;
}


Measured memory_bytes: 3644
//													\[T]/ Praise
//													 (*)  The
//													 / \  Sun



#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double dbl;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<long long> vl;
typedef vector< pair<int, int> > vii;
#define mp make_pair
#define pb push_back
#define invec(a, n) for(ll i = 0; i < n; i++) {cin >> a[i];}
#define rep(n) for(ll i = 0; i < n; i++)
#define fr(i,j,k) for(ll i = j; i < k; i++)
#define FR(i,j,k) for(ll i = j; i >= 0; i--)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define INF 1000000
#define xx first
#define yy second

void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

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

	ll dp[h+1][w+1];
	char a[h+1][w+1];
	fr(i,0,h+1)
		fr(j,0,w+1)
			dp[i][j] = 0;

	fr(i,1,h+1)
		fr(j,1,w+1)
			cin >> a[i][j];


	dp[1][1] = 1;

	fr(i,1,h+1)
	{
		fr(j,1,w+1)
		{
			if(i == 1 && j == 1)
				continue;

			if(a[i][j] == '.')
				dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % MOD;

		}
	}

	cout << dp[h][w];
}

Measured memory_bytes: 9088
//IOI 2021

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

int n, t;
ll ans;
multiset<int> ms;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i =1 ; i <= 3 * n; i++)
		cin >> t, ms.insert(t);
	while (ms.size()) {
		ms.erase(ms.begin());
		auto itr = ms.end();
		--itr;
		ms.erase(itr);
		itr = ms.end();
		--itr;
		ans += *itr;
		ms.erase(itr);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <math.h>

using namespace std;

int main(int argc, char const* argv[])
{
	double a,b,c,n;

	cin >> n;

	for( int i = 0;i < n;i++ ){
		cin >> a >> b >> c;

		if( a == sqrt( b * b + c * c ) || b == sqrt( a * a + c * c ) || c == sqrt( a * a + b * b ) ) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;

}

Measured memory_bytes: 0
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
#define ll long long;
#define MAX 200005;
int main(){
    int a; string s;
    cin >> a >> s;
    if(a >= 3200) cout << s;
    else cout << "red";
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
typedef pair<int, int> P;
vector<int> G[200000];
bool vis[200000];
void dfs(int v) {
	vis[v] = 1;
	rep(i, G[v].size()) {
		if (vis[G[v][i]]) continue;
		dfs(G[v][i]);
	}
}
int main() {
	int N, M;
	cin >> N >> M;
	rep(i, N) {
		int K;
		cin >> K;
		rep(j, K) {
			int L;
			cin >> L;
			L--;
			G[i].push_back(N + L);
			G[N + L].push_back(i);
		}
	}
	dfs(0);
	rep(i, N) {
		if (!vis[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

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


using namespace std;





int main(){
  int d;
  cin >> d; 
 
 if(d==22){
cout<<"Christmas Eve Eve Eve"<<endl;
   }
   else if(d==23){

cout<<"Christmas Eve Eve"<<endl;
	 }
	  else if(d==24){

cout<<"Christmas Eve"<<endl;
	   }
	   else if(d==25){
cout<<"Christmas"<<endl;

		 }



}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;
vector<pair<int, ll>> graph[MAX_N];

int color[MAX_N];

void coloring(int first_color) {
  color[1] = first_color;

  queue<int> que;
  que.push(1);

  while (!que.empty()) {
    int cur_node = que.front();
    que.pop();

    for (auto next: graph[cur_node]) {
      int next_node = next.first;
      ll next_cost = next.second;

      if (color[next_node] >= 0) continue;

      color[next_node] = (next_cost % 2 == 0) ? color[cur_node] : (color[cur_node] + 1) % 2;

      que.push(next_node);
    }
  }
}

void reset() {
  for (int i = 0; i <= n; ++i) {
    color[i] = -1;
  }
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n - 1; ++i) {
    int from, to;
    ll w;

    scanf("%d %d %lld", &from, &to, &w);

    graph[from].push_back(make_pair(to, w));
    graph[to].push_back(make_pair(from, w));
  }

  reset();

  coloring(1);

  for (int i = 1; i <= n; ++i) {
    printf("%d\n", color[i]);
  }

  return 0;
}


Measured memory_bytes: 8320
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


class WeightedUnionFind:
    def __init__(self, node: int) -> None:
        self.n = node
        self.par = [i for i in range(self.n)]
        self.rank = [0 for i in range(self.n)]
        self.diff_weight = [0 for i in range(self.n)]

    # ノードxのルートを求める
    def find(self, x: int) -> int:
        if x == self.par[x]:
            return x
        else:
            r = self.find(self.par[x])
            self.diff_weight[x] += self.diff_weight[self.par[x]]
            self.par[x] = r
            return self.par[x]

    # ノードxのルートからの距離を求める
    def weight(self, x: int) -> int:
        self.find(x)
        return self.diff_weight[x]

    # weight(y) - weight(x) = w となるようにする
    def unite(self, x: int, y: int, w: int) -> bool:
        if self.isSame(x, y):
            # print("x and y has already united")
            return False

        w += self.weight(x)
        w -= self.weight(y)

        rx = self.find(x)
        ry = self.find(y)

        if self.rank[rx] < self.rank[ry]:
            rx, ry = ry, rx
            w = -w

        self.par[ry] = self.par[rx]
        self.diff_weight[ry] = w

        if self.rank[rx] == self.rank[ry]:
            self.rank[rx] += 1

        return True

    def isSame(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)

    def diff(self, x: int, y: int) -> int:
        if self.isSame(x, y):
            return self.weight(y) - self.weight(x)
        else:
            raise ValueError("xとyは同じ木に属していません")


def judge(wuf, state):
    for l, r, d in state:
        if wuf.diff(l, r) != d:
            return False

    return True


n, m = li()
wuf = WeightedUnionFind(n)

lrd = []

for _ in range(m):
    l, r, d = li()
    l -= 1
    r -= 1

    lrd.append((l,r,d))

    wuf.unite(l, r, d)

print("Yes" if judge(wuf, lrd) else "No")

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

using namespace std;

void solve()
{
	int X, A, B;
	cin >> X >> A >> B;
	if (A >= B)
	{
		cout << "delicious" << endl;
	}
	else
	{
		if (X + A < B)
		{
			cout << "dangerous" << endl;
		}
		else
		{
			cout << "safe" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

int main()
{
    int K,A,B;
    cin >> K >> A >> B;
    for(int i=A;i<=B;i++)
    {
        if(i%K==0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3592
def equal_range(li, x):
    """Returns a pair of indices (lower_bound, upper_bound).

    >>> equal_range([1, 2, 2, 3], 0)
    (0, 0)
    >>> equal_range([1, 2, 2, 3], 1)
    (0, 1)
    >>> equal_range([1, 2, 2, 3], 2)
    (1, 3)
    >>> equal_range([1, 2, 2, 3], 3)
    (3, 4)
    >>> equal_range([1, 2, 2, 3], 4)
    (4, 4)
    >>> equal_range([2, 2, 2, 2], 2)
    (0, 4)
    """
    def is_lower_bound(i):
        if i == 0:
            return li[i] >= x
        elif i == len(li):
            return li[i-1] < x
        else:
            return (li[i-1] < x and li[i] >= x)

    def is_upper_bound(i):
        if i == 0:
            return li[i] > x
        elif i == len(li):
            return li[i-1] <= x
        else:
            return (li[i-1] <= x and li[i] > x)

    def find_lower(i, j):
        if i == j:
            return i
        mid = i + (j - i) // 2
        if li[mid] >= x:
            return find_lower(i, mid)
        else:
            return find_lower(mid+1, j)

    def find_upper(i, j):
        if i == j:
            return i
        mid = i + (j - i) // 2
        if li[mid] > x:
            return find_upper(i, mid)
        else:
            return find_upper(mid+1, j)

    def search(lo, hi):
        if is_lower_bound(lo) and is_upper_bound(hi):
            return (lo, hi)

        mid = lo + (hi - lo) // 2
        if li[mid] > x:
            return search(lo, mid)
        elif li[mid] < x:
            return search(mid+1, hi)
        else:
            lo = find_lower(lo, mid)
            hi = find_upper(mid+1, hi)
            return search(lo, hi)

    return search(0, len(li))


def run():
    n = int(input())
    a = [int(x) for x in input().split()]
    assert(n == len(a))

    q = int(input())
    for _ in range(q):
        k = int(input())
        x, y = equal_range(a, k)
        print("{} {}".format(x, y))


if __name__ == '__main__':
    run()



Measured memory_bytes: 17112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll num[200005]={0},goal[200005]={0};
int main(){
  ll n;
  cin>>n;
  priority_queue<P> pque;
  for(int i=0;i<n;i++) cin>>goal[i];
  for(int i=0;i<n;i++) cin>>num[i];
  for(int i=0;i<n;i++){
    ll pas=(i+n-1)%n,nxt=(i+1)%n;
    if(num[pas]+num[nxt]<num[i]&&goal[i]!=num[i]) pque.push(P(num[i],i));
  }
  ll ans=0;
  while(!pque.empty()){
    P p=pque.top();
    pque.pop();
    ll val=p.first,pos=p.second;
    ll pas=(pos+n-1)%n,nxt=(pos+1)%n;
    ll wk=num[pas]+num[nxt];
    if((val-goal[pos])%wk==0) {
      num[pos]=goal[pos];
      ans+=(val-goal[pos])/wk;
      ll nnxt=(pos+2)%n;
      if(goal[nxt]!=num[nxt]&&num[pos]+num[nnxt]<num[nxt]) pque.push(P(num[nxt],nxt));

      ll ppst=(pos+n-2)%n;
      if(goal[pas]!=num[pas]&&num[pos]+num[ppst]<num[pas]) pque.push(P(num[pas],pas));
    }
    else{
      ll nval=val%wk;
      ans+=val/wk;
      if(nval<goal[pos]){
        cout<<-1<<endl;
        return 0;
      }
      else{
        num[pos]=nval;

        ll nnxt=(pos+2)%n;
        if(goal[nxt]!=num[nxt]&&num[pos]+num[nnxt]<num[nxt]) pque.push(P(num[nxt],nxt));

        ll ppst=(pos+n-2)%n;
        if(goal[pas]!=num[pas]&&num[pos]+num[ppst]<num[pas]) pque.push(P(num[pas],pas));
      }
    }
  }
  for(int i=0;i<n;i++){
    if(num[i]!=goal[i]) {
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5620
#include<cstdio>
int N,M,A[110],a[110],b[110],n;
void ins(int x){if(x)b[n++]=x;}
int main(){
	scanf("%d%d",&N,&M);
	int os[2],oc=0;
	for(int i=0;i<M;i++){
		scanf("%d",A+i);
		if(A[i]%2){
			if(oc>1)return puts("Impossible"),0;
			os[oc++]=A[i];
		}
	}
	if(oc<2){
		a[0]=os[0];
		for(int i=0;i<M;i++)if(A[i]%2==0)a[oc++]=A[i];
		for(int i=0;i<M;i++)ins(a[i]-!i);
		ins(1);
	}
	else{
		a[0]=os[0];a[M-1]=os[--oc];
		for(int i=0;i<M;i++)if(A[i]%2==0)a[oc++]=A[i];
		for(int i=0;i<M;i++)ins(a[i]-!i+(i==M-1));
	}
	for(int i=0;i<M;i++)printf("%d%c",a[i]," \n"[i==M-1]);
	printf("%d\n",n);
	for(int i=0;i<n;i++)printf("%d%c",b[i]," \n"[i==n-1]);
}

Measured memory_bytes: 128
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val num = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    if(!solve(num)) {
        println(-1)
    }
}

fun solve(num:MutableList<Int>):Boolean {
    val list = mutableListOf<Int>()
    for(i in (0 until 100)) {
        var idx = -1
        for(j in (num.indices.reversed())) {
            if(j + 1 == num[j]) {
                idx = j
                break
            }
        }
        if(idx < 0) {
            return false
        }
        list.add(idx+1)
        num.removeAt(idx)
        if(num.isEmpty()) {
            break
        }
    }
    list.reversed().forEach { println(it) }
    return true
}

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

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

  int a[n][2];
  int c[m][2];

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

  for (int i=0; i<m; i++) {
    cin >> c[i][0] >> c[i][1];
  }

  for (int i=0; i<n; i++) {
    int min = abs(a[i][0] - c[0][0]) + abs(a[i][1] - c[0][1]);
    int ans = 0;
    for (int j=1; j<m; j++) {
      if (min > abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])) {
        min = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1]);
        ans = j;
      }
    }
    cout << ans+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <bitset>
#include <utility>
#include <ctime>
#include <cassert>
#include <climits>

using namespace std;

#define TRACE
 
#ifdef TRACE
template<class T, class U>
ostream& operator<<(ostream& out, const pair<T,U>& a){out<<"["<<a.first<<" "<<a.second<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const vector<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const set<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const multiset<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T,class U>
ostream& operator<<(ostream& out, const map<T,U>& a){for(auto &it:a)out<<it.first<<" -> "<<it.second<<" | ";return out;}
template<class T,class U>
ostream& operator<<(ostream& out, const multimap<T,U>& a){for(auto &it:a)out<<it.first<<" -> "<<it.second<<" | ";return out;}
#define pra(a,n) cerr<<#a<<" : ";for(int i=0;i<n;++i)cerr<<a[i]<<" ";cerr<<endl;
#define praa(a,n,m) cerr<<#a<<" : "<<endl;for(int i=0;i<n;++i){for(int j=0;j<m;++j)cerr<<a[i][j]<<" ";cerr<<endl;}
#define pr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
} 
#else
#define pr(...)
#define pra(a,n)
#define praa(a,n,m)
#endif

void Main()	{
	int n;
	cin >> n;

	vector<long long> a(n), b(n);
	for(int i = 0; i < n; i++)	{
		cin >> a[i] >> b[i];
	}

	long long ans = 0, inc = 0;
	for(int i = n - 1; i >= 0; i--)	{
		a[i] += inc;
		int tinc = (b[i] - a[i] % b[i]) % b[i];
		ans += tinc;
		inc += tinc;
	}

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

int main()	{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("", "r", stdin);
	//freopen("", "w", stdout);
	Main();
}



























Measured memory_bytes: 1792
import java.io.PrintWriter
import java.util.*

var n: Int = 0
var s: Array<String> = Array(0){""}

fun main(args: Array<String>) = IO().exec {
    n = int()
    s = Array(n){string()}
    println((0 until n).map { isSyn(it) }.count { it } * n)
}

fun isSyn(sx: Int): Boolean {
    for (y in n) for (x in n)
        if (s[y][(x + sx) % n] != s[x][(sx + y) % n]) return false
    return true
}

operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = System.`in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double {
        return string().toDouble()
    }
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}

Measured memory_bytes: 34044
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi>b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    int n,h,w;cin>>n>>h>>w;
    cout<<(n-h+1)*(n-w+1)<<endl;
    //-------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


















































Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 1 << 18;
const int N = 1100;
const int L = 10;

int lvl[MAX];
vector <pii> pre[N];
vector <pii> a;
void rec(int x, int l, vector <pii> v)
{	
	if(x >= a.size()) return;
	v.pb({a[x].f, a[x].s});
	if(l == L) {
		for(int i = 0; i < (1 << L); i++) {
			int ww = 0, vv = 0;
			for(int j = 0; j < L; j++) {
				if((1 << j) & i) {
					ww += v[j].s;
					vv += v[j].f; 
				}
			}
			if(ww <= (int)1e5)
			pre[x].pb({ww, vv});
		}
		sort(all(pre[x]));
		for(int i = 1; i < pre[x].size(); i++)
		pre[x][i].s = max(pre[x][i].s, pre[x][i - 1].s);
		return;
	}
	rec(2 * x, l + 1, v);
	rec(2 * x + 1, l + 1, v);
}
int main()
{
	boost;
	int n, q, x, y, i;
	cin >> n;
	a.pb({0, 0});
	
	lvl[1] = 1;
	foe(i, 2, n)
	lvl[i] = lvl[i / 2] + 1;
	
	foe(i, 1, n) {
		cin >> x >> y;
		a.pb({x, y});
	}
	rec(1, 1, {});
	cin >> q;
	while(q--) {
		int val, W;
		cin >> val >> W;
		vector <int> v;
		int ans = 0;
		if(lvl[val] < L) {
			do {
				v.pb(val);
				val /= 2;
			} while(val);
			
			int x = v.size();
			for(int i = 0; i < (1 << x); i++) {
				int ww = 0, vv = 0;
				for(int j = 0; j < x; j++) {
					if((1 << j) & i) {
						ww += a[v[j]].s;
						vv += a[v[j]].f;
					}
				}
				if(ww <= W) ans = max(ans, vv);
			}
		}
		else {
			while(lvl[val] > L) {
				v.pb(val);
				val /= 2;
			}
			int node = val;
			int x = v.size();
			for(int i = 0; i < (1 << x); i++) {
				int ww = 0, vv = 0;
				for(int j = 0; j < x; j++) {
					if((1 << j) & i) {
						ww += a[v[j]].s;
						vv += a[v[j]].f;
					}
				}
				if(ww <= W) {
					pii p = {W - ww, inf};
					ans = max(ans, vv);
					int ind = upper_bound(all(pre[node]), p) - pre[node].begin();
					--ind;
					if(ind >= 0) ans = max(ans, vv + pre[node][ind].s); 
				}
			}
		}
		cout << ans << '\n';
	}
}


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

int main(int argc, char const* argv[])
{
	char c;
	vector<char> vc;
	while (cin >> c) {
		vc.push_back(c);
	}
	for (int i = vc.size() - 1; i >= 0; --i) {
		cout << vc[i];
	}
	cout << endl;
	return 0;
}

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

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 4e10;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

int n,m;
ll a[200010],b[200010];

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

  int q;
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int j = 1; j <= m; j++) cin >> b[j];

  a[0] = -INF;
  b[0] = -INF;
  a[n+1] = INF;
  b[m+1] = INF;
  while (q--) {
    ll la, lb, ra, rb;
    ll x;
    cin >> x;
    la = a[upper_bound(a,a+n+2,x) - a - 1];
    ra = a[lower_bound(a,a+n+2,x) - a];
    lb = b[upper_bound(b,b+m+2,x) - b - 1];
    rb = b[lower_bound(b,b+m+2,x) - b];

    ll p1 = abs(x - abs(min(la,lb)));
    ll p2 = abs(x - max(ra,rb));
    ll p3 = rb - la + min(abs(x-rb), abs(x - abs(la)));
    ll p4 = ra - lb + min(abs(x - ra), abs(x - abs(lb)));
    cout << min(min(p1,p2), min(p3,p4)) << endl;
  }

  return 0;
}


Measured memory_bytes: 2944
X = int(input())
# A>=0で考えられる
div_list = []
for a in range(1, int(X**0.5)+1):
    if X % a == 0:
        div_list.append((a, X//a))

#print(div_list)
for x, y in div_list:
    for a in range(int(X**0.5)+1):
        b = a - x
        #print(a, b)
        y_hat = a**4 + b*a**3 + b**2*a**2 + b**3*a + b**4
        #print(y_hat)
        if y_hat == y:
            print(a, b)
            exit()

Measured memory_bytes: 9196
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)

int main() {
  ll L, R, d;
  cin >> L >> R >> d;

  ll count = 0;
  for (ll i = L; i <= R; ++i) {
    if (i%d == 0) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

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

int main() {
	int H, W,k=0; cin >> H >> W;
	vector<vector<char>> s(H, vector<char>(W));
	vector<vector<int>> z(H, vector<int>(W,1e9));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> s[i][j];
			if (s[i][j] == '.')k++;
		}
	}
	queue<pair<pair<int, int>,int>> d;
	d.push({ { 0,0 },0 });
	while (d.size()) {
		int x = d.front().first.first, y = d.front().first.second;
		int c = d.front().second;
		d.pop();
		for (int i = 0; i < 4; i++) {
			if (x + dx[i] >= 0 && x + dx[i] < H&&y + dy[i] >= 0 && y + dy[i] < W&&s[x+dx[i]][y+dy[i]]=='.') {
				if (z[x + dx[i]][y + dy[i]] <= c + 1)continue;
				z[x + dx[i]][y + dy[i]] = c + 1;
				d.push({ {x + dx[i],y + dy[i]},c + 1 });
			}
		}
		
	}
	if (z[H - 1][W - 1] == 1e9)cout << -1 << endl;
	else cout << k - z[H - 1][W - 1]-1 << endl;
}





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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		// String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int t = 1;
		for (;; t++) {
			if ((str.length() - t) % 2 != 0)
				continue;
			String s1 = str.substring(0, (str.length() - t) / 2);
			String s2 = str.substring((str.length() - t) / 2, (str.length() - t));
			// System.out.println(s1 + " " + s2);
			if (s1.equals(s2))
				break;
		}
		System.out.println((str.length() - t));
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

ll check1(const vll& a, ll x) {
    rep(i, a.size()) {
        x -= x % a[i];
    }
    return x;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int k;
    cin >> k;
    vll a(k);
    rep(i, k) cin >> a[i];

    ll lo = 1, hi = (1LL << 60);
    while (hi - lo > 1) {
        ll mid = lo + (hi - lo) / 2;
        ll x = check1(a, mid);
        if (x >= 2) {
            hi = mid;
        } else {
            lo = mid;
        }
    }

    if (check1(a, hi) != 2) {
        cout << -1 << endl;
        return 0;
    }
    ll ansh = hi;

    lo = 2, hi = (1LL << 60);
    while (hi - lo > 1) {
        ll mid = lo + (hi - lo) / 2;
        ll x = check1(a, mid);
        if (x <= 2) {
            lo = mid;
        } else {
            hi = mid;
        }
    }

    // cout << lo << " " << hi << endl;

    cout << ansh <<  " " << lo << endl;

    return 0;
}


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

int main(){
    string s;
    cin >> s;
    long long l = s.size(), ans = 0, bCount=0;

    for(int i=0; i<l; i++){
	if(s[i] == 'W')
	    ans += bCount;
	else
	    bCount++;	
    }
    cout << ans << "\n";
}




Measured memory_bytes: 640
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));

int main() {
	string s[3];
	int n = 3;
	rep(i, n)cin >> s[i];
	rep(i, n)s[i][0] += 'A' - 'a';
	rep(i, n)cout << s[i][0];
	return 0;
}




Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

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

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

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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


int main() {
    const int inf=100000000;
    int n, m;
    cin >> n >> m;

    int a[1000], b[1000], c[1000], dist[100][100];

    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; ++j) {
            if(i == j) dist[i][j] = 0;
            else dist[i][j] = inf;
        }
    }

    for(int i = 0; i < m; i++) {
        dist[a[i]][b[i]]=min(dist[a[i]][b[i]], c[i]);
        dist[b[i]][a[i]]=min(dist[b[i]][a[i]], c[i]);
    }

    for(int k = 0; k < n; ++k) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j< n; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    int ans = m;
    for(int i = 0; i < m; i++) {
        bool shortest=false;
        for(int j = 0; j < n; j++) if(dist[j][a[i]] + c[i] == dist[j][b[i]]) shortest = true;
        if(shortest==true) ans--;
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
 
    int move = 'A' - 'a';
    putchar(s1[0] + move);
    putchar(s2[0] + move);
    putchar(s3[0] + move);
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  xs <- replicateM n $ do
    [d1, d2] <- getIntList
    return (d1 == d2)

  let solve [] m res         = max m res
      solve (False:xs) m res = solve xs 0 (max m res)
      solve (True:xs) m res  = solve xs (m+1) res

      ans = if solve xs 0 0 >= 3 then "Yes" else "No"

  putStrLn ans


Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
  ll n;
  cin >>n;
  ll h[n],ans=0;
  for(ll i=0;i<n;i++) cin >>h[i];
  for(ll i=0;i<n-1;i++){
    ll hl=h[i+1]-h[i];
    if(hl<0){
      ans+=(-hl);
    }
  }
  cout <<ans+h[n-1]<<endl;
}


Measured memory_bytes: 256
x = int(input())
a = list(map(int,input().split()))
count = 0
flag = True
while flag:
    count += 1
    for i in range(x):
        if a[i]%2 == 0:
            a[i] = a[i]/2
        
        else:
            flag = False
            break
print(count-1)

Measured memory_bytes: 3060
S = input()
a=int(S[0])
b=int(S[1])
c=int(S[2])
d=int(S[3])
op1=[]
op2=[]
op3=[]
func=(('+',lambda x,y:x+y),('-',lambda x,y:x-y))
for f1 in func:
    op1.append((f1[1](a,b),f1[0]))
for o in op1:
    for f2 in func:
        op2.append((f2[1](o[0],c),o[1]+f2[0]))
for o in op2:
    for f3 in func:
        op3.append((f3[1](o[0],d),o[1]+f3[0]))
for o in op3:
    if o[0] == 7:
        print(str(a)+o[1][0]+str(b)+o[1][1]+str(c)+o[1][2]+str(d)+'=7')
        break

Measured memory_bytes: 3064
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t D, T, S;
  cin >> D >> T >> S;
  if(D <= S * T)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

using namespace std;

using ll = long long;

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)

typedef pair<int, int> P;

const int MOD = (int) 1e9 + 7;

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	
	ll ans = 0;
	REP(i, (1 << (s.length() - 1))) {
		ll sum = 0, cur = 0;
		REP(j, s.length()) {
			if (i & (1 << (j - 1))) {
				sum += cur;
				cur = 0;
			}
			cur = cur * 10 + (s[j] - '0');
		}
		sum += cur;
		ans += sum;
	}
	
	cout << ans << endl;
	
	return 0;
}

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<string> vec_N(N);
    vector<string> vec_M(M);
    rep(i,N){
        cin >> vec_N[i];
    }
    rep(i,M){
        cin >> vec_M[i];
    }
    bool ans = false;
    rep(i,N - M + 1){
        rep(j,N - M + 1){
            int count = 0;
            rep(k,M){
                rep(l,M){
                    if (vec_N[i + k][j + l] == vec_M[k][l]){
                        count++;
                    }
                }
            }
            if (count == M * M){
                ans = true;
            }
            count = 0;
        }
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define INF 1000000000
typedef long long ll;
int N;
int t[16][17];
int dp[1<<17]; //dp[i] := ?????\???????????????????????¨???i???????????????????????\??????

int solve(ll b){
  if(b == (1<<N)-1)return dp[b]=0;
  if(dp[b] != -1)return dp[b];

  int mn=INF;
  //?£????????????§?????\
  for(int i=0; i<N; i++)
    if(!(b&(1<<i))){
      int tmp=solve(b|(1<<i))+t[i][0];
      if(tmp<mn)
	mn=tmp;
    }
      
  //?£????????????§?????\
  for(int i=0; i<N; i++){
    if(!(b&(1<<i))){
      for(int j=1; j<N+1; j++){
	if(b&(1<<(j-1))){
	  int tmp=solve(b|(1<<i))+t[i][j];
	  if(tmp<mn)
	    mn=tmp;
	}
      }
    }
  }
  return dp[b]=mn;
}

int main(){
  while(cin >> N, N!=0){
    //??\???
    for(int i=0; i<N; i++)
      for(int j=0; j<N+1; j++)
	cin >> t[i][j];

    //?????????
    memset(dp, -1, sizeof(dp));

    cout<<solve(0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1680
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
const int p=1e9+7;
char s[N];
long long dp[N];
int last[3];
#define DP(x) (~(x)?dp[(x)]:0)
int main(){
	scanf("%s",s); int len=strlen(s);
	bool flag=0;
	for(int i=1; i<len; ++i)if(s[i]==s[i-1])flag=1;
	if(!flag)return puts("1"),0;
	dp[0]=1; int tmp=0; last[1]=last[2]=-1;
	for(int i=1; i<=len; ++i){
		(tmp+=(s[i-1]=='a'?1:2))%=3;
		if(tmp==0&&i<len)dp[i]=1;
		(dp[i]+=DP(last[0])+DP(last[1])+DP(last[2])-DP(last[tmp]))%=p;
		last[tmp]=i;
	}
	printf("%lld",dp[len]);
	return 0;
}

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

using namespace std;

int main()
{
    int a,b,k,c=0,x,p;
    cin>>a>>b>>k;
    (a<b)?x=a:x=b;
    while(1){

        if (a%x==0 && b%x==0){

            p=x;
            ++c;
            if (c==k)break;

        }
        --x;

    }

    cout<<x<<'\n';

    return 0;

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::pair;using std::set;using std::string;using std::vector;
using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;using vci=vector<int>;using vcl=vector<ll>;
#define ff first
#define ss second
#define pb emplace_back
template<typename T>void _dbg(const char*_s,T _h){cerr<<_s<<" = "<<_h<<"\n";}
template<typename T,typename...Ts>void _dbg(const char*_s,T _h,Ts..._t){int _b=0;while(((_b+=*_s=='(')-=*_s==')')!=0||*_s!=',')cerr<<*_s++;cerr<<" = "<<_h<<",";_dbg(_s+1,_t...);}
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...) 
#endif
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
cerr<<"Time elaped: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#endif
}}init;
const int N=1e5+1;
int a[N];
int p[N];
map<int,ll> c;
int main(){

int n, m;
cin>>n>>m;
++c[0];
for(int i=1;i<=n;++i){
    cin>>a[i];
    p[i]=(p[i-1]+a[i])%m;
    ++c[p[i]];
}
ll ans = 0;
for (auto t : c)
    ans+=(t.ss*(t.ss-1))/2;
cout<<ans<<'\n';

    return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>

int main(void)
{
  int n, i, j, k;
  int ren[4][3][10] = {0};

  scanf("%d", &n);

  int b[n], f[n], r[n], v[n];

  for(i = 0; i < n; i++) {
    scanf("%d %d %d %d", &b[i], &f[i], &r[i], &v[i]);
    ren[b[i]-1][f[i]-1][r[i]-1] += v[i];
  }

  for(i = 0; i < 4; i++) {
    for(j = 0; j < 3; j++) {
      for(k = 0; k < 10; k++) {
	printf("%2d", ren[i][j][k]);
      }
      printf("\n");
    }
    if(i != 3) printf("####################\n");
  }

  return 0;
}

Measured memory_bytes: 624