akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

typedef struct {
	int x0,y0,x1,y1;
} rect;

void solve(int,int);
long areascan(rect*,int,int);
long x(rect*,int,int);
long y(rect*,int,int);

int comp_int(const void*,const void*);
int comp_rect_x(const void*,const void*);
int comp_rect_y(const void*,const void*);

int main(){
	int n,r;
	scanf("%d %d",&n,&r);
	while(n!=0){
		solve(n,r);
		scanf("%d %d",&n,&r);
	}
	return 0;
}

void solve(int n, int r){
	int i;
	rect *rs;
	int *xs,*ys;
	long area,xy;
	rs=calloc(n,sizeof(rect));
	xs=calloc(n*2,sizeof(int));
	ys=calloc(n*2,sizeof(int));
	area=0;
	xy=0;
	
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&rs[i].x0,&rs[i].y0,&rs[i].x1,&rs[i].y1);
		xs[i*2]=rs[i].x0;
		xs[i*2+1]=rs[i].x1;
		ys[i*2]=rs[i].y0;
		ys[i*2+1]=rs[i].y1;
	}
	qsort(ys,n*2,sizeof(int),comp_int);
	qsort(rs,n,sizeof(rect),comp_rect_x);
	
	for(i=0;i<n*2-1;i++){
		if(ys[i]==ys[i+1]) continue;
		area+=(long)(ys[i+1]-ys[i])*areascan(rs,n,ys[i]);
	}
	printf("%ld\n",area);
	
	if(r==2){
		for(i=0;i<n*2-1;i++){
			if(ys[i]==ys[i+1]) continue;
			xy+=(long)(ys[i+1]-ys[i])*y(rs,n,ys[i]);
		}
		
		qsort(xs,n*2,sizeof(int),comp_int);
		qsort(rs,n,sizeof(rect),comp_rect_y);
		for(i=0;i<n*2-1;i++){
			if(xs[i]==xs[i+1]) continue;
			xy+=(long)(xs[i+1]-xs[i])*x(rs,n,xs[i]);
		}
		printf("%ld\n",xy);
	}
	
	free(rs);
	free(xs);
	free(ys);
}

long areascan(rect* rs,int n,int y){
	int i;
	int sum,xe,x1,x0;
	sum=0;
	xe=0;
	for(i=0;i<n;i++){
		if(y<rs[i].y0 || rs[i].y1<=y) continue;
		x0=rs[i].x0>xe?rs[i].x0:xe;
		x1=rs[i].x1>xe?rs[i].x1:xe;
		sum+=x1-x0;
		xe=x1;
	}
	return (long)sum;
}

int comp_int(const void *a,const void *b){
	return *(int*)a-*(int*)b;
}

int comp_rect_x(const void *a,const void *b){
	return ((const rect*)a)->x0-((const rect*)b)->x0;
}

int comp_rect_y(const void *a,const void *b){
	return ((const rect*)a)->y0-((const rect*)b)->y0;
}

long y(rect* rs,int n, int y){
	int i,xe,count;
	xe=0;
	count=0;
	for(i=0;i<n;i++){
		if(rs[i].y0>y || rs[i].y1<=y) continue;
		if(count==0 || xe<rs[i].x0) count+=2;
		xe=xe<rs[i].x1?rs[i].x1:xe;
	}
	return (long)count;
}

