akhauriyash/Code-Regression huggingface dataset:
from collections import deque

S = input()
Q = int(input())

deq = deque(S)

direction = 1

for _ in range(Q):
  q = input()
  if q == '1':
    direction *= -1
  else:
    _, f, c = q.split()
    if direction > 0:
      if f == '1':
        deq.appendleft(c)
      else:
        deq.append(c)
    else:
      if f == '1':
        deq.append(c)
      else:
        deq.appendleft(c)

if direction < 0:
  deq.reverse()
        
print(''.join(deq))


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

int main(int argc, char const *argv[]) {

  int N, L, i, TSUM = 0;
  float T;
  char *m;
  char num1[10];
  m = (fgets(num1, sizeof(num1), stdin));
  sscanf(num1, "%d %d\n", &N, &L);

  if (N < (- L + 1)) {
    i = N;
  }else{
    if (L >= 0) {
      i = 1;
    }
    if (L < 0) {
      i = - L + 1;
    }
  }

  T = N * ( L + 0.5 + 0.5 * N - 1.0) - ( L + i - 1.0 );
  TSUM = (int)T;
  printf("%d\n", TSUM);

  return 0;
}


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

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


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

if n == 1:
    print(p)
    exit()

ans = 1

for i in range(2, 1000001):
    x = 1
    for _ in range(n):
        x *= i
        if x > p:
            break
    if p % x == 0:
        ans = i
    if i == 2 and x > p:
        break

print(ans)

Measured memory_bytes: 40940
n, x, y = map(int,input().split())
ans = [0 for i in range(n)]

for i in range(1, n+1):
    for j in range(i+1, n+1):
        if (i <= x and j <= x) or (y <= i and y <= j):
            ans[j - i] += 1
        elif i <= x and y <= j:
            ans[x-i+1+j-y] += 1
        else:
            dist = min((j-i),(abs(i-x)+1 + abs(y-j)))
            ans[dist] += 1
            
print('\n'.join([str(s) for s in ans[1:]]))

Measured memory_bytes: 3188
n = int(input())
H = list(map(int, input().split()))
ans = 0
while sum(H) > 0:
    prev = 0
    split = 0
    for h in H:
        if prev == 0 and h != 0:
            split += 1
        prev = h
    ans += split
    H = [h-1 if h > 0 else 0 for h in H]

print(ans)


Measured memory_bytes: 3064
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,(n))
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int N;
	cin >> N;
	vi x(N), y(N);
	REP(i, N) {
		cin >> x[i] >> y[i];
	}

	vvi dp(N, vi(N)), dq(N, vi(N));
	REP(i, N) {
		REP(j, N) {
			dp[i][j] = x[j] - x[i];
			dq[i][j] = y[j] - y[i];
		}
	}

	int ans = INF;
	REP(i, N) {
		REP(j, N) {
			if (i == j) {
				continue;
			}
			
			int p = dp[i][j], q = dq[i][j], tmp = N;
			REP(k, N) {
				REP(l, N) {
					if (dp[k][l] == p && dq[k][l] == q) {
						tmp--;
					}
				}
			}

			ans = min(ans, tmp);
		}
	}

	if (N == 1) {
		cout << 1 << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))
if N > 2:
    ans = B[0]
    for i in range(1, N-1):
        if i == N-2:
            ans += B[i]
        ans += min(B[i-1], B[i])
else:
    ans = 2*B[0]
print(ans)

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


int main() {
    int n, a[100005];
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    } 
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == i) {
            ans++;
            if (i < n) swap(a[i], a[i + 1]);
            else swap(a[i], a[i - 1]);
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std; 
  
typedef long long ll; 
typedef pair<ll, ll> pll;
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
 
#define MOD 1000000007  
#define ffor(a, b, c) for (ll(a) = (b); (a) < (c); ++(a))  
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL)); 
#define rep(i, n) ffor(i, 0, n) 
#define ff first 
#define ss second  
#define pb push_back 
#define ALL(v) v.begin(), v.end()  
#define TC(t) while (t--) 
#define N 200005
#define inf 1e18
#define modd 998244353
#define pp(var) cout<<var<<"\n";
#define pm(var1, var2) cout<<var1<<" "<<var2<<"\n"; 


int main(){
    fast;
    ll l,r,i,j,m,k,a,b,c,q,t,x,y,d,n;
    cin>>a>>b>>n;
    x = min(n,b-1);
    pp((a*x)/b);
    
}

Measured memory_bytes: 3640
#include<stdio.h>
 
int s[10000];
int n;
 
int linerSearch(int);
 
int main()
{
  int q, c=0, i;
  int t[500];
 
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &s[i]);
  }
 
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &t[i]);
  }
 
  for(i = 0; i < q; i++){
    if(1 == linerSearch(t[i])) c++;
  }
 
  printf("%d\n", c);
 
  return 0;
}
 
