akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <math.h>

using namespace std;

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string N;
	int K;
	vector<int>v(101,0);
	for (int i = 1; i < 101; i++) {
		v[i] = v[i - 1] + i;
	}
	long long int ans=0;
	cin >> N >> K;
	if (N.length() < K) {
		cout << ans;
		return 0;
	}
	if (K == 1) {
		char a = N[0];
		int b = a - '0';
		ans = N.length() * 9-(9-b);
	}
	else if (K == 2) {
		char a = N[0];
		int b = a - '0';
		int tmplen, tmpi;
		tmplen = N.length()-1;
		ans = (N.length() - 1) * 9 * (b-1);
		while (tmplen != 1) {
			ans += (tmplen - 1) * 9 * 9;
			tmplen--;
		}
		for (int i = 1; i < N.length(); i++) {
			if(N[i]!='0') {
				tmplen = N.length() - i;
				tmpi = i;
				break;
			}
			if (i == N.length() - 1) {
				cout << ans;
				return 0;
			}
		}
		a = N[tmpi];
		b = a - '0';
		ans += tmplen * 9 - (9 - b);
	}
	else {
		char a = N[0];
		int b = a - '0';
		int tmplen,tmpi, t=N.length()-3;
		ans += v[t+1] * 81 * (b - 1);
		while (t != 0) {
			ans += v[t] * 81 * 9;
			t--;
		}
		for (int i = 1; i < N.length(); i++) {
			if (i == N.length() - 1) {
				cout << ans;
				return 0;
			}
			if(N[i]!='0') {
				tmplen = N.length() - i;
				tmpi = i;
				break;
			}
		}
		a = N[tmpi];
		b = a - '0';
		int len = tmplen;
		tmplen -= 1;
		ans += (len - 1) * 9 * (b - 1);
		while (tmplen != 1) {
			ans += (tmplen - 1) * 9 * 9;
			tmplen--;
		}
		for (int i = tmpi+1; i < N.length(); i++) {
			if(N[i]!='0') {
				tmplen = N.length() - i;
				tmpi = i;
				break;
			}
			if (i == N.length() - 1) {
				cout << ans;
				return 0;
			}
		}
		a = N[tmpi];
		b = a - '0';
		ans += tmplen * 9 - (9 - b);
	}
	cout << ans;
	return 0;

}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}

int main(){
  ll N;cin>>N;
  if(N <=111)cout<<111<<endl;
  else if(N<=222)cout<<222<<endl;
  else if(N<=333)cout<<333<<endl;
  else if(N<=444)cout<<444<<endl;
  else if(N<=555)cout<<555<<endl;
  else if(N<=666)cout<<666<<endl;
  else if(N<=777)cout<<777<<endl;
  else if(N<=888)cout<<888<<endl;
  else if(N<=999)cout<<999<<endl;
}

  


Measured memory_bytes: 256
dp = {0:1, -1:0}

def count_valiation(steps):
    
    if steps in dp:
        return dp[steps]
    
    for i in range(1,steps + 1):
        dp[i] = dp[i-1] + dp[i-2]
    
    return dp[steps]
    
    
    
def main():
    
    n, m = [int(x) for x in input().rstrip(" ").split(" ")]
    
    current = 0
    
    answer = 1
    
    for i in range(m):
        broken_step = int(input().rstrip(" "))
        
        normal_steps = (broken_step - 1 )- current
        #print(normal_steps)
        if normal_steps < 0:
            answer = 0
            break
        answer = (answer * count_valiation(normal_steps)) % 1000000007
        
        current = broken_step + 1
    
    if current < n and answer >= 1:
        normal_steps = n - current
        #print(normal_steps)
        answer = (answer * count_valiation(normal_steps)) % 1000000007
    
    
    print(answer)    
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 468604
#include<iostream>
#include<cmath>
#include<cstdio>
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){return Point(x+p.x,y+p.y);}
  Point operator-(Point p){return Point(x-p.x,y-p.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}

  double abs(){return sqrt(norm());}

  double norm(){return (x*x+y*y);}
};
typedef Point Vector;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

double dot(Vector a,Vector b){return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){return (a.x*b.y-a.y*b.x);}

