akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 2e9+7
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mxN=100100;

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y); swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<endl;
}


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;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = /*1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 1'000'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  int v, p;
  cin >> n >> m >> v >> p;
  vector<int> a(n);
  for (int& x : a) {
    cin >> x;
  }
  sort(begin(a), end(a));
  int l = 1, r = n;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    int mx = a[n - mid] + m;
    int64 votes = m * 1ll * (v - 1);
    int above = 0;
    for (int i = n - 1; i >= 0; --i) {
      if (i == n - mid) {
        continue;
      }
      if (a[i] > mx) {
        ++above;
        votes -= m;
      }
      else if (above + 1 < p) {
        if (a[i] + m > mx) {
          ++above;
        }
        votes -= m;
      } else {
        votes -= min(m, mx - a[i]);
      }
    }
    if (votes > 0 || above >= p) {
      r = mid - 1;
    } else {
      l = mid;
    }
  }
  cout << l << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


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

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

  int a=0, b=0;
  char x;
  for(int i = 0; i < s.size(); i++){
    if(i%2 == 0) x = '0';
    else x = '1';
    if(s[i] == x) a++;
    else b++;
  }
  std::cout << std::min(a, b) << std::endl;

 return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
	int n,m, used;
	ArrayList<ArrayList<Integer>> lotateList;
	Guard [] gList;
	LinkedList<Integer> waitList;
	int ans;


	class Guard {
		int remain, ind;
		public Guard(int remain, int ind) {
			this.remain = remain;
			this.ind = ind;
		}
	}

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			m = sc.nextInt();
			if((n|m) == 0)break;
			lotateList = new ArrayList<ArrayList<Integer>>();
			for(int i = 0; i < n; i++){
				lotateList.add(new ArrayList<Integer>());
				int input = sc.nextInt();
				while(input != 0){
					lotateList.get(i).add(input);
					input = sc.nextInt();
				}
			}
			used = 0;
			gList = new Guard[n];
			for(int i = 0; i < n; i++){
				gList[i] = new Guard(lotateList.get(i).get(0), 0);
			}
			waitList = new LinkedList<Integer>();
			ans = 0;

			for(int i = 0; i < m-1; i++){
				decriment();
				inQueue();
				changeUsed();
				deQueue();
				ans += waitList.size();
			}
			System.out.println(ans);
		}
	}

	private void deQueue() {
		if(used == 0){
			if(waitList.size() > 0){
				int deqind = waitList.removeFirst();
				used = deqind + 1;
			}
		}

	}

	private void changeUsed() {
		if(used == 0) return;
		int i = used - 1;
		if(gList[i].remain == 0){
			used = 0;
			int lotateInd = (gList[i].ind + 1) % lotateList.get(i).size();
			int remainValue = lotateList.get(i).get(lotateInd);
			gList[i].remain = remainValue;
			gList[i].ind++;
		}

	}

	private void inQueue() {
		for(int i = 0; i < n; i++){
			if(gList[i].remain == 0 && gList[i].ind % 2 == 0){
				int lotateInd = (gList[i].ind + 1) % lotateList.get(i).size();
				int remainValue = lotateList.get(i).get(lotateInd);
				gList[i].remain = remainValue;
				gList[i].ind++;
				waitList.add(i);
			}
		}
	}

	private void decriment(){
		for(int j = 0; j < n; j++){
			if(gList[j].ind % 2 == 0){
				gList[j].remain--;
			}
		}
		if(used != 0){
			gList[used - 1].remain--;
		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		int l = S.length();
		int min = Integer.MAX_VALUE;
		for(int i = 0; i < l - 2; i++) {
			String s = S.substring(i, i + 3);
			int t = Integer.parseInt(s);
			min = Math.min(min, Math.abs(t - 753));
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 21844
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;


public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskT solver = new TaskT();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskT {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int num_students = in.nextInt();
            
            Map<Integer, Integer> map = new HashMap<>();
            int[] arr = new int[num_students];
            for(int i = 0; i < num_students; i++){
            	int num_present = in.nextInt();
            	// no.1-> 2 present ; no.2 ->  3 present; no.3 -> 1 present
            	arr[i] = num_present;  // when ith student enters then already num_present no. of students in the class 
            	map.put(num_present, i+1) ; // since i is student number start from 1 	
            }
            Arrays.sort(arr);
            for(int i = 0; i < arr.length; i++)
            	System.out.print(map.get(arr[i]) + " ");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 70256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;

int main()
{
	int n,ans=0;
	cin>>n;
	REP(i,n){
		int x,y;
		cin>>x>>y;
		ans+=y-x+1;
	}
	cout<<ans;
	return 0;
}


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

using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>(b);--i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a))
#define mp make_pair
#define All(a) (a).begin(), (a).end()
template <typename T=long long>
inline T IN(){T x; cin>>x; return(x);}
inline void CIN(){}
template <class Head,class... Tail>
inline void CIN(Head&& head,Tail&&... tail){
    cin>>head;
    CIN(move(tail)...);
}
#define CINT(...) int __VA_ARGS__;CIN(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CIN(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CIN(__VA_ARGS__)
 
typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int,V,greater<int>> PQG;

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

int N,C;
int D[30][30];
map<int,int> c[3];

inline ll SUM(map<int,int> color, int paint){
	ll ret=0;
	FOREACH(cp,color){
		if(cp.first!=paint){
			ret+=cp.second*D[cp.first][paint];
		} 
	}
	return ret;
}

int main(){
	cin>>N>>C;
	REP(i,C)REP(j,C){
		D[i][j]=IN();
	}
	REP(i,N)REP(j,N){
		CINT(color);
		color--;
		switch ((i+j)%3){
			case 0:
				c[0][color]++;
				break;
			case 1:
				c[1][color]++;
				break;
			case 2:
				c[2][color]++;
				break;
		}
	}
	ll sum=LINF;
	REP(i,C)REP(j,C)REP(k,C){
		if(j==i|k==i|k==j) continue;
		ll tmp=0;
		tmp+=SUM(c[0],i);
		tmp+=SUM(c[1],j);
		tmp+=SUM(c[2],k);
		sum=min(sum,tmp);
	}
	cout<<sum<<"\n";
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  bool kind = false;
  
  for (int i = 0; i < N; i = i + 1) {
    char color;
    cin >> color;
    if (color == 'Y') {
      kind = true;
    }
  }
  
  if (kind) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}  

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

template<typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b%a, a);
}

template<typename T>
T lcm(T a, T b) {
  return (a*b)/gcd(b%a, a);
}

bool IsMonth(int num) {
  return 1 <= num && num <= 12;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  string s;
  cin >> s;
  int upper = stoi(s.substr(0 ,2));
  int lower = stoi(s.substr(2, 2));
  if (IsMonth(upper) && IsMonth(lower)) {
    cout << "AMBIGUOUS" << endl;
  } else if (!IsMonth(upper) && !IsMonth(lower)) {
    cout << "NA" << endl;
  } else {
    if (IsMonth(upper)) { cout << "MMYY" << endl; }
    else { cout << "YYMM" << endl; }
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 18;
char C[CM + CL], * ci = C + CL, * owa = C + CM, c;

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


	fread(ci, 1, CM, stdin);
	int N = 0;
	while ((c = *ci++) >= '0') N = N * 10 + c - '0';

	ll p[20][20] = {};
	rep(i, N) {
		if (ci - owa > 0) {
			memcpy(C, owa, CL);
			ci -= CM;
			fread(C + CL, 1, CM, stdin);
		}

		ll kari = 0;
		while ((c = *ci++) >= '0') kari = kari * 10 + c - '0';
		int d = 9;
		if (*(ci - 1) == '.') {
			while ((c = *ci++) >= '0') {
				kari = kari * 10 + c - '0';
				d--;
			}
		}

		int a = __builtin_ctzll(kari) + d;
		if (a > 18) a = 18;
		int b = d;
		if (kari % 1953125 == 0) {
			b += 9;
			kari /= 1953125;
		}
		if (kari % 625 == 0) {
			b += 4;
			kari /= 625;
		}
		while (kari % 5 == 0) {
			b++;
			kari /= 5;
		}
		p[a][b]++;
	}
	ll kotae = 0;
	rep(a, 19) rep(b, 19) if (p[a][b]) {
		ll P = p[a][b];
		for (int x = 18 - a; x <= 18; x++) {
			for (int y = 18 - b; y <= 18; y++) {
				kotae += P * p[x][y];
			}
		}
	}
	for (int a = 9; a <= 18; a++) {
		for (int b = 9; b <= 18; b++) {
			kotae -= p[a][b];
		}
	}

	printf("%lld\n", kotae / 2);

	Would you please return 0;
}

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

int main() {
	long long L,R;
	long long l,r;
	cin >>L>>R;
	l=L%2019;
	r=R%2019;
	if(l<r){
		int ans=99999999;
		for(long long i=l;i<r;i++){
			for(long long j=i+1;j<=r;j++){
				if((i*j)%2019<ans){ans=(i*j)%2019;}
			}
		}
		int x,y;
		x=L/2019;y=R/2019;
if(y-x>1){ans=0;}
		cout <<ans<<endl;}
	
	else{cout <<0<<endl;}
	return 0;
}


Measured memory_bytes: 256
N =  int ( input().strip() ) ;
A = list ( map ( int , input().strip().split(" ") ) ) ; 

t = 0 ;
for idx , x in enumerate ( A ) :
	if idx==0 : continue ;

	if A[idx] < A[idx-1] :
		r = A[idx-1] - A[idx] ; 
		t += r ; 
		A[idx] += r ; 

print ( t ) ;




Measured memory_bytes: 32228
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<int> A(1LL<<26,MOD);

int main(){
    string s;
    cin>>s;
    int n=(int)s.size();
    vector<ll> count(n+1,0);
    for(int i=1;i<=n;i++){
        (count[i]=count[i-1])^=1LL<<(s[i-1]-='a');
    }
    int ans=0;
    A[0]=0;
    for(int i=1;i<=n;i++){
        ans=A[count[i]]+1;
        for(ll t=0;t<26;t++){
            ans=min(ans,A[count[i]^(1LL<<t)]+1);
        }
        A[count[i]]=min(ans,A[count[i]]);
    }
    cout<<ans<<endl;
    
    
    return 0;
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

int main(void){
    int K, X;
    scanf("%d %d",&K, &X);

    int min=X-(K-1);
    int max=X+(K-1);

    for(int i=min;i<=max;i++){
        printf("%d\n",i);
    }

    printf("\n");

    return 0;
}

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

int placeChild(int now, int numberR, int numberL, vector<int> &kids){
    int Lstart = now - numberL;
    int Rstart = Lstart - numberR;

    int kidsOnL = numberR / 2 + (numberL + 1) / 2;
    int kidsOnR = numberR + numberL - kidsOnL;

    kids[Lstart - 1] = kidsOnR;
    kids[Lstart] = kidsOnL;
    return 0;
}

int main(){
    string s;
    cin >> s;
    int size = (int)s.size();
    // vector<char> cs(size);
    vector<int> children(size, 0);
    // for (int tsumugi = 0; tsumugi < size; tsumugi++){
    //     cs[tsumugi] = s[tsumugi];
    // }
    
    //csは文字列の配列
    //childrenは最終的な子供の配置とする
    //childrenに答えを代入していく

    int R_renzoku = 0;
    int L_renzoku = 0;
    int L_start;
    bool flag =false;  //R連続からL連続になったときtrueとする
    
    for (int matsuri = 0; matsuri < size; matsuri++){
        if (s[matsuri] == 'R' and flag == false){
            R_renzoku++;
        }
        else if (s[matsuri] == 'L'){
            L_renzoku++;
            if (flag == false){
                L_start = matsuri;
            }
            flag = true;
        }
        else if (s[matsuri] == 'R' and flag == true){
            placeChild(matsuri, R_renzoku, L_renzoku, children);
            R_renzoku = 1;
            L_renzoku = 0;
            flag = false;
        }
        // else if (matsuri == size - 1){
        //     placeChild(matsuri + 1, R_renzoku, L_renzoku + 1, children);
        //     cout << "Done" << endl;
        // }
    }
    placeChild(size, R_renzoku, L_renzoku, children);

    for (int kaori = 0; kaori < size; kaori++){
        cout << children[kaori] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define MOD 1000000007
int main() {
	ll h, w;
	cin >> h >> w;
	vector<vll> grid(h, vll(w, 0));
	for (ll i = 0; i < h; ++i) {
		for (ll j = 0; j < w; ++j) {
			char ch;
			cin >> ch;
			if (ch == '#') grid[i][j] = 1;	
		}
	}
	vector<vll> dp(h, vll(w, 0));
	dp[0][0] = 1;
	for (ll i = 1; i < h; ++i) {
		if (grid[i][0]) break;
		dp[i][0] = 1;
	}
	for (ll i = 1; i < w; ++i) {
		if (grid[0][i]) break;
		dp[0][i] = 1;
	}
	for (ll i = 1; i < h; ++i) {
		for (ll j = 1; j < w; ++j) {
			if (grid[i][j]) dp[i][j] = 0;
			else {
				dp[i][j] = dp[i-1][j] + dp[i][j-1];
				dp[i][j] %= MOD;
			}
		}
	}
	cout << dp[h-1][w-1];
	return 0;
}

Measured memory_bytes: 19016
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/13 18:09:49
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 11;

ll f[N][N], g[N];

void run() {
    int k; cin >> k;
    for (int i = 0; i < 10; i++) f[i][1] = 1;
    for (int t = 2; t < N; t++) {
        for (int i = 0; i < 10; i++) {
            for (int j = max(i - 1, 0); j <= min(i + 1, 9); j++) {
                f[i][t] += f[j][t - 1];
            }
        }
    }
    for (int t = 1; t < N; t++) {
        for (int i = 1; i < 10; i++) {
            g[t] += f[i][t];
        }
    }
    int t;
    for (t = 1; t < N; t++) {
        if (g[t] < k) k -= g[t];
        else break;
    }
    ll x = 0;
    int last = -1;
    for (int i = t; i >= 1; i--) {
        if (last != -1) {
            for (int j = max(last - 1, 0); j <= min(last + 1, 9); j++) {
                if (f[j][i] < k) k -= f[j][i];
                else {
                    last = j;
                    x = x * 10 + j;
                    break;
                }
            }
        } else for (int j = 1; j < 10; j++) {
            if (f[j][i] < k) k -= f[j][i];
            else {
                last = j;
                x = x * 10 + j;
                break;
            }
        }
    }
    cout << x << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

void add(ll& a, ll b){a = (a+b) % MOD;}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    ll minus=0;
    if(a<0&&b<0) minus=abs(b-a)+1;
    if(a<=0&&0<=b){
        cout<<"Zero"<<endl;
    }
    else if(minus%2==1){
        cout<<"Negative"<<endl;
    }
    else{
        cout<<"Positive"<<endl;
    }
}

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

int min(int A,int B){
    return A<B?A:B;
}

int max(int A,int B){
    return A>B?A:B;
}

int main(void){
    char s[15];
    scanf("%s",s);
    int ans=0,count=0;
    for (int i=0; i<strlen(s); i++){
        if (s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
            count++;
        } else {
            ans=max(ans,count);
            count=0;
        }
    }
    printf("%d\n",max(ans,count));
    return 0 ;
}

Measured memory_bytes: 128
/* ITP1_9_D:Transformation */
/* 20181124 AOJ */