int linerSearch(int key)
{
  int i;
   
  i = 0;
  s[n] = key;
  while(s[i] != key) i++;
  if(i == n) return 0;
  else return 1;
}


Measured memory_bytes: 2104
#coding: UTF-8


 
X =int(input())


if X<=599:
  print(8)
elif X<=799:
	print(7)
elif X<= 999:
  print(6)
elif X<= 1199:
  print(5)
elif X<=1399:
  print(4)
elif X<=1599:
  print(3)
elif X<=1799:
  print(2)
else:
  print(1)


Measured memory_bytes: 9168
package main

import (
	"fmt"
	"log"
)

func main() {
	var length int
	if n, err := fmt.Scanf("%d", &length); n != 1 || err != nil {
		log.Fatalln(n, err)
	}

	array := make([]int, length)
	for i := 0; i < length; i++ {
		if n, err := fmt.Scanf("%d", &array[i]); n != 1 || err != nil {
			log.Fatalln(n, err)
		}
	}

	insertionSort(array, length)
	printArray(array, length)
}

func insertionSort(array []int, length int) {
	for i := 1; i < length; i++ {
		printArray(array, length)

		tmp := array[i]
		j := i - 1
		for ; j >= 0 && array[j] > tmp; j-- {
			array[j+1] = array[j]
		}
		array[j+1] = tmp
	}
}

func printArray(array []int, length int) {
	fmt.Print(array[0])
	for i := 1; i < length; i++ {
		fmt.Printf(" %d", array[i])
	}
	fmt.Print("\n")
}


Measured memory_bytes: 1240
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<pair<long long int, long long int>> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i).first>>A.at(i).second;
  }
  sort(A.begin(),A.end());
  long long int ans = 0;
  int ret = M;
  for(int i=0;i<N;i++){
    if(ret>A.at(i).second){
      ans+=A.at(i).second*A.at(i).first;
      ret-=A.at(i).second;
    }else{
      ans+=ret*A.at(i).first;
      break;
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int n,a[200001];
bool b;
 
int main(){
	cin >> n;
    
    for (int i=1; i<=n; i++)
      cin >> a[i];
  
  	sort(a+1, a+n+1);
  
  	for (int i=1; i<n; i++)
      if (a[i]==a[i+1])
        b=1;
  	
  	if (b==0)
      	cout << "YES" << endl;
  	else
      	cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    unordered_map<int, int> mp;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        mp[a]++;
    }
    int ans = 0;
    for(auto& p : mp){
        if(p.first < p.second){
            ans += p.second - p.first;
        }else if(p.first > p.second){
            ans += p.second;
        }
    }
    cout << ans << '\n';
}


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

int main() {
	// your code goes here
	string a,b;
	cin>>a>>b;
	
	if(a.length()==0||b.length()==0)
	{cout<<" "; return 0;}
	
	
	ll l1=a.length();
	ll l2=b.length();
	
	string str[2][l2+1]={""};
	
	for(ll i=0;i<=l2;i++)
{	str[0][i]="";

}	
		


for(int i=1;i<l1+1;i++)
for(int j=1;j<l2+1;j++)
{
	if(a[i-1]==b[j-1])
    {str[i%2][j]=str[(i-1)%2][j-1];str[i%2][j].push_back(a[i-1]);}
	else
	{
		if((str[i%2][j-1].length())>(str[(i-1)%2][j].length()))
		str[i%2][j]=str[i%2][j-1];
		else
		str[i%2][j]=str[(i-1)%2][j];
	}
	
}

if(str[l1%2][l2].length()>0)
cout<<str[l1%2][l2];
else
cout<<" ";

	return 0;
}


Measured memory_bytes: 16816
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = LLONG_MAX/4;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    map<ll,ll> m;
    rep(i,n) {
        cin >> a[i];
        m[a[i]]++;
    }
    ll res = m.size();

    ll cnt = 0;
    for(auto itr = m.begin();itr != m.end();itr++){
        if((*itr).second % 2 == 0)cnt++;
    }
    if(cnt%2)res--;
    cout << res << endl;
}