Point project(Segment s,Point p){
  Vector base=(s.p2-s.p1);
  double r=(dot(p-s.p1,base)/base.norm());
  return (s.p1+base*r);
}

Point reflect(Segment s,Point p){
  return p+(project(s,p)-p)*2;
}

bool isOrthogonal(Vector a,Vector b){
  return equals(dot(a,b),0.0);
}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}

static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT=-2;
static const int ON_SEGMENT=0;

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>eps)return COUNTER_CLOCKWISE;
  if(cross(a,b)<-eps)return CLOCKWISE;
  if(dot(a,b)<-eps)return ONLINE_BACK;
  if(a.norm()<b.norm())return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 &&
          ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

int main()
{
  Point A,B,C,D;
  int q;

  cin>>q;
  for(int i=0;i<q;i++){
    cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>D.x>>D.y;
    if(intersect(A,B,C,D))cout<<1<<endl;
    else cout<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>

#define refund 200
#define numForRefund 15
#define cost 800

int main()
{
        int numOfEat=0;
        int totalPaid=0;
        int totalRefund=0;

        scanf("%d", &numOfEat);

        totalPaid=numOfEat*cost;
        totalRefund=numOfEat/numForRefund*refund;

        printf("%d\n", totalPaid-totalRefund);

        return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int inf=1e7+9;
int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	long long m,n;
	cin>>m>>n;
	if(!(m%n) ){
		cout<<-1<<endl;
		return 0;
	}
	long long ans=2;
	while(!((ans*m)%n)) ans++;
	if(ans*m>1e19) cout<<-1<<endl;
	else cout<<ans*m<<endl;
	return 0;
}

Measured memory_bytes: 256
import pdb

def arrins(arr, s):
    for j in range(x):
        if s == arr[j]:
            break
        elif arr[j] == "" or s < arr[j]:
            for k in range(j, x - 1):
                arr[k + 1] = arr[k]
            arr[j] = s
            break

s = raw_input()
x = int(raw_input())

ic = [0 for i in range(30)]
length = len(s)
for j in range(length):
    c = ord(s[j:(j + 1)]) - ord('a')
    ic[c] += length - j

subs = ["" for i in range(5)]
for j in range(30):
    if ic[j] == 0:
         continue

    for k in range(length):
        if ord(s[k:(k + 1)]) == (j + ord('a')) :
            for l in range(1, length - k + 1):
                t = s[k:(k + l)]
                if subs[x - 1] != "" and t > subs[x - 1]:
                    break
                else:
                    arrins(subs, t)

                #pdb.set_trace()
            
    if subs[x - 1] != "":
        break

print subs[x - 1]

Measured memory_bytes: 3304
import sys
sys.setrecursionlimit(1000000)

N = int(input())
H = list(map(int, input().split()))

# dp = [0] * N
# dp[1] = abs(H[1]-H[0])
#
# # loop
# for i in range(2, N):
#     dp[i] = min((dp[i-1]+abs(H[i-1]-H[i]), dp[i-2]+abs(H[i-2]-H[i])))
#
# print(dp)
# print(dp[N-1])

dp = [0] * N
dp[1] = abs(H[1]-H[0])

# rec
def func(i):
    #print(f'i: {i}')
    if i >= N:
        return 0
    else:
        dp[i] = min((dp[i-1]+abs(H[i-1]-H[i]), dp[i-2]+abs(H[i-2]-H[i])))
        func(i+1)

func(2)
#print(dp)
print(dp[N-1])

Measured memory_bytes: 97184
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: usize,
        p: usize
    }
    let ans = (a * 3 + p) / 2;
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
bool check(int num, vector<int> v) {
  for(auto& itr : v) if(num == itr) return true;
  return false;
}
int main() {
  string s; cin >> s;
  int last = s[s.size()-1] - '0';
  if(last == 3) cout << "bon";
  else if(check(last, {0,1,6,8})) cout << "pon";
  else cout << "hon";
  cout << "\n";
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << x << endl;
#else 
    #define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


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

int can[MX];
int cnt[MX];

void upd(int a, int b) {
    can[b] |= can[a];
    --cnt[a];
    ++cnt[b];
    can[a] = can[a] && cnt[a];
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
       
    int n, m;
    cin >> n >> m;
    fi(0, n) cnt[i] = 1;
    can[0] = 1;
    fi(0, m) {
        int a, b;
        cin >> a >> b;
        upd(a - 1, b - 1);
        /*fj(0, m)
            cout << cnt[j] << ' ' << can[j] << '\n';*/

    } 
    int ans = 0;
    fi(0, n)
        ans += can[i];
    cout << ans << '\n';
}

Measured memory_bytes: 5136
#include<bits/stdc++.h>
using namespace std;
int n,a[1000],ans,k; 
bool cmp(int a,int b){return a>b;}
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n,cmp);
    for(int i=0;i<k;i++)ans+=a[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
z=0
for i in range(1,n-1,1):
  if l[i-1]<l[i]<l[i+1]:
    z+=1
  elif l[i+1]<l[i]<l[i-1]:
    z+=1
  else:
    z+=0
print(z) 
    

Measured memory_bytes: 38384
N,M = map(int, input().split())
boards = [None] * N
passed = [[False] * M for i in range(N)]
for i in range(N):
    boards[i] = list(input())
for i in range(N):
    for j in range(M):
        if boards[i][j] == '#':
            if ((i < N - 1 and boards[i+1][j] == '#') or 
                (i >= 1 and boards [i-1][j] == '#') or 
                (j < M - 1 and boards[i][j+1] == '#') or
                (j >= 1 and boards[i][j-1] == '#')):
                    continue
            else:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
   int N;
   string s;
   int cnt=0;
   cin>>N>>s;
   rep(i,N){
       if(s[i]=='A'){
           if(s[i+1]=='B'){
               if(s[i+2]=='C') cnt++;
           }
       }
   }
    cout<<cnt;
}

Measured memory_bytes: 3632
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順

using namespace std;
using ll = long long int;

ll two_pointers(vector<ll> &minus,vector<ll> &plus,ll x){
    ll sum = 0;
    int right = plus.size() - 1;
    for(int i=0;i<minus.size();i++){
        for(int j=right;j>=0;j--){
            if(minus[i]*plus[j]<=x&&j!=0) continue;
            else if(minus[i]*plus[j]>x){
                sum += plus.size() - (j + 1);
                right = j;
                if(plus[0]==minus[0]&&i>j){
                    sum--;//sumにplus[i]^2が混じっているので取り除く
                }
                break;
            }else{
                sum += plus.size() * (minus.size() - i);
                if(plus[0]==minus[0]) sum -= minus.size() - i;
                right = -1;//これによりこのfor文は以降実行されない
            }
        }
    }
    return sum;
}

ll binary_search(bool which,ll xleft,ll xright ,vector<ll> &minus,vector<ll> &plus,ll K){
    while(xright-xleft>1){//leftを右に寄せて次のxを大きく　rightを左に寄せて次のxを小さく
        ll x = (xright + xleft) / 2;
        ll a = which ? (two_pointers(minus,minus,x) + two_pointers(plus,plus,x))/2
                     : two_pointers(minus,plus,x);
        if(K<=a) xright = x;//このxの値ではK番目の数<xの範囲の数の個数を数え上げている
        else xleft = x;//(a<K)このxの値では(x<K番目の数)の範囲の数の個数の数え上げで終わっている
    }
    return xright;
}

int main(){
    ll N,K;cin>>N>>K;
    vector<ll> plus,minus;
    ll zero = 0;
    for(int i=0;i<N;i++){
        int A;cin>>A;
        if(A>0) plus.push_back(A);
        else if(A<0) minus.push_back(A);
        else zero++;
    }

    ll pos = minus.size()*plus.size();
    if(K<=pos){//K番目の数は負である
        sort(minus.begin(),minus.end(),greater<ll>());
        sort(plus.begin(),plus.end());
        ll xleft = minus.back()*plus.back() - 1;
        ll xright = -1;
        cout << binary_search(false,xleft,xright,minus,plus,K) << endl;
    }else{
        pos += zero * ( minus.size() + plus.size() ) + zero * (zero-1) / 2;
        if(K<=pos) cout << 0 << endl;
        else{//K番目の数は正である
            sort(plus.begin(),plus.end(),greater<ll>());
            sort(minus.begin(),minus.end());//減少関数にするための処理        
            ll xleft = 0;
            ll xright = 1e18;
            cout << binary_search(true,xleft,xright,minus,plus,K-pos) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2420
using System;

class Program {
    static void Main(string[] args) {
        string a = Console.ReadLine();
        int s = 0, t = 0;
        foreach (var i in a) {
            if (i == 'S') {
                s++;
            } else if (i == 'T') {
                if (s > 0) s--;
                else t++;
            }
        }
        Console.WriteLine(s + t);
    }
}

Measured memory_bytes: 11616
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<memory.h>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  ll n;
  cin >> n;
  n*=(n-1);
  n/=2;
  cout << n << endl;
return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n; cin >> n;
	ll sum = 0;
	vl a(n); rep(i,n) cin >> a[i], sum += a[i];
	vl v(101010,0);
	rep(i,n) v[a[i]]++;
	int q; cin >> q;
	while(q--){
		int b,c; cin >> b >> c;
		sum += v[b] * (c-b);
		v[c] += v[b];
		v[b] = 0;
		cout << sum << "\n";
	}
}


Measured memory_bytes: 4836
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n,m; cin >> n >> m;
    cout << ((n == m) ? "Yes" : "No") << endl; return 0;
}


Measured memory_bytes: 256
#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--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(c, b / a) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;vi  v(n); rep(i,n)cin>>v[i];
    int m; cin>>m;vector<pii>d(m);
    rep(i,m)cin>>d[i].first>>d[i].second;
    rep(i,m){
        int ans=0;
        rep(j,n){
            if(d[i].first-1==j)ans+=d[i].second;
            else ans+=v[j];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef  long double ld;
#define inc(i,a,b)  for(long long int i=a;i<=b;i++)
#define dec(i,a,b)  for(long long int i=a;i>=b;i--)
#define fast   ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define pb  push_back
#define all(c)  (c).begin(),(c).end()
#define lv  vector<ll>
#define cv  vector<char>
#define dv  vector<ld>
#define rall(c)  (c).rbegin(),(c).rend()
#define lpr pair<ll,ll>
#define mp make_pair
#define input(c) ll c;cin>>c;
#define lmap map<ll,ll>
#define vinp(a,n) inc(i,1,n){ input(k); a.pb(k); }
#define LIM 1000000007
#define F first
#define S second
#define fr(n) inc(i,0,n-1)
#define fri(n,a) inc(i,0,n-1){ cin>>a[i]; }
void solve()
{
ll i,j;
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll l=0,r=0;
	ll sum=1;
		while(l<n && r<n)
		{
			if(s[l]==s[r])
				r++;
			else
			{
				l=r;
				sum++;
			}
		}
	cout<<sum;
}
int main()
{
	fast;
	ll t=1;
    //cin>>t;
	while(t--)
    solve();
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define vi vector<int>
#define Vi vector<vector<int>>
#define ll long long
#define P pair<int,int>
#define vp  vector<P>
#define mod 1000000009
using namespace std;
int main(){
	int n;
	cin>>n;
	cout<<(1000-n%1000)%1000<<endl;
	return 0;
}


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

int main() {
  ll W, H;
  cin >> W >> H;
  ll ds=-1;
  ll smax1, smin1, smax2, smin2;
  for (ll h=1; h<=H-1; h++) {
    smax1 = max(W*h, max(W*((H-h)/2), W*((H-h)/2 + (H-h)%2)));
    smin1 = min(W*h, min(W*((H-h)/2), W*((H-h)/2 + (H-h)%2)));
    smax2 = max(W*h, max((H-h)*(W/2), (H-h)*(W/2+W%2)));
    smin2 = min(W*h, min((H-h)*(W/2), (H-h)*(W/2+W%2)));
    if (ds==-1||ds > min(smax1-smin1, smax2-smin2)) ds = min(smax1-smin1, smax2-smin2);
  }
  for (ll w=1; w<=W-1; w++) {
    smax1 = max(H*w, max(H*((W-w)/2), H*((W-w)/2 + (W-w)%2)));
    smin1 = min(H*w, min(H*((W-w)/2), H*((W-w)/2 + (W-w)%2)));
    smax2 = max(H*w, max((W-w)*(H/2), (W-w)*(H/2+H%2)));
    smin2 = min(H*w, min((W-w)*(H/2), (W-w)*(H/2+H%2)));
    if (ds==-1||ds > min(smax1-smin1, smax2-smin2)) ds = min(smax1-smin1, smax2-smin2);
  }
  cout << ds << endl;
}

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

int main(){
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    a.push_back(a[0]+k);
    int l=0;
    rep(i,n){
        l = max(l, a[i+1]-a[i]);
    }
    int ans = k-l;
    cout << ans << endl;
    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }


void compute() {

}

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n) cin >> vec[i];
  int maxi = 1;
  int cur = vec[0], cnt = 1;
  REP(i,1,n) {
    if( vec[i] <= cur ) {
      ++cnt;
      cur = vec[i];
    } else {
      maxi = max(maxi,cnt);
      cnt = 1;
      cur = vec[i];
    }
  }
  maxi = max(maxi,cnt);
  cout << maxi-1 << endl;
  compute();
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	if(a>b)
	{
		cout << "a > b\n";
	}

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

Measured memory_bytes: 3036
/*
uchiyan ni gallan
*/

#include<bits/stdc++.h>
#define mod 1000000007
#define pp pair<long long,long long>
#define ll long long
#define ff first
#define ss second
#define horse_power ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

int h,w;
string s[1001];
ll dp[1001][1001]={0};
void solve(){
 cin>>h>>w;
 for(int i=0;i<h;i++)
    cin>>s[i];

 dp[1][1]=1;
 for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
            if(i==1 &&  j==1)
            continue;
        if(s[i-1][j-1]=='.'){
            dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
        }else{
        dp[i][j]=0;
        }

    }
 }
 cout<<dp[h][w]<<"\n";

}

int main(){
horse_power
int t=1;
//cin>>t;
while(t--){
solve();
}


}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
vector<ll>g[N];
ll n,u,v,color[N],c[N],son[N],res[N]={0};
ll f(ll n) {return n*(n+1)/2;}
void dfs(ll u,ll fa){
   ll tmp=c[color[u]];
    for(int  i=0;i<g[u].size();i++){
	//for(auto v:g[u]){
	      ll v=g[u][i];
        if(v==fa) continue;
        c[color[u]]=0;
        dfs(v,u);
        son[u]+=son[v];
        res[color[u]]+=f(son[v]-c[color[u]]);//表示U的子树下还有多少与U不同色的点
    }
    c[color[u]]=tmp+son[u];
}

int main(){
    cin>>n;
    for(ll i=1;i<=n;i++){
        son[i]=1;
        cin>>color[i];
    }
    for(ll i=1;i<n;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,-1);
   /*for(int i=1;i<=n;i++){
        cout<<c[i]<<" "<<son[i]<<endl;
    }*/
    for(int i=1;i<=n;i++){
        cout<<f(n)-f(n-c[i])-res[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 39456
#include<bits/stdc++.h>
using namespace std;
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

#define N 100


signed main(){
	int n;
	int ga,gb,sa,sb,ba,bb;
	cin>>n>>ga>>sa>>ba>>gb>>sb>>bb;
	int maxi=n;
	for(int i=0;i<=5000;i++){
		for(int j=0;j<=5000;j++){
			if(i*ga+j*sa>n) break;
			int k=(n-i*ga-j*sa)/ba;
			if(bb-ba<=0)k=0;
			int ne=n-(i*ga+j*sa+k*ba);
			ne+=i*gb+j*sb+k*bb;
			maxi=max(maxi,ne);
		}
	}
	n=maxi;
	swap(ga,gb);
	swap(sa,sb);
	swap(ba,bb);
	maxi=n;
	if(ga<=gb&&sa<=sb&&ba<=bb){
	for(int i=0;i<=n;i++){
		if(i*ga>n) break;
		for(int j=0;j<=n;j++){
			if(i*ga+j*sa>n) break;
			int k=(n-i*ga-j*sa)/ba;
			if(bb-ba<=0)k=0;
			int ne=n-(i*ga+j*sa+k*ba);
			ne+=i*gb+j*sb+k*bb;
			maxi=max(maxi,ne);
		}
	}
	}
	else{
		int ta,tb;
		int xa,xb;
		if(ga>=gb){
			ta=sa;
			tb=sb;
			xa=ba;
			xb=bb;
		}
		else if(sa>=sb){
			ta=ga;
			tb=gb;
			xa=ba;
			xb=bb;
		}
		else{
			ta=sa;
			tb=sb;
			xa=ga;
			xb=gb;
		}
		for(int i=0;i<=n;i++){
			if(i*ta>n) break;
			int j=(n-i*ta)/xa;
			if(xb-xa<=0) j=0;
			int ne=n-(i*ta+j*xa);
			ne+=i*tb+j*xb;
			maxi=max(maxi,ne);
		}
	}
	cout<<maxi<<endl;
  	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a[100][100], b[100], c[100];
	int i, j, n, m;

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

	for (i = 0; i < n; i++)
	{
		c[i] = 0;
		for (j = 0; j < m; j++)
		{
			c[i] = c[i]+ (a[i][j] * b[j]);
		}
		printf("%d\n", c[i]);
	}
	return 0;
}


Measured memory_bytes: 2112
using System;
using System.Linq;
class aoj
{
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        int[] b = new int[a];
        for (int i = 0; i < a*(a-1)/2; i++)
        {
            int[] c = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if (c[2] < c[3])
                b[c[1] - 1] += 3;
            else if (c[2] > c[3])
                b[c[0] - 1] += 3;
            else
            {
                b[c[0] - 1] += 1;
                b[c[1] - 1] += 1;
            }
        }
        int d = 0, e = 1, k = 0; 
        bool[] f = new bool[a];
        int[] g = new int[a];
        while(true)
        {
            int h = 0;
            d = 0;
            for (int i = 0; i < a; i++)
            {
                if (b[i] > d&&f[i]==false)
                    d = b[i];
            }
            for(int i = 0; i < a; i++)
            {
                if (b[i] >= d && f[i] == false)
                {
                    h++;
                    f[i] = true;
                    g[i] = e;k++;
                }
            }
            e += h;
            if (k == a) break;
        }
        foreach (int i in g)
            Console.WriteLine(i);
    }
}

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

const int N=200005;
int n,a[N];
long long ans;

int main()
{
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++)
	    scanf("%d",&a[i]),a[i]-=i;
	sort(a+1,a+1+n);
	a[0]=a[(n+1)/2];
	for(i=1;i<=n;i++)
	    ans+=abs(a[i]-a[0]);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int tmp;
    char a[8], b[4];
    double t;
    
    scanf("%s%s", a, b);
    
    strcat(a, b);
    
    tmp=atoi(a);
    t=pow(tmp, 0.5);
    //printf("%lf", t);
    
    if (t==ceil(t)&&t==floor(t)) {
        printf("Yes");
    } else {
        printf("No");
    }
    
    return 0;
}


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

int main() {
  int x,a,b;
  cin>>x>>a>>b;
  if(abs(a-x)>abs(b-x)) cout<<'B'<<endl;
  else cout<<'A'<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;

void mod(long long &a){
    if(a > MOD)a %= MOD;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<long long> dp(100100, 0);
    vector<long long> broken(N + 1, true);
    for(int i = 0; i < M; i++){
        int a;
        cin >> a;
        broken[a] = false;
    }
    dp[0] = 1;
    if(broken[1])dp[1] = 1;
    if(broken[2])dp[2] = dp[1] + dp[0];
    for(int i = 3; i <= N; i++){
        if(broken[i]){
            dp[i] = dp[i - 1] + dp[i - 2];
            mod(dp[i]);
        }
    }
    
    cout << dp[N] % MOD << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  long long int a,b;
  cin>>a>>b;
  long long int x=a*b;
  if(a<b)swap(a,b);
  int r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  cout<<x/b<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

    void solve() throws IOException {
        Integer n = Integer.valueOf(bf.readLine());
        Set<String> set = new HashSet<>();
        for (Integer i = 0; i < n; i++) {
            String[] input = bf.readLine().split(" ");
            String command = input[0];
            String str = input[1];
            if (command.equals("insert")) {
                set.add(str);
            } else if (command.equals("find")) {
                System.out.println(set.contains(str) ? "yes" : "no");
            }
        }
    }

    public static void main(String[] args) {
        try {
            new Main().solve();
        }catch (Exception e) {
            //
        }
    }
}



Measured memory_bytes: 189504
package main

import (
	"fmt"
)

func main() {
	var a, b, k int
	fmt.Scanf("%d %d %d", &a, &b, &k)
	if a >= k {
		fmt.Printf("%d %d", a-k, b)
	} else if a+b >= k {
		fmt.Printf("%d %d", 0, a+b-k)
	} else {
		fmt.Println("0 0")
	}
}


Measured memory_bytes: 512
def WalkingTakahashi():
    
    data = list(map(int,input().split()))
    
    position = abs(data[0])
    
    m = min(data[1], position//data[2])
    
    position = position - data[2]*m
    
    data[1] = data[1] - m
    
    data[1] %= 2
    
    position = position - data[2]*data[1]
    
    print(abs(position))
    
if __name__ == '__main__':
    WalkingTakahashi()


Measured memory_bytes: 9144
#include<bits/stdc++.h>
using namespace std;
char c[2000009];
int n,m,i,j,k,l,t,x,y,cost[2000009],cost1[2000009];
int main()
{
  scanf("%s",&c);
  n=strlen(c);
  m=0;
  cost[n-1]=c[n-1]-'0';
  cost1[n-1]=10-cost[n-1]+1;
  for(i=n-2;i>=0;i--)
  {
     l=c[i]-'0';
     x=10-l+1;
     cost1[i]=min(cost[i+1]+x,cost1[i+1]+x-2);
     cost[i]=min(cost1[i+1],cost[i+1])+l;
  }
  printf("%d\n",min(cost[0],cost1[0]));
}


Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
using namespace  std;

const int MAXSIZE = 100000;
const int END = -1;
struct StNod
{
  bool m_bBe;
  int m_nDept;
  int m_nParnt;
  int m_nLChd;
  int m_nRSib;

  StNod() :
    m_bBe(false), m_nDept(0), m_nParnt(END), m_nLChd(END), m_nRSib(END)
  { }
};

void fnInput(int &rnMaxSiz, vector<StNod> &rvoNod)
{
  StNod oNod;
  rvoNod.resize(MAXSIZE, oNod);

  cin >> rnMaxSiz;

  for (int i = 0; i < rnMaxSiz; i++)
  {
    int nParnt, nCCnt, nChd, nBChd = END;
    cin >> nParnt >> nCCnt;
    rvoNod[nParnt].m_bBe = true;
    for (int j = 0; j < nCCnt; j++)
    {
      cin >> nChd;
      rvoNod[nChd].m_bBe = true;
      rvoNod[nChd].m_nParnt = nParnt;
      if (nBChd != END) rvoNod[nBChd].m_nRSib = nChd;
      if (!j)          rvoNod[nParnt].m_nLChd = nChd;
      nBChd = nChd;
    }
  }
}

void fnSetDepth(vector<StNod> &rvoNod, int nx, int nDept)
{
  rvoNod[nx].m_nDept = nDept;
  
  if (rvoNod[nx].m_nRSib != END)
    fnSetDepth(rvoNod, rvoNod[nx].m_nRSib, nDept);

  if (rvoNod[nx].m_nLChd != END)
    fnSetDepth(rvoNod, rvoNod[nx].m_nLChd, nDept + 1);
}

void fnRtdTree(vector<StNod> &rvoNod)
{
  int nx = 0, nDept = 0;
  while (rvoNod[nx].m_nParnt != END)
    nx = rvoNod[nx].m_nParnt;

  fnSetDepth(rvoNod, nx, nDept);
}

void fnResult(const vector<StNod> &cnrvoNod)
{
  for (int i = 0; cnrvoNod[i].m_bBe; i++)
  {
    cout << "node " << i << ": parent = " << cnrvoNod[i].m_nParnt << ", depth = " << cnrvoNod[i].m_nDept;

    if (!cnrvoNod[i].m_nDept)            cout << ", root, ";
    else if (cnrvoNod[i].m_nLChd == END) cout << ", leaf, ";
    else                                 cout << ", internal node, ";

    cout << "[";
    if (cnrvoNod[i].m_nLChd != END)
    {
      int nx = cnrvoNod[i].m_nLChd;
      cout << nx;
      while (cnrvoNod[nx].m_nRSib != END)
      {
        cout << ", " << cnrvoNod[nx].m_nRSib;
        nx = cnrvoNod[nx].m_nRSib;
      }
    }
    cout << "]" << endl;
  }
}

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

  int nMaxSiz;
  vector<StNod> voNod;

  fnInput(nMaxSiz, voNod);
  fnRtdTree(voNod);
  fnResult(voNod);
  return 0;
}

Measured memory_bytes: 6276
#include<stdio.h>

int main (void){
  int a,b;
  double c;
  scanf("%d %d", &a, &b);
  c=((double)a+(double)b)/2;
  if((int)c==c ){
    printf("%d\n",(int)c);
  }
  else{
  printf("IMPOSSIBLE\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

int n,m;
int main(){
    cin >> n >> m;
    ll a[n] = {};
    ll wa[n] = {};
    inrep(n,a);
    wa[0] = a[0];
    rep(i,1,n)wa[i] += a[i]+wa[i-1];
    rep(i,0,n)wa[i] %= m;
    map<ll,ll> ma;
    ll ans = 0;
    rep(i,0,n){
	ans += ma[wa[i]];
	ma[wa[i]]++;
    }
    P(ans+ma[0]);
    return  0;
}


Measured memory_bytes: 5760
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
#include<numeric>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
#define mkp(a,b) make_pair(a,b)
using namespace std;

inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	// This is code taken from geeksforgeek
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
/*ll power(ll x, ll y)
{
	// This is code taken from geeksforgeek
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}*/
ll power(ll x, 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;
}


ll modInverse(ll n, ll p)
{
	return power(n, p - 2, p);
}

ll nCrModPFermat(ll n, ll r, ll p)
{
	if (r == 0)
		return 1;

	vector<ll> fac(n + 1, 0);
	fac[0] = 1;
	for (ll i = 1; i <= n; i++)
		fac[i] = fac[i - 1] * i % p;

	return (fac[n] * modInverse(fac[r], p) % p *
		modInverse(fac[n - r], p) % p) % p;
}

bool check(ll a)
{
	ll count = 0;
	while (a % 2 == 0)
	{
		a /= 2;
		count += 1;
	}
	if (count > 1)
		return false;
	bool flag = true;
	for (ll i = 3; i <= sqrt(a); i += 2)
	{
		if (a % i == 0)
		{
			flag = false;
			break;
		}
	}
	return flag;
}
ll sum(ll n)
{
	return (n * (n + 1)) / 2;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, k;
	cin >> n >> k;
	vector<ll> arr(n, 0);
	f(i, 0, n)
	{
		cin >> arr[i];
	}
	sort(all(arr));
	ll sum = 0;
	f(i, 0, k)
	{
		sum += arr[i];
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main implements Runnable {

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(), C = sc.nextInt();
        int[][] u = new int[C][200002];
        for (int i = 0; i < N; i++) {
            int s = sc.nextInt(), t = sc.nextInt(), c = sc.nextInt() - 1;
            for (int j = s * 2 - 1; j < t * 2; j++) {
                u[c][j] = 1;
            }
        }

        int max = 0;
        for (int i = 1; i < 200002; i++) {
            int sum = 0;
            for (int j = 0; j < C; j++) {
                sum += u[j][i];
            }
            max = Math.max(max, sum);
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 121848
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define PI          3.14159265358979323846
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ld          long double
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
const ll M = 1e9 + 7;
ll dp[N];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x;
        cin >> x;
        dp[x] = -1;
    }
    dp[0] = 1;
    if(dp[1] != -1){
        dp[1] = 1;
    }
    for(int i = 2; i <= n; i++){
        if(dp[i] != -1)
            dp[i] = max(0LL, dp[i - 1]) + max(0LL, dp[i - 2]);
        if(dp[i] >= M){
            dp[i] -= M;
        }
    }
    cout << dp[n];
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 1024