long x(rect *rs,int n,int x){
	int i,ye,count;
	ye=0;
	count=0;
	for(i=0;i<n;i++){
		if(rs[i].x0>x || rs[i].x1<=x) continue;
		if(count==0 || ye<rs[i].y0) count+=2;
		ye=ye<rs[i].y1?rs[i].y1:ye;
	}
	return (long)count;
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n, m;
  cin >> n >> m;
  vector<pll> v(n);
  rep(i,n) cin >> v[i].first >> v[i].second;
  sort(ALL(v));
  ll c = 0;
  ll ans = 0;
  rep(i,n) {
    if (c == m) break;
    ll l = m - c;
    if (l >= v[i].second) {
      c += v[i].second;
      ans += v[i].first * v[i].second;
    } else {
      c += l;
      ans += v[i].first * l;
    }
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 4852
s = input()
n = len(s)
s2 = s[:(n-1)//2]
s3 = s[((n+3)//2)-1:]
if (s == s[::-1]) & (s2 == s2[::-1]) & (s3 == s3[::-1]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 8940
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val tasks= (0 until n).map {
        val (a, b) = readLine()!!.split(' ').map { it.toLong() }
        return@map Pair(a, b)
    }.sortedBy { it.second }

    var t = 0L

    for (task in tasks) {
        t += task.first
        if (t > task.second) {
            println("No")
            return
        }
    }

    println("Yes")
}

Measured memory_bytes: 136320
const base_n = (n,d)=> (n/d >= 1) ? base_n( Math.floor(n/d),d ) + (n%d).toString() : ( (n%d) || '1').toString();
function Main(input) {
  input = input.trim().split(' ').map(data=>parseInt(data));
  console.log(base_n(input[0],input[1]).length)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21320
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  ll n;
  cin>>n;
  vector<ll> a(n);
  ll sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  ll mi=sum;
  ll tsum=0;
  for(int i=0;i<n;i++){
    tsum+=a[i];
    ll l=tsum,r=sum-tsum;
    mi=min(mi,abs(l-r));
  }
  cout<<mi<<endl;
}


Measured memory_bytes: 1792
// https://atcoder.jp/contests/abl/tasks/abl_e
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;

using modint = atcoder::modint998244353;

struct S {
    modint val, unit;
};
using F = long long;

const F ID = 8e18;

// 区間に対する演算方法
S op(S a, S b) { return {a.val + b.val, a.unit + b.unit}; }

// 単位元 a⋅e = e⋅a = a
S e() { return {0, 0}; }

// f(x) を返す関数
S mapping(F f, S x) {
    if (f != ID)
        x.val = f * x.unit;
    return x;
}
// f∘g を返す関数
F composition(F f, F g) { return (f == ID ? g : f); }
// id を返す関数
F id() { return ID; }

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<S> init(N);
    modint pow10 = 1;
    for (int i = N - 1; i >= 0; i--) {
        init[i] = {pow10, pow10};
        pow10 *= 10;
    }
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(init);
    while (Q--) {
        int l, r, d;
        cin >> l >> r >> d;
        seg.apply(l - 1, r, d);
        cout << seg.all_prod().val.val() << "\n";
    }
}


Measured memory_bytes: 10900
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a+b == c+d) {
  cout << "Balanced"<< endl;
  }
  else if (a+b < c+d)
    cout << "Right" << endl;
  else
    cout << "Left" << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int A;
  int B;
  int C;

  std::cin >> A >> B >> C;

  if (C >= A && C <= B) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int k, x;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> k >> x;
	for(int i = x - k + 1; i < x + k; i++)
		if(i <= 1e6 && i >= -1e6) cout << i << " "; 
	return 0;
}

Measured memory_bytes: 256
N = int(input())
n = []
ans = 0
for i in range(N) :
    if (i + 1 ) % 15 == 0 :
        n.append('FizzBuzz')
    elif ( i + 1 ) % 3 == 0 :
        n.append('Fizz')
    elif (i + 1) % 5 == 0 :
        n.append('Buzz')
    else :
        n.append(i + 1)
        ans += i + 1

print(ans)


Measured memory_bytes: 33484
#include<bits/stdc++.h>
using namespace std;
int mn=1000000;
int main()
{
	int x;
	cin>>x;
	int s[1000];
	s[0]=x;
	for(int i=0;i<=1000;i++)
	{
		if(s[i]%2==0)
		s[i+1]=s[i]/2;
		else if(s[i]%2==1)
		s[i+1]=s[i]*3+1;
	}
	for(int j=0;j<=1000;j++)
	{
		for(int k=j+1;k<=1000;k++)
		{
			if(s[k]==s[j])
			{
				mn=min(mn,k+1);	
			}
		}
	}
	cout<<mn<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,i,j,k;
    int a,b,c;
    int h,w;
    cin>>h>>w>>k;
    m=0;
    char s[h][w+1];
    for(i=0;i<h;i++) cin>>s[i];
    for(i=0;i<(1<<h);i++){
        for(j=0;j<(1<<w);j++){
                c=0;
            for(a=0;a<h;a++){
                for(b=0;b<w;b++){
                    if((i&(1<<a))||(j&(1<<b))) continue;
                    else if(s[a][b]=='#') c++;
                }
            }
            if(c==k) m++;
        }
    }
    cout<<m<<endl;

}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main(void) {
	int n, x, t;
	cin >> n >> x >> t;
	int time = 0;
	time = ceil(double(n) / x)*t;
	cout << time;
	return 0;
}

Measured memory_bytes: 3632
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, Read};
use std::usize;

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, ab: [(usize, usize); n]);
    let mut count = 0;
    for (a, b) in ab {
        if a == b {
            count += 1;
        } else {
            count = 0;
        }
        if count >= 3 {
            println!("{}", "Yes");
            return;
        }
    }
    println!("{}", "No");
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int N,M;
double dp[211][211];
int R[211][2111];
double Y[211][211];