Measured memory_bytes: 7296
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		while (true) {
			String r = sc.next(), a = sc.next();
			if (r.equals("0") && a.equals("0")) break;
			int h, b;
			h = b = 0;
			for (int i = 0; i < 4; i++) {
				if (r.charAt(i) == a.charAt(i))
					h++;
				else {
					for (int j = 0; j < 4; j++)
						if (r.charAt(i) == a.charAt(j))
							b++;
				}
			}
			out.printf("%d %d\n", h, b);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

# define ll long long
# define mod 1000000007
# define MAX 100005
# define PI 3.141592653589793238                                                                                  //shortcut keys

# define pb push_back
# define mp make_pair
# define all(x) x.begin(),x.end()
# define fr(i,a,b) for(int i=a;i<=b;i++)

# define decimal(k) fixed<<setprecision(k)
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------
using namespace std;

int main()
{
	int n;cin>>n;
	if(n>=30)cout<<"Yes"<<'\n';
	else cout<<"No"<<'\n';

	return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string>
#include <iomanip>
#include <locale>
#include <list>
#include <bitset>
#include <tuple>
using namespace std;
#define FORN(i,m,n) for(int i=(m); i<int(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
typedef long long ll;

const int ms = 2e3 + 3;
int n, x, y, ans[ms];
vector<int> edges[ms];

void solve(int cur){
  queue<pair<int,int> > q;
  vector<bool> vis(n, false);
  vis[cur] = true;
  q.push({cur,0});
  while(!q.empty()){
    int u = q.front().first, d = q.front().second;
    q.pop();
    ans[d]++;
    for(int e : edges[u]){
      if(!vis[e]){
	q.push({e, d+1});
	vis[e] = true;
      }
    }
  }
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  cin>>n>>x>>y;
  FORN(i,0,n-1){
    edges[i].push_back(i+1);
    edges[i+1].push_back(i);
  }
  x--, y--;
  edges[x].push_back(y);
  edges[y].push_back(x);
  FORN(i,0,n) ans[i] = 0;
  FORN(i,0,n) solve(i);
  FORN(i,1,n) cout<<(ans[i] >> 1)<<endl;
}

Measured memory_bytes: 384
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define endl "\n"
#define inf 1e18

void solve(){
	string s; cin>>s;
	if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){

	int a, b;
	cin >> a >> b;
	if(a+b==15){
		cout << "+" << endl;
	} else if(a*b==15){
		cout << "*" << endl;
	} else {
		cout << "x" << endl;
	}

	return 0;
}


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

int main()
{
  int a , b , c , d ;
  
  cin >> a >> b >> c >> d ;
  
  if(a+b > c+d)
    cout << "Left" << endl ;
  
  if(a+b == c+d)
    cout << "Balanced" << endl ;
  
  if(a+b < c+d)
    cout << "Right" << endl ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

vector<vector<int>> g;
vector<int> mkd;
int delta[3];

bool dfs(int v, int prv = -1){
    bool ans = true;
    for(auto u: g[v]){
        if(mkd[u] >= 1){
            if(mkd[u] != 3 - mkd[v]){
                ans = false;
            }
            continue;
        }
        mkd[u] = 3 - mkd[v];
        ++delta[mkd[u]];
        ans = ans & dfs(u, v);
    }
    return ans;
}


int main() {
    ios_base::sync_with_stdio(false);
    int n, m;
    int x, y;
    cin >> n >> m;
    g.resize(n);
    mkd.resize(n, 0);
    for(int i = 0; i < m; ++i){
        cin >> x >> y;
        --x;
        --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    ll ok = 0;
    for(int i = 0; i < n; ++i){
        if(!mkd[i]){
            delta[1] = delta[2] = 0;
            mkd[i] = 1;
            ++delta[mkd[i]];
            bool b = dfs(i, -1);
            if(b){
                ok += delta[1] * 1LL * delta[2];
            }else{
                ok += ((delta[1] + delta[2]) * 1LL * (delta[1] + delta[2] - 1)) / 2;
            }
        }
    }
//    cout << ok << endl;
    ok -= m;
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int H,W;
  cin>>H>>W;
  vector<int> A(26);
  for(int i=0;i<H*W;i++){
    char c;
    cin>>c;
    A[c-'a']++;
  }
  int cnt1=0,cnt2=0;
  for(int i:A){
    if(i%2==1)
      cnt1++;
    if(i%4==2)
      cnt2++;
  }
  if(cnt1>H*W%2 || cnt2>H/2*(W%2)+W/2*(H%2))
    puts("No");
  else
    puts("Yes");
}

Measured memory_bytes: 3624
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

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

  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> X(M);
  for (int64_t i = 0; i < M; ++i) {
    cin >> X[i];
  }
  if (N >= M) {
    cout << 0 << endl;
    return 0;
  }

  sort(X.begin(), X.end());
  vector<int64_t> ds(M - 1);
  for (int64_t i = 1; i < M; ++i) {
    ds[i - 1] = X[i] - X[i - 1];
  }
  sort(ds.begin(), ds.end());

  for (int64_t i = 0; i < N - 1; ++i) {
    ds.pop_back();
  }
  int64_t result = 0;
  for (int64_t d : ds) {
    result += d;
  }
  cout << result << endl;
  return 0;
}


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

int main() {
	int N;
	cin >> N;
	if (N == 1) {
		cout << 1 << endl << 0 << endl;
		return 0;
	}
	if (N == 2) {
		cout << 2 << endl << 0 << endl << 11 << endl;
		return 0;
	}
	cout << N - 1 << endl;
	for (int i = 2; i <= N; i++) {
		cout << 0;
		for (int j = 1; j < i - 1; j++) cout << 1;
		cout << 0 << endl;
	}
}


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

using namespace std;

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

Measured memory_bytes: 256
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  S = input()
  A = int(S[0:2])
  B = int(S[2:4])
  if(1<=A<=12):
      if(1<=B<=12):
          print("AMBIGUOUS")
      else:
          print("MMYY")
  elif(1<=B<=12):
      print("YYMM")
  else:
      print("NA")
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <iostream>
#include <set>
using namespace std;
int main(void){
    int n, lft[30001], rit[30001];
    set<int> t;
    string s;
    cin >> n >> s;
    lft[0] = rit[n-1] = 0;
    for(int i=0;i<n;i++){
        int v = s[i] - '0';
        lft[i+1] = lft[i] | (1 << v);
    }
    for(int i=n-1;i>0;i--){
        int v = s[i] - '0';
        rit[i-1] = rit[i] | (1 << v);
    }

    for(int i=1;i<n-1;i++){
        int v = s[i] - '0';
        for(int j=0;j<10;j++){
            if(((lft[i] >> j)&1) == 0)continue;
            for(int k=0;k<10;k++){
                if(((rit[i] >> k)&1) == 0)continue;
                t.insert(j*100+v*10+k);
                //cout << j*100+v*10+k << endl;
            }
        }
    }
    cout << t.size() << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> v(n + 1);
	int r=0, w=0;
	for (int i = 0;i < m;i++)
	{
		int p;
		string s;
		cin >> p >> s;
		if (v[p] == 0)

		{
			if (s == "AC")
				r++,v[p]=-1;
			else
				v[p]=1;
		}
		else if (v[p] == -1)
		{

		}
		else
		{
			if (s == "AC")
				r++,w+=v[p], v[p] = -1;
			else {
				v[p]++;
			}
		}
	}
	cout << r << " " << w << endl;

	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<double> money(N);
    vector<string> kind(N);
    double rate = 380000.0;
    double ans = 0.0;


    for (int i = 0; i < N;i++){
        cin >> money.at(i) >> kind.at(i);
    }


    for (int i = 0; i < N; i++)
    {
        if(kind.at(i)=="JPY"){
            ans += money.at(i);
        }
        else if(kind.at(i)=="BTC"){
            ans += money.at(i) * rate;
        }
    }

    cout << ans << endl;
}

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

typedef long long ll;

ll dp[100006];

int v[100005];

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i = 1; i <= n ; i++)
    {
        scanf("%d",&v[i]);
    }

    dp[0] = 1e15;
    for(int i = 2; i <= n ; i++)
    {
        dp[i] = 1e15;
        for(int j = max(0, i-k); j < i; j++)
        {
            dp[i] = min(dp[i], dp[j] + abs(v[i] - v[j]));  
        }
        //cout << dp[i] << ' ';
    }
    printf("%lld\n",dp[n]);
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,sum,Fizz,Buzz,FizzBuzz;
    lli i,l,k;
    cin>>n;
    sum=(1+n)*n/2;
    Fizz=n/3;
    Buzz=n/5;
    FizzBuzz=n/15;
    Fizz=3*(1+Fizz)*Fizz/2;
    Buzz=5*(1+Buzz)*Buzz/2;
    FizzBuzz=15*(1+FizzBuzz)*FizzBuzz/2;
    sum+=FizzBuzz-Fizz-Buzz;
    cout<<sum<<endl;
}


Measured memory_bytes: 3620
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int>X(N);
for(int i=0;i<N;i++)cin>>X[i];
    double sum=0;
    for(int i=0;i<N;i++){
        sum+=X[i];
    }
    double a=sum/N;
    int y=round(a);
    int ans=0;
    for(int j=0;j<N;j++){
        ans+=pow(X[j]-y,2);
    }
cout<<ans;
return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def main():
    n, a, b = map(int, input().split())
    total = 0

    for num in range(1, n + 1):
        chars = list(str(num))
        tmp = 0
        for char in chars:
            tmp += int(char)
        if a <= tmp and tmp <= b:
            total += num

    print(total)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]

