akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    string S,T;
    char s[128],t[128];
    cin >> S >>T;
    REP(i,S.size()){
        s[i]=S[i];
    }
    REP(i,T.size()){
        t[i]=T[i];
    }
    sort(s,s+S.size());
    sort(t,t+T.size());
    REP(i,T.size()){
        t[i]=t[T.size()-1-i];
    }
    if(strcmp(s,t)<0){cout <<"Yes" << endl;}else{cout << "No"<<endl;}
    
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<double,double> pdd;
typedef pair<string,int> psi;

const int MOD = 1e9 + 7;
const int N = 100011;

typedef long long ll;

int ans , n , a[N],wat[N];

int main() {
	//freopen("input.txt","r",stdin);
	scanf("%d",&n);
	for (int i = 1; i <= n; ++i){
		scanf("%d",&a[i]);
	}
	ans = n;
	for(int i = 2 ; i <= n ; i++){
		if(wat[i-1] == 0){
			if(a[i] == a[i-1]){
				ans--;
			}else if(a[i] > a[i-1]){
				wat[i] = 1;
				ans--;
			}else{
				wat[i] = 2;
				ans--;
			}
		}else if(wat[i-1] == 1 && a[i] >= a[i-1]){
			wat[i] = 1;
			ans--;
		}else if(wat[i-1] == 2 && a[i] <= a[i-1]){
			wat[i] = 2;
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
    int N;
    bool verif = false;
    int dir = 0, esq = 0;
    string S;
    cin >> N;
    cin >> S;



    //Numero de parenteses abrindo
    for(int i=0; i<N; i++) {

        if(S[i] == ')') {

            if(!dir)
                cout << '(';
            else
                dir--;

        }else{
            dir++;
        }
    }

    cout << S;

    for(int i=0; i<dir; i++) {
        cout << ')';
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

const int M=2005;
const int MO=1e9+7;
int inv[M],fa[M],ifa[M];

int add(int x,int y)
{
	x+=y;
	if(x>=MO) x-=MO;
	return x;
}
int mul(int x,int y)
{
	return 1LL*x*y%MO;
}

void init()
{
	fa[0]=ifa[0]=1;
	inv[1]=fa[1]=ifa[1]=1;
    for(int i=2;i<M;i++)
    {
    	fa[i]=mul(fa[i-1],i);
    	inv[i]=mul(MO-MO/i,inv[MO%i]);
    	ifa[i]=mul(inv[i],ifa[i-1]);
    }
}

int qp(int x,int n)
{
	int ans=1;
	while(n)
	{
		if(n&1)
			ans=mul(ans,x);
		x=mul(x,x);
		n>>=1;
	}
	return ans;
}

int C(int n,int m)
{
	if(n<m) return 0;
	return mul(mul(fa[n],ifa[m]),ifa[n-m]);
}

int main()
{
	init();
	int n,k;
	scanf("%d%d",&n,&k);
	n-=k;
	for(int i=1;i<=k;i++)
	{
		int ans=C(k-1,i-1);
		ans=mul(ans,C(n+1,i));
		printf("%d\n",ans);
	}
	return 0;
}

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

int main() {
  vector<int> v(3);
cin>>v.at(0)>>v.at(1)>>v.at(2);
int m=v.at(0)+v.at(1)+v.at(2),
  m01=v.at(0)+v.at(1),
  m02=v.at(0)+v.at(2),
  m12=v.at(2)+v.at(1);
  cout<<min(m12,min(m01,m02))<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

long long int func(long long int a, long long int b)
{
	if(a>b)
	{
		long long int s1 = func(a%b,b);
		long long int s2 = a%b;
		return s1<s2?s1:s2;
	}
	else
	{
		long long int s1 = (b-a);
		long long int s2 = a;
		return s1<s2?s1:s2;
	}
}
int main()
{
	long long int a,b;
	scanf("%lld%lld",&a,&b);
	
	printf("%lld",func(a,b));
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n,k;cin >> n >> k;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    rep2(i,k,n){
        if(a[i]>a[i-k])cout << "Yes";
        else cout << "No";
        cout << endl;
    }
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, C, ans=0;
  cin >> N >> M >> C;
  vector<int> B(M), S(N);
  for (int i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      S.at(i) += A.at(i).at(j) * B.at(j);
    }
    S.at(i) += C;
  }
  for (int i = 0; i < N; i++) {
    if (S.at(i) > 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(void) {
	int a, b;
	std::cin >> a >> b;
	if (a > b * 2) {
		std::cout << a - b * 2 <<std::endl;
		
	}
	else {
		std::cout << 0 << std::endl;
		
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    cout << ((a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) ? "Possible" : "Impossible");
    cout << endl;


    return 0;
} 

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
    int count = 0;

    for(int a= 0; a<= A ; a++ ){
        for(int b =0; b <= B ; b++){
            int c = (X - a*500 - b*100)/50;
            if(c<=C && c>= 0){
                count++;
            }
        }
    }
        System.out.println(count);
        sc.close();
    }    
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <map>
#include <set>
#include <utility>
using namespace std;

struct edge {
    int to, d, c;
};
bool operator<(const edge &a, const edge &b) {
    return a.to < b.to;
}

struct node {
    int d, from, cost;
};
bool operator<(const node &a, const node &b) {
    return a.d != b.d? a.d > b.d: a.cost > b.cost;
}

int main() {
    int n, m;
    while (scanf("%d%d", &n, &m) != EOF) {
        if (n==0 && m==0) break;

        // read map
        map<int, set<edge>> graph;
        for (int i = 0, u, v, d, c; i < m; i++) {
            scanf("%d%d%d%d", &u, &v, &d, &c);
            if (graph.count(u) == 0)
                graph[u] = set<edge>();
            graph[u].insert(edge{v, d, c});
            if (graph.count(v) == 0)
                graph[v] = set<edge>();
            graph[v].insert(edge{u, d, c});
        }

        // recod the mininum path
        const int INF = 10000000;
        vector<int> d(n+1, INF);
        vector<int> c(n+1, 0);
        int result = 0;
        priority_queue<node> que;

        d[1] = c[1] = 0; que.push(node{0, 1, 0});
        while (!que.empty()) {
            int from = que.top().from;
            que.pop();
            if (graph[from].empty()) continue;
            for (auto &i : graph[from]) {
                if (d[i.to] > d[from] + i.d) {
                    d[i.to] = d[from] + i.d;
                    result += i.c - c[i.to];
                    c[i.to] = i.c;
                    que.push(node{d[i.to], i.to, c[i.to]});
                } else if (d[i.to] == d[from] + i.d) {
                    if (c[i.to] > i.c) {
                        result += i.c - c[i.to];
                        c[i.to] = i.c;
                        que.push(node{d[i.to], i.to, c[i.to]});
                    }
                }
            }
        }
#ifdef NDEBUG
        for (int i = 1; i <= n; i++)
            cout << c[i] << ' ';
        cout << endl;
#endif
        cout << result << endl;
    }
    return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    VL a(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    int now = a[1];
    int ans;
    for (ans = 1; ans <= n+1; ans++) {
        if (now == 2) {
            break;
        }
        now = a[now];
    }
    if (ans > n) {
        cout << -1 << endl;
    }
    else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath> 
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <numeric> 
#include <iomanip>
#include <map> 
#include <stack>
#include <sstream>
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int MAX = 1e6;
long long max(long long a, long long b) { if (a > b)return a; else return b; }
long long min(long long a, long long b) { if (a < b)return a; else return b; }
const int MAXN = 1000000 + 30;
int a[MAXN];


  		     		    	   				   	

int main()
{
	
		ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
		int n;
		cin >> n;
		int ans = n / 500 * 1000;
		ans += n % 500 / 5 * 5;
		cout << ans << endl;
		return 0;

}




	

  



Measured memory_bytes: 3168
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll       =    long long;
using   ld       =    long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int>vi;
typedef vector<ll>vii;
typedef set<int>si;
typedef set<ll>sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const ll MOD =(ll)1e9+1147483647;
const ll INF = (ll)1e18+5;

int main()
{
    _SAD()
    int n,k;
    cin>>n>>k;
    vi a(n);
    rep(i,n)cin>>a[i];
    int j=0;
    for(int i=k;i<n;i++)
    {
       // cout<<a[i]<<" "<<a[j]<<nl;
        if(a[i]>a[j])cout<<"Yes"<<nl;
        else cout<<"No"<<nl;
        j++;
    }
    return 0;
}


Measured memory_bytes: 3964
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

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;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];
int t[64];
int d[100100];
int n;
ll rec(int num) {
	if (num == 0) return 0;
	return rec(num - 1) + num;
}

void Solve() {
	int n;
	cin >> n;
	map<ll, int> m;
	ll sum = 0;
	m[0] = 1;
	for (size_t i = 0; i < n; i++)
	{
		ll s;
		cin >> s;
		sum += s;
		m[sum]++;
	}
	ll res = 0;
	for (map<ll,int>::iterator i = m.begin(); i != m.end(); i++)
	{
		res += rec(i->second - 1);
	}
	cout << res << endl;
} 


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



Measured memory_bytes: 18432
from collections import deque
N, M = map(int, input().split())
ways = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  ways[a].append(b)
  ways[b].append(a)
searched = [0 for i in range(N)]
searched[0] = 1
ans = [0 for i in range(N)]
d = deque([])
d.append(0)
while d:
  tmp = d.popleft()
  for w in ways[tmp]:
    if searched[w] == 0:
      searched[w] = 1
      ans[w] = tmp
      d.append(w)
print("Yes")
for a in ans[1:]:
  print(a + 1)

Measured memory_bytes: 35804
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define dbug(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  return is;
}


int main(){

  int N, K;

  cin>>N>>K;

  char d[10];

  string s;
  bool kirai;
rep(i,K){
  char x;
  cin >> x;
  d[i]=x;

}
  while(true){
    kirai=false;
    s=to_string(N);
    rep(i,s.length()){
      rep(j,K){
        if(s[i]==d[j]){
          kirai=true;
          i=s.length();
        }
      }
    }
  if(kirai==false)break;
  N++;
  }

  std::cout << N << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	int glass;

	glass = c;
	
	if (a - b - c > 0)
		glass = 0;
	else
		glass = c - (a - b);

	cout << glass << endl;
	


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int x,y;
  cin >> x >> y;
  vector<int> a = {1, 3, 5, 7, 8, 10, 12, 4, 6, 9, 11, 2};
  auto it = find(a.begin(),a.end(),x);
  auto it2 = find(a.begin(),a.end(),y);
  int nx = it -a.begin();
  int ny = it2-a.begin();
  if(max(nx,ny) < 7 || (7 <= min(nx,ny) && max(nx,ny) <= 10 )|| 10 < min(nx,ny)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n;
	string s;
	cin>>n>>s;
	
	map<char,llong> mp;
	REP(i,n) mp[s[i]]++;
	
	llong ans=mp['R']*mp['G']*mp['B'];
	//debug(ans);
	
	for(int i=1;i<=n;++i){
		int p=0;
		if(p+2*i>=n) break;
		while(1){
			if(p+2*i>=n) break;
			if(s[p]==s[p+i] or s[p+i]==s[p+2*i] or s[p+2*i]==s[p]){}
			else{
				ans--;
				//debug(i);
				//debug(p);
			}
			p++;
		}
	}
	
	cout<<ans<<endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    char s;
    cin >> s;
    printf("%c", s + 1);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int n,w;
vector<ll> cost(101);
vector<ll> weight(101);
const ll INF = 1E18+5;
int main(){
    cin>>n>>w;
    int i, j;
    for(i=0;i<n;i++)
        cin>>weight[i]>>cost[i];
    ll dp[n+1][w+1];
    memset(dp,0,sizeof(dp));
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=w;j++)
        {
            if(weight[i-1]<=j)
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight[i-1]]+cost[i-1]);
            else dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[n][w];
}




Measured memory_bytes: 82304
#include <stdio.h>

auto main(void) -> int {
    int n;
    scanf("%d", &n);
    int* arr = new int[n];

    for (size_t i = 0; i < n; i++) {
        int aux;
        scanf("%d", &aux);
        arr[i] = aux;
    }

    int count = 0;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                if ((arr[i] != arr[j]) && (arr[i] != arr[k]) &&
                    (arr[j] != arr[k])) {
                    if (arr[i] < arr[j] + arr[k] && arr[k] < arr[i] + arr[j] &&
                        arr[j] < arr[k] + arr[i]) {
                        count++;
                    }
                }
            }
        }
    }
    count /= 6;
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 3236
n,a,b=map(int,input().split())
h=[int(input()) for _ in range(n)]

def judge(t):
    res=0
    for x in h:
        if x-b*t>0:
            res+=-(-(x-b*t)//(a-b))
    return res<=t
low=0
high=10**9+1
while high-low>1:
    mid=(low+high)//2
    if judge(mid):
        high=mid
    else:
        low=mid
print(high)

Measured memory_bytes: 50520
#include <iostream>
#include <numeric>

using namespace std;
typedef long long ll;

ll gcl(ll a, ll b) {
    if(a < b) {
        ll tmp = a;
        a = b;
        b = tmp;
    }
    ll r;
    r = a % b;
    while(r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}


ll lcm(ll a, ll b) {
    return a * b / gcl(a, b);
}

int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    ll ans;

    ans = B / C + B / D - B / lcm(C, D);
    ans -= (A - 1) / C + (A - 1) / D - (A - 1) / lcm(C, D);

    cout << B - A + 1 - ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int H[100];
int main(){
  int i, res;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(H[Lj4PdHRW]);
    }
  }
  res = H[0];
  for(i=1;i<N;i++){
    if(H[i] > H[i-1]){
      res += H[i] - H[i-1];
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// int N, H[100];
// {
//   int i, res;
//   rd(N,H(N));
//   res = H[0];
//   rep(i,1,N) if(H[i] > H[i-1]) res += H[i] - H[i-1];
//   wt(res);
// }


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

struct Node{
	int max,mode,count;
	Node(){max=0,mode=0,count=0;}
};

int main(){
	static int n,a[100010];
	static int ans=0,ans2=0,ans3=0;
	static int num[100010]={};
	Node c,d;
	Node c2,d2;
	vector<int> v,v2;
	cin>>n;
	REP(i,n){
		cin>>a[i];
		if(i%2==0){
			v.push_back(a[i]);
		}
		else{
			v2.push_back(a[i]);
		}
	}
	REP(i,v.size()){
		num[v[i]-1]++;
	}
	REP(i,100000){
		if(c.max<num[i]){
			c.max=num[i];
			c.mode=i+1;
		}
	}
	REP(i,100000){
		if(c.mode!=i+1&&c2.max<num[i]){
			c2.max=num[i];
			c2.mode=i+1;
		}
	}
	REP(i,v.size()){
		if(c.mode==v[i]){
			c.count++;
		}
		else if(c2.mode==v[i]){
			c2.count++;
		}
	}
	ans+=n/2-c.count;
	ans2+=n/2-c2.count;
	ans3+=n/2-c.count;
	fill(num,num+100000,0);
	REP(i,v2.size()){
		num[v2[i]-1]++;
	}
	REP(i,100000){
		if(d.max<num[i]){
			d.max=num[i];
			d.mode=i+1;
		}
	}
	REP(i,100000){
		if(d.mode!=i+1&&d2.max<num[i]){
			d2.max=num[i];
			d2.mode=i+1;
		}
	}
	REP(i,v2.size()){
		if(d.mode==v2[i]){
			d.count++;
		}
		else if(d2.mode==v2[i]){
			d2.count++;
		}
	}
	ans+=n/2-d.count;
	ans2+=n/2-d.count;
	ans3+=n/2-d2.count;
	DEB(ans)DEB(ans2)DEB(ans3)END
	DEB(c.count)DEB(d.count)END
	DEB(c2.count)DEB(d2.count)END
	if(c.mode!=d.mode){
		cout<<ans<<endl;
		DEB("a")END
	}
	else{
		cout<<std::min(ans2,ans3)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <string>
typedef long long LL;
using namespace std;

int main()
{
	string s;
	cin >> s;
	LL ans = 0;
	int pre = 0;
	for(int i = 0;i < s.length();i++){
		if(s[i] == 'W'){
			ans += i - pre;
			pre++;
		}
	}
	cout << ans << endl;
	return 0;	
} 


Measured memory_bytes: 640
n,q=map(int,input().split())
import sys
sys.setrecursionlimit(10**9) #再帰の上限をあげる

root=[i for i in range(n+1)] #自分が親なら自身の番号を、そうでないなら（元）親の番号を示す
def r(x):   #親は誰？
    if root[x]==x:
        return x
    else:
        root[x]=r(root[x])
        return root[x]
def unite(x,y):
    x=r(x)
    y=r(y)
    if x==y:
        return
    if x>y:
        x,y=y,x
    root[y]=x
for i in range(q):
    t,x,y=map(int,input().split())
    if t==0:
        unite(x,y)
    else:
        if r(x)==r(y):
            print(1)
        else:
            print(0)


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

int main() {
  int a,b,h,m;cin>>a>>b>>h>>m;
  double PI=acos(-1);
  double hh=(double)(60*h+m)/720*2*PI;
  double mm=(double)m/60*2*PI;
  double x1=a*cos(hh),y1=a*sin(hh);
  double x2=b*cos(mm),y2=b*sin(mm);
  double dx=x1-x2,dy=y1-y2;
  double ans=sqrt(dx*dx+dy*dy);
  cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 4076
#include<iostream>
#include<cctype>
#include<stdio.h>
using namespace std;

int main(){
	char ch[1200];
	int i = 0;

	while (1){
		i++;
		scanf("%c", &ch[i]);

		if (isupper(ch[i])){
			ch[i] = tolower(ch[i]);
		}
		else if (islower(ch[i])){
			ch[i] = toupper(ch[i]);
		}

		if (ch[i] == '\n')break;
		cout << ch[i];
	}

	cout << endl;


	return 0;
}


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

typedef long long int ll;
using namespace std;

const ll MOD = 1e9 + 7;

int main()
{
	int n; cin>>n;
	vector<int> a,v;
	for(int i=0;i<n;i++){
		int x; cin>>x; a.push_back(x);
	}
	bool fok=true;
	for(int i=0;i<n;i++){
		bool ok=false;
		for(int i=a.size()-1;i>=0;i--){
			if(a[i]==i+1){
				ok=true;
				v.push_back(i+1);
				a.erase(a.begin()+i); break;
			}
		}
		if(!ok) {fok = false; break;}
	}

	if(fok){
		for(int i=n-1;i>=0;i--) cout<<v[i]<<endl;
	}
else cout<<"-1";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

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

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

    ll cnt = 0;
    rep(i, N-1) if(S[i] == S[i+1]) cnt++;

    ll ans = min(cnt+2*K, N-1);
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(void) {
  int i, ans = 0;
  char s[100010];
  scanf("%s", s);
  for(i = 0; i < (strlen(s) + 1) / 2;  ++i) if(s[i] == 'p') --ans;
  for(; i < strlen(s); ++i) if(s[i] == 'g') ++ans;
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> arr(n);
	long long int head = 0, tail = 0, ans;

	for(int i = 0; i < n; i++) {
		cin >> arr[i];
		tail += arr[i];
	}
	for(int i = 0; i < n - 1; i++) {
		head += arr[i];
		tail -= arr[i];
		if(i == 0) ans = abs(head - tail);
		if(abs(head - tail) < ans) ans = abs(head - tail);
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main()
{
    string s; cin >> s;
    for (int i = 0; i < 3; i++) {
        if (s[i] == '1') cout << '9';
        else             cout << '1';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 888
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

const INF: i64 = 1001001001001001;

fn main() {
   input! {
      n: usize,
      a: [i64; n]
   }
   let mut dp = vec![vec![INF as i64; n]; n];
   rec(0, n-1, &mut dp, &a);
   println!("{}", dp[0][n-1]);
}

fn rec(i: usize, j: usize, dp: &mut Vec<Vec<i64>>, a: &[i64]) {
   if dp[i][j] != INF {
      ()
   }else if i == j {
      dp[i][j] = if dp.len()%2 == 1 {a[i]} else {-a[i]};
   } else {
      rec(i+1, j, dp, a);
      rec(i, j-1, dp, a);
      if (dp.len() + i - j) % 2 == 1 {
         dp[i][j] = std::cmp::max(a[i] + dp[i+1][j], a[j] + dp[i][j-1]);
      } else {
         dp[i][j] = std::cmp::min(-a[i] + dp[i+1][j], -a[j] + dp[i][j-1]);
      }
   }
}


Measured memory_bytes: 90492
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll dp[100005]={0};
int main(){
  ll n;
  cin>>n;
  vector<P> vec;
  for(int i=0;i<n;i++){
    ll x,l;
    cin>>x>>l;
    vec.push_back(P(x+l,x-l));
  }
  sort(vec.begin(),vec.end());
  ll ans=0,las_t=-17441744174417;
  for(int i=0;i<n;i++){
    if(las_t<=vec[i].second){
      ans++;
      las_t=vec[i].first;
    }
  }
  cout<<ans<<endl;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, m; read(n, m);
	multiset<int> ms;

	rep(i, 0, n) {
		int t; read(t);
		ms.insert(t);
	}

	rep(i, 0, m) {
		auto it = prev(ms.end());
		int v = *it / 2;
		ms.erase(it);
		ms.insert(v);
	}

	ll ans = 0;
	for (int s : ms) ans += s;
	die(ans);
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
#define all(x) (x).begin(), (x).end()

/**ABC 164*/
int main(){
    int n,m,o,p;
    cin>>n>>m>>o>>p;
    while(n>0 && p>0){
        o-=m;
        n-=p;
    }
    if(n<=0 && o>0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  std::vector<long long> A(3);
  for (int i = 0; i < 3; i++) {
    scanf("%lld", &A[i]);
  }

  ll total = accumulate(all(A), 0LL);
  if (total >= 22) {
    put("bust");
  } else {
    put("win");
  }
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

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

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


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

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => -x).ToList();
        var alice = 0;
        var bob = 0;
        for (var i = 0; i < A.Count; i++)
        {
            if (i % 2 == 0)
            {
                alice += A[i];
            }
            else
            {
                bob += A[i];
            }
        }
        Console.WriteLine(alice-bob);
    }
}



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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

void solve() {
    int a, b, c, d, x;
    scanf("%d%d%d%d%d", &a, &b, &c, &d, &x);

    int ans = c*60+d - (a*60+b) - x;
    printf("%d\n", ans);

}

int main() {

    int T = 1;
    // scanf("%d", &T);
    while (T--) solve();

    return 0;
}

Measured memory_bytes: 3824
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    String t = s.substring(0,n/2);
    if(t.equals(s.substring(n/2,n))){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


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

using namespace std;

int main(){
    string s;
    cin >> s;
    string result = "Yes";
    for(int i = 0; i < s.length(); i++){
        if(s[i] != s[s.length() - 1 - i]){
            result = "No";
        }
    }
    for(int i = 0; i < (s.length() - 1) / 2; i++){
        if(s[i] != s[(s.length() - 1) / 2 - 1 - i]){
            result = "No";
        }
    }
    for(int i = (s.length() + 3) / 2 - 1; i < s.length(); i++){
        if(s[i] != s[s.length() - 1 - i]){
            result = "No";
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>

using namespace std;
using ll = long long;

template <class T>
struct Edge {
    int to;
    T cost;
    Edge(int to, T cost) : to(to), cost(cost){};
};

template <class T = int>
class Graph {
public:
    explicit Graph(int N = 0) : size(N) { path.resize(size); }
    void span(int u, int v, T cost = 1) { path[u].push_back(Edge<T>(v, cost)); }
    vector<Edge<T>> operator[](int v) const { return path[v]; }

    int size;
    vector<vector<Edge<T>>> path;
};

const ll INF = 1LL << 50;

template <class T>
vector<T> dijkstra(const Graph<T>& graph, int s) {
    vector<T> dist(graph.size, INF);
    dist[s] = 0;

    priority_queue<pair<int, T>, vector<pair<int, T>>, greater<pair<int, T>>> que;
    que.push(make_pair(0, s));

    while (!que.empty()) {
        int v;
        T d;
        tie(d, v) = que.top();
        que.pop();
        if (d > dist[v]) continue;

        for (const auto& e : graph[v]) {
            if (dist[e.to] <= dist[v] + e.cost) continue;
            dist[e.to] = dist[v] + e.cost;
            que.push(make_pair(dist[e.to], e.to));
        }
    }
    return dist;
}

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

    Graph<ll> graph(N);
    for (int i = 0; i < N; ++i) {
        int v, k;
        cin >> v >> k;
        for (int j = 0; j < k; ++j) {
            int sv;
            ll c;
            cin >> sv >> c;
            graph.span(v, sv, c);
        }
    }

    auto dist = dijkstra<ll>(graph, 0);
    for (int v = 0; v < N; ++v) cout << v << " " << dist[v] << endl;
    return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  int a,b,x;
  cin >> a >> b >> x;
  if((a + b) >= x && x >= a){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

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

typedef long long ll;
#define mod 1000000007

void solve(){
    ll a, r, c;
    long double b;
    cin>>a>>b;
    c = b;
    r = a*c + (a * (b-c));
    cout<<r;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();

    return 0;
}

Measured memory_bytes: 3756
#include <stdio.h>

int main() {
    int a,b,k;
    scanf("%d %d %d", &a, &b, &k);
  int count=0;
  int i;
  int large = a;
  if(large<b){large = b;}
  for(i=large;i>0;i--){
    if(a%i==0){
      if(b%i==0){
        count++;
        if(count==k){
          break;
        }
      }
    }
  }
    printf("%d", i);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  long int N; cin >> N;
  long int i = int(sqrt(N)), j;
  for(; i > 0; i--){
    if(N % i == 0){
      j = N / i;
      break;
    }
  }
  cout << i + j - 2 << endl;
  return 0;
}

Measured memory_bytes: 256
function parseInt(x) parse(Int, x) end

function main()
	n = readline() |> parseInt
	a = readline() |> split |> a -> parseInt.(a)
	b = map(i ->a[i]-i, eachindex(a))
	m = median(b)
	sum = 0
	for i in 1:n
		sum += abs(b[i]-m)
	end
	println(convert(Int, sum))
end

main()

Measured memory_bytes: 157788
sa=list(input())
sb=list(input())
sc=list(input())
owner="a"
while True:
    if owner=="a":
        if len(sa):
            owner=sa[0]
            del sa[0]
        else:
            break
    elif owner=="b":
        if len(sb):
            owner=sb[0]
            del sb[0]
        else:
            break
    else:
        if len(sc):
            owner=sc[0]
            del sc[0]
        else:
            break
if owner=="a":
    print("A")
elif owner=="b":
    print("B")
else:
    print("C")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
const int MOD = 1000000007;
// long long a;
int main(){
  int n,k,x,y;
  cin >> n>>k>>x >> y;
  if(n > k )cout << k*x + (n - k)*y << endl;
  else cout << n*x <<endl;
}


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

int main(int argc, const char * argv[]) {
    int a1=0,a2=0,a3=0,a4=0,dice[7],dice2[7],i=0,a=0,z=0,j=0;
    
    for(i = 1;i <= 6;i++){
        scanf("%d",&dice[i]);
    }
    for(i = 1;i <= 6;i++){
        scanf("%d",&dice2[i]);
    }
    for(i=0;i<10000;i++){
            z = rand()%4;
            if(z==0){
                a1=dice[1];
                a2=dice[3];
                a3=dice[4];
                a4=dice[6];
                dice[1]=a3;
                dice[3]=a1;
                dice[4]=a4;
                dice[6]=a2;
            }else if(z==1){
                a1=dice[1];
                a2=dice[2];
                a3=dice[5];
                a4=dice[6];
                dice[1]=a2;
                dice[2]=a4;
                dice[5]=a1;
                dice[6]=a3;
            }else if(z==2){
                a1=dice[1];
                a2=dice[2];
                a3=dice[5];
                a4=dice[6];
                dice[1]=a3;
                dice[2]=a1;
                dice[5]=a4;
                dice[6]=a2;
            }else if(z==3){
                a1=dice[1];
                a2=dice[3];
                a3=dice[4];
                a4=dice[6];
                dice[1]=a2;
                dice[3]=a4;
                dice[4]=a1;
                dice[6]=a3;
            }
        for(a = 1;a <= 6;a++)
            if(dice[a] != dice2[a])
                break;
        if(a == 7){
            printf("Yes\n");return 0;
        }
//        for(a = 1;a <= 6;a++){
//            if(dice[a] != dice2[a]){
//                break;
//            }else{
//                printf("Yes\n");
//                return 0;            }
//        }
//            if(a == 7){
//                printf("Yes\n");return 0;
//            }
//        for(a = 1;a <= 7;a++){
//                if(a == 7){
//                    printf("Yes\n");
//                    return 0;
//                }else if(dice[a] != dice2[a])
//                    break;
//        }
//            for(j=1;j<=7;j++){
//                if(j == 7){
//                    printf("Yes\n");
//                    return 0;
//                }else if(dice[j] != dice2[j]){
//                    break;
//                }
//            }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ll Pow(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod )) % mod ;
	return (c * c) % mod ;
}

//check modulo
int main(){
	IOS;
	cout.precision(30) ;
	int n , m ; cin >> n >> m ;
	vll a(n) ;for(int i = 0 ; i < n ; i++) cin >> a[i] ;
	vector<pll> v(m);
	ll b , c;
	for(int i= 0 ; i < m; i++){cin >> b >> c ;v[i] = mp(c , b) ;}
	sort(v.rbegin() , v.rend()) ;
	int j = 0 ;
	sort(a.begin() , a.end()) ;
	for(int i = 0 ; i < n ; i++){
		//cout << a[i] << " " << v[j].x <<  " "<< v[j].y << "  " << j  << endl ;
		if(j >= m) break ;
		if(a[i] >= v[j].x) break ;
		a[i] = v[j].x ;
		v[j].y-- ;
		//cout << a[i] << " " << v[j].x <<  " "<< v[j].y  << endl ;
		if(v[j].y == 0) j++ ;
	}
	ll ans = 0 ;
	for(int i = 0  ; i < n ; i++) ans += a[i] ;
	cout << ans << endl ;
	
		
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <string>

using namespace std;

class recipe{
public:
	vector<string> src;
	string dst;
	int num;
};

int main(void){
	int n;
	
	while(cin >> n && n){
		int k;
		map<string,int> m;
		vector<recipe> rs;
		string str;
		
		int tmp;
		for(int i=0;i<n;i++){
			cin >> str >> tmp;
			m[str] = tmp;
		}
		cin >> n;
		for(int i=0;i<n;i++){
			recipe r;
			cin >> str;
			r.dst = str;
			cin >> k;
			r.num = k;
			for(int i=0;i<k;i++){
				cin >> str;
				r.src.push_back(str);
			}
			rs.push_back(r);
		}
		
		bool ended = false;
		while(!ended){
			ended = true;
			for(int i=0;i<rs.size();i++){
				tmp = 0;
				for(int j=0;j<rs[i].num;j++){
					tmp += m[rs[i].src[j]];
				}
				if(m[rs[i].dst] > tmp){
					ended = false;
					m[rs[i].dst] = tmp;
				}
			}
		}
		cin >> str;
		cout << m[str] << endl;
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int c[][]=new int[3][3];
		for(int i=0;i<3;i++) {
			for(int j=0;j<3;j++) {
				c[i][j]=scan.nextInt();
			}
		}
		scan.close();
		int check=0;
		for(int i=0;i<2;i++) {
			for(int j=0;j<2;j++) {
				if(c[j][i]-c[j][i+1] !=  c[j+1][i]-c[j+1][i+1]) {
					check=1;break;
				}
			}
			if(check==1)break;
		}

		for(int i=0;i<2;i++) {
			for(int j=0;j<2;j++) {
				if(c[i][j]-c[i+1][j] !=  c[i][j+1]-c[i+1][j+1]) {
					check=1;break;
				}
			}
			if(check==1)break;
		}

		System.out.println((check==0)?"Yes":"No");
	}

}

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


int main(void){
    int n;
    string a,b,c;
    cin>>n>>a>>b>>c;
    int ans=0;
    for(int i=0;i<n;i++){
        if(a[i]==b[i]&&b[i]==c[i]) continue;
        else if(a[i]==b[i] || b[i]==c[i] || c[i]==a[i]) ans++;
        else ans+=2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def comb(a,b):
        return f[a]*inv[b]*inv[a-b]%mod
    n,m = LI()
    N = n+m
    f = [1]*(N+1)
    for i in range(1,N+1):
        f[i] = f[i-1]*i%mod
    inv = [None]*(N+1)
    inv[N] = pow(f[N],mod-2,mod)
    for i in range(N)[::-1]:
        inv[i] = inv[i+1]*(i+1)%mod
    ans = comb(m,n)*f[n]
    for i in range(1,n+1):
        if i&1:
            ans -= comb(n,i)*comb(m-i,n-i)*f[n-i]%mod
        else:
            ans += comb(n,i)*comb(m-i,n-i)*f[n-i]%mod
        ans %= mod
    print(ans*comb(m,n)*f[n]%mod)
    return

#Solve
if __name__ == "__main__":
    solve()


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

using namespace std;

int main() {
	string a, b, c;
	int counta = 0, countb = 0, countc = 0;
	int turn = 1;
	cin >> a >> b >> c;
	while (1) {
		if (turn == 1) {
			counta++;
			if (a[counta - 1] == 'a') {
				turn = 1;
			}
			else if (a[counta - 1] == 'b') {
				
				turn = 2;
			}
			else if(a[counta-1]=='c'){
				
				turn = 3;
			}
			else break;
		}
		else if (turn == 2) {
			countb++;
			if (b[countb - 1] == 'a') {
				
				turn = 1;
			}
			else if (b[countb - 1] == 'b') {
				
				turn = 2;
			}
			else if(b[countb - 1] == 'c'){
				
				turn = 3;
			}
			else break;
		}
		else {
			countc++;
			if (c[countc - 1] == 'a') {
				
				turn = 1;
			}
			else if (c[countc - 1] == 'b') {
				
				turn = 2;
			}
			else if(c[countc - 1] == 'c'){
				
				turn = 3;
			}
			else break;
		}
	}
	if (counta-1 == a.size())cout << 'A' << endl;
	else if (countb-1 == b.size())cout << 'B' << endl;
	else cout << 'C' << endl;
	return 0;
}




Measured memory_bytes: 256