akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

ll N,K;
vector<ll> A;
vector<ll> F;

int main(){
    cin >> N >> K;
    A.resize(N);
    F.resize(N);
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<N;i++) cin >> F[i];
    sort(A.begin(),A.end());
    sort(F.begin(),F.end(),greater<ll>());
    ll s = -1;
    ll e = 1e12+1;
    ll d;
    while(s < e-1){
        ll m = (s + e) / 2;
        d = 0;
        for(int i=0;i<N;i++){
            ll f = A[i] * F[i];
            if(f <= m) continue;
            ll g = m / F[i];
            d += (A[i] - g); 
        }
        if(d > K){
            s = m;
        }else{
            e = m;
        }
    }
    cout << e << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
using namespace std;
typedef long long ll;
#define inf 2123456789
#define maxn 100005
int main() {
	string a;
	cin >> a;
	if (a[1] == 'R')cout << "ABC" << endl;
	else cout << "ARC" << endl;
}

Measured memory_bytes: 3628
import sys
readline = sys.stdin.readline

# dp[i] = 高さiのときの最大価値
# 順に見ていって、高さH[i]が来た時に、dp[i - 1]の最大値(美しさ)にA[i]を足したものをdp[i]に入れる
# セグメント木

# 求める値によって以下を書き換える
# DEF=結果に影響を与えない初期値(ex.最小値を求める場合INF)
# __choose__():結果の算出ロジック(ex.最小値を求める場合return min(a,b))
class SegmentTree:
  arr=None
  tree=None
  n=0
  # 結果に影響を与えないdefault value
  DEF=0
  def __init__(self,arr):
    self.arr=arr
    size=len(arr)
    # n階層目は2**(n-1)要素
    self.n=1
    while self.n<size:
      self.n*=2
    self.tree=[self.DEF]*(2*self.n-1)
    # 親=(n-1)//2
    # 子=2*n+1,2*n+2
    # 最下階層の要素を埋めていく
    for i in range(size):
      self.tree[i+self.n-1]=arr[i]
    for i in range(self.n-2,-1,-1):
      self.tree[i]=self.__choose__(self.tree[2*i+1],self.tree[2*i+2])
    
  # 区間からの代表値の選び方を定義する（最小値を選ぶ場合はminなど）
  def __choose__(self,a,b):
    return max(a,b)
  
  # 添字xをvalで更新する
  def update(self,x,val):
    x+=self.n-1
    
    self.tree[x]=val
    while x>0:
      x=(x-1)//2
      self.tree[x]=self.__choose__(self.tree[2*x+1],self.tree[2*x+2])
      
  # 対象区間[a,b)の値を求めるクエリ (bは含まないので注意)
  # k:自分がいるノードのindex
  # [l,r):検査する区間
  def get_val(self,a,b,k=0,l=0,r=-1):
    # 最初に呼び出されたときは対象区間が[0,N)
    if r<0:
      r=self.n
      
    # 要求区間と対象区間が交わらない
    if r<=a or b<=l:
      return self.DEF
    
    # 要求区間が対象区間を完全に満たす->対象区間を計算に使用する
    if a<=l and r<=b:
      return self.tree[k]
    
    # 要求区間が対象区間の一部を満たす->子を探索
    ll=self.get_val(a,b,2*k+1,l,(l+r)//2)
    rr=self.get_val(a,b,2*k+2,(l+r)//2,r)
    
    return self.__choose__(ll,rr)
    
  def show(self):
    print(self.tree)
    
N = int(readline())
H = list(map(int,readline().split()))
A = list(map(int,readline().split()))

dp = [0] * (N + 1)
ST = SegmentTree(dp)

for i in range(len(H)):
  h = H[i]
  a = A[i]
  # そこまでの最大値を求める
  maxval = ST.get_val(0,h)
  ST.update(h, maxval + a)

print(ST.get_val(0, N + 1))


Measured memory_bytes: 119976
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
	Scanner scanner = new Scanner(System.in);
	int deck = scanner.nextInt();	//ターン数,山札数
	int count = 0;
	int sum_t = 0;
	int sum_h = 0;
  	int Judge = 0;
  	int card_stlength_t;
  	int card_stlength_h;
  	int card_stlength;
  	int case_st = 0;
  	String work_t,work_h;
  	String alf[] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
  			"q","r","s","t","u","v","w","x","y","z"};
  	boolean bJudge = true;
  	
  	
  	do {
		String card_t = scanner.next();	//太郎の文字
		String card_h = scanner.next();	//花子の文字
  		
  		//引き分け
  		if( card_t.equals(card_h) ){
  			Judge = 0;
  		}
  		//カードの文字数取得
  		card_stlength_t = card_t.length();
  		card_stlength_h = card_h.length();
  		
  		if( card_stlength_t == card_stlength_h ){
  			card_stlength = card_stlength_t;
  			case_st = 0;
  		}else if( card_stlength_t > card_stlength_h ){
  			card_stlength = card_stlength_t;
  			case_st = 1;
  		}else{
  			card_stlength = card_stlength_h;
  			case_st = 2;
  		}
  		
  		//カードの比較
  		for( int i = 0; i < card_stlength ; i ++ ) {
		  		//System.out.println("比較判定");
  			if( case_st == 1 && i == card_stlength_h ){
  				Judge = 1;
  		  		//System.out.println("太郎勝ち");
  				break;
  			}else if( case_st == 2 && i == card_stlength_t ){
  				Judge = 2;
  		  		//System.out.println("花子勝ち");
  				break;
  			}else{
	  			work_t = card_t.substring(i, i +1);
	  			int j = 0;
  				int k = 0;
	  			int ncard_t = 0,ncard_h = 0;
  				//太郎の強さ
				while( true  ) {
					ncard_t ++;
					if(work_t.equals( alf[j] ))
						break;
					j ++;
				}
  				work_h = card_h.substring(i, i+ 1);
				//花子の強さ
				while( true  ) {
					ncard_h ++;
					if(work_h.equals( alf[k] ))
						break;
					k ++;
				}
	  			
	  			if( ncard_t > ncard_h ) {
	  		  		//System.out.println("太郎勝ち");
	  				Judge = 1;
	  				break;
	  			}else if( ncard_t < ncard_h ) {
	  		  		//System.out.println("花子勝ち");
	  				Judge = 2;
	  				break;
	  			}
  			}
  			
  		}
  		
  		
  		//点の加点
  		switch ( Judge ){
  		case 0:
  			sum_t ++;
  			sum_h ++;
  			break;
  		case 1:
  			sum_t += 3;
  			break;
  		case 2:
  			sum_h += 3;
  			break;
  		}
  		
  		//終了判定
  		count ++;
  		if( count >= deck ) {
  			bJudge = false;
  		}
  		
  	}while( bJudge );
  	
  	  	//結果出力
  		System.out.println(sum_t + " " + sum_h);
	
  	//後処理
	scanner.close();
  }
}


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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int ans,a,b;
    char c[100];
    stack<int> S;
    while(scanf("%s",&c)!=EOF){
        if(c[0]=='+'){
            a=S.top(), S.pop(), b=S.top(), S.pop();
            S.push(a+b);
        }else if(c[0]=='-'){
            a=S.top(), S.pop(), b=S.top(), S.pop();
            S.push(b-a);
        }else if(c[0]=='*'){
            a=S.top(), S.pop(), b=S.top(), S.pop();
            S.push(a*b);
        }else{
            S.push(atoi(c));
        }
    }
    printf("%d\n",S.top()); 
    return 0;
}