for i in range(n):
    min_dis = float("inf")
    min_idx = 0
    for j in range(m):
        dis = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if dis < min_dis:
            min_dis = dis
            min_idx = j
    print(min_idx + 1)

Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int a = sc.nextInt();
        double min = Double.MAX_VALUE;
        int ans = 0;
        for(int i = 1;i <= n;i++){
            double tpr = Math.abs(a-(t - sc.nextInt()*0.006));
            if(min > tpr){
                min = tpr;
                ans = i;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22996
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
#include<functional>
using namespace std;
#define LL long long
#define MOD 1000000007

int v,e,r,vc[1002],edge[2002][3];//s,t,d
bool NC = false, END;

int main(){
	cin >> v >> e >> r;
	for(int i=0; i<v; i++) vc[i] = MOD;
	for(int i=0; i<e; i++) cin >> edge[i][0] >> edge[i][1] >> edge[i][2];		
	
	vc[r] = 0;
	for(int i=0; i<v; i++){
		if(END)break;
		if(i == v-1){
			NC = true;
			break;
		}
		END = true;
		for(int j=0; j<e; j++){
			if((vc[edge[j][1]] > vc[edge[j][0]] + edge[j][2]) && vc[edge[j][0]] != MOD){
				END = false;
				vc[edge[j][1]] = vc[edge[j][0]] + edge[j][2];
			}
		}
	}

	if(NC && e)cout << "NEGATIVE CYCLE" << endl;
	else{
		for(int i=0; i<v; i++){
			if(vc[i] == MOD) cout << "INF" <<endl;
			else cout << vc[i] << endl;
		}
	}
	return 0;
}




Measured memory_bytes: 3156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int count = 1;
		while (N >= K) {
			N = N / K;
			count++;
		}
		System.out.println(count);
		return ;
	}
}

