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

int main(void) {
    int d;
    int s;
    int length;
    while (std::cin >> d) {
        s = 0;
        for (int i = 0; i < (600 / d); i++) {
            s += d * d * d * i * i;
        }
        std::cout << s << std::endl;
    }
    return 0;
}

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

#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int n; cin>>n;
  vector<int> a(n, 0);
  vector<int> x(n, 0);
  for (int i=0; i<n; i++) {
    int t; cin>>t;
    a[i] = t;
    x[i] = t-(i+1);
  }
  SORT(x);
  int b = x[n>>1];
  ll ans=0;
  for (int i=0; i<n; i++) {
    ans += abs(a[i] - (b+(i+1)));
  }
  cout << ans << endl;
}

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


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

using namespace std;


int main() {

    int N;
    cin >> N;

    if(N == 1)
    {
        cout << "1.0000000000" ;
        return 0;
    }

    if(N % 2 == 0)
    {
        cout << "0.5000000000";
    } else
    {
        cout << double((N/2)+1)/N;
    }

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define drrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int MOD = 1'000'000'000 + 7;
const int INF = 1'000'000'000 + 5;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(16);

	int n; std::cin >> n;
	int ans = -1;
	rrep(x, n) {
		if (x + (x * 8) / 100 == n)
			ans = x;
	}
	if (ans == -1)
		std::cout << ":(" << "\n";
	else
		std::cout << ans << "\n";
}


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

int graph[8][8] = {0};

int N, M;
int res = 0;
int perm[8];

void permute(int pos, int n){
    for(int i=0; i<N; i++) perm[i] = i;

    do{
        if(perm[0] != 0) continue;
        for(int i=0; i<N-1; i++){
            if(graph[perm[i]][perm[i+1]] == 0) break;
            if(i+1 == N-1) res++;
        }
    }while(next_permutation(perm, perm+N));
}

int main(){
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        graph[a-1][b-1] = 1;
        graph[b-1][a-1] = 1;
    }

    permute(0, N);
    cout << res << endl;
}


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

using namespace std;

int main(void) {
    int N, L;
    cin >> N >> L;
    vector<string> s(N);
    for(int i=0; i<N; i++) {
        cin >> s[i];
    }
    
    sort(s.begin(), s.end());
    for(int i=0; i<N; i++) {
        cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,min = INT_MAX,c = 0;
  cin >> n;
  for(int i = 0; i < n; ++i){
    int a;
    cin >> a;
    c = 0;
    while(a % 2 == 0){
      c++;
      a /= 2;
    }
    if(min > c)
      min = c;
    }

    cout << min << endl;
  }


Measured memory_bytes: 256
// created_by  Rishi_Mohan

#include<bits/stdc++.h>

#define    ll           long long
#define    db1(x)       cout<<#x<<"="<<x<<'\n'
#define    db2(x,y)     cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define    db3(x,y,z)   cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

using namespace std;
void solve()
{
   int x;
   cin >>x ;
   int ans = 0;
   for(int i=1;i<=500;i++)
   {
     if((360*i) % x==0)
        {
            ans = (360*i)/x;
            break;
        }
   }
   cout << ans << endl;
}

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


Measured memory_bytes: 3648
#include<stdio.h>
#include<stdlib.h>


int int_sort( const void * a , const void * b ) {
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}

int main(void){
 
  int N;
  int A[200000];
  int i,j;
  
  size_t data_cnt;
  
   scanf("%d\n",&N);
  
  for(i=0;i<N;i++){
  	
    scanf("%d ",&A[i]);
  
  }
  
  
 
  data_cnt =N;
  
  qsort((void*)A, data_cnt , sizeof(A[0]), int_sort );
  
  int y=1;
 
  for(i=0;i<N-1;i++){
  	if(A[i]==A[i+1]){
    	y=0;
    }
  }
   
  if(y==1){
  	printf("YES\n");
  }else{printf("NO\n");}
  
  
  return 0;
  
}

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

using namespace std;

int main(){
    int n;cin >> n;
    int d=0;
    string s;cin >> s;
    for(auto c : s)
        if(c == 'R')
            d ++;
        else
            d --;
    cout << (d>0 ? "Yes" : "No") << "\n";
    return 0;
}



Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
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);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
signed main()
{
	fastio;
	string s;	cin>>s;
	if(s[2]==s[3] && s[4]==s[5])
		cout<<"Yes";
	else
		cout<<"No";
}











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

using namespace std;