Measured memory_bytes: 1168
from collections import Counter
n,p=map(int,input().split())
s=input()
DP=[0]
ans=0

if p==2 or p==5:
    for i,j in enumerate(s):
        if int(j)%p==0:
            ans +=i+1
else:
    num,point=0,1
    for i in s[::-1]:
        num +=int(i)*point
        num %=p
        DP.append(num)
        point *=10
        point %=p

    DP=Counter(DP)
    for v,m in DP.items():
        if m>=2:ans +=m*(m-1)//2
print(ans)

Measured memory_bytes: 50132
import sys
sys.setrecursionlimit(10**9)

N, M = map(int, input().split())
paths = [[] for _ in range(N)]

for _ in range(M):
    a, b, z = map(int, input().split())
    paths[a-1].append(b-1)
    paths[b-1].append(a-1)

visited = [False] * N

def dfs(node, prev):
    if visited[node]:
        return
    visited[node] = True
    for n in paths[node]:
        if n != prev:
            dfs(n, node)
count = 0
for i in range(N):
    if visited[i] == False:
        count += 1
        dfs(i,-1)

print(count)


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

const int N = 1e5 + 5;

int a[N];
int main()
{
    ios::sync_with_stdio(false);    cin.tie(NULL);  cout.tie(NULL);
    int n;  cin >> n;
    for(int i = 0 ; i < n ; i++)    cin >> a[i];

    a[n] = 2e9+5;
    for(int i = 0 ; i < n ; i++) a[i] = (a[i+1] > a[i]);

    int ans = 0;
    int last = 0 , ch = -1;
    for(int i = 0 ; i < n ; i++)
        if(ch != a[i])
        {
            if(a[i])
                ans = max(ans , i - last);

            ch = a[i];
            last = i;
        }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<string,int> P;

int main(){
  	int A, B;
    cin >> A >> B;

    bool judge = true;

    int l= A + B + 1;
    for(int i=0;i<l;i++){
        char ch;
        cin >> ch;
        if(i==A && ch!='-') judge = false;
        if(i!=A && ch=='-') judge = false;
    }

    if(judge) cout << "Yes" <<endl;
    else cout << "No" <<endl;



  return 0;
}






Measured memory_bytes: 256
/*
      author : nishi5451
      created: 12.08.2020 14:24:49
*/

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


int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if( (a<c && c<b) || (b<c) && (c<a) ) 
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
using namespace  std;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
signed main(){
    int N; cin>>N;
    vector<int> A(N+1);
    vector<int> B(N+1);
    REP(i,N+1) cin>>A[i];
    REP(i, N) cin>>B[i];
    long long  res = 0;
    for(int i=0; i<N; i++){
        int x = min(A[i], B[i]);
        A[i] -= x;
        B[i] -= x;
        res += x;
        int y = min(A[i+1], B[i]);
        A[i+1] -= y;
        //B[i] -= y;
        res += y;
        if(x<0 or y<0) {
            while(true);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;

int main() {
    string s;
    cin >> s;
    ll zeros = 0;
    ll ones = 0;
    for (auto & c : s) {
        if (c == '0') {
            ++zeros;
        } else {
            ++ones;
        }
    }
    cout << min(zeros, ones) * 2 << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
    ll N, K; cin>>N>>K;
    vector<ll> A(N);
    for(ll i=0;i<N; i++) cin>>A[i];
    ll maxDigit = 55;
    // dp1 is smaller one, dp2 is exact one
    vector<ll> dps(maxDigit+1, -1), dpe(maxDigit+1, -1);
    dpe[0] = 0;
    for(ll d=0; d<maxDigit; d++){
        ll mask = 1LL << (maxDigit-1-d);
        ll cnt = 0;
        for(ll i=0; i<N; i++){ if(mask&A[i]) cnt++; }
        ll score[2] = {mask*cnt, mask*(N-cnt)};

        // smalle -> samller
        if(dps[d]!=-1){
            dps[d+1] = max(dps[d+1], dps[d] + max(score[0], score[1]));
        }
        // exact -> smaller
        if(dpe[d]!=-1){
            if(mask & K) dps[d+1] = max(dps[d+1], dpe[d] + score[0]); 
        }
        // exact -> exact
        if(dpe[d]!=-1){
            if(mask & K) dpe[d+1] = max(dpe[d+1], dpe[d] + score[1]); 
            else dpe[d+1] = max(dpe[d+1], dpe[d] + score[0]); 
        }

    }
    cout << max(dps[maxDigit], dpe[maxDigit]) << endl;
    return 0;
}

Measured memory_bytes: 1152
N, K = map(int, input().split())
S = list(input())

cnt_b = sum([(S[i] != S[i + 1]) for i in range(N - 1)])
    
if cnt_b < 2 * K:
    cnt_a = 0
else:
    cnt_a = cnt_b - 2 * K

# print("#", N, cnt_b, cnt_a)
print(max(0, N - (cnt_a + 1)))

Measured memory_bytes: 4652
i = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
# print(a)
n = a[0]
m = n // 2
diff = 100200300400500
ans = -1
for i in a[1:]:
    r1 = abs(m - i)
    r2 = abs(m - n + i)
    if min(r1, r2) < diff:
        diff = min(r1, r2)
        ans = i
print(n, ans)

Measured memory_bytes: 14428
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int X;
  cin>>X;
  int ans=1;
  REP(b,50){
    FOR(p,2,11){
      int tmp=(pow(b,p)+0.5);
      if(tmp<=X)ans=max(ans,tmp);
    }
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 512
N=int(input())
from cmath import phase
XY=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x: phase(x[0]+x[1]*1j))
XY+=XY
ans=0
for l in range(N):
    a=[0,0]
    for r in range(l,min(2*N,l+N)):
        a[0]+=XY[r][0]
        a[1]+=XY[r][1]
        ans=max(ans,abs(a[0]+a[1]*1j))
print(ans)

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

const int mod = 1000000007;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  mint operator^(const mint& a)const{
  	ll res=1,n=a.x,xx=x;
	while(n>0){
		if(n&1)res=res*xx%mod;
		xx=xx*xx%mod;
		n>>=1;
	}
  	return mint(res);
  }
  mint operator/(const mint& a)const{ return mint(*this)*(a^(mod-2)); }
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

mint dp[1111][1111];
mint fact[11111];
mint finv[11111];
ll a,b,c,d;

int main(){
	cin.sync_with_stdio(false);
	fact[0].x=fact[1].x=1;
	finv[0].x=finv[1].x=1;
	repl(i,1,10000){
		fact[i+1]=fact[i]*mint(i+1);
		finv[i+1]=mint(1LL)/fact[i+1];
	}
	ll n;
	cin>>n>>a>>b>>c>>d;
	dp[0][a-1].x=1;
	rep(i,n+1)repl(j,a,b+1){
		dp[i][j]+=dp[i][j-1];
		for(int k=c;i+j*k<=n&&k<=d;k++){
			dp[i+j*k][j]+=dp[i][j-1]*fact[n-i]*finv[n-i-k*j]*finv[k]*(finv[j]^k);
		}
	}
	cout<<dp[n][b].x<<endl;
	return 0;
}


Measured memory_bytes: 10620
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define debug(x) cout << #x << " => " << x << endl
const int MAX_N = 7 + 100000;
vector<int> G[MAX_N];
///----------------------------------------------
int val[MAX_N];
pii tab[MAX_N];
pii dfs(int u,int p,int type) {
    pii ret=~val[u]?mp(val[u],val[u]):mp(-1000000,2000000);
    //debug(u);
    rep(i,0,sz(G[u])) {
        int v=G[u][i]; if (v==p) continue;
        pii tmp=dfs(v,u,type^1);
        ret.fi=max(ret.fi,tmp.fi-1);
        ret.se=min(ret.se,tmp.se+1);
    }
    if ((ret.fi&1)!=type) ret.fi++;
    if ((ret.se&1)!=type) ret.se--;
    if (ret.fi>ret.se) { puts("No"); exit(0); }
    tab[u]=ret;
    return ret;
}

void dfs2(int u,int p) {
    rep(i,0,sz(G[u])) {
        int v=G[u][i]; if (v==p) continue;
        tab[v].fi=max(tab[v].fi,tab[u].fi-1);
        dfs2(v,u);
    }
}
///----------------------------------------------
int main() {

    ///freopen ( "xx.in" , "r" , stdin );

    ///init
    memset(val,-1,sizeof(val));

    ///read
    int n; cin>>n;
    rep(i,1,n) {
        int a,b; scanf("%d%d",&a,&b);
        G[a].pb(b);
        G[b].pb(a);
    }
    int m; cin>>m; int beg;
    rep(i,0,m) {
        int v,p; scanf("%d%d",&v,&p);
        val[v]=p;
        beg=v;
    }

    ///
    dfs(beg,0,val[beg]&1); puts("Yes");
    dfs2(beg,0);
    rep(i,1,n+1) printf("%d\n",tab[i].fi);

}


Measured memory_bytes: 16896
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string  O, E;
  cin>>O>>E;
  for(int i=0;i<O.size()+E.size();++i) {
    if(i%2==0) cout<<O[i/2];
    else cout<<E[i/2];
  }
  cout<<endl;
}



Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define def(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(ll i=a;i<n;i++)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        ll n; cin>>n;
        vector<ll> a(n+1,0);
        FOR(i,1,n+1) cin>>a[i];
        vector<ll> sum(n+1,0),diff(n+1,0);
        FOR(i,1,n+1) sum[i] = a[i]+i,diff[i] = i-a[i];
        ll ans = 0;
        map<ll,ll> mp;
        for(ll i=n;i>=1;i--){
            ans+=mp[sum[i]];
            mp[diff[i]]++;
        }
        cout<<ans;
    }   
}



Measured memory_bytes: 30540
def Dxy(a,b,dim):

    if dim == 'inf':
        c=[abs(x-y) for (x,y) in zip(a,b)]
        result = max(c) 
        return result
    else:
        sum = 0.0 
        for i in range(n):
            tmp = abs(a[i]-b[i])
            sum += pow(tmp,dim)
        result = pow(sum,1.0/dim)
        return result

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

print(f'{Dxy(x,y,1):6f}')
print(f'{Dxy(x,y,2):6f}')
print(f'{Dxy(x,y,3):6f}')
print(f'{Dxy(x,y,"inf"):6f}')



Measured memory_bytes: 5668
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  
  int N; 
  cin >> N;
  int array[N];
  
  for(int i=0; i<N; i++){
    cin >> array[i];
  }
  
  sort(array,array+N);
  int sum =0;
  sum = array[N/2]-array[N/2-1];
  
  cout <<  sum << '\n';
}

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class A753 {
public:
	void solve(istream& in, ostream& out) {
        int x; in >> x;
        if(x == 3 || x == 5 || x == 7) out << "YES" << endl;
        else out << "NO" << endl;
	}
};

int main() {
	A753 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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

#define endl "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m) {
    int res = 1; a %= m; while (b > 0) { if (b & 1) res = (res * a) % m;
    a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2, HELL)
#define size(a) (int) a.size()

int32_t main() { fastio;
	string n; cin >> n;
	if (n[0] == '7' or n[1] == '7' or n[2] == '7') {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
    return 0;
}


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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

if N == 1:
    ans = 0
else:
    ans = 0
    checked = set()
    fact = factorization(N)
    candidates = []
    for num in fact:
        for i in range(1,num[1]+1):
            candidates.append(num[0]**i)

    candidates.sort(reverse=True)
    #print(candidates)
    while N != 1 and len(candidates) > 0:
        
        while len(candidates) != 0:
            tmp = candidates.pop()
            if N%tmp == 0:
                break
        #print(N,tmp)
        if N >= tmp:
            N = N//tmp
            ans += 1


print(ans)

Measured memory_bytes: 9508
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int n,s;
	int data[100001];
	scanf("%d %d",&n,&s);
	for(int i=0;i<n;i++){
		scanf("%d",&data[i]);
	}
	int l=0,r=0;
	int sum=0,ans=0;
	while(1){
		while(r<n){
			sum+=data[r];
			if(s<=sum) break;
			r++;
		}
		if(n<=r) break;
		while(l<=r){
			int sum1;
			sum1=sum-data[l];
			if(sum1<s) break;
			sum=sum1;
			l++;
		}
		int d=r-l+1;
		if(ans==0) ans=d;
		else if(d<ans) ans=d;
		r++;
	}
	printf("%d\n",ans);
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  string s;
  cin >> s;
  vector<char> c;

  REP(i,s.size()-1){
    if(s[i]=='B' && s[i+1]=='C'){
      c.emplace_back('D');
      i++;
    }else{
      c.emplace_back(s[i]);
      if(i==s.size()-2){
        c.emplace_back(s[i+1]);
      }
    }
  }

  // REP(i,c.size()){
  //   cout << c[i];
  // }
  // cout << endl;

  ll cnt=0;
  ll ans=0;
  REP(i,c.size()){
    if(c[i]=='B' || c[i]=='C'){
      cnt=0;
    }else if(c[i]=='A'){
      cnt++;
    }else{
      ans += cnt;
    }

  }
  cout << ans << endl;
}



Measured memory_bytes: 3928
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int cnt = 0;
int digit;
int n;
void rec(string now,int a,int b,int c){
	if(now.size() > digit)return;
	if(a >= 1 && b >= 1 && c >= 1 && stoi(now) <= n)cnt++;
	rec(now+'7',a,b,c+1);
	rec(now+'5',a,b+1,c);
	rec(now+'3',a+1,b,c);
}

int main(){
	cin >> n;
	digit = to_string(n).size();

	rec("",0,0,0);

	cout << cnt << endl;
}


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

using namespace std;

int main() {
  string S;
  cin >> S;
  int last_invalid = -1;
  int answer = 0;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      answer = max(answer, i - last_invalid);
    } else {
      last_invalid = i;
    }
  }
  cout << answer;

  return 0;
}


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