#define _CRT_SECURE_NO_WARNINGS
#define N 8
#define M 1001
#include <stdio.h>
#include <string.h>

void print(char *str, int a, int b);
void replace(char *str, char *temp, int a, int b);
void reverse(char *str, int a, int b);

int main(void) {
	int i, n, a, b;
	char cmd[N], str[M], temp[M];

	scanf("%s", str);
	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%s", cmd);
		
		if(strcmp(cmd, "print") == 0) {
			scanf("%d %d", &a, &b);
			print(str, a, b);
		}else if(strcmp(cmd, "reverse") == 0) {
			scanf("%d %d", &a, &b);
			reverse(str, a, b);
		}else if(strcmp(cmd, "replace") == 0) {
			scanf("%d %d %s", &a, &b, temp);
			replace(str, temp, a, b);
		}else {
		
		}
	}

	return 0;
}

void print(char *str, int a, int b) {
	int i;
	
	for(i = a; i <= b; i++) printf("%c", str[i]);
	printf("\n");
}

void replace(char *str, char *temp, int a, int b) {
	int i;

	for(i = a; i <=b; i++) {
		str[i] = *(temp++);
	}
}
void reverse(char *str, int a, int b) {
	int i, j;
	char temp;

	i = a;
	j = b;
	while(i < j) {
		temp = str[i];
		str[i] = str[j];
		str[j] = temp;
		i++;
		j--;
	}
}



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