Measured memory_bytes: 35800
#[cfg(debug_assertions)]
include! {"./debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

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

fn main() {
    let n = read!(i32);
    let sp = read!(String, i32; n);

    let mut spi = sp
        .iter()
        .map(|&(ref s, p)| (s, -p))
        .zip(0..n)
        .collect::<Vec<_>>();
    spi.sort();

    debug!(spi);

    for (_, i) in spi {
        println!("{}", i + 1);
    }
}


Measured memory_bytes: 4476
p="+"
h="<"
ans=[]
def f(a,b,c,d):ans.append([a,b,c,d])
f(p,0,1,3)
f(h,2,3,3)
f(p,2,3,10)
f(p,2,3,100)
for i in range(29):
  f(p,10+i,10+i,11+i)
  f(p,100+i,100+i,101+i)
for i in range(29,-1,-1):
  f(p,8,10+i,9)
  f(h,0,9,10+i)
  f(h,10+i,3,9)
  f(p,98,100+i,99)
  f(h,1,99,100+i)
  f(h,100+i,3,99)
  f(h,100+i,3,100+i)
  for j in range(i):
    f(p,9,9,9)
    f(p,99,99,99)
  f(p,8,9,8)
  f(p,98,99,98)
for i in range(30):
  f(h,4,4,4)
  for j in range(30):
    f(h,10+i,100+j,5)
    for k in range(j):f(p,5,5,5)
    f(p,4,5,4)
  for k in range(i):f(p,4,4,4)
  f(p,2,4,2)
print(len(ans))
for i in ans:print(*i)

#file=open("AtCoder\AGC\AGC047\E\E1.txt","w")
#file.write(str(len(ans))+"\n")
#for i in ans:file.write(" ".join(list(map(str,i)))+"\n")


Measured memory_bytes: 10592
def examC():
    N = I()
    print(0)
    q = input()
    if q=="Vacant":
        exit()
    left = 0; right = N - 1
    for _ in range(20):
        cur = (left + right) // 2
        print(cur)
        next = input()
        if next=="Vacant":
            exit()

        if (cur % 2 == 1 and next == q) or (cur % 2 == 0 and next != q):
            right = cur
        else:
            left = cur + 1

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()


Measured memory_bytes: 38852
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)];rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

show_flg=False
show_flg=True

ans=0


n,k=LI()
a=LI()
m=[0]*n
s=0
for i in range(n):
    for j in range(n):
        if a[i]<a[j]:
            m[j]+=1
        if a[i]<a[j] and i>j:
            s+=1
ans=s*k%mo
for i in range(n):
    ans+=m[i]*(k-1)*k//2
    ans%=mo
print(ans)


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

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit();
  int N,K; long long a,b,x=0,y=0; cin>>N>>K;
  vector<long long>A(N,0);
  for(int i=0; i<N; i++){
    cin>>a;
    A[i]=a;
  }
  sort(A.begin(), A.end());
  for(int i=K-1; i<N; i++){
    x+=(A[i]*COM(i,K-1))%MOD;
    x%=MOD;
  }
  for(int i=0; i<=N-K; i++){
    y+=(A[i]*COM(N-1-i,K-1))%MOD;
    y%=MOD;   
  }
  if(x-y<0) x+=MOD;
  cout<<(x-y)%MOD<<endl;
}


Measured memory_bytes: 12928
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#define ll long long
using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	int res = 180 * n - 360;
	printf("%d\n", res);
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")
 
bool isprime(int p) {
  if (p==1) return false;
    FOR(i,2,p) {
      if (p%i==0) return false;
    }
  return true;
}
 