class Solution {
public:
	void solve() {
		int s, w;
		cin >> s >> w;
		if (s <= w)
			cout << "unsafe\n";
		else
			cout << "safe\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <deque>

using namespace std;

int main(void)
{
	int n;
	string str;
	
	cin >> n;
	while (n--){
		cin >> str;
		
		deque <char> d;
		d.push_back(str[0]);
		bool done[30] = {false};
		done[str[0] - 'a'] = true;
		for (int i = 3; i < str.length(); i += 3){
			int now = str[i] - 'a';
			if (done[now]) {
				// cout << i << " vst" << endl;
				continue;
			}
			if (str[i - 1] == '>'){
				d.push_back(str[i]);
				done[now] = true;
			}
			else {
				d.push_front(str[i]);
				done[now] = true;
			}
		}
		for (int i = 0; i < d.size(); i++){
			cout << d[i];
		}
		cout << endl;
	}
	
	return 0;
}

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


void solve () {
    int n;
    cin >> n;
    map<int, int> mp;
    bool ok = 0;
    bool okk = 1;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int c = x / 400;
        if (c >= 8) {
            ok = 1;
            mp[8]++;
        } else {
            mp[c]++;
            okk = 0;
        }
    }
    cout << mp.size() - ok + okk << " " << mp.size() + mp[8] - ok << endl;

}

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


Measured memory_bytes: 3660
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
    
        var sc = new Scanner(System.in);
    
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        
        var y = new int[h+1];
        var x = new int[w+1];
        int maxY = 0;
        int maxX = 0;
        var set = new HashSet<Long>();
        for(int i = 0; i < m; i++){
            int hi = Integer.parseInt(sc.next());
            int wi = Integer.parseInt(sc.next());
            y[hi]++;
            x[wi]++;
            maxY = Math.max(y[hi], maxY);
            maxX = Math.max(x[wi], maxX);
            set.add(hi * 10000000L + wi);
        }
        
        var listY = new ArrayList<Integer>();
        for(int i = 1; i <= h; i++){
            if(y[i] == maxY) listY.add(i);
        }
        var listX = new ArrayList<Integer>();
        for(int i = 1; i <= w; i++){
            if(x[i] == maxX) listX.add(i);
        }
        
        int a = listY.size();
        int b = listX.size();
        boolean c = false;
        for(int i = 0; i < a; i++){
            int hi = listY.get(i);
            for(int j = 0; j < b; j++){
                int wj = listX.get(j);
                if(!set.contains(hi * 10000000L + wj)){
                    c = true;
                    break;
                }
            }
        }
        if(c){
            System.out.println(maxY + maxX);
        }else{
            System.out.println(maxY + maxX -1);
        }
    }
}

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

ans = 0
for A in range(1, 1000):
    for B in range(A, 1000000):
        C = N - A * B
        if C <= 0:
            break
        # print(A, B, C)
        if A != B:
            ans += 2
        else:
            ans += 1
print(ans)


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

int main() {
  int n;cin>>n;
  string t="MARCH";
  vector<int> cnt(5);
  rep(i,n){
    string s;cin>>s;
    rep(j,5){
      if(s[0]==t[j])cnt[j]++;
    }
  }
  ll ans=0;
  rep(i,3)for(int j=i+1;j<4;j++)for(int k=j+1;k<5;k++){
    ans+=(ll)cnt[i]*cnt[j]*cnt[k];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3616
from collections import Counter


S = input()
N = len(S)

L = [0] * (N + 1)
s = 0
for i in range(N):
    s += int(S[N - 1 - i]) * pow(10, i, 2019)
    L[i + 1] = (s % 2019)

C = Counter(L)
cnt = 0
for key in list(C.keys()):
    k = C[key]
    cnt += (k * (k - 1)) // 2

print(cnt)


Measured memory_bytes: 70824
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8


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

Node *root, *NIL;

void  serch(int k){
    Node  *y = NIL;
    Node  *x = root;
    Node  *z;

    z = (Node *)malloc(sizeof(Node));
    z -> key = k;

    while( x!=NIL ) {
        if( z->key == x->key ){
            cout << "yes" << endl;
            return;
        }
        y = x;
        if(z->key < x->key){
            x = x->left;
        }
        else{
            x = x->right;
        }
    }
    cout << "no" << endl;
}

void insert(int k){
    Node  *y = NIL;
    Node  *x = root;
    Node  *z;

    z = (Node *)malloc(sizeof(Node));
    z -> key = k;
    z -> left = NIL;
    z -> right = NIL;

    while( x!=NIL ) {
        y = x;
        if(z->key < x->key){
            x = x->left;
        }
        else{
            x = x->right;
        }
    }
    z->parent =y;
    if(y==NIL){
        root = z;
    }
    else{
        if (z->key < y->key){
            y->left = z;
        }
        else{
            y->right = z;
        }
    }
}

void inorder(Node *u){
    if(u==NIL){
        return;
    }
    inorder(u->left);
    cout <<" "<< u->key ;
    inorder(u->right);
}

void preorder(Node *u){
    if(u==NIL){
        return;
    }
    cout <<" "<< u->key ;
    preorder(u->left);
    preorder(u->right);
}

void pastorder(Node *u){
    if(u==NIL){
        return;
    }
    pastorder(u->left);
    pastorder(u->right);
    cout <<" "<< u->key ;
}

int main(){
	int N,X;
    string S;
    cin >> N;
    rep(i,N){
        cin >> S;
        if(S[0]=='i'){
            cin >> X;
            insert(X);
        }
        if(S[0]=='p'){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
        if(S[0]=='f'){
            cin >> X;
            serch(X);
        }
    }
}


Measured memory_bytes: 26540
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> vector<T> make_vec(size_t n) { return vector<T>(n); }
template<typename T, typename... Args> auto make_vec(size_t n, Args... args) {
    return vector<decltype(make_vec<T>(args...))>(n, make_vec<T>(args...));
}
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U& u, const V... v) {
    for (auto& e : u) fill_v<T>(e, v...);
}

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

    int n;
    string s;
    cin >> n >> s;
    int mx = 0;
    int now = 0;
    rep(i, n) {
        if (s[i] == 'I') now++;
        else now--;
        chmax(mx, now);
    }
    cout << mx << '\n';
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// aの入力
		int a = sc.nextInt();
		
		// sの入力
		String s = sc.next();
		
		if (a >= 3200) {
			System.out.println(s);
		}
		else {
			System.out.println("red");
		}
		
		sc.close();
	}

}