typedef pair<int, int> P;

int n;

vector<vector<P>> G(1510);
vector<vector<int>> dist(1510, vector<int>(1510, 1e9));
void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s][s] = 0;
    que.emplace(0, s);

    while(!que.empty()){
        int ccost, cv;
        tie(ccost, cv) = que.top();
        que.pop();

        if(dist[s][cv] < ccost) continue;

        for(auto x : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = x;
            
            if(dist[s][cv] + ncost < dist[s][nv]){
                dist[s][nv] = dist[s][cv] + ncost;
                que.emplace(dist[s][nv], nv);
            }
        }
    }
}

int main(){
    int r; cin>>n>>r;
    for(int i=0; i<r; i++){
        int s, t, d; cin>>s>>t>>d;
        s--, t--;
        G[s].emplace_back(t, d);
        G[t].emplace_back(s, d);
    }

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

    int maxdist = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            maxdist = max(maxdist, dist[i][j]);
        }
    }

    vector<P> sg;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(dist[i][j] != maxdist) continue;

            sg.emplace_back(i, j);
        }
    }

    vector<bool> visited(n, false);
    for(int i=0; i<n; i++){
        for(auto j:sg){
            int s, g;
            tie(s, g) = j;
            if(dist[s][i] + dist[i][g] == maxdist){
                visited[i] = true;
                break;
            }
        }
    }

    vector<int> ans;
    for(int i=0; i<n; i++){
        if(!visited[i]){
            ans.emplace_back(i+1);
        }
    }

    cout << ans.size() << endl;
    for(auto i:ans){
        cout << i << endl;
    }
}


