akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int n, m;
ll dp[222][N], w[N], v[N];

ll f(int id, ll s)
{
	if(s < 0 || id > n)
		return 0;
	if(dp[id][s] != -1)
		return dp[id][s];
	if(s < v[id])
		return dp[id][s] = f(id + 1, s);
	return dp[id][s] = max(f(id + 1, s), (w[id] + f(id + 1, s - v[id])));
}

int main()
{
	memset(dp, -1, sizeof dp);
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> v[i] >> w[i];
	cout << f(1, m) << '\n';



	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 387072
#include <iostream>
using namespace std;
int A[100005];
int B[100005];

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

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

	long long ans = 0;

	for (int i = 0; i < N; ++i)
	{
		int temp = B[i];
		if (temp <= A[i])
		{
			ans += temp;
			A[i] -= temp;
		}
		else
		{
			ans += A[i];
			temp -= A[i];
			A[i] = 0;
			if (temp <= A[i+1])
			{
				ans += temp;
				A[i+1] -= temp;
			}
			else
			{
				ans += A[i+1];
				A[i+1] = 0;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int n;
  cin >> n;
  ivec a(n);
  REP(i, n) { cin >> a[i]; }

  int count = 1;
  int ans = 0;
  REP(i, n) {
    if (a[i] != count) {
      ans++;
    } else {
      count++;
    }
  }
  if (ans == a.size()) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


class Vertex:
    def __init__(self, value):
        self.edge = []
        self.value = value


visited = []
flg = True      # 2部グラフかどうか
def dfs(G, v, pv, col):
    global flg

    visited[v] = True
    G[v].value = col

    for nv in G[v].edge:
        if visited[nv]:
            if nv != pv and G[nv].value == G[v].value:
                flg = False
            continue
        dfs(G, nv, v, (col + 1) % 2)


def main():
    N, M = map(int, input().split())
    G = [Vertex(0) for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1; b -= 1
        G[a].edge.append(b)
        G[b].edge.append(a)
    
    for _ in range(N):
        visited.append(False)
    dfs(G, 0, -1, 0)

    if flg:
        bw = [0, 0]     # [black, white]
        for i in range(N):
            bw[G[i].value] += 1
        print(bw[0] * bw[1] - M)
    else:
        print(N*(N-1) // 2 - M)


if __name__ == '__main__':
    main()

Measured memory_bytes: 59044
def is_m(n):
    return 1 <= n & n <= 12


s=input()
h=int(s[0:2])
t=int(s[2:4])

if is_m(h) & is_m(t):
    print('AMBIGUOUS')
elif is_m(h):
    print('MMYY')
elif is_m(t):
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut sum = 0;
    for i in 1..n + 1 {
      if check(i) {
        sum += 1;
      }
    }

    println!("{}", sum);
}


fn check(x: usize) -> bool {
  let mut x = x;
  let mut sum = 0;

  while x != 0 {
    sum += 1;
    x /= 10;
  }

  sum % 2 == 1
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t r,c;
  cin >> r >> c;
  
  int sumColumn[c] = {};
  int value;
  for(int i=0;i<r+1;i++){
      int sumRow = 0;
      for(int j=0;j<c;j++){
          if(i==r){
            value = sumColumn[j];
          }
          else{
            cin >> value;
            sumColumn[j] += value;
          }
          sumRow += value;
          cout << value << " ";
      }
      cout << sumRow << endl;
  }

  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s,t,r;
	int a,b;
	cin >>s >>t;
	cin >>a >>b;
	cin >>r;
	if (r==s)
		cout <<a-1 <<" "<<b<<endl;
	else
		cout <<a <<" "<<b-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
long long chmin(long long a, long long b){ if(a > b){ return b; } return a;}

int main(){
    long long n; cin >> n;
    long long min = n - 1;
    for(long long i = 1; i <= (int)sqrt(n); i++){
        long long j = n/i;
            if(n%i == 0){ min = chmin(min, i -1 + j -1); }
    }
    cout << min << endl;
    return 0;
}

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

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


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

  if(H%A==0) cout<<H/A;
  else cout<<H/A + 1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
  int M,K;
  cin >> M >> K;
  int len = 1<<M;
  if(K>=len) {
    cout << -1 << endl;
    return 0;
  }
  if(M==0) {
    if(K!=0) {
      cout << -1 << endl;
    } else {
      printf("%d %d\n",0,0);
    }
    return 0;
  }
  if(M==1) {
    if(K!=0) {
      cout << -1 << endl;
    } else {
      printf("%d %d %d %d\n",0,0,1,1);
    }
    return 0;
  }
  rep(k,len) {
    if(k==K) continue;
    cout << k << " ";
  }
  cout << K << " ";
  drep(k,len) {
    if(k==K) continue;
    cout << k << " ";
  }
  cout << K << endl;
}

Measured memory_bytes: 3720
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
A2 = [A[i] for i in range(1,n,2)]
A0 = [A[i] for i in range(0,n,2)]
if len(A) == 1:
    ans = A
else:
    ans = A0[::-1]
    ans += A2
if n % 2 == 0:
    ans = ans[::-1]
print(*ans)

Measured memory_bytes: 26192
import sys
import time
st = time.perf_counter()
def inpl():
    return list(map(int, input().split()))
# ------------------------------

N = int(input())
A = inpl()

s = set(A)
table = [0] * (N+1)
for i in A:
    table[i] += 1

comb = 0
for i in s:
    comb += table[i] * (table[i]-1) // 2

for i in A:
    print(comb - (table[i]-1))


# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


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

int main() {
  ll n, a, b; cin >> n >> a >> b;
  if ((b-a)%2 == 0) {cout << (b-a)/2 << endl; return 0;}
  
  ll an = 5e18;
  ll x = a, y = b, sm = 0;
  x -= a-1, y -= a, sm += a; //cout << x << " " << y << " " << sm << endl;
  an = min(an, sm+(y-x)/2);
  x = a, y = b, sm = 0;
  x += n-b+1, y += n-b, sm += n-b+1; //cout << x << " " << y << " " << sm << endl;
  an = min(an, sm+(y-x)/2);
  cout << an << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double eps=1e-9;
int a,b,c,d;
inline double f(double x){
	return x*x*x*a+x*x*b+x*c+d;
}
inline double ABS(double x){return max(x,-x);}
int main(){
	int t;scanf("%d",&t);
	while(t--){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		if(a<0){
			a=-a;b=-b;c=-c;d=-d;
		}
		int r1=0;
		int r2=0;
		int D=b*b-3*a*c;
		if(D<0){
			if(f(0)<-eps)r1++;
			if(f(0)>eps)r2++;
		}else if(D==0){
			double t=(double)-b/3/a;
	//		printf("%f\n",t);
			if(ABS(f(t))<eps){
				if(t>eps)r1+=3;
				if(t<-eps)r2+=3;
			}else{
				if(f(0)<-eps)r1++;
				if(f(0)>eps)r2++;
			}
		}else{
			double t1=((double)-b-sqrt(D))/3/a;
			double v1=f(t1);
			double t2=((double)-b+sqrt(D))/3/a;
			double v2=f(t2);
			double v0=f(0);
		//	printf("%f %f %f %f\n",t1,v1,t2,v2);
			if(ABS(v1)<eps){
				if(t1<-eps)r2+=2;
				if(t1>eps)r1+=2;
			}else if(v1>eps){
				if(t1<-eps)r2++;
				else{
					if(v0>eps)r2++;
					if(v0<-eps)r1++;
				}
				if(ABS(v2)<eps){
					if(t2<-eps)r2+=2;
					if(t2>eps)r1+=2;
				}else if(v2<-eps){
					if(t2<-eps)r2++;
					else if(t1>eps)r1++;
					else{
						if(v0>eps)r1++;
						if(v0<-eps)r2++;
					}
				}
			}
			if(v2<-eps){
				if(t2>eps)r1++;
				else{
					if(v0>eps)r2++;
					if(v0<-eps)r1++;
				}
			}
		}
		printf("%d %d\n",r1,r2);
	}
}

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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;
using ll = long long;
using P = pair<int, int>;

int n, u, v;
vector<vector<int>> G;

vector<int> dist;
void dfs(int a, int p, int d) {
  dist[a] = d;
  for (auto b : G[a]) {
    if (b == p) continue;
    dfs(b, a, d + 1);
  }
};

vector<int> calcDist(int a) {
  dist = vector<int>(n);
  dfs(a, -1, 0);
  return dist;
}

void Main() {
  cin >> n >> u >> v;
  u--;
  v--;
  G.resize(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  vector<int> U = calcDist(u);
  vector<int> V = calcDist(v);
  int mx = 0;
  rep(i, n) {
    if (V[i] > U[i]) mx = max(mx, V[i]);
  }
  cout << mx - 1 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N, K; cin >> N >> K;
	string S; cin >> S;

	if(S[K-1] == 'A') S[K-1] = 'a';
	else if(S[K-1] == 'B') S[K-1] = 'b';
	else if(S[K-1] == 'C') S[K-1] = 'c';

	cout << S << endl;


	return 0;

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 21000000;
const int K = 19;
const int mod = 1e9 + 7;
int f[N], invf[N], inv2, inv3;
int binpow(int x, int y){
    if (y == 0) return 1;
    if (y % 2) return x * binpow(x, y - 1) % mod;
    int z = binpow(x, y / 2);
    return z * z % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int h, w, k;
    cin >> h >> w >> k;
    invf[0] = 1;
    f[0] = 1;
    for (int i = 1; i < N; i++) f[i] = f[i - 1] * i % mod;
    invf[N - 1] = binpow(f[N - 1], mod - 2);
    for (int i = N - 2; i >= 1; i--){
        invf[i] = invf[i + 1] * (i + 1) % mod;
    }
    inv2 = binpow(2, mod - 2);
    inv3 = binpow(3, mod - 2);
    int ans = 0;
    for (int i = 0; i <= min(k, h); i++){
        int b = i;
        int wh = k - i;
        if (wh < 0 || wh > w) continue;
        int s1 = wh * (wh - 1) % mod * b % mod * inv3 % mod;
        int s2 = b * (b - 1) % mod * wh % mod * inv3 % mod;
        int s3 =  wh * (wh - 1) % mod  * inv2 % mod;
        int s4 =  b * (b - 1) % mod  * inv2 % mod;
        int s5 = 2 * b * wh % mod;
        int s = (s1 + s2 + s3 + s4 + s5 + b + wh + k) % mod;
       // cout << s << " " << s2 << " " << s3 << " " << s4 << " " << " " << s5 << " " << b << " " << wh << endl;
        int p = f[k] * invf[wh] % mod * invf[b] % mod * f[h] % mod * f[w] % mod * invf[w - wh] % mod * invf[h - b] % mod;
        ans = (ans + p * s) % mod;
    }
    cout << ans ;
}


Measured memory_bytes: 328448
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int input(int n){
    string ss[] = {"Vacent", "Male", "Female"};
    cout << n << endl;
    string str;
    cin >> str;
    if(str == ss[0])exit(0);
    if(str == ss[1])return 1;
    else return 2;
    
}
main(){
    int N;
    cin >> N;
    
    int l = 0, r = N-1;
    int vl = input(l), vr = input(r);
    while(r - l >= 3){
        //[l,r]→[l,k], [k,r]
        int k = (l + r) / 2;
        int vk = input(k);
        //[l,k]にVacentがあるとき
        if(((k-l) % 2 == 0) ^ (vl == vk) ){
            r = k;
            vr = vk;
        }else{
            l = k;
            vl = vk;
        }
    }
    //cout << l << "," << vl << ":" << r << "," << vr << endl;
    input((l + r) / 2);
    cerr << "error!" << endl;
}

Measured memory_bytes: 852
def selection_sort(array):
    for i in range(len(array)):
        j = min(range(i, len(array)), key=lambda x: array[x])
        array[i], array[j] = array[j], array[i]


class SegmentTree(object):

    def __init__(self, size, op=min, init=float("inf")):
        self.size = 1
        self.op = op
        self.init = init
        while self.size < size:
            self.size *= 2
        self.data = [init] * (self.size*2+2)

    def update(self, idx, value):
        k = idx + self.size - 1
        self.data[k] = value
        while k > 0:
            k = (k - 1) // 2
            self.data[k] = self.op(self.data[k*2+1], self.data[k*2+2])

    def __getitem__(self, val):
        return self.data[(self.size-1)+val]

    def find(self, start, end):
        def query(k, left, right):
            if right <= start or end <= left:
                return self.init
            if start <= left and right <= end:
                return self.data[k]
            vl = query(k*2+1, left, (left+right)//2)
            vr = query(k*2+2, (left+right)//2, right)
            return self.op(vl, vr)
        return query(0, 0, self.size)


def swap_count(array):
    count = 0
    rmq = SegmentTree(len(array), op=min, init=(float("inf"), float("inf")))
    for i, v in enumerate(array):
        rmq.update(i, (v, i))
    for i in range(len(array)):
        vi, _ = rmq[i]
        vj, idx = rmq.find(i, len(array))
        j = idx
        if rmq[i] <= rmq[j]:
            continue
        count += 1
        rmq.update(i, (vj, i))
        rmq.update(j, (vi, j))
    return count

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    print(*sorted(A))
    count = swap_count(A)
    print(swap_count(A))

Measured memory_bytes: 7868
#!/usr/bin/env python3.4

# abc127_d

import collections
import itertools
import functools

def main():
    # Input
    _, m = [int(s) for s in input().split()]
    cards = [int(s) for s in input().split()]
    acts = [[int(s) for s in input().split()] for _ in range(m)]
    # Get ans
    cards = collections.deque(sorted(cards))
    acts.sort(key=lambda a: a[1], reverse=True)
    for b, c in acts:
        for _ in range(b):
            if cards[0] >= c:
                break
            cards.popleft()
            cards.append(c)
    ans = sum(cards)
    # Output
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 27596
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

#define INF 100000000


int main() {
	int n, ans;
	cin >> n;
	ans = 180 * (n - 2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define MAX 200000
#define INF (ll)1e10
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

void solve(void){
    int n, t;
    scanf("%d%d\n", &n, &t);
    int as[n];
    rep(n, i) scanf("%d ", &as[i]);
    int maxdiff = 0, ans = 0, mina = as[0];
    Rep(0, n-1, i) {
        mina = min(as[i], mina);
        if (as[i]-mina > maxdiff) {
            maxdiff = as[i]-mina;
            ans = 1;
        }
        else if (as[i]-mina == maxdiff) ans++;
    }
    printf("%d\n", ans);
}

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


Measured memory_bytes: 640
/** 
  If comrades that you trust gather around you, hope can take physical form and become visible. That’s what I believe.
  */
#include <bits/stdc++.h>
using namespace std;
/**
  (▀̿Ĺ̯▀̿ ̿) (ง ͠° ͟ل͜ ͡°)ง
  */
using ll = long long;
const int N = 2e5 + 7;
vector<int> g[N];
int c[N], cnt[N], sub[N];
ll ans[N];
ll all = 0LL;
int dfs(int v, int p = -1) {
    sub[v] = 1;
    auto bfr = cnt[c[v]];
    for (auto u: g[v]){
        if (u == p) continue;
        ll pre = all - cnt[c[v]];
        sub[v] += dfs(u,v);
        ll nxt = all - cnt[c[v]];
        ans[c[v]] -= (nxt - pre) * (nxt - pre - 1) / 2;
    }
    cnt[c[v]] = bfr + sub[v];
    all++;
    return sub[v];
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int n; cin>>n;
	for (int i = 1;i <= n; i++) { 
        cin >> c[i];
        ans[i] = (ll) n * (n-1) / 2;
    }
	for (int i = 1;i < n; i++){
		int a,b; cin >> a >> b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	dfs(1);
	for(int i = 1; i <= n; ++i){
		ll pre = 0, nxt = n - cnt[i];
		ans[i] -= (nxt - pre) * (nxt - pre - 1) / 2;
	}
    for (int i = 1; i <= n; ++i) ans[c[i]]++;
    for (int i = 1; i <= n; ++i) cout << ans[i] << '\n';
	return 0;
}


Measured memory_bytes: 37128
using System;
using System.Collections;

class Program {
    static void Main (string[] args) {
        ulong X = ulong.Parse (Console.ReadLine ());

        int year = 0;
        ulong now = 100;
        while (now < X) {
            now += (ulong) Math.Floor ((double) now / 100);
            year++;
        }
        Console.WriteLine (year);
    }
}

Measured memory_bytes: 27612
def main():
    N=input()
    one=int(N[len(N)-1])

    if one==2 or one==4 or one==5 or one==7 or one==9:
        j="hon"
    elif one==0 or one==1 or one==6 or one==8:
        j="pon"
    else:
        j="bon"

    print(j)

if __name__=="__main__":
    main()



Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

ll power(ll a, ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}

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

int main()
{
    IOS;
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    repf(i,1,n+1) cin>>a[i];
    ll dp[n+1][k+1];
    ll pref[n+1][k+1];
    memset(dp,0,sizeof dp);
    memset(pref,0,sizeof pref);
    repf(i,0,n+1) dp[i][0]=1,pref[i][0]=1;
    repf(i,0,k+1) pref[0][i]=1;
    repf(i,1,n+1)
    {
        repf(j,1,k+1)
        {
            if(j-a[i]-1>=0) dp[i][j]=(dp[i][j]+(pref[i-1][j]-pref[i-1][j-a[i]-1]+mod)%mod)%mod;
            else dp[i][j]=(dp[i][j]+pref[i-1][j])%mod;
            pref[i][j]=(pref[i][j-1]+dp[i][j])%mod;
        }
    }
    cout<<dp[n][k]<<endl;
    return 0;  
}

Measured memory_bytes: 158080
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None
A, B = LI()
print(max(A+B, A-B, A*B))


Measured memory_bytes: 67052
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

const int INF = 1e9;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(m);
  rep(i, m) cin >> c[i];
  vector<int> dp(n+1, INF);
  dp[0] = 0;
  for(int i=1; i<=n; i++) {
    rep(j, m) {
      if(i-c[j] >= 0) {
        chmin(dp[i], dp[i-c[j]]+1);
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}


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

int N;
vector<int> A, L;

// 広義単調減少部分列の長さ
int solve(){
  L[0] = A[0];
  int length = 1;
  for (int i = 1; i < N; i++) {
    if (L[length - 1] <= A[i]) {
      L[length] = A[i];
      length++;
    } else {
      auto iter = upper_bound(L.begin(), L.begin() + length, A[i]);
      L[iter - L.begin()] = A[i];
    }
  }
  return length;
}
int main() {
  cin >> N;
  A.resize(N);
  L.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] = - A[i];
  }
  cout << solve() << "\n";
  return 0;
}

Measured memory_bytes: 1024
#-*- coding: utf-8 -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_d -d test-d
oj test -d test-d -c "python abc116d.py"
oj test -d test-d -c "python abc116d.py" test-d/sample-3.in
"""
from collections import defaultdict
import sys
import math
from datetime import datetime
import re

def sol(S):
    #YYMM, MMYY, AMBIGUOUS, NA のうち正しいものを出力せよ。
    if re.match("^[0][0][0][0]$", S):
        return 'NA'
    if re.match("^[0][0][0-1][0-2]$", S):
        return 'YYMM'
    if re.match("^[0-1][0-2][0][0]$", S):
        return 'MMYY'
    elif re.match("^[0-1][0-2][0-1][0-2]$", S):
        return 'AMBIGUOUS'
    elif re.match("^[0-9][0-9][1][0-2]$", S):
        return 'YYMM'
    elif re.match("^[0-9][0-9][0][1-9]$", S):
        return 'YYMM'
    elif re.match("^[1][0-2][0-9][0-9]$", S):
        return 'MMYY'
    elif re.match("^[0][1-9][0-9][0-9]$", S):
        return 'MMYY'
    else:
        return 'NA'


do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    # n = int(parsed_lines[0][0])
    # k = int(parsed_lines[0][1])
    S = parsed_lines[0][0]
    return S


if not do_submit:
    S = input_parse("""
    1905
    """)
    print(sol(S))

    S = input_parse("""
    0112
    """)
    print(sol(S))

    S = input_parse("""
    1700
    """)
    print(sol(S))

    S = input_parse("""
    0000
    """)
    print(sol(S))

    S = input_parse("""
    1001
    """)
    print(sol(S))



else:
    #n, k = list(map(int, input().split()))
    S = input()
    print(sol(S))

    # S = input().strip()
    # print(sol(S))





Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  cin>>N>>M;
  vector<int> X(N);
  cin>>X;

  map<int, int> cnt[M];
  for(int x:X) cnt[x%M][x]++;

  auto calc = [&](int a, int b){
    if(a == b){
      int sum = 0;
      for(auto p:cnt[a]) sum += p.second;
      return sum / 2;
    }
    
    int res = 0;    
    deque<int> A, B;
    for(auto p:cnt[a]) A.emplace_back(p.second);
    for(auto p:cnt[b]) B.emplace_back(p.second);
    sort(A.begin(), A.end(), [](auto &p, auto &q){return p%2 > q%2;});
    sort(B.begin(), B.end(), [](auto &p, auto &q){return p%2 > q%2;});

    while(1){
      while(!A.empty() && A[0] == 0) A.pop_front();
      while(!B.empty() && B[0] == 0) B.pop_front();
      if(A.empty() || B.empty()) break;
      res++;
      int a = A[0] - 1, b = B[0] - 1;
      A.pop_front(), B.pop_front();
      (a%2 == 0)? A.push_back(a):A.push_front(a);
      (b%2 == 0)? B.push_back(b):B.push_front(b);
    }
    while(!A.empty()) res += A[0] / 2, A.pop_front();
    while(!B.empty()) res += B[0] / 2, B.pop_front();
    return res;
  };

  int ans = 0;
  for(int i=0;i<M;i++){
    int a = i;
    int b = (M - i) % M;
    if(a <= b) ans += calc(a, b);
  }

  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 9984
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var alist = new List<int>();
        for (int i = 0; i <= 9; i++)
        {
            var ok = false;
            for (int j = 0; j < k; j++)
                if (i == a[j]) { ok = true; break; }
            if (!ok) alist.Add(i);
        }
        for (int i = n; i <= 99999; i++)
            if (checkNum(alist, i)) { Console.WriteLine(i); break; }

    }
    public static bool checkNum(List<int> a, int n)
    {
        var ns = n.ToString();
        for (int i = 0; i < ns.Length; i++)
            if (!a.Contains(int.Parse(ns[i].ToString()))) return false;
        return true;
    }
}


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


#define DEBUG(x) 			   cout << '>' << #x << ':' << x << endl;
#define D(x)        		   cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         		   cerr << __LINE__ << ": Hi" << '\n'
#define fresh                  {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define read                   freopen("in.txt","rt",stdin)
#define write                  freopen("out.txt","wt",stdout)
#define PI                     3.1415926535897932384626433832795
#define mems(ds_name,val)      memset(ds_name,val,sizeof(ds_name))


int main()
{
//    fresh;
//    read;
//	write;

    int t;
    cin>>t;
    int divs = t/2;
    int mods=t%2;
    if(!mods){
        cout<<divs*divs<<endl;
    }
    else{
        cout<<divs*(divs+1)<<endl;
    }



}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

right = 0
res = 0
sum = 0

for left in range(n):
    while right < n and sum + a[right] == sum ^ a[right]:
        sum += a[right]
        right += 1

    res += right - left

    if right == left:
        right += 1
    else:
        sum -= a[left]

print(res)


Measured memory_bytes: 23560
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 105

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


int main() {

	int a, b;
	cin >> a >> b;
	cout << max(max(a + b, 2 * a - 1), 2 * b - 1) << endl;
	



}

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

using namespace std;

int main(){
  int a,b,cnt=0;

  cin>>a>>b;

  for(int i=a; i<=b; ++i){
    if(i/1000 == (i%10)*10+(i%100)/10) ++cnt;
  }

  cout << cnt << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

string parse(string s){
  stack<char> st;

  for(int i=0;i<s.size();i++){
    if(s[i] == '+' || s[i] == '-' || s[i] == '['){
      st.push(s[i]);
    }else if(s[i] == ']'){
      string t;
      while(st.top() != '['){
        t += st.top();
        st.pop();
      }
      st.pop();
      for(int i=0;i<t.size();i++) st.push(t[i]);
    }else{
      while(st.size() && (st.top() == '-' || st.top() == '+')){
        char c = st.top(); st.pop();
        if(s[i] != '?'){
          if(c == '-') s[i] = (s[i] - 'A' + 25)%26 + 'A';
          else s[i] = (s[i] - 'A' + 1)%26 + 'A';
        }
      }
      st.push(s[i]);
    }
  }

  string ans = "";
  while(st.size()){
    ans = st.top() + ans;
    st.pop();
  }

  return ans;
}

bool solve(){
  string s, ans;
  cin >> s;

  if(s == ".") return false;
  
  ans = parse(s);

  for(int i=0;i<ans.size();i++){
    if(ans[i] == '?') ans[i] = 'A';
  }

  cout << ans << endl;

  return true;
}

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



Measured memory_bytes: 3144
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toLong() }

    val isOdd = A.count { it < 0L } % 2 == 1
    val B = A.asSequence().map { Math.abs(it) }.sortedDescending()
    println(B.sum() - if (isOdd) 2 * B.last() else 0)
}

Measured memory_bytes: 59768
a, b, m = list(map(int, input().split()))
# 割引券
a_ary = list(map(int, input().split()))
b_ary = list(map(int, input().split()))
waribiki = []
for i in range(m):
    waribiki.append(list(map(int, input().split())))
# 普通に買った場合の最小
min_cost = min(a_ary) + min(b_ary)
# 割引券を使った場合の最小
for i in range(m):
    tmp = a_ary[waribiki[i][0]-1] + b_ary[waribiki[i][1]-1] - waribiki[i][2]
    if tmp < min_cost:
        min_cost = tmp
print(min_cost)

Measured memory_bytes: 38568
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vpll> vvpll;
typedef unordered_map<ll, ll> um;
typedef unordered_set<ll> us;

#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ts ll t; in(t) while (t--) solve();
#define ks ll t; in(t) FOR(i, 1, t+1) out("Case #" << i << ": " << solve());
#define endl '\n'
#define ln cout << endl;
#define in(x) cin >> x;
#define out(x) cout << x << endl;
#define flush cout << flush;
#define reset(a, b) memset(a, b, sizeof(a));
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FORI(i, a, b, c) for (ll i = a; i < b; i += c)
#define FORD(i, a, b) for (ll i = a; i > b; --i)
#define FOREACH(it, v, r) for (auto it = v.begin() + r; it != v.end(); it++)
#define FORALL(it, v) for (auto it : v)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define vin(v, x) vll v(x); FOR(i, 0, x) in(v[i])
#define all(v) v.begin(), v.end()
#define allr(v, r) v.begin(), v.begin() + r
#define showv(v) FORALL(it, v) cout << it << ' '; ln
#define printv(v) FORALL(it, v) out(it)
#define show2d(v) FORALL(it, v) { FORALL(j, it) cout << j << ' '; ln}
#define showm(v) FORALL(it, v) cout << it.F << ": " << it.S << ' '; ln
#define sortv(v) sort(all(v));
#define revv(v) reverse(all(v));
#define maxv(v) *max_element(all(v))
#define minv(v) *min_element(all(v))
#define gcd __gcd
#define checkbit(n, i) (n >> i) & 1               // check ith bit
#define bitcount __builtin_popcount               // count set bits
#define firstbitindex __builtin_ctz               // count trailing zeros
#define lastbitindex __builtin_clz                // count leading zeros
#define bitparity __builtin_parity                // check set bits are even or odd
#define findv(v, x) (find(all(v), x) != v.end())
#define findsm(u, x) (u.find(x) != u.end())
#define findstr(s, x) (s.find(x) != string::npos)
#define sz(a) a.size()
#define precise(x) cout << fixed << setprecision(x);

const ll MAXN = 1e6, MOD = 998244353, SIZE = 2e7, INF = 0x7f7f7f7f7f7f7f7f;
const double EPS = 1e-9, PI = acos(-1);
const int INFi = 0x7f7f7f7f;

//<<------Declare Variables Here----->>//
ll n, q, x, b, c, s;

//<<-----Implement Functions Here---->>//
void solve()
{
    in(n)
	um a(n);
	s = 0;
	while(n--)
	{
		in(x)
		++a[x];
		s += x;
	}
	in(q)
	while(q--)
	{
		in(b >> c)
		s += (c - b) * a[b];
		a[c] += a[b];
		a[b] = 0;
		out(s)
	}
}

//<<----------Start of Main---------->>//
int main()
{
    fastio
    //ts
    solve();
    return 0;
}


Measured memory_bytes: 7048
n = int(input())
v = list(int(n) for n in input().split())
c = list(int(n) for n in input().split())
sum = 0
vc = [v - c for (v, c) in zip(v, c)]

# print(vc)

for i in range(n):
    if 0 < vc[i]:
        sum += vc[i]

print(sum)

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



int main() {
    string s;
    cin >> s;
    
    if(s == "Sunny")
        cout << "Cloudy" << endl;
    else if(s == "Cloudy")
        cout << "Rainy" << endl;
    else
        cout << "Sunny" << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3452
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int c[16];
int x[20000];
int n,m;

int memo[20000][256];

int solve(int now, int prev, int kabe){
  if(now == n) return 0;
  if(memo[now][prev]!=-1) return memo[now][prev];

  int ret = INT_MAX;
  REP(i,m){
    int t = min(255,max(0,prev + c[i]));
    int g = (t - x[now]) * (t - x[now]);
    if(kabe - g > 0){
      ret = min(ret, g + solve(now+1, t, kabe - g));
    }
  }
  return memo[now][prev] = ret;
}

int main(){
  while(scanf("%d%d",&n,&m), n+m){
    REP(i,m) scanf("%d",c+i);
    REP(i,n) scanf("%d",x+i);
    memset(memo,-1,sizeof(memo));
    printf("%d\n",solve(0,128,INT_MAX));
  }
  return 0;
}

Measured memory_bytes: 21000
def main(n, x):
    ans = []

    for p in range(1, n + 101):
        t = 0
        for _x in x:
            t += (_x - p) ** 2

        ans.append(t)

    print(min(ans))


if __name__ == "__main__":
    n = int(input())
    x = list(map(int, input().split()))

    main(n, x)


Measured memory_bytes: 2940
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353

class Segtree:
    def __init__(self, A, ide_ele, segfunc, initialize=True):
        self.n = len(A)
        self.size = 2 ** (self.n - 1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        if initialize:
            self.data = [ide_ele] * self.size + A + [ide_ele] * (self.size - self.n)
            for i in range(self.size - 1, 0, -1):
                self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
        else:
            self.data = [ide_ele] * (2 * self.size)

    def update(self, k, x):
        k += self.size
        self.data[k] = x
        while k:
            k = k >> 1
            self.data[k] = self.segfunc(self.data[2 * k], self.data[2 * k + 1])

    def query(self, l, r):
        L, R = l + self.size, r + self.size
        s = self.ide_ele
        while L < R:
            if R & 1:
                R -= 1
                s = self.segfunc(s, self.data[R])
            if L & 1:
                s = self.segfunc(s, self.data[L])
                L += 1
            L >>= 1
            R >>= 1
        return s


n = I()
XD = sorted(LIR(n))
X = []
D = []
for x, d in XD:
    X += [x]
    D += [d]

last = [l for l in range(n)]
st = Segtree(last, -INF, max)
for i in range(n - 2, -1, -1):
    r = bisect_left(X, X[i] + D[i])
    ret = st.query(i, r)
    st.update(i, ret)
    last[i] = ret

dp = [1] * (n + 1)
for j in range(n - 1, -1, -1):
    k = last[j]
    dp[j] = (dp[j + 1] + dp[k + 1]) % mod


print(dp[0])


Measured memory_bytes: 118036
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s;
	while(cin>>s)
	{
		bool ok=1;
		for(int i=1;i<s.size();++i)
		{
			if(s[i]!='9')
			{
				ok=0;
				break;
			}
		}
		if(ok)
		{
			cout<<(s.size()-1)*9+s[0]-'0'<<endl;
			continue;
		}
		if(s[0]=='1')
		{
				cout<<(s.size()-1)*9<<endl;
		}
		else
		{
			cout<<(s.size()-1)*9+s[0]-'0'-1<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256