akhauriyash/Code-Regression huggingface dataset:
/*
 * @Autor: valk
 * @Date: 2020-04-04 14:56:12
 * @LastEditTime: 2020-09-17 16:46:22
 * @Description: 如果邪恶  是华丽残酷的乐章 它的终场 我会亲手写上 晨曦的光 风干最后一行忧伤 黑色的墨 染上安详
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#define emplace_back push_back
#define pb push_back
// #define fuck(a, b) cout << a << ' ' << b << ' ' << endl
// #define fuck(a, b, c) cout << a << ' ' << b << ' ' << c << ' ' << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll seed = 12289;
const double eps = 1e-6;
const ll inf = 0x3f3f3f3f;
const ll N = 2e5 + 10;

int main()
{
    ll a, b, c, d;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    ll maxn = max(a * c, max(a * d, max(b * c, b * d)));
    if (a <= 0 && b >= 0)
        maxn = max(maxn, 0LL);
    if (c <= 0 && d >= 0)
        maxn = max(maxn, 0LL);
    printf("%lld\n", maxn);
    return 0;
}

Measured memory_bytes: 3212
#include <iostream>
#include <cstdio>
#include <cstring>
//#define fre
//#define DEBUG
using namespace std;
int excl[10];
struct Node
{
    char num[10];
    int len;
    void incre()
    {
        num[len - 1]++;
        int i = len - 1;
        while (num[i] == '9' + 1) 
        {
            num[i] = '0', num[--i]++;
        }
    }
    bool judge()
    {
        if (num[0] != '0' && excl[num[0] - '0']) return false;
        for (int i = 1; i < len; ++i) 
            if (excl[num[i] - '0']) return false;
        return true; 
    }
} tar, cur;
int main()
{
    int k, t;
    tar.num[0] = '0';
    scanf("%s", tar.num + 1);
    tar.len = strlen(tar.num);
    memcpy(cur.num, tar.num, sizeof(tar.num));
    cur.len = tar.len;
    scanf("%d", &k);
    memset(excl, 0, sizeof(excl));
    for (int i = 0; i < k; ++i) scanf("%d", &t), excl[t] = 1;
    while (1)
    {
        if (cur.judge() && strcmp(cur.num, tar.num) >= 0)
        {
            if (cur.num[0] != '0') printf("%s\n", cur.num);
            else printf("%s\n", cur.num + 1);
            break;
        }
        cur.incre();
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    map<char, char> at;
    at['A'] = 'T';
    at['C'] = 'G';
    at['G'] = 'C';
    at['T'] = 'A';
    
    char b;
    cin >> b;
    cout << at[b] << endl;
    
    
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int MAXN = 200100;

int N;
ll K;
ll A[MAXN];
ll F[MAXN];

bool works (ll X)
{
    ll nt = 0;
    for (int i = 0; i < N; i++)
    {
        if (A[i] * F[i] > X)
        {
            nt += A[i] - X / F[i];
        }
    }
    return nt <= K;
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> F[i];
    }

    sort (A, A + N);
    sort (F, F + N);
    reverse (F, F + N);

    ll lo = 0, hi = 1e18;
    while (lo < hi)
    {
        ll mid = (lo + hi) / 2;
        if (works (mid))
            hi = mid;
        else
            lo = mid + 1;
    }
    cout << lo << "\n";
}

Measured memory_bytes: 3328
//ABC111B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include<stdio.h>
#include<climits>
#include<cfloat>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n-1);
	for(int i=0;i<n;i++){
		cin >> a.at(i);
	}
	for(int i=0;i<n;i++){
		cin >> b.at(i);
	}
	for(int i=0;i<n-1;i++){
		cin >> c.at(i);
	}
	int sigma = b.at(a.at(0)-1);
	for(int i=1;i<n;i++){
		if(a.at(i) == a.at(i-1)+1){
			sigma += b.at(a.at(i)-1) + c.at(a.at(i-1)-1);
		}else{
			sigma += b.at(a.at(i)-1);
		}
	}
	cout << sigma << endl;
	return 0;
}

Measured memory_bytes: 256
#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 MAX 100005
#define MOD 1000000007
typedef long long ll;

int main(){

	int n,m;
	cin >> n>>m;
	ll a[MAX] = {};

	rep(i, m) {
		cin >> a[i];
	}

	ll dp[MAX] = {};

	int br = 0;
	FOR(i, 1, n+1) {
		if (i==a[br]) {
			br++;
			continue;
		}

		if (i==1) {
			dp[1] = 1;
		} else if (i==2) {
			dp[2] = dp[1] + 1;
		} else {
			dp[i] = dp[i-1] + dp[i-2];
			dp[i] %= MOD;
		}
	}

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




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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int n, m, k, a, b, c;
string s, t, r;
char c1, c2, c3;

int A[200005];
int B[200005];
int C[200005];

int main() {
	cin >> n >> a;
	if (n>=10) cout <<a<<endl;
	else cout <<a+100*(10-n)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main(){
	unsigned long long int N;
	int F = 100;
	cin >> N;
	for(int i = 1; i <= sqrt(N); i++){
		if(N % i == 0){
			if(F > (int)log10(N/i) + 1){
				F = (int)log10(N/i) + 1;
			}
		}
	}
	cout << F << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
    ll n,m;
    cin>>n>>m;
	ll ans=n*m;
	if (n>m) swap(n,m);
	if (n==1){
		ans=m-2;
	}else{
		ans-=n*2+m*2-4;
	}
	if (ans<0) ans=0;
	if (n==1&&m==1) ans=1;
	cout<<ans;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define MAX_N 1000000007
#define INF 100000000000000

int main(){
  int a;
  cin >> a;
  bool flag = false;
  for(int i=1;i<10;i++){
    if(a%i == 0){
      if(a/i < 10) flag = true;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#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(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1 ; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1 ; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/***************************************/