Measured memory_bytes: 28376
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;

int x[30][30];

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, d;

    cin>>n>>d;

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

    int cnt = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int sum = 0;
            for(int k = 0; k < d; k++){
                sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            int sq = sqrt(sum);
            if(sq * sq == sum){
                cnt++;
            }
        }
    }

    cout<<cnt<<endl;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  long long a[n];
  REP(i, n) cin>>a[i];
  
  long long ans = 0;
  REP(i, n){
    if(i == 0) continue;
    if(a[i - 1] <= a[i]) continue;
    long long temp = a[i - 1] - a[i];
    ans += temp;
    a[i] = a[i - 1];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> h(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> h.at(i);
  }

  ll l = 0, r = divceil(*max_element(h.begin(), h.end()), B);
  while (l + 1 != r)
  {
    ll c = (l + r) / 2;

    ll x = 0;
    for (ll i = 0; i < N; i++)
    {
      ll h0 = h.at(i);
      h0 -= B * c;
      chmax(h0, 0LL);
      x += divceil(h0, A - B);
    }

    if (c >= x)
      r = c;
    else
      l = c;

    //cerr << l << " " << c << " " << r << " " << x << endl;
  }

  cout << r << endl;
}

Measured memory_bytes: 1024
n,m,k = map(int,input().split())
s = []
for i in range(n+1):
    for j in range(m+1):
        hoge = (i*j+(n-i)*(m-j))
        s.append(hoge)
        s.append(n*m-hoge)