int main(){
  cin >>  N >> M;
  for(int i=0;i<N;i++){
    int k; cin >> k;
    int sum = 0;
    for(int j=0;j<k;j++){
      int s,h;
      cin >> s >> h;
      for(int k=sum;k<sum+s*h;k++)
        R[i][k] = s;
      sum += s * h;
    }

    for(int j=1;j<=M;j++){
      if( R[i][j-1] == 0 )
        Y[i][j] = Y[i][j-1];
      else
        Y[i][j] = Y[i][j-1] + 1.0/(double)R[i][j-1];
      //  cout <<i << " , "  << j << " - " <<  Y[i][j] << endl;
    }

  }


  for(int i = 0;i < N;i++){
    for(int j=0;j<=M;j++){
      for(int k=j;k<=M;k++){
        int ut = k-j;        
        dp[i+1][k] = max( dp[i+1][k], dp[i][j] + Y[i][ut] );
      }
    }
  }
  printf("%.10lf\n",dp[N][M]);
}

Measured memory_bytes: 3304
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    s = str(stdin.readline().rstrip())
    t = str(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    ans = 0
    for i in range(len(s)):
        if s[i] != t[i]:
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9392
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
	ll n;
	cin>>n;
	ll arr[n];
	vector<ll> vec;
	for(ll i=0;i<n;i++)
		cin>>arr[i];
	for(ll i=0;i<n;i++)
	{
		if(n%2 == 0)
			if(i%2 != 0)
				vec.insert(vec.begin(), arr[i]);
			else
				vec.push_back(arr[i]);
		else
			if(i%2 == 0)
				vec.insert(vec.begin(), arr[i]);
			else
				vec.push_back(arr[i]);

	}
	for(auto i = vec.begin(); i!=vec.end();i++)
		cout<<*i<<" ";
	return 0;
}

Measured memory_bytes: 6844
// ref: https://img.atcoder.jp/abc105/editorial.pdf
// ref: https://drken1215.hatenablog.com/entry/2018/08/13/123600

#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s;
    
    int N; cin >> N;
    while(N!=0){
        int r = abs(N%2);
        N = (N-r)/(-2);
        s += (r==0 ? '0':'1');
    }
    
    reverse(s.begin(), s.end());
    if(s.size()==0){ s='0'; }
    cout << s << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

   int h = n / 100;
   int ans = 0;
   if(n > h * 100 + h * 10 + h){
      ans = (h+1) * 100 + (h+1) * 10 + h + 1;
   }else{
      ans = h * 100 + h * 10 + h;
   }

   cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100

int bubbleSort(int*,int);

int main(){
  int i,j,A[N],count;
  
  scanf("%d",&i);

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

  count=bubbleSort(A,i);

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

  printf("\n%d\n",count);

  return 0;
}

int bubbleSort(int *A,int n){
  int i,j,temp,count=0;

  for(i=0;i<n;i++){
    for(j=n-1;j>0;j--){
      if(*(A+j)<*(A+j-1)){
	temp=*(A+j);
	*(A+j)=*(A+j-1);
	*(A+j-1)=temp;
	count++;
      }
    }
  }
  
 
  return count;
}
	
    



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

d={}

for i in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and n != 1:
        print(-1)
        exit()
    elif s not in d:
        d[s] = c
    else:
        if d[s] != c:
            print(-1)
            exit()
if 1 not in d and n != 1:
    d[1] = 1
if 1 not in d and n == 1:
    d[1]=0
    
for i in range(2, n+1):
    if i not in d:
        d[i] = 0