int main() {
  int d;
  int c[26];
  int last[26];
  scanf("%d", &d);
  for ( int i = 0; i < 26; i++ ) {
    scanf("%d", &c[i]);
    last[i] = 0;
  }
  int s[d][26];
  for ( int i = 0; i < d; i++ ) {
    for ( int j = 0; j < 26; j++ ) {
      scanf("%d", &s[i][j]);
    }
  }
  int t[d];
  for ( int i = 0; i < d; i++ ) {
    cin >> t[i];
    t[i]--;
  }

  int now = 0;
  int val = 0;
  while ( now < d ) {
    int contest = t[now];
    val += s[now][contest];
    now++;
    last[contest] = now;
    for ( int i = 0; i < 26; i++ ) {
      val -= c[i]*(now-last[i]);
    }
    printf("%d\n", val);
  }

  return 0;
}


Measured memory_bytes: 3756
N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(N):
    if A[i] % 2 == 0:
        B.append(A[i])
a = 0
for j in range(len(B)):
    if B[j] % 3 == 0:
        a = a+0
    elif B[j] % 5 == 0:
        a = a+0
    else:
        a = a+1

if a == 0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3064
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var inputs = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            var n = inputs[0];
            var p = inputs[1];
            var time=0;
            var queue = new Queue<Process>(n);
            while (queue.IsFull() == false)
            {
                var temp=Console.ReadLine().Split();
                var process = new Process();
                process.Name = temp[0];
                process.Time = int.Parse(temp[1]);
                queue.Enqueue(process);
            }

            while (queue.IsEmpty() == false)
            {
                var process = queue.Dequeue();
                var temp = process.Time - p;
                if (temp > 0)
                {
                    time += p;
                    process.Time = temp;
                    queue.Enqueue(process);
                }
                else
                {
                    time += process.Time;
                    Console.WriteLine("{0} {1}", process.Name, time);
                }
            }

            Console.Read();
        }
    }
    class Process
    {
        public string Name { get; set; }
        public int Time { get; set; }
    }
    class Queue<T>
    {
        private T[] array;
        private int top = 0;
        private int back = 0;
        private bool isFull = false;

        public Queue(int capacity)
        {
            array = new T[capacity];
        }
        public void Enqueue(T item)
        {
            array[top++] = item;
            if (top == array.Length)
            {
                top = 0;
            }
            if (top == back)
            {
                isFull = true;
            }
        }
        public T Dequeue()
        {
            isFull = false;
            var temp = array[back++];
            if (back == array.Length) back = 0;
            return temp;
        }
        public bool IsEmpty()
        {
            if (isFull == true) return false;
            return top == back;
        }
        public bool IsFull()
        {
            return isFull;
        }
        
    }

}