if k in s:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 82428
#include<stdio.h>

int main(void){
  float a,b,c,d,e,f,x,y;
  while(scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f) != EOF){
    if(a*e == b*d){
      printf("This equiation has no real number solution");
      break;
    }
    x = (e * c + (-1)*b*f)/(a*e-b*d);if(x==0)x=0;
    y = ((-1)*d*c + a * f)/(a * e - b* d);if(y==0)y=0;
    printf("%.3f %.3f\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 648
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

struct Point {
    double x;
    double y;
public : 
    Point(): x(0), y(0) {};
    Point(double _x, double _y): x(_x), y(_y) {};
};

double beki(double m, double n){
    return m*m + n*n;
}

int main(){

    double x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1,&x2, &y2);

    Point A(x1, y1);
    Point B(x2, y2);

    double i = 0, j = 0;
    double _x, _y;
    _x = A.x-B.x;
    _y = A.y-B.y;
    i = beki(_x, _y);
    j = sqrt(i);

    printf("%.8lf\n", j);
    return 0;
}


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

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double th = ((60 * h) + m) / 720 * 360;
  double tm = m / 60 * 360;
  cout << fixed << setprecision(20);
  double t = abs(th - tm);
  if (t > 180.0) {
    t = 360 - t;
  }
  cout << sqrt((a * a) + (b * b) - (2 * a * b * cos(PI / 180 * t))) << endl;
  return 0;
}

Measured memory_bytes: 4112
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int ,int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N, t;
	cin >> N >>t;
	cout << max(0, N-t) << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