Measured memory_bytes: 23764
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    a, b, c = map(int, input().split())
    a, b, c = sorted([a, b, c])
    for i in range(10000):
        if (a % 2) + (b % 2) + (c % 2) > 0:
            return i
        a, b, c = (a + b) // 2, (a + c) // 2, (b + c) // 2
    return -1

print(main())


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

int main () {

    int N, K, Q;
    scanf("%d %d %d", &N, &K, &Q);

    vector<int> p(N, 0);

    vector<int> A(Q);
    for (int i = 0; i < Q; i++) {
        scanf("%d", &A[i]);
        A[i]--;

        p[0] += -1;
        p[A[i]] += 1;
        if (A[i] != N-1) {
            p[A[i]+1] += -1;
        }
    }

    for (int i = 1; i < N; i++) {
        p[i] += p[i-1];
    }

    for (int i = 0; i < N; i++) {
        if (K + p[i] > 0) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
  int N, L;
  int ALL_TASTE = 0;

  cin >> N >> L;
  vector<int> taste(N);
  vector<int> taste_abs(N);

  for(int i=0;i<N;i++){
    ALL_TASTE += L+(i+1)-1;
  }
  
  for(int k=0;k<N;k++){
    taste[k] = L+(k+1)-1;
    taste_abs[k] = abs(taste[k]);
  }
  vector<int>::iterator minIt = min_element(taste_abs.begin(), taste_abs.end());
  size_t minIndex = distance(taste_abs.begin(), minIt);
  
  cout << ALL_TASTE-taste[minIndex] << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
typedef long long ll;
const int MAXN=4e5+7;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;

int fa[MAXN];
struct edge
{
    int u,v,w;
}e[MAXN];
int tot=0;
void addedge(int u,int v,int w)
{
    e[tot].u=u;
    e[tot].v=v;
    e[tot++].w=w;
}
bool cmp(edge a,edge b){return a.w<b.w;}

int Find(int x)
{
    if(fa[x]==-1) return x;
    else return fa[x]=Find(fa[x]);
}
ll kruskal(int n)
{
    memset(fa,-1,sizeof(fa));
    sort(e,e+tot,cmp);
    int cnt=0;
    ll ans=0;
    for(int i=0;i<tot;++i)
    {
        int u=e[i].u,v=e[i].v,w=e[i].w;
        int t1=Find(u),t2=Find(v);
        if(t1!=t2)
        {
            ans+=w;
            fa[t1]=t2;
            cnt++;
        }
        if(cnt==n-1) return ans;
    }
    return -1;
}

struct node
{
    int x,y,id;
}p[MAXN];
bool cmp1(node a,node b)
{
    return a.x<b.x;
}
bool cmp2(node a,node b)
{
    return a.y<b.y;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>p[i].x>>p[i].y;
        p[i].id=i+1;
    }
    sort(p,p+n,cmp1);
    for(int i=0;i<n;++i)
    {
        if(i==0) addedge(p[i].id,p[i+1].id,abs(p[i+1].x-p[i].x));
        else if(i==n-1) addedge(p[i].id,p[i-1].id,abs(p[i-1].x-p[i].x));
        else
        {
            addedge(p[i].id,p[i+1].id,abs(p[i+1].x-p[i].x));
            addedge(p[i].id,p[i-1].id,abs(p[i-1].x-p[i].x));
        }
    }
    sort(p,p+n,cmp2);
    for(int i=0;i<n;++i)
    {
        if(i==0) addedge(p[i].id,p[i+1].id,abs(p[i+1].y-p[i].y));
        else if(i==n-1) addedge(p[i].id,p[i-1].id,abs(p[i-1].y-p[i].y));
        else
        {
            addedge(p[i].id,p[i+1].id,abs(p[i+1].y-p[i].y));
            addedge(p[i].id,p[i-1].id,abs(p[i-1].y-p[i].y));
        }
    }
    cout<<kruskal(n)<<endl;
    return 0;
}


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

int main() {
  string n;
  cin >> n;
  for (int i = 0; i < n.size();i++)
  {
    if (n.at(i) == '1')
    {
      n.at(i) = '9';
    }
    else if (n.at(i) == '9')
    {
      n.at(i) = '1';
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 3572
/*
*/
#include<cstdio>
#include<iostream>
#define LL long long 
using namespace std;
main() {
 	LL N, A, B;
 	cin >> N >> A >> B;
 	cout << max((LL)0, (N - 1) * B + A - (N - 1) * A - B + 1);
    return 0;
}
/*

*/


Measured memory_bytes: 256
import string
from sys import stdin
N = int(stdin.readline().rstrip())
S = list(stdin.readline().rstrip())
alpha = list(string.ascii_uppercase)
dic = {c:i for i, c in enumerate(alpha)}
ans = []
for c in S:
  idx = dic[c]+N
  if idx >= 26:
    idx -= 26
  ans.append(alpha[idx])
print(''.join(ans))

Measured memory_bytes: 39408
#include <iostream>
#include <cstring>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;

vector<pair<int, pair<int , int> > > l;

int v[20010];
int n, m, ans;


int main(void){
	int i;
	pair<int, pair<int, int> > p;
	while( cin >> n >> m, n){
		ans = 0;
		l.clear();
		memset(v, 0, sizeof(v));
		for(i = 0; i < m; i++){
			cin >> p.first >> p.second.first >> p.second.second;
			l.push_back(p);
		}
		sort(l.begin(), l.end());
		v[1] = 1;
		for(i = 0; i < m; i++) if(v[l[i].second.first]) v[l[i].second.second] = 1;
		for(i = 1; i <= n; i++) if(v[i]) ans++;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n;cin >> n;
    vl a(n),b(n);
    rep(i,n)cin >> a[i] >> b[i];
    ll cum=0;
    per(i,n){
        cum+=(b[i]-(cum+a[i])%b[i])%b[i];
    }
    cout << cum <<endl;
}

Measured memory_bytes: 4764
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val (n, k ,l ) = readIntegerList()
    val uf1 = UnionFind(n)
    repeat(k) {
        val (p, q) = readIntegerList().map { it - 1 }
        uf1.unite(p, q)
    }

    val uf2 = UnionFind(n)
    repeat(l) {
        val (p, q) = readIntegerList().map { it - 1 }
        uf2.unite(p, q)
    }

    val map = mutableMapOf<Pair<Int, Int>, Int>()
    for (i in 0 until n) {
        val p = Pair(uf1.findRoot(i), uf2.findRoot(i))
        map[p] = (map[p] ?: 0) + 1
    }

    val ansList = IntArray(n)
    for (i in 0 until n) {
        val p = Pair(uf1.findRoot(i), uf2.findRoot(i))
        ansList[i] = map[p]!!
    }
    println(ansList.joinToString(" "))
}

/**　Union find 0 ~ (n - 1)　*/
class UnionFind(n: Int) {
    val parent = IntArray(n) { it }
    val rank = IntArray(n)
    val size = IntArray(n) { 1 }

    /** O(α(n)) */
    fun findRoot(x: Int): Int {
        if (parent[x] == x) return x

        parent[x] = findRoot(parent[x])
        return parent[x]
    }

    /** O(α(n)) */
    fun sameRoot(x: Int, y: Int) = findRoot(x) == findRoot(y)

    /** O(α(n)) */
    fun unite(x: Int, y: Int) {
        val x = findRoot(x)
        val y = findRoot(y)
        if (x == y) return

        if (rank[x] < rank[y]) {
            parent[x] = y
            size[y] += size[x]
        } else {
            parent[y] = x
            if (rank[x] == rank[y]) rank[x]++

            size[x] += size[y]
        }
    }

    /** O(α(n)) */
    fun getSize(x: Int) = size[findRoot(x)]
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 96236
r=range(int(input()))
p=[[int(i)for i in input().split()] for _ in r]
p.sort(key=lambda x: x[2])
a,b,c=p[-1]
for x in range(101):
  for y in range(101):
    h=c+abs(a-x)+abs(b-y)
    if all(k==max(h-abs(i-x)-abs(j-y),0) for i,j,k in p):
      print(x,y,h)
      exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF 10000000000LL
using namespace std;
typedef long long ll;

ll X, K, R[200000], Q, T[200000], A[200000];

int main(void) {
  cin >> X >> K;
  R[0] = 0;
  REP(i, 1, K + 1) cin >> R[i];
  R[K + 1] = INF;
  cin >> Q;
  REP(i, 0, Q) cin >> T[i] >> A[i];

  ll lower = 0;
  ll upper = X;

  ll sum = 0;
  ll k = 0;
  REP(i, 0, K + 1) {
    if(i > 0) {
      lower = X - max(lower - (R[i] - R[i - 1]), 0LL);
      upper = X - max(upper - (R[i] - R[i - 1]), 0LL);
      swap(lower, upper);
    }
    sum += (i % 2 == 0 ? 1 : -1) * (R[i] - R[i - 1]);

    while(k < Q && R[i] <= T[k] && T[k] <= R[i + 1]) {
      ll a = i % 2 == 0 ? A[k] + sum : X - A[k] - sum;
      if(a <= lower) a = lower;
      if(a >= upper) a = upper;
      cout << (i % 2 == 0 ? max(a - (T[k] - R[i]), 0LL) : X - max(a - (T[k] - R[i]), 0LL)) << endl;
      k++;
    }
  }
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
#define INF 1e9;
using namespace std;
using ll = long long;
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; }
typedef pair<int,int> P;
struct Node{
    vector<P> edges;
    bool done;
    int cost;
};
int V,E,R;
vector<Node> nodes(100010);
priority_queue<P,vector<P>,greater<P>> q;
void dijkstra(){
    while(!q.empty()){
        P p = q.top();
        q.pop();
        int v = p.second;
        if (nodes[v].done) continue;
        nodes[v].done = true;
        for (P e:nodes[v].edges){
            if(nodes[e.first].cost > nodes[v].cost + e.second){
                nodes[e.first].cost = nodes[v].cost + e.second;
                q.push(P(nodes[e.first].cost,e.first));
            }
        }
    }
}
int main(){
    cin >> V >> E >> R;
    int s,t,d;
    rep (i,100010){
        nodes[i].done = false;
        nodes[i].cost = INF;
    }
    rep(i,E){
        cin >> s >> t >> d;
        nodes[s].edges.push_back(P(t,d));
    }
    nodes[R].cost = 0;
    q.push(P(0,R));
    dijkstra();
    rep(i,V){
        if (nodes[i].cost != 1000000000){
            PRINT(nodes[i].cost);
        }
        else PRINT("INF");
    }
}


Measured memory_bytes: 13468
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int P[200000];

int d[200001];
void solve(){
	int ans = N;
	rep(i, N){
		d[P[i]] = d[P[i] - 1] + 1;
		chmin(ans, N - d[P[i]]);
	}
	cout<< ans <<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) {
		cin>>P[i];
	}
	solve();
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();
    if(k<=a){
      System.out.println(k);
    }
    else if(k<=(a+b)){
      System.out.println(a);
    }
    else if(k>(a+b)){
      System.out.println(a-(k-(a+b)));
    }
  }
}

Measured memory_bytes: 35748
#include <iostream>
#include <cstdio>
#include <cstring> 
#define MN 201000
#define mod 1000000007

int inv[MN], cnt[MN], a[MN], nxt[MN];
int f[MN], s[MN];
int c[MN];
int n; 

int qpow(int x, int p)
{
	int ans = 1;
	for(; p; p >>= 1, x = 1ll * x * x % mod) if(p & 1) ans = 1ll * ans * x % mod;
	return ans;
}

void add(int x, int v) {for(int i = x; i <= n; i += i & -i) c[i] = (c[i] + v) % mod;}
int query(int x) {int ans = 0; for(int i = x; i; i -= i & -i) ans = (ans + c[i]) % mod; return ans;}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		cnt[a[i]]++;
	}
	int tot = 1, ans = 0;
	nxt[n] = n; for(int i = n - 1; i >= 1; i--) cnt[i] += cnt[i + 1] - 1, nxt[i] = cnt[i + 1] == 1 ? i : nxt[i + 1];
	for(int i = 1; i <= n; i++) tot = 1ll * tot * cnt[i] % mod;
	inv[0] = inv[1] = 1;
	for(int i = 2; i <= n; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
	s[0] = 1; for(int i = 1; i <= n; i++) s[i] = 1ll * s[i - 1] * (cnt[i] == 1 ? 1 : 1ll * inv[cnt[i]] * (cnt[i] - 1) % mod) % mod;
	for(int i = 1; i <= n; i++) f[i] = (1ll * f[i - 1] * inv[cnt[i]] % mod * (cnt[i] - 2) + 1ll * tot * inv[cnt[i]]) % mod;
	for(int i = n; i >= 1; i--)
	{
		ans = (ans + 1ll * f[a[i]] * (query(nxt[a[i]]) - query(a[i] - 1) + mod) % mod * qpow(s[a[i]], mod - 2)) % mod;
		add(a[i], s[a[i]]);
	}
	memset(c, 0, sizeof(c)); 
	for(int i = 1; i <= n; i++)
	{
		ans = (ans - 1ll * f[a[i]] * (query(nxt[a[i]]) - query(a[i]) + mod) % mod * qpow(s[a[i]], mod - 2) % mod + mod) % mod;
		add(a[i], s[a[i]]);
	}
	memset(c, 0, sizeof(c));
	for(int i = 1; i <= n; i++)
	{
		ans = (ans + 1ll * (query(n) - query(a[i])) * tot) % mod;
		add(a[i], 1);
	}
	printf("%d\n", ans);
}

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

int main()
{
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++)
  {
    if (i % 3 == 0)
      continue;
    if (i % 5 == 0)
      continue;
    ans += i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
W, H, N = [int(i) for i in input().split()]

x_min = 0
x_max = W
y_min = 0
y_max = H

for i in range(N):
  x, y, a = [int(j) for j in input().split()]
  
  if a == 1:
    x_min = max(x, x_min)
  elif a == 2:
    x_max = min(x, x_max)
  elif a == 3:
    y_min = max(y, y_min)
  else:
    y_max = min(y, y_max)

width = x_max - x_min
height = y_max - y_min

if width > 0 and height > 0:
  print(width * height)
else:
  print(0)

Measured memory_bytes: 3064
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU

// Author : Ritik Patel
// Institution: Pandit Deendayal Petroleum University
 
#include <bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define what_is(x) cout << #x << " is: " << x << endl;

template<typename T> T fast_power(T x,T y,T m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
template<typename T>
T extgcd(T a, T b, T &x, T &y) {  //when a and b are coprimes(or gcd(a,b)==1) in ax+by = t*gcd(a,b);
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  T p = b / a;
  T g = extgcd(b - p * a, a, y, x);
  x -= p * y;
  return g;
}

typedef long long ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

/******************* MAIN PROGRAM ***************/

int main(){
	FAST
	string s,t ;
	cin >> s >> t;
	cout << t + s << '\n';
	
	return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 a,b;
  cin >> a >> b;
  if(max(a,b) <= 9){
    ANS(a * b);
  }else{
    ANS(-1);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define pb                push_back
#define int               long long
#define M                 1000000007
#define mod                998244353
#define popf              pop_front
#define popb              pop_back
#define fi                first
#define se                second
#define vc                vector
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define piii              pair<int,pii>
#define f(i,a,b)           for(int i=a;i<b;i++)
#define fd(i,a,b)          for(int i=a;i>=b;i--)
float pd(float n, float a) 
{ 
  
    // Side and side length cannot be negative 
    if (a < 0 && n < 0) 
        return -1; 
  
    // diagonal 
    // degree converted to radians 
    return 2 * a * sin((((n - 2) * 180) / (2 * n)) * 3.14159 / 180); 
} 
      signed main() {
    
           int t=1;
          //cin>>t;
           while(t--)
           {
                   
                        int n,k,w,sum=0,mx=-M;
                     int a1=0,b1=0,xx=0;
                     int n0=0,n1=0,n2=0;
                     
                    cin>>n;
                    k=n%10;
                    if(k==2||k==5||k==4||k==7||k==9)cout<<"hon"<<endl;
                     else if(k==3)cout<<"bon"<<endl;
                     else cout<<"pon"<<endl;
                     



} 



    } 

Measured memory_bytes: 3676
#include <cstdio>
#include <algorithm>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMPLL(a, n) REP(i, n) printf("%lld%c", a[i], i + 1 == n ? '\n' : ' ')

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

const int N_MAX = 100000;

int N;
int a[N_MAX];
P b[N_MAX + 1];
ll c[N_MAX];

bool compare_vd_ia (const P &p1, const P &p2) {
  if (p1.first != p2.first) return p1.first > p2.first;
  return p1.second < p2.second;
}

void solve() {
  REP(i, N) b[i] = P(a[i], i);
  b[N] = P(0, 0);
  sort(b, b + N + 1, compare_vd_ia);
  // REP(i, N) printf("(%d, %d)\n", b[i].first, b[i].second + 1);
  int i = 0;
  int wk_i = N;
  while (i < N) {
    ll wk_v = b[i].first;
    wk_i = min(wk_i, b[i].second);
    while (i < N && b[i].first == wk_v) i++;
    c[wk_i] += (wk_v - b[i].first) * i;
  }
  REP(i, N) printf("%lld\n", c[i]);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", a + i);
}

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


Measured memory_bytes: 2944
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=505,M=N*N;
int n,i,x,j,a[M];
struct arr{int x,k;}d[N];
bool operator < (arr A,arr B){return A.x<B.x;}
void write(int x){if (x>9) write(x/10);putchar(x%10+48);}
int main(){
	for (scanf("%d",&n),i=1;i<=n;i++)
		scanf("%d",&d[i].x),d[i].k=i;
	sort(d+1,d+n+1);x=1;
	for (i=1;i<=n;i++){
		int k=d[i].k,nx=d[i].x;
		for (j=k-1;j&&x<nx;j--){
			for (;a[x];x++);a[x]=k;
		}
		if (a[nx]){puts("No");return 0;}
		a[nx]=k;
	}
	for (x=n*n,i=n;i;i--){
		int k=d[i].k,nx=d[i].x;
		for (j=n-k;j&&x>=nx;j--){
			for (;a[x];x--);a[x]=k;
		}
		if (x<nx){puts("No");return 0;}
	}
	puts("Yes");
	for (i=1;i<=n*n;i++) write(a[i]),putchar(' ');
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int>h(n);
    for(int i=0;i<n;i++)
        cin>>h[i];
    int c[n]={0};
    int tr[n]={0};
    tr[0]=1;
    queue<int>q;
    q.push(0);
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        for(int i=1;i<=k;i++)
        {
        if(x+i<n)
        {
            if(tr[x+i]==0)
            {
                c[x+i]=c[x]+abs(h[x]-h[x+i]);
                q.push(x+i);
                tr[x+i]=1;
            }
            else
            {
                if(c[x+i]>c[x]+abs(h[x]-h[x+i]))
                {
                    q.push(x+i);
                    c[x+i]=c[x]+abs(h[x]-h[x+i]);
                }
            }
        }
    }
    }
    cout<<c[n-1]<<endl;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(){
	int n, k;
	scanf("%d", &n);
	scanf("%d", &k);
	int temp = 1;
	while(n--){
		if(temp*2 < temp+k) temp*=2;
		else temp+=k;
	}
	printf("%d\n", temp);
	return 0;
}

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

int main() {
	int q;

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

		while (c > 0 && a > 0 && n > 0) {
			c--;
			a--;
			n--;
			cnt++;
		}
		while (c > 1 && a > 0) {
			c -= 2;
			a--;
			cnt++;
		}
		while (c > 2) {
			c -= 3;
			cnt++;
		}
		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


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

    int ans = 0;
    rep(i, 3) {
        if (s[i]=='1') ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, a, b) for (ll i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define w(tc) ll tc;cin>>tc;while(tc--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define PI 3.14159265359
static const int INF = 1e9+7;
using namespace std;
ll minimumProduct(ll a,ll b,ll x,ll y,ll n)//Check once by reducing a first and b second and then vice versa.
{
    ll m1=min(a-x,n);
    n=n-m1;
    ll m2=min(b-y,n);
    a=a-m1;
    b=b-m2;
    ll ans=a*b;
    return ans;
}
int main()
{
    ll n;
    cin>>n;
    vector<ll>a(n);
    rep(i,n)
    {
        cin>>a[i];
        a[i]=a[i]%INF;
    }
    vector<ll>prefix(n);
    prefix[0]=a[0]%INF;
    repr(i,1,n)
    {
        prefix[i]=(prefix[i-1]+a[i])%INF;
    }
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        ll ad=(a[i]*(prefix[n-1]-prefix[i]))%INF;
        sum=sum+ad;
        sum=sum%INF;
    }
    if(sum<0)
    {
        cout<<sum+INF<<endl;
    }
    else
    {
        cout<<sum<<endl;
    }
}


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

int main(){
   int N, X;
   std::cin >> N >> X;
   int x;
   std::vector<int> y(N);
   for(int i=0; i<N; ++i){
      std::cin >> x;
      y[i] = abs(x - X);
   }

   std::sort(y.begin(),y.end());
   int ans = 0;
   int q = y[0];
   for(int i=1; i<N; ++i){
      int p = y[i];
      while(p%q != 0){
	 int tmp = q;
	 q = p % q;
	 p = tmp;
      }
   }
   std::cout << q << std::endl;
   return 0;
}


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

int main() {
  long n,m;
  cin >> n >> m;
  string S,T;
  cin >> S >> T;
  
  long i;
  for(i=1; i<m; i++){
    if((i*n)%m==0) break;
  }
  
  long lcm=i*n,gcm=n*m/lcm;
  for(i=0; i<gcm; i++){
    if(S[i*(n/gcm)]!=T[i*(m/gcm)]){
      cout << -1; return 0;
    }
  }
  cout << lcm;
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

//D日目時点のスコアを計算
int score(int D, int c[], int s[][26], int t[]){
    int pen_day[26];
    for(int i=0; i<26; i++){
        pen_day[i]=1;
    }
    int score=0;
    
    for(int i=0; i<D; i++){
        int type=t[i]-1;
        pen_day[type]=0;
        //満足度増加
        score+=s[i][type];
        //満足度低下
        for(int j=0; j<26; j++){
            int dec=c[j]*pen_day[j];
            score-=dec;
        }
        //日数追加
        for(int j=0; j<26; j++){
            pen_day[j]++;
        }        
    }
    return score;
}

//満足度の変移
int hen_pen(int st, int end, int c[], int s[][26], int t[], int type1, int type2){
    int sum=0;
    int de_type1=0;
    int de_type2=0;
    int last1=0, last2=0;

    for(int i=st; i<=end; i++){
        if(t[i]==type1){
            de_type1++;
            last1=i;
        }
        if(t[i]==type2){
            de_type2++;
            last2=i;
        }
    }

    sum+=c[type1]*de_type1;
    sum+=c[type2]*de_type2;
    sum+=(end-last1)*c[type1];
    sum-=(last2-st)*c[type2];

    return sum;
}

void Greedy(int D, int c[], int s[][26]){
    int t[D], max_type=0, max_score=0;

    for(int i=0; i<D; i++){
        max_score=0;
        for(int j=0; j<26; j++){
            t[i]=j+1;
            int S=score(i+1, c, s, t);
            if(max_score < S){
                max_score = S;
                max_type=j+1;
            }
        }
        t[i]=max_type;
    }

    //局所探索
    int tmp;
    int roop_num=0;
    int MAX=max_score;
    while(1){
        int a=rand()%D;
        int b=rand()%D;

        if(a>b){
            tmp=a;
            a=b;
            b=tmp;
        }

        //t[a],t[b]を入れ替え
        tmp=t[a];
        t[a]=t[b];
        t[b]=tmp;

        //scoreを計算
        int now_score=score(fmax(a,b), c, s, t);
        if(MAX<now_score) MAX=now_score;
        else{
            tmp=t[a];
            t[a]=t[b];
            t[b]=tmp;  
        }
        roop_num++;
        if(roop_num==D*100) break;
    }

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

int main(void){
    int D, c[26], s[365][26];

    //入力
    scanf("%d", &D);
    for(int i=0; i<26; i++){
        scanf("%d", &c[i]);
    }
    for(int i=0; i<D; i++){
        for(int j=0; j<26; j++){
            scanf("%d", &s[i][j]);
        }
    }

   /*ここから処理*/
   /*
    int num=1;
    for(int i=0; i<D; i++){
        printf("%d\n", num);
        num++;
        if(num>26) num=1;
    }
    */

   Greedy(D, c, s);


    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

int calc(vint A){
	int N=A.size();
	sort(all(A));
	if(N&1){
		return A[N/2];
	}
	else{
		return A[N/2]+A[N/2-1];
	}
}

signed main(){
	int N;
	cin>>N;
	vint A(N),B(N);
	rep(i,N)cin>>A[i]>>B[i];

	int ma=calc(A);
	int mb=calc(B);
	cout<<mb-ma+1<<endl;
    return 0;
}


Measured memory_bytes: 8008
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << n / 2 << endl;
  } else {
    cout << n / 2 + 1 << endl;
  }
  return 0;
}

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

int main() {
	// your code goes here
	int a,b,c;
	cin >> a >> b >> c;
	if(((a==5)&&(b==5)&&(c==7))||((a==5)&&(b==7)&&(c==5))||((a==7)&&(b==5)&&(c==5))){
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

	string alp = "0abcdefghijklmnopqrstuvwxyz";
	ll N;
	cin >> N;
	string s = "";	
	while (N != 0) {
		char c;
		c = alp[N % 26];
		N /= 26;

		if (c == '0') {
			c = 'z';
			N--;
		}
		s += c;
	}
	for (auto it = s.rbegin(); it != s.rend(); it++) {
		cout << *it;
	}
	cout << endl;

EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 3688
d, g = gets.to_s.split.map{|i|i.to_i}
s, c = Array.new(d){ gets.to_s.split.map{|i|i.to_i} }.transpose

ans = 1000
(2**d).times do |b|
  
  tot = 0
  n   = 0
  d.times do |i|
    if 1 == b[i]
      tot += c[i] + s[i] * 100 * (i+1)
      n += s[i]
    end
  end
  # p [n, tot]
  if tot < g
    (d-1).downto(0) do |i|
      next if 1 == b[i]
      score = 100 * (i+1)
      r = ( g - tot + score - 1 ) / score
      r = s[i] - 1 if r > s[i] - 1
      tot += score * r
      n   += r
      break if tot >= g 
    end
  end
  
  ans = n if ans > n && tot >= g
end

puts ans


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

int main(){
    int n;
    ll k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    
    int cnt = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a.at(i)>a.at(j)) cnt++;
        }
    }
    sort(a.rbegin(),a.rend());
    int cnt_sort = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a.at(i)>a.at(j)) cnt_sort++;
        }
    }
    
    ll divide = pow(10,9)+7;
    ll d = (k*(k-1)/2)%divide;
//    ll ans = cnt*k + cnt_sort*k*(k-1)/2;
    ll ans = cnt*k + cnt_sort*d;
    
        cout << ans%divide<< endl;
    
}


Measured memory_bytes: 256