int main() {
	int m, n;
	vector<int> ans[101];
	while (cin >> m >> n, m || n) {
		if (ans[m].empty()) {
			int maxnum = 7500000;
			int maxsize = 501000;
			vector<bool> is_prime(maxnum + 1, true);
			REP(i, m) is_prime[i] = false;
			for (ll i = m; i <= maxnum; i++) if (is_prime[i]) {
				ans[m].push_back(i);
				if (ans[m].size() >= maxsize) break;
				for (ll j = 1; i * j <= maxnum; j++) is_prime[i * j] = false;
			}
			for (int i = 0; i <= maxnum && ans[m].size() < maxsize; i++)
				if (is_prime[i]) ans[m].push_back(i);
		}
		if (debug) printf("@ ");
		cout << ans[m][n] << endl;
	}
	return 0;
}



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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    map<ll, ll> even, odd;

    REP(i, N){
        ll v;
        cin >> v;
        if(i%2==0) even[v]++;
        else odd[v]++;
    }

    ll even_1=0,even_2=0,odd_1=0,odd_2=0;
	ll e1=0,e2=0,o1=0,o2=0;
	ll cnt;

    // evenの1番
    cnt = 0;
    for(auto itr = even.begin();  itr != even.end() ; ++itr){
        if(itr->second > cnt){
            cnt = itr->second;
            even_1 = itr->first;
        }
    }
    e1 = cnt;

    // evenの2番
    cnt = 0;
    for(auto itr = even.begin();  itr != even.end() ; ++itr){
        if(itr->second > cnt && itr->first != even_1){
            cnt = itr->second;
            even_2 = itr->first;
        }
    }
    e2 = cnt;

    // oddの1番
    cnt = 0;
    for(auto itr = odd.begin();  itr != odd.end() ; ++itr){
        if(itr->second > cnt){
            cnt = itr->second;
            odd_1 = itr->first;
        }
    }
    o1 = cnt;

    // oddの2番
    cnt = 0;
    for(auto itr = odd.begin();  itr != odd.end() ; ++itr){
        if(itr->second > cnt && itr->first != odd_1){
            cnt = itr->second;
            odd_2 = itr->first;
        }
    }
    o2 = cnt;

    if(even_1 != odd_1){
        cout << N - e1 - o1 << endl;
    }
    else{
        cout << N - max(e1+o2, o1+e2) << endl;
    }
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		string c;
		int dice[3][4]  = {{0, 5, 0, 0},
						   {4, 1, 3, 6},
						   {0, 2, 0, 0}};
		int kari;
		int sum = 1;
		for (int i = 0; i < n; i++) {
			cin >> c;
			if (c == "North") {
				kari = dice[0][1];
				dice[0][1] = dice[1][1];
				dice[1][1] = dice[2][1];
				dice[2][1] = dice[1][3];
				dice[1][3] = kari;
				sum += dice[1][1];
			} else if (c == "South") {
				kari = dice[2][1];
				dice[2][1] = dice[1][1];
				dice[1][1] = dice[0][1];
				dice[0][1] = dice[1][3];
				dice[1][3] = kari;
				sum += dice[1][1];
			} else if (c == "West") {
				kari = dice[1][0];
				for (int i = 0; i < 3; i++) {
					dice[1][i] = dice[1][i+1];
				}
				dice[1][3] = kari;
				sum += dice[1][1];
			} else if (c == "East") {
				kari = dice[1][3];
				for (int i = 3; i > 0; i--) {
					dice[1][i] = dice[1][i-1];
				}
				dice[1][0] = kari;
				sum += dice[1][1];
			} else if (c == "Right") {
				kari = dice[2][1];
				dice[2][1] = dice[1][2];
				dice[1][2] = dice[0][1];
				dice[0][1] = dice[1][0];
				dice[1][0] = kari;
				sum += dice[1][1];
			} else {
				kari = dice[2][1];
				dice[2][1] = dice[1][0];
				dice[1][0] = dice[0][1];
				dice[0][1] = dice[1][2];
				dice[1][2] = kari;
				sum += dice[1][1];
			}
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
n = int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
lists = []
cnt = 0
Max = -999999
for i in range(n):
    cnt = 0
    lists = []
    lists = a1[:i+1]
    cnt += sum(lists)
    lists = []
    lists = a2[i:n+1]
    cnt += sum(lists)
    if Max < cnt:
        Max = cnt
print(Max)



Measured memory_bytes: 3064
#include <stdio.h>

int n;
int A[101][101];
int B[101],d[101],f[101];
int u,v,k,time;

void visit(int u){
  int i;
  B[u] = 1;
  d[u] = ++time;
  for(i=1;i<=n;i++){
    if(A[u][i]==0){continue;}
    if(B[i]==0){
      visit(i);
    }
  }
  B[u] = 2;
  f[u] = ++time;
}

void dfs(){
  int i;
  for(i=1;i<=n;i++){
    B[i] = 0;
  }
  time = 0;

  for(i=1;i<=n;i++){
    if(B[i]==0){
      visit(i);
    }
  }
  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
}

int main(){
  int i,j;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      A[i][j] = 0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d %d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&v);
      A[u][v] = 1;
  }
}
dfs();