ans = 0
for i in range(1, n+1):
    ans += d[i] * pow(10, n-i)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  if(s[k-1]=='A'){
    s[k-1]='a';
  }
  else if(s[k-1]=='B'){
    s[k-1]='b';
  }
  else{
s[k-1]='c';
  }
  cout<<s<<endl;
}
  
    


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    char C[2][3];
    bool flag;

    for(int i=0;i<2;++i){
        for(int j=0;j<3;++j){
            cin >> C[i][j];
        }
    }

    for(int j=0;j<3;++j){
        if(C[0][j]==C[1][2-j]){
            flag = true;
        }else{
            flag = false;
            break;
        }
    }
    if(flag){
        cout << "YES";
    }else{
        cout << "NO";
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

ll n,k;

void solve(istream& cin, ostream& cout) {
	cin >> n;
	ll sum= 0;
	REP(i, n) REP(j, n) REP(k, n) {
		sum += gcd(gcd(i+1, j+1), k+1);
	}
	cout <<sum<<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
int main() {
    ll  a,b;
    cin >> a >>b;
    if (a/2+a%2>=b){
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
dp=[[0,0,0] for i in range(n+1)]

for i in range(n):
    #j==kの場合を除く
    for j in range(3):
        for k in range(3):
            
            if j!=k:
                dp[i+1][j]=max(dp[i+1][j],dp[i][k]+l[i][j])
                
print(max(dp[-1]))

Measured memory_bytes: 47320
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<pii, lint> ppl;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
typedef vector<lint> poly;

int main(){
    int n;
    double L;
    scanf("%d%lf", &n, &L);
    double t[n];
    rep(i, n) scanf("%lf", &t[i]);

    xy_t ans = xy_t(0);
    rep(i, n)For(j, i+1, n){
        xy_t m = polar(1.0, M_PI*(t[i]+t[j])/L);
        ans += m * 2.0 * (1.0*n-2.0*(j-i)) / (1.0*n*(n-1)*(n-2));
    }

    ans *= 3.0;
    printf("%.10lf %.10lf\n", ans.real(), ans.imag());
}

Measured memory_bytes: 256
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！
    配列は少し多めにとっておく

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//イテレータ
#define all_range(C) begin(C), end(C)
//簡略化
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//関数

//最大公約数を求める
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//最小公約数を求める
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//xのy乗を求める ※参考：10^18乗まで
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
  }

  return sum;
}

//main.cpp----------------------------


void solve();

ll n;
ll a[100100], b[100100];

int main() {
  cin >> n;
  rep(i, n) cin >> a[i] >> b[i];

  solve();

  return 0;
}

void solve() {

  ll cnt = 0;
  for(int i=n-1; i>=0; --i) {
    if((cnt+a[i])%b[i]!=0) {
      cnt += b[i]-((cnt+a[i])%b[i]);
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
typedef long long ll;
ll a,b,c,d,x,y,z;
ll ans;
ll calc(){return a+b+c+d-(a%2)-(c%2)-(d%2);}
int main()
{
	scanf("%lld%lld%lld%lld%lld%lld%lld",&a,&b,&x,&c,&d,&y,&z);
	ans=calc();
	if(a&&c&&d)a--,c--,d--,ans=std::max(ans,calc()+3);
	printf("%lld\n",std::max(ans,0ll));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ll n; cin >> n;
  vector<double> v(n);
  rep(i, n)
    cin >> v.at(i);
  
  vector<double> w(n);
  rep(i, n)
    w.at(i) = 1 / v.at(i);
  
  double sum = 0;
  rep(i, n){
    sum += w.at(i);
   // cout << w.at(i);
  }
  cout << 1/sum << endl;
}

Measured memory_bytes: 3780
// <<<<GOD>>>> lET'S gO
// shhhh LODB is coding . .
//                       |
//                      ~~~

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

typedef long long ll;
const int N = 3e5 + 100;

ll n, ans, a[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++)
		if(a[i] - a[i - 1] > 1) {
			cout << -1;
			return 0;
		}
	if(a[0]) {
		cout << -1;
		return 0;
	}
	for (int i = 1; i < n; i++)
		ans += (a[i] == a[i - 1] + 1? 1: a[i]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
 int main(void){
	 int D;
	 cin >> D;
	 if(D==25){
		 cout << "Christmas" << endl;
	 }else if(D==24){
		 cout << "Christmas Eve" <<  endl;
	 }else if(D==23){
		 cout <<  "Christmas Eve Eve" << endl;
	 }else if(D==22){
		 cout << "Christmas Eve Eve Eve" << endl;
	 }
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) int((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl '\n'
#define ff first
#define ss second
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 200200;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v) cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

struct pair_hash {
	template<class T1, class T2>
	size_t operator() (const pair<T1, T2> &p) const {
		auto h1 = hash<T1> {}(p.first);
		auto h2 = hash<T2> {}(p.second);
		return h1 ^ h2;
	}
};

int fast_mod(int x, int m = MOD) {
	while (x <= m) x -= m;
	if (x < 0) x += m;
	return x;
}

int mod_add(int x, int y) {
	return fast_mod(x + y);
}

int n, a[MAXN];

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

	cin >> n;


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

	vector<int> v(1, 1);

	bool found = false;
	int l = 0;

	for (int i = 0 ; i < n ; ++i) {
		if (found) {
			if (v[l] + 1 == a[i]) {
				v.push_back(a[i]);
				l++;
			}
		} else {
			found |= (a[i] == 1);
		}
	}

	if (found) cout << n - sz(v) << endl;
	else cout << -1 << endl;


	return 0;
}

Measured memory_bytes: 2168
#include<stdio.h>
int main (void){
  int N,M;
  double MAX = 0;
if(scanf("%d %d",&N,&M) == 1){
    M++;
  M--;
}
  int A[N][2],i,CHECK = 0;
  for(i=0;i<N; i++){
    if(scanf("%d",&A[i][0]) == 1)
      M++;
      M--;
    A[i][1] = 0;
    MAX = MAX + A[i][0];
  }
  MAX = MAX / (4 * M);
  for(i = 0; i<N;i++){
    if(MAX <= A[i][0])
      CHECK++;
  }
  if(CHECK >= M)
    printf("Yes");
  else
    printf("No");
}


Measured memory_bytes: 1700
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int res;
  for(int i = 0;i < N;++i){
    for(int j = 0;j < N;++j){
     int M = 4*i + 7*j;
      if(M == N) ++res;
     }
    }
   if(res > 0) cout << "Yes" << endl;
   else cout << "No" << endl;
  }

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

int main() {
  int a,b;
  cin >> a >> b;

  if (a > b){
    cout << "a > b" << endl;
  }else if(a < b){
    cout << "a < b" << endl;
  }else{
    cout << "a == b" << endl;
  }

  return 0;
}


Measured memory_bytes: 3080
#include <iostream>
    #include <stdio.h>
    #include <string>
    #include <math.h>
    #include<algorithm>
    #include <numeric>
    using namespace std;
     
    int main(){
      int A, B;
      cin >> A >> B;
      if((A*B)%2==0){
       cout << "No" << endl; 
      }
      else{
       cout << "Yes" << endl; 
      }
      return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;

int n;

int popcnt(int m) {
	int cnt = 0;
	for (int i = 0; i < n; i++) cnt += (m >> i) & 1;
	return cnt;
}

string makebits(int m) {
	string ret;
	for (int i = 0; i < n; i++) ret += (m >> i) & 1 ? '1' : '0';
	reverse(ret.begin(), ret.end());
	return ret;
}

int dec(string s) {
	int ret = 0;
	for (int i = 0; i < n; i++) {
		ret *= 2;
		ret += s[i] == '1';
	}
	return ret;
}

void makeord(const string &s, const string &t, vector<string> &ord) {
	if (s.size() == 1) {
		ord.push_back(s);
		ord.push_back(t);
		return;
	}
	int m = s.size(), pos = 0;
	for (int i = 0; i < m; i++) {
		if (s[i] != t[i]) {
			pos = i;
			break;
		}
	}
	string snxt = s.substr(0, pos) + s.substr(pos + 1, m);
	string tnxt = t.substr(0, pos) + t.substr(pos + 1, m);
	string mid = snxt;
	if (snxt[0] == tnxt[0]) mid[0] = snxt[0] == '0' ? '1' : '0';
	else mid[1] = snxt[1] == '0' ? '1' : '0';
	vector<string> fst, scd;
	makeord(snxt, mid, fst);
	makeord(mid, tnxt, scd);

	for (string v : fst) {
		ord.push_back(v.substr(0, pos) + string(1, s[pos]) + v.substr(pos, m));
	}
	for (string v : scd) {
		ord.push_back(v.substr(0, pos) + string(1, t[pos]) + v.substr(pos, m));
	}
}

int main() {
	int a, b; cin >> n >> a >> b;
	if (popcnt(a) % 2 == popcnt(b) % 2) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	string s = makebits(a), t = makebits(b);
	vector<string> ans;
	makeord(s, t, ans);
	for (int i = 0; i < (int)ans.size(); i++) {
		cout << dec(ans[i]) << " \n"[i == (int)ans.size() - 1];
	}
	return 0;
}


Measured memory_bytes: 18672
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int H=in(),W=in();
	vector<int> S(H*W),X(H*W,0),Y(H*W,0);
	REP(i,H){
		string str=in<string>();
		for(int j=0;j<W;j++){
			if(str[j]=='#') S[j+i*W]=1;
			else S[j+i*W]=0;
		}
	}
	REP(i,H){
		bool find_zero=false;
		int zero_count = 0,old_j;
		REP(j,W){
			if(!find_zero){
				if(S[j+i*W]==0){
					find_zero = true;
					zero_count=1;
					old_j = j;
				}
				else{
					zero_count = 0;
				}
			}
			else if(find_zero){
				if(S[j+i*W]==0){
					zero_count++;
				}
				else{
					find_zero = false;
					for(int k=old_j;k<j;k++){
						X[k+i*W] = zero_count;
					}
					zero_count = 0;
				}
			}
		}
		if(find_zero){
			for(int k=old_j;k<W;k++){
				X[k+i*W] = zero_count;
			}
		}
	}

	REP(j,W){
		bool find_zero=false;
		int zero_count = 0,old_i;
		REP(i,H){
			if(!find_zero){
				if(S[j+i*W]==0){
					find_zero = true;
					zero_count=1;
					old_i = i;
				}
				else{
					zero_count = 0;
				}
			}
			else if(find_zero){
				if(S[j+i*W]==0){
					zero_count++;
				}
				else{
					find_zero = false;
					for(int k=old_i;k<i;k++){
						Y[j+k*W] = zero_count;
					}
					zero_count = 0;
				}
			}
		}
		if(find_zero){
			for(int k=old_i;k<H;k++){
				Y[j+k*W] = zero_count;
			}
		}
	}

	int max_num = 0;
	REP(i,H){
		REP(j,W){
			max_num = max(max_num,X[j+i*W]+Y[j+i*W]-1);
		}
	}
	
	cout << max_num << endl;
	return 0;
}

Measured memory_bytes: 47104
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 500;

int n, m;
char a[maxn][maxn + 1], b[maxn][maxn + 1], c[maxn][maxn + 1];

int main(void) {
  scanf("%d%d", &n, &m);
  memset(b, '.', sizeof b);
  memset(c, '.', sizeof c);
  for (int i = 0; i < n; ++i) {
    b[i][0] = '#';
    c[i][m - 1] = '#';
    for (int j = 1; j < m - 1; ++j) {
      (i & 1 ? b : c)[i][j] = '#';
    }
    scanf("%s", a[i]);
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '#') {
        b[i][j] = c[i][j] = '#';
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      putchar(b[i][j]);
    }
    putchar('\n');
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      putchar(c[i][j]);
    }
    putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std; 
int main() 
{
string s;
cin>>s;
s[3]='8';
cout<<s;
system("pause");
return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



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

  int l = 0, r = s.length() - 1, ans = 0;
  while (l != r) {
    if (s[l] == s[r]) {
      l++;
      if (l == r) break;
      r--;
    }
    else if (s[l] == 'x') {
      ans++;
      l++;
    }
    else if (s[r] == 'x') {
      ans++;
      r--;
    }
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " <<to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
void solve(){
    int n;
    string s,t;
    cin>>n>>s>>t;
    string r="";
    rep(i,n){
      r+=s[i];
      r+=t[i];
    }
    cout<<r<<"\n";
}
 
int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 256
class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        self.range = [(-1,n)] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
            self.range[self.num + i] = (i,i)
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
            self.range[i] = (self.range[2 * i][0],self.range[2 * i + 1][1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

    def bisect_l(self,l,r,x):
        l += self.num
        r += self.num
        Lmin = -1
        Rmin = -1
        while l<r:
            if l & 1:
                if self.tree[l] >= x and Lmin==-1:
                    Lmin = l
                l += 1
            if r & 1:
                if self.tree[r-1] >=x:
                    Rmin = r-1
            l >>= 1
            r >>= 1

        if Lmin != -1:
            pos = Lmin
            while pos<self.num:
                if self.tree[2 * pos] >=x:
                    pos = 2 * pos
                else:
                    pos = 2 * pos +1
            return pos-self.num
        elif Rmin != -1:
            pos = Rmin
            while pos<self.num:
                if self.tree[2 * pos] >=x:
                    pos = 2 * pos
                else:
                    pos = 2 * pos +1
            return pos-self.num
        else:
            return N

import sys

input = sys.stdin.readline

N,Q = map(int,input().split())
A = list(map(int,input().split()))

Seg = SegmentTree(A,max,0)

for _ in range(Q):
    query = list(map(int,input().split()))
    if query[0] == 1:
        gomi,idx,val = query
        Seg.update(idx-1,val)
    elif query[0] == 2:
        gomi,l,r = query
        print(Seg.query(l-1,r))
    else:
        gomi,l,val = query
        print(Seg.bisect_l(l-1,N,val)+1)

Measured memory_bytes: 116732
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll x;
    cin >> x;
    if(x == 3 || x == 5 || x == 7){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
def calcAreas(sections):
    areas = []

    for s in sections:
        if len(s) <= 1:
            continue;

        areas.append(toArea(s))

    return areas

def toArea(section):
    a = 0
    b, _ = section[0]

    for s, e in section:
        a += (max(s, e) - b) - (0.5 if s != e else 0)

    return int(a)

def toDelta(p):
    if '/' == p:
        return -1
    if '\\' == p:
        return 1
    return 0

def toPaths(path):
    h = 0
    ph = 0
    paths = []

    for p in path:
        h += toDelta(p)
        paths.append((ph,h))
        ph = h

    return paths

def update(sections):
    [(lf, ll)] = sections.pop()

    n = None

    for i in range(len(sections)-1, -1, -1):
        if sections[i][0][0] == ll:
            n = i
            break

    if n == None:
        sections.append([(lf, ll)])
        return False

    lst = [(lf, ll)]
    for i in range(len(sections)-1, n-1, -1):
        s = sections.pop()
        lst = s + lst

    sections.append(lst)
    return True

def main():
    paths = toPaths(input())

    prev = -1
    sections = []

    prev_update = True

    for f, l in paths:
        sections.append([(f, l)])
        if l < prev:
            if prev_update:
                prev_update = update(sections)
        else:
            prev_update = True

        prev = l

    areas = calcAreas(sections)
    l = len(areas)

    print(sum(areas))
    print(l, end='')
    if l > 0:
        print(' {}'.format(' '.join([str(x) for x in areas])), end='')
    print()

if __name__ == '__main__':
    main()



Measured memory_bytes: 10588
#include <cstdio>
#include <map>

using namespace std;

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

typedef long long ll;

//------------------------------------------------------------------------------
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

//------------------------------------------------------------------------------
map<ll, int> prime_factor(ll n) {
  map<ll, int> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) {
        res[i]++;
        n /= i;
      }
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

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

ll A, B;

void solve() {
  ll n = gcd(A, B);
  map<ll, int> pf = prime_factor(n);

  printf("%d\n", pf.size() + 1);
}

void input() {
  scanf("%lld%lld", &A, &B);
}

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


Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long sum = 0;
    for(int i = 0; i < n; i++) sum += nums[i];
    sum /= 2;
    long[] answers = new long[n];

    answers[n-1] = sum;
    for(int i = 0; i < n/2; i++)
    {
      answers[n-1] -= nums[2*i];
    }

    for(int i = 0; i < n-1; i++)
    {
      answers[n-2-i] = nums[n-2-i] - answers[n-1-i];
    }
       
    for(int i = 0; i < n; i++) answers[i] *= 2;
		Console.WriteLine(string.Join(" ", answers));
	}
}

Measured memory_bytes: 33952
#include <bits/stdc++.h>
            using namespace std;
            int min(int, int);

            int main() {
              int N, K, sum, tmp, i;   
              int box[100];
              cin >> N >> K;
              for (i = 0; i< N; i++){
                cin >> box[i];
              }
              for (i = 0; i < N; i++){
                tmp = min(box[i], K - box[i]);
                sum += tmp;
              }
              sum *= 2;
              cout << sum << endl;
            }

            int min(int x, int y){
              //cout << x << endl << y << endl;
              int ret;
              if(x > y) {
                ret = y;
                return ret;
              } else {
                ret = x;
                return ret;
              }
            }

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  ll N, M; scanf("%lld %lld", &N, &M);
  ll ans = 0;
  if (M < 2 * N) {
    ans += (M / 2);
  }
  else {
    M -= 2 * N;
    ans += N;
    ans += (M / 4);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 380
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

vector<int> ps;

ll f3(ll x) {
	for (ll p: ps) {
		ll p3 = (ll)p * p * p;
		while (x % p3 == 0) x /= p3;
	}
	return x;
}

int main() {
	vector<bool> is_p(2201, true);
	is_p[0] = is_p[1] = false;
	for (int i = 2; i <= 2200; i++)
		if (is_p[i]) {
			ps.push_back(i);
			for (int j = i * 2; j <= 2200; j += i)
				is_p[j] = false;
		}
	map<ll, int> mp;
	int N; cin >> N;
	while (N--) {
		ll x; cin >> x;
		mp[f3(x)]++;
	}
	set<ll_ll> st;
	int ans = 0;
	for (ll_i z: mp) {
		ll x = z.first, _x = x, y = 1;
		if (x == 1) {
			ans = 1;
			continue;
		}
		double Y = 1;
		for (int p: ps) {
			if (x % (p * p) == 0) {
				x /= p * p;
				y *= p;
				Y *= p;
			}
			else if (x % p == 0) {
				x /= p;
				y *= p * p;
				Y *= p;
			}
		}
		if (x > 2200 * 2200) continue;
		y *= (ll)x * x;
		Y *= (ll)x * x;
		if (Y < 1e11) {
			if (_x > y) swap(_x, y);
			st.insert(ll_ll(_x, y));
		}
	}
	for (ll_ll z: st) {
		ans += max(mp[z.first], mp[z.second]);
		mp[z.first] = mp[z.second] = 0;
	}
	for (ll_i z: mp) if (z.first != 1) ans += z.second;
	cout << ans << endl;
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#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 FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S.at(i);
    }
    FOR(h, 0, H) {
        FOR(w, 0, W) {
            if (S.at(h).at(w) == '#') {
                cout << '#';
                continue;
            }
            int bom = 0;
            FORE(i, max(0, h - 1), min(h + 2, H)) {
                FORE(j, max(0, w - 1), min(w + 2, W)) {
                    if (S.at(i).at(j) == '#') { ++bom; }
                }
            }
            cout << bom;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3660
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    String str = scanner.next();
    char s0 = str.charAt(0);
    char s1 = str.charAt(1);
    char s2 = str.charAt(2);

    if(s0 == s1 || s1 == s2 || s2 == s0){
      System.out.println("No");
    } else{
      System.out.println("Yes");
    }
  }
}


Measured memory_bytes: 23764
#include<stdio.h>
int main()
{
    int H,W,i,j;
    while(1)
    {
         scanf("%d %d",&H,&W);
            if(W==0 && H==0)
            {
                break;
            }
        for(i=0;i<H;i++)
    {
        for(j=0;j<W;j++)
        {

            if(i==0||i==H-1||j==0||j==W-1)
            {
                printf("#");
            }
            else{
                printf(".");
            }
        }
            printf("\n");

        }
        printf("\n");
    }

    return 0;

}



Measured memory_bytes: 2056
#include <iostream>
#include <vector>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n,Weight;
    cin >> n >> Weight;
    vector<int> w(110);
    vector<int> v(110);
    for(int i = 0; i < n; i++){
        cin >> w.at(i) >> v.at(i);
    }
    vector<vector<long long>> dp(110,vector<long long>(101000));
    for(int i = 0; i < n; i++){
        for(int sumw = 0; sumw <= Weight; sumw++){
            if(sumw - w[i] >= 0){
                dp[i+1][sumw] = max(dp[i][sumw], dp[i][sumw - w[i]] + v[i]);
            }
            dp[i+1][sumw] = max(dp[i+1][sumw], dp[i][sumw]);
        }
    }

    cout << dp[n][Weight] << endl;
}

Measured memory_bytes: 88192
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

ll n, a, b;
ll h[100010];
bool isok(ll x){
    ll cnt = 0;
    rep(i, n){
        ll y = h[i] - b*x;
        if(y <= 0)continue;
        cnt += y/a + min(y%a, (ll)1);
    }
    return cnt <= x;
}
int main(){
    cin >> n >> a >> b;
    a -= b;
    rep(i, n)cin >> h[i];
    ll no = 0, yes = 10000000000;
    while(no+1 != yes){
        ll pos = (no+yes)/2;
        if(isok(pos))yes = pos;
        else no = pos;
    }
    cout << yes << endl;
}

Measured memory_bytes: 1024