Measured memory_bytes: 13012
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
    string S;
    cin>>S;
    for(int i=0;i<S.size();++i){
        if(S[i]=='?') S[i] = 'D';
    }
    cout<<S<<endl;
}



Measured memory_bytes: 3752
#include <iostream>

namespace ABC170
{

  class A
  {
  public:
    A() = default;
    ~A() = default;


    void Run()
    {

      int A = 0;
      for (int i = 1; i <= 5; ++i)
      {
        int N;
        std::cin >> N;
        if (N == 0) A = i;
      }

      std::cout << A << std::endl;
    }
  };

}

int main()
{

  ABC170::A prob;
  prob.Run();

  return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;


int main() {
	

	int n;
	ll k;
	cin >> n >> k;
	VLL a(n);
	VLL f(n);
	REP(i, n)cin >> a[i];
	REP(i, n)cin >> f[i];
	if (n == 1) {
		a[0] = max(0LL, a[0] - k);
		cout << a[0] * f[0];
		return 0;
	}
	sort(ALL(a));
	sort(ALL(f));
	reverse(ALL(f));

	ll ok = 1e12;
	ll ng = -1;
	while (ok - ng > 1) {
		ll mid = (ok + ng) / 2;
		ll cnt = 0;
		REP(i, n) {
			ll j = mid / f[i];
			cnt += max(0LL, a[i] - j);
		}
		if (cnt > k)ng = mid;
		else ok = mid;
	}
	cout << ok << endl;


}


Measured memory_bytes: 3328
#include <iostream>

using namespace std;
#define sq(x) x*x2 3
/*
template<class T>
T sq(T x)
{
    return x*x;
}
*/
///=============================================================function for calculating BIGMOD===================================================
//................................
#define MOD 1000000007

long long bigmod(long long m,long long n)
{
  if(n==1)return m;
  long long v;
  v=bigmod(m,n/2)%MOD;
  if(n%2==0)
    return (v*v)%MOD;
  else return ((v*v)%MOD*m)%MOD;
}


int main()
{
    //cout << "Hello world!" << endl;
    long long m,n;
    cin >> m >> n;
    //long long  p = 1000000007;
    cout << bigmod(m,n) << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int cnt[n][256] = {};
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (char c : s) {
            cnt[i][c]++;
        }
    }
    for (char c = 'a'; c <= 'z'; c++) {
        int l = 51;
        for (int i = 0; i < n; i++) {
            l = min(cnt[i][c], l);
        }
        for (int i = 0; i < l; i++) {
            cout << c;
        }
    }
}

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

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