return 0;
}



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

int main(void){
  string s, t;
  string s1, s2;
  cin >> s >> t;
  int count = 0;
  bool flag = false;
  while(count <= t.length()){
    if(s.compare(t) == 0){
      flag = true;
      break;
    }
    s1 = s.substr(0, s.length() - 1);
    s2 = s.substr(s.length() - 1 , 1);
    s2 += s1;
    s = s2;
    count++;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
con = []
counter = 0

for i in range(1, N+1):
    if i % 2 == 1:
        for s in range(1, i+1):
            if i % s == 0:
                counter += 1
            
        con.append(counter)
        counter = 0


print(con.count(8))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

typedef long long ll;

int gcd(int a, int b) {
	int c = a%b;
	while(c!=0) {
		a = b;
		b = c;
		c=a%b;
	}
	return b;
}

int main() {
	int n,x;
	cin >> n >> x;
	vector<int> v;
	v.push_back(x);
	for(int i = 0; i < n; i++) {
		int _x;
		cin >> _x;
		v.push_back(_x);
	}
	sort(v.begin(),v.end());
	for(int i = n; i >= 0; i--) {
		v[i] -= v[0];
	}
	int ans = -1;
	for(int i = 1; i < n; i++) {
		int res = gcd(v[i],v[i+1]);
		if(ans>0) res = gcd(ans,res);
		ans = res;
	}
	if(ans==-1) ans = v[1];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 892
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve()
{
    string a, b, c;
    cin >> a >> b >> c;
    int asize = a.size();
    int bsize = b.size();
    if (a[asize - 1] == b[0] && b[bsize - 1] == c[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

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

Measured memory_bytes: 3632
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val as = Vector.fill(n)(BigInt(sc.nextInt))
  val lcm = as.foldLeft(BigInt(1)) { (acc, next) =>
    acc * next / acc.gcd(next)
  }

  def f(m: BigInt): BigInt =
    as.foldLeft(BigInt(0)) { (acc, next) => acc + (m % next) }

  println(f(lcm - 1))
}


Measured memory_bytes: 46624
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <random>
#include <cstdint>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<long long, long long>
#define pdd pair<long double, long double>
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define file 0
 
const ll mod = 998244353;
const int N = 1e6 + 5, M = 21;
const ld pi = acos(-1);
 
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
//mt19937_64 rnd(239);
    
ll power(ll x, unsigned ll y, ll p) {
        ll res = 1; 
        x = x % p;
        while (y > 0)
        {
            if (y & 1)
                res = (res*x) % p;
            y = y>>1;
            x = (x*x) % p;  
        }
    return res;
}
int freq[N];
bool dp[N];
    
int main() { 
 
    FAST;
    if(file) {
        freopen("input.in","r",stdin);
        freopen("output.out","w",stdout);
    }
    
    ll n;
    cin >> n;
    for(int i=0;i<n;i++) {
        int x;
        cin >> x;
        freq[x] ++;
    }
    for(int i=1;i<N;i++) {
        if(!freq[i]) {
            continue;
        }
        for(int j=2*i;j<N;j+=i) {
            dp[j] = true;
        }
    }
    int ans = 0;
    for(int i=1;i<N;i++) {
        if(!dp[i] && freq[i] == 1) {
            ans ++;
        }
    }
    cout << ans;
    return 0;
}

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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 2e5 + 10;
const ll mod = 1e9 + 7;

int n;
ll a[maxN];
ll fact[1000010], ifact[1000010];

ll power(ll a, ll b)
{
    ll r = 1;
    while (b)
    {
        if (b & 1)
        {
            r = r * a % mod;
        }
        b /= 2;
        a = a * a % mod;
    }
    return r;
}

void init()
{
    fact[0] = 1;
    for (int i = 1; i <= 1e6; ++i)
    {
        fact[i] = fact[i - 1] * i % mod;
    }
    ifact[1000000] = power(fact[1000000], mod - 2);
    for (int i = 999999; i >= 0; --i)
    {
        ifact[i] = ifact[i + 1] * (i + 1) % mod;
    }
}

ll nCk(int n, int k)
{
    return fact[n] * ifact[k] % mod * ifact[n - k] % mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    init();
    cin >> n;
    for1(i, n)
    {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1, greater <ll>());
    ll ans = 0;
    for1(i, n)
    {
        ans += a[i] * (i + 1) % mod * power(2, i * 2 - 2) % mod * power(4, n - i) % mod;
        ans %= mod;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 17408
from collections import defaultdict
D = defaultdict(int)
N = int(input())
for s in map(int,input().split()):
	D[s] += 1

T = defaultdict(int)
M = int(input())
for s in map(int,input().split()):
    T[s] += 1

for key,value in T.items():
   if not(key in D):
       print("NO")
       exit()
   else:
       if value > D[key]:
           print("NO")
           exit()

else:
    print("YES")

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	ll n, k;
	ll a = 0, aa = 0, sum = 0LL, tmp = 0LL;
	ll mod = 1e9 + 7LL;
	cin >> n >> k;
	vector<ll>arr(n), arrr(2 * n), apea(n), apeaa(n);
	rep(i, n) {
		cin >> arr[i];
		arrr[i] = arr[i];
		arrr[i + n] = arr[i];
	}
	rep(i, n)for (int j = i + 1; j < n; j++) {
		if (arr[j] < arr[i])a++;
	}
	rep(i, n)for (int j = n; j < 2 * n; j++)if (arrr[j] < arrr[i])aa++;
	sum = a * k;
	tmp = aa * (((k * (k - 1)) / 2)%mod);
	tmp %= mod;
	sum += tmp;
	sum %= mod;
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, E;

  cin >> N;
  cin >> A;
 
  E = N % 500;
  if (E != 0) {
    if (A - E >= 0){
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3580
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N, K = map(int, input().split())
MOD = 10 ** 9 + 7

for i in range(1, K+1):
    if i > N-K+1:
        print(0)
        continue
    a = cmb(N-K+1, i)
    a %= MOD
    b = cmb(K-1, i-1)
    b %= MOD
    print((a * b)%MOD)


Measured memory_bytes: 3940
from math import factorial

from sys import stdin


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def main():
    k = int(stdin.readline())

    ans = 0

    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * factorial(3) // factorial(3 - len(set([a, b, c])) + 1)

    print(ans)


if __name__ == "__main__":
    main()


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

using ll=long long;
const ll INF=1LL<<60;
const ll MOD=1e9+7;

vector<int> P, Q;
vector<int> order, seen;
int id=0;
int a, b;

void Order_judge(int N, int cnt=1){
    if(cnt == N+1){
        id++;
        bool ok1=true, ok2=true;
        for(int i=0; i<N; i++){
            if(order[i+1] != P[i]) ok1=false; 
            if(order[i+1] != Q[i]) ok2=false;
        }
        if(ok1) a=id;
        if(ok2) b=id;
        return;
    }
    for(int i=1; i<=N; i++){
        if(seen[i]) continue;
        seen[i]=true;
        order[cnt]=i;
        Order_judge(N, cnt+1);
        seen[i]=false;
    }
}

int main(){
    int N; cin >> N;
    P.resize(N);
    Q.resize(N);
    order.resize(N+1);
    seen.resize(N+1);
    for(auto &x: P) cin >> x;
    for(auto &x: Q) cin >> x;
    Order_judge(N);
    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#include <numeric>
#include <set>
#include <queue>
#include <deque>
#include <array>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <map>
#include <functional>
#include <bitset>
#include <complex>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;

int32_t main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;

	vi a(n), b(n);

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

	if (a == b) {
		cout << 0 << '\n';
		return 0;
	}

	ll ans = 0;
	vi beta;

	for (int i = 0; i < n; i++) {

		if (a[i] <= b[i]) {

			ans += b[i];
		}
		else {

			beta.pb(i);
		}
	}

	if (sz(beta) >= 2) {

		sort(all(beta), [&](int i, int j) { return b[i] > b[j]; });

		for (int i = 0; i < sz(beta) - 1; i++) {

			ans += b[beta[i]];
		}
	}

	cout << ans;
}


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

const int mo=1e9+7;
const int maxn=2010*2010;

int n,k,dp[2][2010],fac[maxn],inv[maxn];

int power(int x,int k)
{
	int res=1;
	while (k)
	{
		if (k&1) res=(LL)res*x%mo;
		x=(LL)x*x%mo;
		k>>=1;
	}
	return res;
}

int C(int n,int m)
{
	return (LL)fac[n]*inv[n-m]%mo*inv[m]%mo;
}

int main()
{
#ifdef h10
	freopen("ball.in","r",stdin);
	freopen("ball.out","w",stdout);
#endif
	int i,j,fk=0;
	scanf("%d%d",&n,&k);
	if (k==1) {puts("1"); return 0;}
	fac[0]=1;
	for (i=1;i<=n*k;i++)
		fac[i]=(LL)i*fac[i-1]%mo;
	inv[0]=inv[1]=1;
	for (i=2;i<=n*k;i++)
		inv[i]=mo-(LL)inv[mo%i]*(mo/i)%mo;
	for (i=1;i<=n*k;i++)
		inv[i]=(LL)inv[i]*inv[i-1]%mo;

	dp[fk][0]=1;
	for (i=0;i<n<<1;i++)
	{
		fk^=1;
		memset(dp[fk],0,sizeof(dp[fk]));
		for (j=1;j<=n&&j<=n+n-i;j++)
			(dp[fk][j-1]+=dp[fk^1][j])%=mo;
		for (j=0;j<n&&j<n+n-i;j++)
			if (dp[fk^1][j]) (dp[fk][j+1]+=(LL)dp[fk^1][j]*C((i+j)*k/2-j+k-2,k-2)%mo)%=mo;
	}
	printf("%lld\n",(LL)dp[fk][0]*fac[n]%mo);
}


Measured memory_bytes: 31616
n, m = STDIN.gets.strip.split.map(&:to_i)
pys = []
m.times do
  pys << STDIN.gets.strip.split.map(&:to_i)
end

ans = {}
pys.sort_by { |v| v[1] }.each do |p, y|
  ans[p] ||= []
  ans[p] << y
end
yans = {}
ans.each do |pref, ys|
  ys.each_with_index do |y, i|
    yans[y] = "%06d%06d" % [pref, i+1]
  end
end
pys.each do |p, y|
  puts yans[y]
end

Measured memory_bytes: 39368
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

int main() {
	ll n, k;
	cin >> n >> k;
	cout << min(n%k,k-n%k) << endl;
}


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

int main()
{
    string s;
    int zero = 0, one = 0;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '0')
            zero++;
        else
            one++;
    }
    cout << min(zero, one) * 2 << endl;
    return 0;
}


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

int main()
{
	int n=0;cin>>n;
	int a[100]={0};
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	
	int cnt=0,f=1;
	for(int j=0;f==1;j++)
	{
		f=0;
		for(int i=n-1;i>j;i--)
		{
			if(a[i]<a[i-1])
			{
				cnt++;
				swap(a[i],a[i-1]);
				f=1;
			}
		}
	}
	
	cout<<a[0];
	for(int i=1;i<n;i++)
	{
		cout<<" "<<a[i];
	}
	cout<<endl<<cnt<<endl;
	return 0;
}

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


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

int n, sum[128][128], f[128][128];

int solve()
{
        int ans = f[0][0];
        for (int si = 0; si < n; si++) {
                for (int ti = si+1; ti <= n; ti++) {
                        int l = 0, r = 0, s = 0;
                        while(l < n) {
                                if(s < 0) {
                                        l = r;
                                        s = 0;
                                }
                                else if(r < n) {
                                        s += sum[ti][r]-sum[si][r];
                                        r++;
                                        ans = max(ans, s);
                                }
                                else break;
                        }
                }
        }
        return ans;
}

void input()
{
        cin >> n;
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                        cin >> f[i][j];
                        sum[i+1][j] = sum[i][j]+f[i][j];
                }
        }
}

int main()
{
        input();
        cout << solve() << endl;
        return 0;
}

Measured memory_bytes: 1264
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

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

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

struct UnionFind {
  vector<int> data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

ll fuven(ll N) {
  return N * (N - 1) / 2;
}

int main() {
  ll N, M; cin >> N >> M;
  vi A(M), B(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
  }

  UnionFind uf(N);
  vi ans(M+1, fuven(N));
  ll diff = 0;
  for (int i = M-1; i >= 0; i--) {
    ans[i] = ans[i+1] - diff;
    int a = A[i], b = B[i];
    ll sa = uf.size(a), sb = uf.size(b);
    // cout << "sa, sb = " << sa<<", "<<sb << endl;
    if (!uf.unite(a, b)) {
      diff = 0;
    } else {
      diff = sa * sb;
    }
  }
  for (int i = 0; i < M; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4096
#include "bits/stdc++.h"
using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if (s[0] == s[n - 1]) {
        if (n & 1) puts("Second");
        else puts("First");
    }
    else {
        if (n & 1) puts("First");
        else puts("Second");
    }
}

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

int f_rec(int cnt){
  return 2 * f_rec(cnt / 2) + 1;
}


int main(){
  int64_t h, ans=1;
  cin >> h;
  while(h > 0){
    ans *= 2;
    h /= 2;
  }
  cout << ans-1 << endl;
  return 0;
}


Measured memory_bytes: 3532
import itertools
n,m = map(int,input().split())
tf = [[False for _ in range(n)] for _ in range(n)]
for _ in range(m):
  ai,bi = map(int,input().split())
  ai -= 1
  bi -= 1
  tf[ai][bi] = True
  tf[bi][ai] = True
l = [i for i in range(1,n)]
c = 0
for v in itertools.permutations(l,n-1):
    if tf[0][v[0]] == True:
      flag = True
      for i in range(n-2):
        if tf[v[i]][v[i+1]] == False:
          flag = False
          break
      if flag:
        c += 1
print(c)

Measured memory_bytes: 69792
from collections import Counter
c = Counter()

N, M = map(int,input().split())
a = list(map(int,input().split())) 
s = 0
c[s] += 1
for i in range(N):
  s = (s + a[i]) % M
  c[s] += 1
# print(c)
S=0
# t=0
for (i,k) in c.items():
  if k > 1:
    S += (k-1)*k//2
  # t += k
print(S)
# print(t)

Measured memory_bytes: 14956
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

int main()
{
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    long long ans = 0;
    if (k < a)
        ans = k;
    else if (a <= k && k <= a + b)
        ans = a;
    else
        ans = a - (k - (a + b));
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[100010],ans=0;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        if(a[i]%2==1) ans++;
    }
    if(ans%2==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
template <typename T>
T gcd(T m, T n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
         r %= 1000000007;
         rr %= 1000000007;
    }
    r /= rr;
     r %= 1000000007;
    return r;
}
#define rep(a,b,c) for(ll a = b; a < c; ++i)
ll mod = 1000000007;
//---------------------------------------------------------------------------------------------------
ll f[101010];
void init() {
    f[0] = 1;
    rep(i, 1, 101010) f[i] = (f[i - 1] * i) % mod;
}
//---------------------------------------------------------------------------------------------------
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = f[n-k]; // = (n-k)!
    ll c = f[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * inv(bc)) % mod;
}
ll pow2_(ll n){
  
  ll div = 1000000007ll;
  ll ans = 0,k=2;
  {
    bitset<48> b(n);
    FOR(i,32){
      ans+=b[i]*k%div;
      ans%=div;
      k*=k;
      k%=div;
    }
  }
  return ans;
}
int main(){
  ll K,N;
  cin>>K>>N;
  vector<ll> A(N);
  FOR(i,N){
    cin>>A[i];
  }
  ll max_=K-A[N-1]+A[0];
  FOR(i,N-1){
    ll t = A[i+1]-A[i];
    if(t>max_)max_=t;
  }
  cout<<K-max_<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a==5&&b==5&&c==7) cout << "YES" << endl;
  else if (a==5&&b==7&&c==5) cout << "YES" << endl;
  else if (a==7&&b==5&&c==5) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
using System;

namespace Transfer
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);

            int bucketA = a - b;
            int bucketB = 0;
            if (bucketA < c)
                bucketB = c - bucketA;

            Console.WriteLine(bucketB);
        }
    }
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,cnt1=0,cnt2=0,t=0,ca,cb;
	cin>>n;
	vector<int>v(n),a(n),b(n);
	for(int i=0;i<n;i++)cin>>v.at(i);
	a=v;
	for(int i=0;i<n;i++)cin>>v.at(i);
	b=v;
	sort(v.begin(),v.end());
	do{
		t++;
		for(int i=0;i<n;i++){
			if(v.at(i)==a.at(i)){
				cnt1++;
				if(cnt1==n){
					ca=t;
				}
			}
			if(v.at(i)==b.at(i)){
					cnt2++;
					if(cnt2==n){
					cb=t;
				}
			}
		}
		cnt1=0;
		cnt2=0;
	}while(next_permutation(v.begin(),v.end()));
	cout<<abs(ca-cb)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    int ans=0;
    for(int i=1;i<=N;i++){
        int x=0;
        int y=i;
        while(y>0){
            x++;
            y=y/10;
        }
        if(x%2==1) ans++;
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
import sys
from collections import deque
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7


def inp(): return int(sys.stdin.readline())


def inp_list(): return list(map(int, sys.stdin.readline().split()))


def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
r = -1
if 0 < N < 10:
    r = N
else:
    r = int(str(N)[-1])

if r in [2, 4, 5, 7, 9]:
    print('hon')
elif r in [0, 1, 6, 8]:
    print('pon')
else:
    print('bon')



Measured memory_bytes: 9952
S = input()
if S == "RRR":
  print(3)
elif S == "RRS":
  print(2)
elif S == "SRR":
  print(2)
elif S == "RSS":
  print(1)
elif S == "SRS":
  print(1)
elif S == "SSR":
  print(1)
elif S == "RSR":
  print(1)
else:
  print(0)

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

int res[4096][12];
int books[12][12];
int price[12];

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  rep(i, n) {
    cin >> price[i];
    rep(j, m) cin >> books[i][j];
  }
  int res_size = 1;
  rep(i, n) res_size *= 2;
  rep(i, res_size) rep(j, m) res[i][j] = 0;
  
  int min = 10000000;
  rep(i, res_size) {
    int cost = 0;
    rep(j, n) {
      if (i >> j & 1) {
        cost += price[j];
        rep(k, m) {
          res[i][k] += books[j][k];
        }
      }
    }
    bool flug = true;
    rep(j, m) if (res[i][j] < x) flug = false;
    if ((flug) && (min > cost)) min = cost;
  }
  if (min == 10000000) cout << -1 << endl;
  else cout << min << endl;
  return 0;
}


Measured memory_bytes: 3776
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
 
 
const int INF = 1000000;
 
 
const int MAX_V = 10000;


bool calc(vector<string> v, int n){
	for(int i = 0; i < v.size(); i++){
		for(int j = 0; j < v[i].size(); j++){
			if(v[i][j] == 'X') v[i][j] = '0' + n;
		}
		if(v[i].size() > 1 && v[i][0] == '0') return false;
		reverse(all(v[i]));
	}
	string s(v[2].size(), -'0');
	for(int i = 0; i < v[2].size(); i++){
		//s[i] += v[0][i] - '0' + v[1][i];
		s[i] += i < v[0].size() ? v[0][i] : '0'; 
		s[i] += i < v[1].size() ? v[1][i] : '0';
		if(s[i] > '9'){
			s[i] -= 10;
			if(i + 1 < s.size()) s[i + 1]++;
			else return false;
		}
	}
	//cout<<v[0]<< " "<<v[1]<<" "<<v[2]<<" "<<s<<endl;
	return s == v[2];
}


int main(){
	string s;
	while(cin>>s){
		vector<string> v;
		int a = s.find("+"), b = s.find("=");
		v.pb(s.substr(0, a));
		v.pb(s.substr(a + 1, b - a - 1));
		v.pb(s.substr(b  + 1));
		int ans = -1;
		for(int i = 9; i >= 0; i--){
			if(calc(v, i)){
				ans = i;
				break;
			}
		}
		if(ans == -1) cout<<"NA"<<endl;
		else cout<<ans<<endl;
	}
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    ll n;
    ll cost = 0;
    cin >> n;
    vector<ll> a(n),b(n);

    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    for (int i = n-1; i >= 0; --i) {
        a[i] += cost;
        ll amari = a[i]%b[i];
        if(amari == 0) continue;
        cost += b[i]-amari;
    }
    cout << cost << endl;
    return 0;
}


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

//標準偏差を求めるプログラム
int main(){
    int n, i;
    double ave, s, dev;
    
    while(1){
        cin >> n;
        if (n == 0) break;
        int data[n] = {};
        ave = 0;
        i = 0;
        while(i < n){
            cin >> data[i];
            ave = ave + data[i];
            i++;
        }
        
        ave = ave / n;
        dev = 0;
        i = 0;
        while(i < n){
            dev = dev + pow(data[i] - ave, 2.0);
            i++;
        }
        s = sqrt(dev / n);

        cout << fixed << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
int eval1(string S){
  int N = S.size();
  int ans = 0;
  int p = 1;
  for (int i = 0; i < N; i++){
    if (S[i] == '+'){
      ans += p;
      p = 1;
    } else if (S[i] != '*'){
      p *= S[i] - '0';
    }
  }
  ans += p;
  return ans;
}
int eval2(string S){
  int ans = 0;
  int N = S.size();
  ans = S[0] - '0';
  for (int i = 1; i < N; i += 2){
    if (S[i] == '+'){
      ans += S[i + 1] - '0';
    } else {
      ans *= S[i + 1] - '0';
    }
  }
  return ans;
}
int main(){
  string S;
  cin >> S;
  int N;
  cin >> N;
  int M = eval1(S);
  int L = eval2(S);
  if (M == N){
    if (L == N){
      cout << 'U' << endl;
    } else {
      cout << 'M' << endl;
    }
  } else {
    if (L == N){
      cout << 'L' << endl;
    } else {
      cout << 'I' << endl;
    }
  }
}


Measured memory_bytes: 3196
# -*- coding: utf-8 -*-
#https://atcoder.jp/contests/abc141/tasks/abc147_b
import sys
#import collections

#n= int(input())
s= input()
#tmp = input().split()
#a,b,c = list(map(lambda a: int(a), tmp))


total=0
for i in range(0,len(s)//2):
	if (s[i]!=s[len(s)-i-1]):
		total+=1
print(total)

Measured memory_bytes: 2940
let (+@) a b = (a + b) mod 1000000007
let f = max_int
let trans =
  [(0, [1; 0; 2; 0]); (1, [1; 3; 4; 5]);
   (2, [6; 0; 2; 0]); (3, [1; 0; f; 0]);
   (4, [6; f; 7; 8]); (5, [1; 0; 9; 0]);
   (6, [1; f; 4; 5]); (7, [6; f; 2; 0]);
   (8, [1; f; 2; 0]); (9, [6; f; 2; 0]);]
let transr =
  Array.init 10 (fun i ->
    List.fold_left (fun stk (u, vs) -> 
      List.fold_left (fun stk v ->
        if v = i then u::stk else stk) stk vs) [] trans)
let () =
  Scanf.scanf "%d" @@ fun n ->
  let rec g i arr =
    if i >= n then Array.fold_left (+@) 0 arr else
    Array.map (fun vs ->
      List.fold_left (fun s i -> s +@ arr.(i)) 0 vs) transr
    |> g (i+1)
  in
  g 0 [|1;0;0;0;0;0;0;0;0;0;|] |> Printf.printf "%d\n"




Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <numeric>

using namespace std;

int main(){
    int m, n;
    while(cin >> m >> n, m&&n){
        vector<int> card_t, card_h;
        int tmp;
        for(int i=0; i<m; i++){
            cin >> tmp;
            card_t.push_back(tmp);
        }
        for(int i=0; i<n; i++){
            cin >> tmp;
            card_h.push_back(tmp);
        }

        //sort(card_t.begin(), card_t.end());
        //sort(card_h.begin(), card_h.end());

        int sum_t =  accumulate(card_t.begin(), card_t.end(), 0);
        int sum_h =  accumulate(card_h.begin(), card_h.end(), 0);

        int min = 999999999, tmin = 0, hmin = 0;
        for(auto t: card_t){
            for(auto h: card_h){
                //if((t-h)*2 == (sum_t - sum_h) && min > t+h){
                if(sum_t - t + h == sum_h - h + t && min > t+h){
                    tmin = t;
                    hmin = h;
                    min = t+h;
                }
            }
        }
        if(min == 999999999){
            cout << -1 << endl;
        }else{
            cout << tmin << " " << hmin << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
int n,d[maxn],a[maxn],b[maxn],ans,co[maxn];
vector<pair<int,int> > G[maxn];
void dfs(int u,int c,int fa)
{
	int cnt=0;
	for(int i=0;i<(int)G[u].size();i++)
	{
		int v=G[u][i].first,id=G[u][i].second;
		if(v==fa) continue;
		if(++cnt==c) cnt++;
		co[id]=cnt;
		dfs(v,cnt,u);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		G[a[i]].push_back(make_pair(b[i],i));
		G[b[i]].push_back(make_pair(a[i],i));
		d[a[i]]++;
		d[b[i]]++;
		ans=max(ans,max(d[a[i]],d[b[i]]));
	}
	printf("%d\n",ans);
	dfs(1,0,0);
	for(int i=1;i<n;i++) cout<<co[i]<<endl;
	return 0;
}

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

using namespace::std;



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

	if ((N % 2) == 0) {
		int M = 0.5 * (N - 1) * N - 0.5 * N;
		cout << M << endl;
		for (int i = 1; i < N; i++) {
			for (int j = i + 1; j <= N; j++) {
				if (j == N - i + 1) {

				}
				else {
					cout << i << " " << j << endl;
				}
			}
		}


	}
	else {
		int M = 0.5 * (N - 1) * N - 0.5 * (N-1);
		cout << M << endl;
		for (int i = 1; i < N; i++) {
			for (int j = i + 1; j <= N; j++) {
				if (j == N - i) {

				}
				else {
					cout << i << " " << j << endl;
				}
			}
		}

	}

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

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

ll dp[1010][1010];
bool seen[1010][1010];

int main(){
  int h,w; cin >> h >> w;
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  a--; b--; c--; d--;
  vector<string> g(h);
  rep(i,h) cin >> g[i];
  rep(i,h)rep(j,w) dp[i][j]=lnf;
  queue<pair<int,int> > q;
  q.push(make_pair(a,b));
  dp[a][b]=0;
  set<pii> st;
  const int dy[4]={-1,1,0,0};
  const int dx[4]={0,0,1,-1};
  while(!q.empty()){
    int y,x;
    tie(y,x)=q.front();
    q.pop();
    seen[y][x]=1;
    if(st.count(pii(y,x))) st.erase(pii(y,x));
    for(int i=-2;i<=2;i++){
      for(int j=-2;j<=2;j++){
        if(seen[y+i][x+j]) continue;
        if(0<=y+i&&y+i<h&&x+j>=0&&x+j<w&&g[y+i][x+j]=='.'&&(!(i==0&&j==0))){
          chmin(dp[y+i][x+j],dp[y][x]+1);
          st.insert(pii(y+i,x+j));
        }
      }
    }
    rep(dir,4){
      int ny=y+dy[dir];
      int nx=x+dx[dir];
      if(0<=ny&&ny<h&&nx>=0&&nx<w&&g[ny][nx]=='.'&&seen[ny][nx]==0){
        chmin(dp[ny][nx],dp[y][x]);
        seen[ny][nx]=1;
        q.push(pii(ny,nx));
      }
    }
    if(q.empty()&&st.size()){
      for(auto v:st) q.push(pii(v.first,v.second));
      set<pii> st;
    }
  }
  if(seen[c][d]==0){
    cout << -1 << endl;
    return 0;
  }
  cout << dp[c][d] << endl;
}

Measured memory_bytes: 14616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define MAX 128
#define fst first
#define sec second
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
#define int long long
const double PI = 3.141593;
const ll MOD = 1e9 + 7;
const int INF = 100100100;
const double EPS = 1e-9;
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;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }     //最小公倍数
ll combination(ll n, ll r){if (r * 2 > n)r = n - r;ll dividend = 1;ll divisor = 1;for (ll i = 1; i <= r; ++i){dividend *= (n - i + 1);divisor *= i;}return dividend / divisor;}


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

    int a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;

    return 0;
}

Measured memory_bytes: 256
m, n, x, y = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

ans = 'War'
for z in range(-100, 101):
    if x < z <= y and max(xs) < z <= min(ys):
        ans = 'No War'
        break
    
print(ans)

Measured memory_bytes: 3060