// 間隔gを指定した挿入ソート
void insertionSort(int A[],int n,int g) {
	for(int i=g;i<n;i++) {
		int v = A[i];
		int j = i - g;
		while(j>=0 && A[j] >v) {
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n) {
	// 数列G = {1, 4, 13, 40, 121, 364, 1093, ...}を生成
	for(int h=1; ;) {
		if(h>n) break;
		G.push_back(h);
		h = 3*h + 1;
	}
	
	// 逆順にG[i] = gを指定
	for(int i=G.size()-1; i>=0; i--) {
		insertionSort(A, n, G[i]);
	}
}

int main(void) {
	cin >> n;
	// より速い入力scanf関数を使用
	for(int i=0; i<n; i++) scanf("%d",&A[i]);
	cnt = 0;

	shellSort(A,n);
	
	cout << G.size() << endl;
	for(int i=G.size()-1; i>=0; i--) {
		printf("%d", G[i]);
		if(i) printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	for(int i=0;i<n;i++) printf("%d\n",A[i]);
	
	return 0;
}

Measured memory_bytes: 7084
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	for(int i = 1; i <= 5; i++){
		int val;
		cin >> val;
		if(!val){
			cout << i << "\n";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
using ll = long long;
int M = 1000000007;
int main() {
	int N; cin >> N;
	ll res = 1;
	for (int i = 2; i <= N; i++) {
		res *= i;
		res %= M;
	}
	cout << res << endl;
	//system("pause");
	return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    if(A == B) {
        cout << 0 << endl;
    } else {
        //cout << (A - B)*(1 - 2*(K%2)) << endl;
        cout << (A - B)*(ll)pow(-1,K%2) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3744
S = input()
S = set([s for s in S])
l_list = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
ans = 'None'
for l in l_list:
  if l in S:
    continue
  else:
    ans = l
    break
print(ans)

Measured memory_bytes: 4016
import sys
sys.setrecursionlimit(10 ** 6)

n, q = map(int, input().split())

connect = [set() for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x

ans = [0] * n
def dfs(me, parent, cum):
    cum += counter[me]
    ans[me] = cum
    for child in connect[me]:
        if child != parent:
            dfs(child, me, cum)

dfs(0, -1, 0)

print(*ans)

Measured memory_bytes: 266160
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	int i=0;
	while(N >= pow(2,i)){
		i++;
	}
	int ans=pow(2,i-1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=998244353;
int c[4040][4040];
int p1[2020][2020];
int p2[2020][2020],s[2020][2020];
int pp2[2020];
int main()
{
	int n,k,k1,k2,ans;
	scanf("%d%d",&k,&n);
	memset(c,0,sizeof(c));
	for(int i=0;i<=4001;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=i;j++)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	memset(p1,0,sizeof(p1));
	p1[0][0]=1;
	for(int i=1;i<=k;i++)
		for(int j=0;j<=n;j++)
			p1[i][j]=c[j+i-1][i-1];
	pp2[0]=1;
	for(int i=1;i<=2000;i++)
		pp2[i]=pp2[i]*2%mod;
	memset(p2,0,sizeof(p2));
	p2[0][0]=1;
	for(int i=0;i<=n;i++)
		s[0][i]=1;
	for(int i=1;i<=k;i++)
	{
		p2[i][0]=1;
		s[i][0]=1;
		for(int j=1;j<=n;j++)
		{
			p2[i][j]=(s[i-1][j-1]*2%mod+p2[i-1][j])%mod;
			s[i][j]=(s[i][j-1]+p2[i][j])%mod;
		}
	}
	for(int i=2;i<=k*2;i++)
	{
		k1=k;
		k2=min(k,i-1)-max(i-k,1)+1;
		k1-=k2;
		ans=0;
		k2/=2;
		if(i%2==0)
		{
			for(int j=0;j<n;j++)
				ans=((long long)p1[k1][j]*p2[k2][n-j-1]+ans)%mod;
		}
		for(int j=0;j<=n;j++)
			ans=((long long)p1[k1][j]*p2[k2][n-j]+ans)%mod;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 111872
#include<bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
const int inf=0x3f3f3f3f;
int n,a,b;
main()
{
	cin>>n>>a>>b;if(a>b)swap(a,b);
	if((b-a)%2==0)cout<<(b-a)/2;
	else
	{
		int ret=a+(b-a)/2;
		b=n-b+1,a=n-a+1;swap(a,b);
		ret=min(ret,a+(b-a)/2);
		cout<<ret;
	}
	return 0;
}


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

int main(){
  int N,K;
  int ans = 0;
  cin >> N >> K;
  vector<bool> vec(N);
  for(int i=0;i<K;++i){
    int d;
    cin >> d;
    for(int j=0;j<d;++j){
      int s;
      cin >> s;
      vec.at(s-1) = true;
    }
  }
  for(int i=0;i<N;++i){
    if(!vec.at(i)) ans+= 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
n, m = gets.split.map(&:to_i)
lists = gets.split.map(&:to_i).uniq.sort.reverse
lcm = lists.inject(:lcm)
p lcm/lists.inject(:gcd)%2*(m+lcm/2)/lcm
# if (lcm / 2) % 2 == 0
#   puts 0
# else
#   puts 0 if lcm / 2 > m
#   ans = (m - lcm / 2) / lcm + 1
#   puts ans
# end


Measured memory_bytes: 9088
#include <stdio.h>
#include <math.h>

int main(){

  int n;
  double x1,y1,x2,y2,x3,y3,tmp=0,xo=0,yo=0,r=0;

  scanf("%d",&n);

  while(n--){
    scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);

    tmp=(x1*x1+y1*y1)*(y2-y3)+(x2*x2+y2*y2)*(y3-y1)+(x3*x3+y3*y3)*(y1-y2);
    xo=tmp/(2*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)));

    tmp=(x1*x1+y1*y1)*(x3-x2)+(x2*x2+y2*y2)*(x1-x3)+(x3*x3+y3*y3)*(x2-x1);
    yo=tmp/(2*(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2)));

    tmp=(x1-xo)*(x1-xo)+(y1-yo)*(y1-yo);
    r=sqrt(tmp);

    printf("%.3f %.3f %.3f\n",xo,yo,r);
  }
  return 0;
}


Measured memory_bytes: 664
from collections import deque

n = int(input())
num_list = list(map(int,input().split()))
dq =deque()

for i in range(len(num_list)):
    if i%2 == (n-1)%2:
        dq.appendleft(num_list[i])
    else:
        dq.append(num_list[i])

ans = [str(i) for i in dq]
print(' '.join(ans))

Measured memory_bytes: 32968
N = int(input())
a_list = []
for n in range(N):
    a_list.append(int(input()))

count = 0
pos = 1
for n in range(N):
    count += 1
    if a_list[pos-1]==2:
        print(count)
        break
    pos = a_list[pos-1]
    
if a_list[pos-1]!=2:
    print(-1)

Measured memory_bytes: 7084
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 100000

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    int ans = 1;
    for(int i = 1; i <= M; i++) ans *= 2;
    int temp = ans;
    ans *= 1900 * M;
    for(int i = 1; i <= temp; i++) ans += (N-M)*100;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
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; }

int mmax=1E5+1;

int main(){
    int N;
    ll sum=0;
    cin >> N;
    vector<int> v(mmax);
    rep(i,N){
        int tmp;
        cin >> tmp;
        v[tmp]++;
    }
    rep(i,mmax){
        sum+=i*v[i];
    }

    int Q,B,C;
    cin >> Q;
    rep(i,Q){
        cin >> B >> C;
        int tmp = v[B];
        v[B] = 0;
        v[C] += tmp;
        sum = sum - tmp*(B-C);
        cout << sum << endl;
    }

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Range Set Counter
//-------------------------------------------------
template<typename T>
class RangeSet
{
private:
    ::std::vector<int> v;
    ::std::unordered_map<T, int> Map;
    ::std::vector<::std::vector<int> > data;
    int kind;
public:
    RangeSet(const ::std::vector<T> &v_):v(v_.size()){
        int sz = v_.size(); kind = 0;
        for(int i=0;i<sz;i++){
            T t = v_[i];
            if (Map.count(t)){
                data[Map[t]].push_back(i);
            }else{
                Map[t] = kind++;
                data.push_back(::std::vector<int>());
                data.back().push_back(i);
            }
            v[i] = Map[t];
        }
    }
    //query for all elements
    int query(T x){
        if (!Map.count(x)) return 0;
        return data[Map[x]].size();
    }
    //query for [a, b]
    int query(int a, int b, T x){
        if (a>b) return 0;
        if (!Map.count(x)) return 0;
        int xi = Map[x];
        auto right = ::std::upper_bound(data[xi].begin(),data[xi].end(),b);
        auto left  = ::std::lower_bound(data[xi].begin(),data[xi].end(),a);
        return right-left;
    }
    //search x for [k, tail]
    int find(int k, T x){
        if (!Map.count(x)) return -1;
        int xi = Map[x];
        auto itr = ::std::lower_bound(data[xi].begin(),data[xi].end(),k);
        if (itr!=data[xi].end()){
            return *itr;
        }else{
            return -1;
        }
    }
};

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,p; cin>>n>>p;
    string s; cin>>s;
    vi a(n);
    ll ans=0;
    rep(i,n) a[i] = s[i]-'0';
    if (p==2 || p==5){
        rep(i,n){
            if (a[i]%p==0){
                ans+=i+1;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    vi d10(n);
    d10[n-1] = 1;
    rep(i,n-1) d10[n-i-2] = d10[n-i-1]*10 % p;
    vi b(n);
    rep(i,n) b[i] = a[i]*d10[i] % p;
    rep(i,n-1) b[i+1]=(b[i+1]+b[i])%p;
    // for(auto e:b){
    //     cout<<e<<" ";
    // }cout<<endl;
    RangeSet<int> rs(b);
    rep(i,n){
        ans+=rs.query(i+1,n-1,b[i]);
    }
    ans+=rs.query(0,n-1,0);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5840
#include<bits/stdc++.h>
using namespace std;
#define N 110
#define ll long long
ll a[5];
int main()
{
    ll n;
    scanf("%lld",&n);
    for(int i=0;i<5;i++)cin>>a[i];
    sort(a,a+5);
    ll v=a[0];
    printf("%lld",max(1ll*5,4+(n+a[0]-1)/a[0]));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

using namespace std;

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

    int p[N];
    int s[N];

int last = 0;
int count = 0;
    for (int i = 0; i < N; i ++) {
        cin >> p[i];
        s[i] = p[i];
    }

    sort(s, s + N);

    for (int i = 0; i < N; i ++) {
        if (s[i] != p[i]) {
            count++;
        }
    }

if (count <= 2) {

                    cout << "YES" << endl;
} else {

                    cout << "NO" << endl;
}

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

int main() {

	int N;
	cin >> N;

	int A[200] = {};
	
	rep(i, N) {
		int A0;
		cin >> A0;
		int saisho = 0;
		while (A0 % 2 == 0) {
			A[i]++;
			A0 /= 2;
		}
	}
	co(*min_element(A, A + N));
	Would you please return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  ll x; cin>>x;
  ll ans=x/11*2;
  x%=11;
  ans+=(x+5)/6;
  cout << ans << endl;
}

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


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 1001001001;

int main(){
	int s; cin >> s;
	int pre = s / 100, post = s % 100;
	bool f1=true, f2 = true;
	if(pre>12 || pre == 0) f1 = false;
	if(post>12 || post == 0) f2 = false;
	if(f1 && f2) cout << "AMBIGUOUS" << endl;
	else if (!f1 && !f2) cout << "NA" << endl;
	else if (!f1) cout << "YYMM" << endl;
	else cout << "MMYY" << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ x, a, b ] <- readInts
	putStrLn $ solve x a b

solve x a b
	| b <= a = "delicious"
	| b <= a + x = "safe"
	| otherwise = "dangerous"


Measured memory_bytes: 508
x,y = map(int,input().split())

list1 = [1,3,5,7,8,10,12]
list2 = [4,6,9,11]
list3 = [2]

if x in list1 and y in list1:
	print('Yes')
	
elif x in list2 and y in list2:
	print('Yes')
	
elif x in list3 and y in list3:
	print('Yes')
	
else:
	print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define hell 998244353
#define PI acos(-1.0)
#define S second
#define F first
#define lli long long int
#define li long int
#define ld long double
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
 
#define run(j, n) for(auto ii=j;ii!=n;ii++)
#define out(j, n) for(auto ii=j;ii!=n;ii++) cout<<(*ii)<<" ";


int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << showpoint;
cout << setprecision(11);

int n;cin>>n;
int ar[n+1];
run(1, n+1) cin>>ar[ii];
int ct = 0;
for(int i=1;i<=n;i++)
{
    if(i&1 && ar[i]&1) ct++;
}

cout<<ct;
return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>

using namespace std;
int main(void){

 vector<int> A(35,0);
 int n,m,k,l;
 int ans=0;
 cin>>n>>m;
 
 for(int i=0; i<n; i++){
  cin>>k;
  for(int j=0; j<k; j++){
   cin>>l;
   A[l]++;
  }
 }

 for(int i=1; i<=m; i++)if(A[i]==n)ans++;
 cout<<ans<<endl;

 return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    String a=sc.nextLine();
    double i=Double.parseDouble(a);
    int sum=0;
    for(double j=1;j<=3;j++){
      sum+=(int) Math.pow(i,j);
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 35756
using System;
using System.Collections.Generic;
using System.Linq;

class F
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var n = h[0];
		var qs = new int[h[1]].Select(_ => Read()).ToArray();

		var r = (long)(n - 2) * (n - 2);

		// i -> j
		var l1 = new List<(int i, int j)> { (n, n) };
		// j -> i
		var l2 = new List<(int j, int i)> { (n, n) };

		foreach (var q in qs)
		{
			if (q[0] == 1)
			{
				var li = Last(0, l2.Count - 1, x => l2[x].j > q[1]);
				var i = l2[li].i;
				r -= i - 2;
				if (q[1] < l1.Last().j) l1.Add((i, q[1]));
			}
			else
			{
				var li = Last(0, l1.Count - 1, x => l1[x].i > q[1]);
				var j = l1[li].j;
				r -= j - 2;
				if (q[1] < l2.Last().i) l2.Add((j, q[1]));
			}
		}
		Console.WriteLine(r);
	}

	static int Last(int l, int r, Func<int, bool> f)
	{
		int m;
		while (l < r) if (f(m = r - (r - l - 1) / 2)) l = m; else r = m - 1;
		return l;
	}
}


Measured memory_bytes: 53160