using namespace std;

#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define ll long long
#define rep(i,n)  for(ll i=0;i<n;i++)
#define repi(i,n)  for(ll i=1;i<=n;i++)
#define mem(arr,x) memset(arr,x,sizeof(arr))

typedef vector<ll> vi;
typedef vector<char> vc;
     
#define mp make_pair
#define ff first
#define ss second
     
const double PI = 3.1415926535897932;
const int mod = 1e9 + 7;  
const int inf = 1e9 + 5;
ll lcm(ll a,ll b)
{
        return (a*b)/__gcd(a,b);
}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
int max(int a,int b)
{
        if(a<b)
        return b;
        return a;
}

int main()
{
  fast_io;
  int T=1;
 //  cin>>T;
  while(T--)
  { 
      ll x;
      cin>>x;
      if(x==0)
        cout<<1;
      else
        cout<<0;

  }
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  string S;

  cin >> N;
  cin >> S;

  int count = 0;
  for (char i1 = '0'; i1 <= '9'; i1++) {
        for (char i2 = '0'; i2 <= '9'; i2++) {
              for (char i3 = '0'; i3 <= '9'; i3++) {
                for (int i = 0; i < N; i++)
                {
                  if (S[i] == i1) {
                    for (int j = i + 1; j < N; j++) {
                      if (S[j] == i2) {
                        for (int k = j + 1; k < N; k++)
                        {
                          if (S[k] == i3) {
                            count++;
                            goto here;
                          }
                          if (k == N - 1) goto here;
                        }
                      }
                      if (j == N - 1) goto here;
                    }
                  }
                }
                here: continue;
              }
        }
  }

  cout << count << endl;
}


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