int main(){
  int a,b,c,k;
  cin >> a >> b >> k;
  REP(i,k){
      if (a+i>b) break;
      cout << a+i << endl;
      c = a + i;
  }
  REP(i,k){
      if (b-k+i+1 > c) cout << b-k+i+1 << endl;
  }
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

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

    // input
    ll N, K;
    cin >> N >> K;

    if(K==0){
        p(N*N);
        return 0;
    }

    // left side
    ll a = N - K;
    ll leftNum = a * (a+1) / 2;

    // right side
    ll rightNum = 0;
    FOR(i, K+1, N){
        ll step = i;
        ll length = N - i + 1;
        ll num = length / step;
        ll countPerStep = step - K;
        rightNum += num * countPerStep;

        // あと端切れの分
        ll hagire = length - num * step;
        ll diff = hagire - K;
        if(diff > 0){
            rightNum += diff;
        }
    }

    p(leftNum + rightNum);

    return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

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

    int k, q;
    cin >> k >> q;
    Vl d(k);
    for (int i = 0; i < k; i++) {
        cin >> d[i];
    }

    Vl m(q), x(q), n(q);
    for (int i = 0; i < q; i++) {
        cin >> n[i] >> x[i] >> m[i];
    }

    Vl dm(k);
    for (int i = 0; i < q; i++) {
        ll out = 0;
        for (int j = 0; j < k; j++) {
            dm[j] = d[j] % m[i];
        }
        for (int j = 0; j < k; j++) {
            if (dm[j] == 0) {
                if (j <= (n[i] - 1) % k - 1)
                    out += (n[i] - 1) / k + 1;
                else
                    out += (n[i] - 1) / k;
            }
        }
        ll a_last = x[i];
        for (int j = 0; j < k; j++) {
            if (j <= (n[i] - 1) % k - 1)
                a_last += dm[j] * ((n[i] - 1) / k + 1);
            else
                a_last += dm[j] * ((n[i] - 1) / k);
        }
        out += a_last / m[i] - x[i] / m[i];
        cout << n[i] - 1 - out << "\n";
    }

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[55],n,k,ans=0;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=min(k,n);i>=1;i--){
		int len=min(n,k-(k-i)/2-(k-i)%2);
		for(int ed=len;ed>=0;ed--){
			int sum=0;vector<int> p;
			for(int j=1;j<=len;j++){
				int pos=a[(ed-j+n)%n+1];
				p.push_back(pos);
			}
			sort(p.begin(),p.end());
			reverse(p.begin(),p.end());
			for(int j=0;j<i;j++){
				sum+=p[j];
			}
			//cout<<len<<" "<<i<<" "<<sum<<endl;
			ans=max(ans,sum);
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <cmath>
#include <cstdio>
 
using namespace std;
 
int main(){
    double d[4] = {};
    int n;
    int x[100], y[100];
 
    cin >> n;
 
    for(int i = 0;i < n;i++){
        cin >> x[i];
    }
    for(int i = 0;i < n;i++){
        cin >> y[i];
    }
 
    double z[100];
    for(int i = 0;i < n;i++){
        z[i] = fabs(x[i] - y[i]);
    }
 
    for(int p = 1;p <= 3;p++){
        for(int i = 0;i < n;i++){
            d[p-1] += pow(z[i],p);
        }
        d[p-1] = pow(d[p-1],1.0/p);
    }
 
    for(int i = 0;i < n;i++) d[3] = (d[3] < z[i] ? z[i]:d[3]);
 
    for(int i = 0;i < 4;i++) printf("%lf\n",d[i]);
    return 0;
}


Measured memory_bytes: 3340
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    string S; cin >> S;
    sort(begin(S), end(S));
    if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> mat;
// mat dtable(M, vl(N, 0)); M行N列 のサイズで,0で初期化


const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    ll N, K; cin >> N >> K;
    vl A(N);
    REP(i, N) cin >> A[i];
    mat dtable;
    int D;
    if (K > 0){
        D = ceil(log2(K)) + 1;
        dtable = mat(D, vl(2, 0));
    }else{
        D = 0;
        dtable = mat(1, vl(2, 0));
    }
    REP(i, N){
        REP(j, D){
            int d = 1 & (A[i] >> j);
            if (d == 0) dtable[j][0]++;
            else dtable[j][1]++;
        }
    }

    ll X = 0;
    for(int i=D-1; i>=0; --i){
        if (dtable[i][0] >= dtable[i][1] && (X + (1LL << i)) <= K){
            X += (1LL << i);
        }
    }

    ll ans = 0;
    REP(i, N) ans += (A[i] ^ X);
    cout << ans << endl;
}

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

int main() {
  ll N,T,sum=0;
  cin >> N >> T;
  vector<ll> t(N);
  for(ll i=0;i<N;i++){
    cin >> t[i];
  }
  for(ll i=0;i<N-1;i++){
    ll tmp=t[i+1]-t[i];
    if(tmp<T){
      sum+=tmp;
    }else{
      sum+=T;
    }
  }
  sum+=T;
  cout << sum << endl;
}

Measured memory_bytes: 1920
s=int(input())
a=[s]
k=1
while k>0:
    if s%2==0:
        x=int(s/2)
        s=x
        a.append(x)
    else:
        x=int(3*s+1)
        s=x
        a.append(x)
    for i in range(len(a)-1):
        if a[len(a)-1]==a[i]:
            print(len(a))
            k=0       




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

const int RLEN=1<<18|1;
inline char nc() {
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
    char ch=nc(); int i=0,f=1;
    while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
    while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
    return i*f;
}

const int N=1e5+50;
int n,m,stx,sty,dep[N],fa[N],s[N];
vector <int> edge[N]; LL ans=0;
inline void dfs(int x,int f,int val) {
    dep[x]=dep[f]+1; fa[x]=f; s[x]=val;
    for(auto v:edge[x]) {
        if(v!=f) {
            if(dep[v]) stx=x, sty=v;
            else dfs(v,x,-val), s[x]+=s[v];
        }
    }
}
inline int lca(int x,int y) {
    while(dep[x]>dep[y]) x=fa[x];
    while(dep[x]<dep[y]) y=fa[y];
    while(x!=y) x=fa[x], y=fa[y];
    return x;
}
int main() {
    n=rd(), m=rd();
    for(int i=1;i<=m;i++) {
        int x=rd(), y=rd();
        edge[x].push_back(y);
        edge[y].push_back(x);
    } dfs(1,0,1);
    if(m==n-1) {
        if(s[1]) {puts("-1"); return 0;}
        for(int i=1;i<=n;i++) ans+=abs(s[i]);
    } else {
        if((dep[stx]-dep[sty])&1) { // even circle
            if(s[1]) {puts("-1"); return 0;}
            static int a[N],tot;
            int l=lca(stx,sty);
            for(int u=stx;u!=l;u=fa[u]) a[++tot]=s[u],dep[u]=-1;
            for(int u=sty;u!=l;u=fa[u]) a[++tot]=-s[u],dep[u]=-1;
            a[++tot]=0; int mid=tot/2;
            nth_element(a+1,a+mid,a+tot+1);
            int z=a[mid];
            for(int i=1;i<=n;i++) if(~dep[i]) ans+=abs(s[i]);
            for(int i=1;i<=tot;i++) ans+=abs(a[i]-z);
        } else {
            if(s[1]&1) {puts("-1"); return 0;}
            int z=-s[1]/2; ans+=abs(z);
            for(int u=stx;u;u=fa[u]) s[u]+=z;
            for(int u=sty;u;u=fa[u]) s[u]+=z;
            for(int i=1;i<=n;i++) ans+=abs(s[i]);
        }
    } cout<<ans<<'\n';
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> a(3 * N);
    REP(i, 3 * N)
    {
        cin >> a[i];
    }
    sort(ALL(a));
    ll ans = 0;
    REP(i, N)
    {
        ans += a[3 * N - 1 - 2 * i - 1];
    }

    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define rep(i, n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

signed main() {
    int A, B;
    char op;
    cin >> A >> op >> B;

    auto ans = op == '+' ? A + B : A - B;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [list(map(int, input().split())) for i in range(2)]

li = [[a[0][0]] + [0]*(n-1), [a[0][0]+a[1][0]] + [0]*(n-1)]
for i in range(1,n):
    li[0][i] = li[0][i-1] + a[0][i]

for i in range(1,n):
    li[1][i] = max(li[0][i] + a[1][i], li[1][i-1] + a[1][i])
    
print(li[1][n-1])

Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    md = 10 ** 9 + 7
    n, m = MI()
    fac = [1, 1]
    for i in range(2, n + 5):
        fac.append(fac[-1] * i % md)
    if abs(n - m) > 1:
        print(0)
        exit()
    if n < m: n, m = m, n
    if n == m:
        ans = 2 * fac[n] ** 2 % md
    else:
        ans = fac[n] * fac[m] % md
    print(ans)

main()


Measured memory_bytes: 7060
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
vector<ll>adj[300005];
ll vis1[300005];
vector<ll>v1,v2;
void find_cover(ll s,ll p)
{
	vis1[s]=1;
    if(p==0)
    	v1.pb(s);
    else 
    	v2.pb(s);
    for(auto it : adj[s])
    	if(!vis1[it])
             find_cover(it,1-p);
}
signed main()
{   
    Senky_Bansal
    IIIT_ALLAHABAD
    
    ll a,b,c;
  cin>>a>>b>>c;
  ll d = max({a,b,c});
  cout<<a+b+c-d;
}

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

int main() {
  int p, q, r;
  cin >> p >> q >> r;
  int res = min(p+q, q+r);
  int ans = min(res, r+p);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=500005;
int n,K,P[maxn],ans[maxn];priority_queue<int> H;bool vis[maxn];
inline int read()
{
	int ret=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=getchar();}
	return ret*f;
}
struct SegmentTree
{
	int Tree[maxn*4];
	inline void PushUp(int rt){Tree[rt]=(P[Tree[rt*2]]<P[Tree[rt*2+1]]?Tree[rt*2+1]:Tree[rt*2]);}
	inline void Build(int L=1,int R=n,int rt=1)
	{
		if(L==R){Tree[rt]=L;return;}
		int M=(L+R)>>1;
		Build(L,M,rt*2);
		Build(M+1,R,rt*2+1);
		PushUp(rt);
	}
	inline void Update(int P,int L=1,int R=n,int rt=1)
	{
		if(L==R) return;
		int M=(L+R)>>1;
		if(P<=M) Update(P,L,M,rt*2);
		if(M<P) Update(P,M+1,R,rt*2+1);
		PushUp(rt);
	}
	inline int Query(int LL,int RR,int L=1,int R=n,int rt=1)
	{
		if(LL<=L&&R<=RR) return Tree[rt];
		int ret=0,M=(L+R)>>1;
		if(LL<=M)
		{
			int tep=Query(LL,RR,L,M,rt*2);
			if(P[tep]>P[ret]) ret=tep;
		}
		if(M<RR)
		{
			int tep=Query(LL,RR,M+1,R,rt*2+1);
			if(P[tep]>P[ret]) ret=tep;
		}
		return ret;
	}
}ST;
inline void Solve()
{
	for(int i=1;i<=n;i+=K)
	{
		int t=ST.Query(i,min(n,i+K-1));
		if(t==ST.Query(max(1,t-K+1),min(n,t+K-1)))
		{H.push(t);vis[t]=true;}
	}
	for(int i=n;i;i--)
	{
		int qh=H.top();H.pop();ans[qh]=i;
		P[qh]=0;ST.Update(qh);
		for(int j=(qh-1)/K;j<=(qh-1)/K+2;j++)
		{
			int L=(j-1)*K+1,R=j*K;
			if(L>n||R<1) continue;
			L=max(1,L);R=min(n,R);
			int t=ST.Query(L,R);
			if(t&&t==ST.Query(max(1,t-K+1),min(n,t+K-1))&&!vis[t])
			{H.push(t);vis[t]=true;}
		}
	}
}
int main()
{
	n=read();K=read();
	for(int i=1;i<=n;i++) P[i]=read();
	ST.Build();
	Solve();
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 17776
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
  int i,j,k;
  char S[4];
  scanf("%d",&k);
  int A,B;
  /*A=(S[0]*10+atoi(S[1]);
  B=atoi(S[2])*10+atoi(S[3]);*/
  
  A = k /100;
  B = k % 100;
  
  if(A >= 1 && A<=12){
    if(B >= 1 && B<=12){
      puts("AMBIGUOUS");
      return 0;
    }
    else if(B>=0){
      puts("MMYY");
      return 0;
    }
  }
  /*else if(A>=13){
    if(B >= 1 && B<=12){
      puts("YYMM");
      return 0;
    }
    else{
      puts("NA");
      return 0;
    }
  }*/
  else if(B >=1 && B <= 12){
    if(A>=0){
      puts("YYMM");
      return 0;
    }
  }
  puts("NA");
  return 0;
}




Measured memory_bytes: 128
from itertools import *
n,m,x=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(n)]
a=10**7
for i in range(1,n+1):
    for j in combinations(L,i):
        b=[0]*(m+1)
        for k in j:
            b=[b[i]+k[i] for i in range(m+1)]
        if all(i>=x for i in b[1:]):
            a=min(a,b[0])
print(-1 if a==10**7 else a)

Measured memory_bytes: 9156
def floor(a, b):
    return (-a)//b*(-1)


N = int(input())
A = []
B = []
total_add = 0
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


ans = 0
for i in reversed(range(N)):
    a = A.pop(-1)
    a += total_add
    b = B.pop(-1)
    inc = b*floor(a, b)-a
    total_add += inc

print(total_add)


Measured memory_bytes: 11064
#include<bits/stdc++.h>
using namespace std;
int64_t euler_phi(int64_t n) {
  int64_t ret = n;
  for(int64_t i = 2; i * i <= n; i++) {
    if(n % i == 0) {
      ret -= ret / i;
      while(n % i == 0) n /= i;
    }
  }
  if(n > 1) ret -= ret / n;
  return ret;
}

int main(){
  int n;
  cin>>n;
  cout<<euler_phi(n)<<'\n';
  return(0);
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (i == n - 1) {
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 3604