int main() {
  int k, a, b;
  bool flg = false;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      flg = true;
      break;
    }
  }
  if (flg) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(void) {
    int N, m=0;
    cin >> N;
    map<string, int> mp;
    while(N--) {
        string S;
        cin >> S;
        mp[S]++;
        m = max(m, mp[S]);
    }

    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        if(itr->second == m) {
            cout << itr->first << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 25216
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll L,n,a[MAXN],ans;
ll dp[MAXN];
ll go(ll x,ll y,bool dir)
{
    ll ret;
    if(dir) ret=y-x; else ret=x-y;
    if(ret<0) ret+=L;
    return ret;
}
ll findans(ll step)
{
    if(step==n) return go(0,a[n],true);
    else if(step==n-1) return go(0,a[n-1],true)+go(a[n-1],a[n],false);
    if(dp[step]!=-1) return dp[step];
    ll st=step,ed=(n-step)/2;
    return dp[step]=findans(step+2)+2*go(0,a[st],true)+2*go(a[n-ed+1],0,true)+((n-step)&1?1:-1)*(a[n-ed+1]-a[n-ed])-2*go(a[st+1],a[n-ed],true);
}
int main()
{
    scanf("%lld%lld",&L,&n);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    memset(dp,-1,sizeof(dp));
    ll ans=0;
    for(ll i=1;i<=n;i++) ans=max(ans,findans(i));
    reverse(a+1,a+n+1);
    for(ll i=1;i<=n;i++) a[i]=L-a[i];
    memset(dp,-1,sizeof(dp));
    for(ll i=1;i<=n;i++) ans=max(ans,findans(i));
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
long long n,a[233],ans=1000;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
    cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<n;i++)
	    if(a[i]<a[i+1])
	    	ans=ans%a[i]+ans/a[i]*a[i+1];
	cout<<ans<<endl;
}

Measured memory_bytes: 3636
n,m,k = map(int,input().split())
num = [1 for _ in range(n)]
pre = [i for i in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  num[a] += 1
  num[b] += 1
  A = [a]
  B = [b]
  la = 1
  lb = 1
  while a != pre[a]:
    a = pre[a]
    A.append(a)
    la += 1
  while b != pre[b]:
    b = pre[b]
    B.append(b)
    lb += 1
  #print(a,b)
  if a != b:
    if la > lb:
      pre[b] = a
      for aa in A:
        pre[aa] = a
      for bb in B:
        pre[bb] = a
    else:
      pre[a] = b
      for aa in B:
        pre[aa] = b
      for bb in B:
        pre[bb] = b
root = [10**6 for _ in range(n)]
cnt = [0 for _ in range(n)]
for i in range(n):
  if root[i] < 10**6:
    cnt[root[i]] += 1
    continue
  I = int(i)
  J = [I]
  while I != pre[I]:
    I = pre[I]
    J.append(I)
  for x in J:
    root[x] = I
  cnt[I] += 1
#print(pre)
#print(root)
#print(cnt)
ans = []
for i in range(n):
  ans.append(cnt[root[i]]-num[i])
#print(ans)
for _ in range(k):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  if root[a] == root[b]:
    ans[a] -= 1
    ans[b] -= 1
print(' '.join(map(str,ans)))

Measured memory_bytes: 19888
#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 ALL(x) x.begin(),x.end()
#define REVERSE(x) reverse(x.begin(),x.end())
#define P pair<int,int>
typedef long long LL;
const int INF=1000000007;
using namespace std;
int N,A,B,C;
int l[10];
int dfs(int a,int b,int c,int i){
if(i==N){
  int ans=0;
  ans=abs(A-a)+abs(B-b)+abs(C-c)-30;
  if(min({a,b,c})==0){ans=INF;}
  return ans;
}
else{
  int ansA,ansB,ansC,ans;
  ansA=dfs(a+l[i],b,c,i+1)+10;
  ansB=dfs(a,b+l[i],c,i+1)+10;
  ansC=dfs(a,b,c+l[i],i+1)+10;
  ans=dfs(a,b,c,i+1);
  return min({ansA,ansB,ansC,ans});
}
}
int main(){
  cin>>N>>A>>B>>C;
  REP(i,N){
    cin>>l[i];
  }
  int ans=dfs(0,0,0,0);
  cout<<ans;
}

Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n,sum = 0;
  cin >> n;

  rep(i,n)
  {
    int l,r;
    cin >> l >> r;
    sum += r - l + 1;
  }

  cout << sum << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int M;
ll res, d, c, s;


int main() {
	cin >> M;
	res = -1;
	for (int i = 0; i < M; i++) {
		cin >> d >> c;
		res += c;
		s += d*c;
	}
	while (s>=10) {
		res += s / 10;
		s = s % 10 + s / 10;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {

	int N, A, B;
	scanf("%d%d%d",&N, &A, &B);

	int ans = 0;

	for (int i = 1; i <= N;i++) {
		int n1 = i % 10;
		int n2 = (i % 100) / 10;
		int n3 = (i % 1000) / 100;
		int n4 = (i % 10000) / 1000;
		int n5 = (i % 100000) / 10000;

		int sum = n1 + n2 + n3 + n4 + n5;

		if (sum >= A && sum <= B) {
			ans+= i;
		}


	}

	printf("%d", ans);



}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXS 10

long long ans,sum;
char ch[MAXS+5];

int main() {
	scanf("%s",ch);
	int len=strlen(ch);
	int w=len-1;
	int Lim=1<<w;
	for(int s=0;s<Lim;s++) {
		sum=ch[0]-'0';
		for(int j=0;j<w;j++)
			if((1<<j)&s)
				ans+=sum,sum=ch[j+1]-'0';
			else sum=10*sum+ch[j+1]-'0';
		ans+=sum;
	}
	printf("%lld\n",ans);
	return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define repr(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define repf(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define inf 1e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &&i : a)
    {
        cin >> i;
    }

    sort(all(a));
    int alice = 0, bob = 0;

    for (size_t i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
            alice += a[i];            
        }
        else
        {
            bob += a[i];
        }
    }

    cout << abs(alice - bob) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 305;

int n,k,mo;
LL f0[N][N],f1[N][N],suf0[N][N],suf1[N][N];
LL c[N][N];

LL add(LL x,LL y){return x+y>=mo?x+y-mo:x+y;}
LL dec(LL x,LL y){return x<y?x-y+mo:x-y;}

int main(){
	n=get();k=get();mo=get();
	fo(i,1,k)f0[1][i]=f1[1][i]=1;
	c[0][0]=1;
	fo(i,1,n){
		c[i][0]=1;
		fo(j,1,i)c[i][j]=add(c[i-1][j],c[i-1][j-1]);
	}
	fo(d,1,1)
	fd(x,k,1){
		suf1[d][x]=add(suf1[d][x+1],f1[d][x]);
		suf0[d][x]=add(suf0[d][x+1],f0[d][x]);
	}
	fo(d,2,n){
		fo(x,1,k){
			//f0
			fo(t,1,d-1)f0[d][x]=add(f0[d][x],suf0[t][x+1]*f0[d-t][x]%mo*c[d-2][t-1]%mo);
			//f1
			fo(t,1,d-1)f1[d][x]=add(f1[d][x],suf0[t][x+1]*f1[d-t][x]%mo*c[d-2][t-1]%mo);
			fo(t,1,d-1)f1[d][x]=add(f1[d][x],suf1[t][1]*f0[d-t][x]%mo*c[d-2][t-1]%mo);
		}
		fd(x,k,1){
			suf1[d][x]=add(suf1[d][x+1],f1[d][x]);
			suf0[d][x]=add(suf0[d][x+1],f0[d][x]);
		}
	}
	LL ans=0;
	fo(i,1,k)ans=add(ans,f1[n][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3840
n,c,k=gets.split.map(&:to_i)
t = []
n.times do
  t.push gets.chomp.to_i
end
st = t.sort
count = 1
q = []
first = st[0]
st.each do |e|
  if q.size == c
    count += 1
    first = e
    q = [e]
    next
  end
  if e <= first + k
    q.push e
  else
    count += 1
    first = e
    q = [e]
  end
end
puts count


Measured memory_bytes: 4216
import fractions
n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(1, len(a)):
    if i == 1:
        ans = fractions.gcd(a[0], a[1])
    else:
        ans = fractions.gcd(ans, a[i])

print(ans)

Measured memory_bytes: 16240
# coding: utf-8
# Your code here!

while True:
    N = int(input())
    if N == 0:
        break
    
    for i in range(N):
        x1,y1,z1,w1,x2,y2,z2,w2 = [int(j) for j in input().split()]
        a1 = x1*x2 - y1*y2 - z1*z2 - w1*w2
        a2 = x1*y2 + y1*x2 + z1*w2 - w1*z2
        a3 = x1*z2 - y1*w2 + z1*x2 + w1*y2
        a4 = x1*w2 + y1*z2 - z1*y2 + w1*x2
        print(a1,a2,a3,a4)
    
        


Measured memory_bytes: 5604
#include <stdio.h>


int main(void)
{
  int card[4][13];
  char Char;
  int num;
  
  int i;
  int j;
  
  for( i = 0; i < 4; i++ ){
    for ( j = 0; j < 13; j++ ){
      card[i][j] = 1;
    }
  }
  
  int n;
  scanf("%d", &n);
  
  for( i = 0; i < n; i++ ){    
    scanf(" %c %d", &Char, &num );
    
    if( Char == 'S' ) card[0][num-1] = 0;
    if( Char == 'H' ) card[1][num-1] = 0;
    if( Char == 'C' ) card[2][num-1] = 0;
    if( Char == 'D' ) card[3][num-1] = 0;
    
  }
  
  
  for( i = 0; i < 4; i++ ){
    for( j = 0; j < 13; j++ ){
      switch( i ){
        case 0: { if( card[i][j] ) printf("S %d\n", j+1); break; }
        case 1: { if( card[i][j] ) printf("H %d\n", j+1); break; }
        case 2: { if( card[i][j] ) printf("C %d\n", j+1); break; }
        case 3: { if( card[i][j] ) printf("D %d\n", j+1); break; }
      }
    }
  }
  
  
  
  return 0;

 
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

const int INF=1001001001;

int main() {
  double A,B,H,M;
  cin>>A>>B>>H>>M;
  double h=(H/12+M/60/12)*2*M_PI;
  double m=M/60*2*M_PI;
  double bx=B*cos(m),by=B*sin(m);
  double ax=A*cos(h),ay=A*sin(h);
  double dx=ax-bx,dy=ay-by;
  cout<<fixed<<setprecision(10)<<sqrt(dx*dx+dy*dy)<<endl;
  return 0;
}

Measured memory_bytes: 4096
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    ll x;
    cin >> x;
    ll ans = x;
    for(ll i = 1; i*i <= x; i++){
        if(x%i) continue;
        ans = min(ans, i-1 + x/i-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384