akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void) {
	int x, n;
	int i, j, k;
	int count = 0;

	scanf("%d %d", &n, &x);

	while (1) {
		if (x == 0 && n == 0) {
			break;
		}
		for (i = 1; i <= n - 2; i++) {
			for (j = i + 1; j <= n - 1; j++) {
				for (k = j + 1; k <= n; k++) {

					if (i + j + k == x && i != j && j != k && k != i) {
						count++;

					}
				}
			}
		}
		printf("%d\n", count);
		count = 0;
		scanf("%d %d", &n, &x);
	}

	return 0;
}



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

int main() {
    int n;
    long long ans = 1;
    long long prev_ans = 1;
    cin >> n;
    vector<long long> a(n);
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }

    for(int i=0; i<n; i++) {
        if(a[i]==0) {
            cout << 0 << endl;
            return 0;
        }
    }

    for(int i=0; i<n; i++) {
            //cout << 1000000000000000000.0/ans  << endl;
        if (1000000000000000000.0/ans < a[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    if (ans > 1000000000000000000) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  
  vector<int>s(M);
  vector<int>c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
    if (c.at(i) == 0){
      if (s.at(i) == 1 && N != 1){
        cout << -1 << endl;
        return 0;
      }
    }
    for (int j = 0; j < i; j++) {
      if (s.at(j) == s.at(i) && c.at(i) != c.at(j)){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  
  vector<int>A(N,0);
  for (int i = 0; i < M; i++) {
    A.at(s.at(i)-1) = c.at(i);
  }
  
  if (A.at(0) == 0 && N != 1){
    A.at(0) = 1;
  }
  
  for (int i = 0; i < N; i++) {
    cout << A.at(i);
  }
  cout << endl;
}
 
  

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define pb push_back

#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define int long long
using namespace std;
#define mod 1000000007
signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int maxi = arr[0], ans = 0;
    for(int i = 1; i < n; i++)
    {
        if(arr[i] < maxi)
        {
            ans += maxi - arr[i];
        }
        else
        {
            maxi = max(maxi, arr[i]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5212
def getConverseCodes(args, n):
    converseCodes = ''
    for s in args:
        #アスキーコードに変換
        s = ord(s)
        s = s + n
        if s > 90:
          s = s - 26
        #アスキーコードから文字を取得
        s = chr(s)
        converseCodes += s
    return converseCodes

N = int(input())
S = input()

print(getConverseCodes(S, N))

Measured memory_bytes: 3060
#include <stdio.h>

int main() {
	int c,i,j,sum;
	int x[1000];
	
	i = 0;
	while((c = getchar()) != EOF) {
		if(c == '\n') {
			sum = 0;
			for(j = 0;j < i;j++) {
				sum += x[j];
				x[j] = 0;
			}
			printf("%d\n",sum);
			i = 0;
		}else{
			if(i == 0 && c == '0') break;
			x[i] = c-'0';
			i++;
		}
	}
	
	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string s; cin >> s;
  int N = s.size();
  int l = -1, r = -1;
  for (int i = 0; i + 1 <= N; ++i) {
    if (s[i] == s[i + 1]) {
      l = i + 1;
      r = i + 1 + 1;
      break;
    }
    else if (i + 2 <= N and s[i] == s[i + 2]) {
      l = i + 1;
      r = i + 2 + 1;
      break;
    }
  }
  printf("%d %d\n", l, r);
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  string n;
  cin >> n;
  if (n[0] == n[1] && n[1] == n[2]) {
    cout << "Yes";
  } else if (n[1] == n[2] && n[2] == n[3]) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}

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

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    cout << b/c - (a%c ? a/c+1 : a/c) +1 << endl;
}


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

int main() {
	int k,x;
	cin>>k>>x;
	if(500*k>=x)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
s = input()
n = len(s)
count = 0
if s == s[::-1]:
    count += 1

if s[0:(n-1)//2] == s[0:(n-1)//2][::-1]:
    #print((n-1)//2,s[0:(n-1)//2])
    count += 1

if s[(n+3)//2-1:] == s[(n+3)//2-1:][::-1]:
    #print((n+3)//2-1,s[(n+3)//2-1:])
    count += 1


if count >= 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
N = int(input())
S = [input() for _ in range(N + 1)]

def convert(s):
    l = []
    for i in range(len(s)):
        if s[i].isdigit():
            if len(l) != 0 and isinstance(l[-1], list):
                l[-1].append(s[i])
            else:
                l.append([s[i]])
        else:
            l.append(s[i])

    return [int(''.join(e)) if isinstance(e, list) else e for e in l]

S = [convert(e) for e in S]
t = S[0]

def compare(s):
    for i in range(min([len(s), len(t)])):
        if type(s[i]) == type(t[i]):
            if s[i] < t[i]:
                return '-'
            elif s[i] > t[i]:
                return '+'
        else:
            if type(s[i]) == int:
                return '-'
            else:
                return '+'
    if len(t) <= len(s):
        return '+'
    else:
        return '-'

for s in S[1:]:
    print(compare(s))



Measured memory_bytes: 5828
#include <iostream>
using namespace std;
int main(void){
 
 
 
    int a,b;
 
    cin >> a>>b;
    
  if(a<b){
            cout<<"a"<<" "<<"<"<<" "<<"b"<<endl;
    
    } 
    
      if(a>b){
            cout<<"a"<<" "<<">"<<" "<<"b"<<endl;
    
    }
  
    if(a==b){
            cout<<"a"<<" "<<"=="<<" "<<"b"<<endl;
    
    }
 
 
 
    return 0;
 
}

Measured memory_bytes: 1160
#include <stdio.h>

int main()
{
    int n,a[20],b[20],c[20],i,j,ans = 0;

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

    ans += b[a[0] - 1];
    for (i = 1; i < n; i++)
    {
        ans += b[a[i] - 1];
        if (a[i] == a[i - 1] + 1)
        {
            ans += c[a[i] - 2];            
        }
    }
    
    printf("%d",ans);
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

struct SegTree {
  int n_count;
  vector<ll> pos;

  SegTree(ll N) {
    n_count = 1; while(n_count<N) n_count<<=1;
    pos.resize(2*n_count, 0);
  }

  ll operator[](const ll &k) const { return pos[k+n_count]; }

  void set(ll k, const ll x) { pos[k+n_count] = x; }
  void build() { for (int i=n_count-1; i>=0; i--) pos[i] = pos[i*2] + pos[i*2+1]; }
  void update(ll k, const ll x) { set(k,x); k += n_count; while(k >>= 1) pos[k] = pos[k*2] + pos[k*2+1]; }
  ll query(ll a,ll b) {
    ll L = 0, R = 0;
    for ( a+=n_count, b+=n_count; a<b; a>>=1, b>>=1 ) {
      if (a&1) { L+=pos[a]; a++; }
      if (b&1) { b--; R+=pos[b]; }
    }
    return L + R;
  }

};

struct pos { int i; int to; };

int main() {
  string S; cin >> S;
  int l = S.length();
  map<char, vector<pos>> c; rep(i,l) c[S[i]].push_back({i,i});
  int m_med = 0; for (auto x: c) m_med += x.second.size()%2;
  if (m_med>=2) { cout << -1 << endl; return 0; }

  map<char, int> num;
  int p = 0;
  rep(i,l) {
    if ((num[S[i]]+1)*2<=c[S[i]].size()) {
      c[S[i]][num[S[i]]].to = p;
      num[S[i]]++;
      p++;
    }
  }

  int ft[l+1] = {};
  for (auto x: c) {
    vector<pos> vec = x.second;
    ll vs = vec.size();
    if (vs%2) vec[vs/2].to = l/2;
    repr(i,(vs+1)/2,vs) {
      vec[i].to = (l-1) - vec[(vs-1)-i].to;
    }
    for (auto y: vec) ft[y.i+1] = y.to+1;
    // cout << x.first << ":"; rep(i,vs) cout << vec[i].i << "->" << vec[i].to << " "; cout << endl;
  }
  // debug(ft,ft+l+1);

  SegTree tree(l+1);
  ll result = 0;
  rep(i,l+1) {
    result += i - tree.query(0,ft[i]);
    tree.update(ft[i],1);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 8348
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n;
  cin >> n;
  while(n--) {
    string s;
    cin >> s;
    int cnt = 0;
    while(s.size() > 1) {
      int a = s[0]-'0' + s[1]-'0';
      stringstream ss;
      ss<<a<<s.substr(2);
      s=ss.str();
      cnt++;
    }
    if (cnt%2)
      cout << "Fabre wins." << endl;
    else
      cout << "Audrey wins." << endl;
  }
  
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <deque>

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

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	
	int ans = max(a, b);

	if (a == ans)
		ans += max(ans - 1, b);
	else
		ans += max(ans - 1, a);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int res = 0;
        int count = 0;
        while (true) {
            boolean key = false;
            a : for (int i = 0; i < 10; i++) {
                int num = N*i+res;
                if (num%10 == 7) {
                    count++;
                    String s = Integer.toString(num);
                    for (char c : s.toCharArray()) {
                        if (c != '7') {
                            res = num/10;
                            key = true;
                            break a;
                        }
                    }
                    count += s.length();
                    System.out.println(count-1);
                    return;
                } else {
                    continue;
                }
            }
            if (!key) {
                System.out.println(-1);
                return;
            }
        }

    }
}

Measured memory_bytes: 54040
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProCon
{

    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            string[] input = Console.ReadLine().Split(' ');
            List<int> nums = new List<int>();
            for( int i = 0; i < input.Count(); ++i)
            {
                nums.Add(int.Parse(input[i]));
            }
            nums.Sort();
            nums.Reverse();
            int nMax = 1000000001;
            int nMax2 = 1000000001;
            bool ismax = false;
            bool isc = false;
            foreach (int i in nums)
            {
                if( nMax == i && !ismax)
                {
                    ismax = true;
                }
                else if( !ismax)
                {
                    nMax = i;
                }
                else if( nMax2 == i)
                {
                    isc = true;
                    break;
                }
                else
                {
                    nMax2 = i;
                }
            }
            if( isc)
            {
                long nas = (long)nMax * (long)nMax2;
                Console.WriteLine(nas);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }

}

Measured memory_bytes: 21216
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int x[310][310];
vector < pair<int,ll> > a[100010];
bool vis[310];
ll dik(int x, int y){
  memset(vis, 0, sizeof vis);
  priority_queue < pair<ll,int> > q;
  q.push(mk(0, x));
  pair<ll, int> tp;
  int tmp;
  while(!q.empty()){
    tp=q.top();
    q.pop();
    tmp=tp.sc;
    if(vis[tmp])
      continue;
    vis[tmp]=1;
    if(tmp==y){
      return -tp.fs;
    }
    for(int i=0; i<a[tmp].size(); ++i){
      q.push(mk(tp.fs-a[tmp][i].sc, a[tmp][i].fs));
    }
  }
  return 1e14;
}
int main(){
  int n;
  while(cin>>n){
    vector < pair<int, pair<int,int> > > v;
    for(int i=0; i<n; ++i){
      for(int j=0; j<n; ++j){
        scanf("%d",&x[i][j]);
        if(j>=i)
          v.push_back(mk(x[i][j], mk(i, j)));
      }
    }
    sort(v.begin(), v.end());
    ll ans=0, tmp, tmp1, tmp2;
    bool l=1;
    for(int i=0; i<v.size(); ++i){
      tmp1=v[i].sc.fs;
      tmp2=v[i].sc.sc;
      tmp=dik(tmp1, tmp2);
      if(tmp>v[i].fs){
        a[tmp1].push_back(mk(tmp2, v[i].fs));
        a[tmp2].push_back(mk(tmp1, v[i].fs));
        ans+=v[i].fs;
      }
      else if(tmp<v[i].fs){
        l=0;
        break;
      }
    }
    if(l){
      printf("%lld\n",ans);
    }
    else{
      printf("-1\n");
    }
  }
  return 0;
}


/*
for (k = 0; k < V; k++)
    {
        for (i = 0; i < V; i++)
        {
            for (j = 0; j < V; j++)
            {
                if (b[i][k] + b[k][j] < b[i][j])
                    b[i][j] = b[i][k] + b[k][j];
            }
        }
    }
    */


Measured memory_bytes: 3708
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
vector<int> G[202];
int a[101];
int b[101];
int c[101];
int d[101];
bool used[202];
int match[202];
int n,V;

bool dfs(int v){
    used[v] = true;
    for(int i=0;i<G[v].size();i++){
        int u = G[v][i], w = match[u];
        if(w < 0 || !used[w] && dfs(w)){
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching(){
    int res = 0;
    memset(match,-1,sizeof(match));
    for(int v =0;v<V;v++){
        if(match[v] < 0){
            memset(used,0,sizeof(used));
            if(dfs(v)){
                res++;
            }
        }
    }
    return res;
}

int main(void)
{
    
    cin >> n ;
    V = 2*n;
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }

    for(int j=0;j<n;j++){
       cin >> c[j] >> d[j];
       for(int i=0;i<n;i++){
           if(a[i] < c[j] && b[i] < d[j]){
               G[i].push_back(j+n);
               G[j+n].push_back(i);
           }
       }
    }

    cout << bipartite_matching();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=200000+5;
const int inf=1e9;
const ll mod=1e9+7;


int main()
{
    FasterIO;
    int tc, a, b;
    cin>>a>>b;
    cout<<(a/b)+(a%b!=0)<<endl;
    return 0;
}


Measured memory_bytes: 256
n,m = (int(i) for i in input().split())
like = {}
for i in range(n):
    tmp = list(int(i) for i in input().split())
    for j in range(len(tmp)):
        if not j==0:
            if not tmp[j] in like:
                like[tmp[j]] = 1
            else:
                like[tmp[j]] += 1

count = 0
for k, v in like.items():
    if v == n:
        count += 1

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define pb push_back
#define m 1000000007
ll bigmod(ll a,ll b,ll c){
    if(b==0) return 1;
    if(b%2==0)
    {
        ll x=bigmod(a,b/2,c);
        return ((x%c)*(x%c))%c;
    }
    else return ((a%c) * (bigmod(a,b-1,c)%c))%c;
}
ll ncr(ll n,ll r){
    ll lob=1,hor=1;
    for(ll i=n,j=1;i>=n-r+1&&j<=r;i--,j++){
        lob=(lob*i)%m;
        hor=(hor*j)%m;
    }
    hor=bigmod(hor,m-2,m);
    //cout<<lob<<" "<<hor<<endl;
    return (lob*hor)%m;
}
int main(){
    fast;
    ll n,a,b;
    cin>>n>>a>>b;
    ll u=bigmod(2,n,m);
    u=(u-1);
    a=ncr(n,a);
    b=ncr(n,b);
    //cout<<a<<" "<<b<<endl;
    u=(u-a-b)%m;
    ll ans=(u+m)%m;
    //cout<<ans<<endl;
    if(ans<=0)cout<<'0'<<endl;
    else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;

ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

int main(void){
    ll a,b,ans=1;
    cin>>a>>b;
    ll g=gcd(a,b);
    ll i=2;
    for(i=2;i<=(ll)sqrtl(g)+2;i++){
        if(g%i==0){
            while(g%i==0)g/=i;
            ans++;
        }
    }
    if(g>1)ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, m;
string a[55];
string b[55];
bool sol, aux;

int main(){
    ios::sync_with_stdio(0);
    cin >> n >> m;
    forn(i,n){
        cin >> a[i];
    }
    forn(i,m){
        cin >> b[i];
    }

    sol = false;

    if(m > n){
        cout << "No\n";
        return 0;
    }

    forn(i,n-m+1){
        forn(j,n-m+1){
            aux = true;
            forn(k,m){
                forn(l,m){
                    if(a[i+k][j+l] != b[k][l]){
                        aux = false;
                        break;
                    }
                }
                if(!aux)
                    break;
            }
            if(aux){
                sol = true;
                break;
            }
        }
    }

    if(sol){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;  
int main()
{
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		ans+=n%i==0?(n/i)-1:n/i;
	}
	cout<<ans;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main() {
	int i, n, l[100], max = 0;
	int sum = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &l[i]);
		sum += l[i];
		if (l[i] >= max) max = l[i];
	}

	printf(max < sum - max ? "Yes\n" : "No\n");

	return 0;
}

Measured memory_bytes: 128
A, B, C, D = map(int, input().split())
def gcd(a, b):
  if a % b is 0:
    return b
  return gcd(b, a % b)
 
def solve(n):
  return n - (n // C) - (n // D) + (n // (C * D // gcd(C, D)))
 
print(solve(B) - solve(A - 1))

Measured memory_bytes: 3060
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (a, b) = get!(usize, usize);
    let s: Vec<char> = util::line().chars().collect();

    if s.len() == (a + b + 1) && s[..a].iter().all(|c| c.is_digit(10)) && s[a] == '-'
        && s[a + 1..].iter().all(|c| c.is_digit(10))
    {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int h, w;
int flag[101][101];
char fe[101][101];
char flu[3] = {'#','@','*'};
int xdim[4] = {1,-1,0,0};
int ydim[4] = {0,0,1,-1};
char o = 'o';

void dfs(int x, int y){

  if(fe[y][x] == o) return;
  if(fe[y][x] == '#'){
    fe[y][x] = o;
    for(int i = 0; i < 4; i++){
      int nx = x + xdim[i], ny = y + ydim[i]; 
      if(fe[ny][nx] == '#' && nx >= 0 && nx < w && ny >= 0 && ny < h) dfs(nx,ny);
    }
  }
  else  if(fe[y][x] == '*'){
    fe[y][x] = o;
    for(int i = 0; i < 4; i++){
      int nx = x + xdim[i], ny = y + ydim[i]; 
      if(fe[ny][nx] == '*' && nx >= 0 && nx < w && ny >= 0 && ny < h) dfs(nx,ny);
    }
  }
  else if(fe[y][x] == '@'){
    fe[y][x] = o;
    for(int i = 0; i < 4; i++){
      int nx = x + xdim[i], ny = y + ydim[i]; 
      if(fe[ny][nx] == '@' && nx >= 0 && nx < w && ny >= 0 && ny < h) dfs(nx,ny);
    }
  }
}

int main(){

  while(cin >> h >> w && (h || w)){

    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	cin >> fe[i][j];
      }
    }
    int cnt = 0;
    for(int l = 0; l < h; l++){
      for(int m = 0; m < w; m++){
	for(int i = 0; i < 3; i++){
	  if(fe[l][m] == flu[i]){
	    dfs(m,l);
	    cnt++;
	    /* for(int p = 0; p < h; p++){
	      for(int e = 0; e < w; e++){
		cout << fe[p][e];
	      }
	      cout << endl;
	    }
	    cout << endl;
	    */
	  }
	}
   
      }
     
    }
    cout << cnt << endl;

  }


  return 0;
}

Measured memory_bytes: 1484
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
 vector<int> a(13);
 a[1]=1;
 a[2]=3;
 a[3]=1;
 a[4]=2;
 a[5]=1;
 a[6]=2;
 a[7]=1;
 a[8]=1;
 a[9]=2;
 a[10]=1;
 a[11]=2;
 a[12]=1;
 int f,g;
 cin >> f >> g;
 if (a[f]==a[g]) cout << "Yes" << endl;
 else cout << "No" << endl;
}


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

class Dice{
public:
  vector<int> d;
  void spin(string s){
    if(s == "S"){
      swap(d[0],d[4]);
      swap(d[4],d[1]);
      swap(d[4],d[5]);
    }
    if(s == "E"){
      swap(d[0],d[3]);
      swap(d[2],d[3]);
      swap(d[3],d[5]);
    }
    if(s == "N"){
      swap(d[0],d[1]);
      swap(d[1],d[5]);
      swap(d[4],d[5]);
    }
    if(s == "W"){
      swap(d[0],d[2]);
      swap(d[2],d[5]);
      swap(d[3],d[5]);
    }
  }
};


int main(){

  Dice saikoro;
  vector<int> in(6);
  for(int i=0; i<6; i++){
    cin >> in[i];
  }
  saikoro.d = in;
  /*
  for(int i=0; i<6; i++){
    cout << saikoro.d[i] << " ";
  }
  cout << "\n";
  */
  string s; cin >> s;
  for(int i=0; i<s.size(); i++){
    saikoro.spin(s.substr(i,1));
    /*
    for(int i=0; i<6; i++){
      cout << saikoro.d[i] << " ";
    }
    cout << "\n";
    */
  }
  cout << saikoro.d[0] << endl;

}

Measured memory_bytes: 1236
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int inf = 2e9;
const int sz = 2e5 + 5;

int n;
vector<int> g[sz];
int a[sz];
int ans[sz];
int dp[sz];

void dfs(int v, int pred) {
	bool change = 0;
	int was = -1;
	int cur = upper_bound(dp, dp + sz, a[v]) - dp;
	if (dp[cur - 1] < a[v] && a[v] < dp[cur]) {
		was = dp[cur];
		dp[cur] = a[v];
		change = 1;
	}

	ans[v] = lower_bound(dp, dp + sz, inf) - dp - 1;

	for (int to : g[v])
		if (to ^ pred)
			dfs(to, v);
	if (change)
		dp[cur] = was;
}

void solve() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	fill(dp, dp + sz, inf);
	dp[0] = -inf;
	dfs(0, -1);
	for (int i = 0; i < n; i++)
		cout << ans[i] << '\n';
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

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

int gcd(int x, int y) {
	if (x < y) swap(x, y);
	while (y > 0) {
		int r = x % y;
		x = y;
		y = r;
	}

	return x;
}

int main() {
	int x, y;
	cin >> x >> y;
	int ans = gcd(x, y);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3084
// Insertion_Sort.c

#include <stdio.h>

#define N 1000

int main() {

  int n, j, a[N], i, key = 0, k;

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

  for(i = 0; i < n; i++) {

    key = a[i];
    j = i - 1;
    while(j >= 0 && a[j] > key) {
      a[j + 1] = a[j];
      j--;
      a[j + 1] = key;
    }

    for(k = 0; k < n; k++) {
      if(k < n - 1) {
	printf("%d ", a[k]);
      } else {
	printf("%d\n", a[k]);
      }
    }

  }

return 0;

}

Measured memory_bytes: 604
#include <iostream>
#define ll long long

using namespace std;

int main() {
  ll w, h, x, y;
  scanf("%lld %lld %lld %lld", &w, &h, &x, &y);

  bool b = ((x == w / 2.0 && y == h / 2.0) ? 1 : 0);

  cout << w * h / 2.0 << " " << b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

// ビット演算
namespace Bits {
    // 整数 x を左に i ビットシフトした値を返す
    static Int LeftBitShift(Int x, Int i);
    // 整数 x を右に i ビットシフトした値を返す
    static Int RightBitShift(Int x, Int i);
    // 整数x の 下から i 桁目が1かどうかを返す
    static bool IsFlagUp(Int x, Int i);
    // 整数x の 下から i 桁目が0かどうかを返す
    static bool IsFlagDown(Int x, Int i);

    // 整数 x を左に i ビットシフトした値を返す
    Int LeftBitShift(Int x, Int i) {
        return (x << i);
    }
    // 整数 x を右に i ビットシフトした値を返す
    Int RightBitShift(Int x, Int i) {
        return (x >> i);
    }
    // 整数x の 下から i 桁目が1かどうかを返す
    bool IsFlagUp(Int x, Int i) {
        return ((x & (1 << i)) != 0);
    }
    // 整数x の 下から i 桁目が0かどうかを返す
    bool IsFlagDown(Int x, Int i) {
        return ((x & (1 << i)) == 0);
    }
}
using namespace Bits;


Int CountBlack(vector<vector<char> >& table, char target) {
    Int height = table.size();
    Int width = table[0].size();
    Int cnt = 0;
    for (Int i = 0; i < height; ++i) {
        for (Int j = 0; j < width; ++j) {
            if (table[i][j] == target) {
                ++cnt;
            }
        }
    }
    return cnt;
}
bool Func(vector<vector<char> > table, Int hs, Int ws, Int k) {
    Int height = table.size();
    Int width = table[0].size();
    for (Int i = 0; i < height; ++i) {
        if (IsFlagUp(hs, i)) {
            for (Int j = 0; j < width; ++j) {
                table[i][j] = '.';
            }
        }
    }
    for (Int j = 0; j < width; ++j) {
        if (IsFlagUp(ws, j)) {
            for (Int i = 0; i < height; ++i) {
                table[i][j] = '.';
            }
        }
    }
    Int black = CountBlack(table, '#');
    //cout << black << endl;
    return (black == k);
}

int main(void) {
    Int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char> > c(h, vector<char>(w));
    for (Int i = 0; i < h; ++i) {
        for (Int j = 0; j < w; ++j) {
            cin >> c[i][j];
        }
    }

    Int result = 0;
    for (Int i = 0; i < pow(2, h); ++i) {
        for (Int j = 0; j < pow(2, w); ++j) {
            //cout << i << " " << j << " ";
            if (Func(c, i, j, k)) {
                ++result;
            }
        }
    }
    cout << result << endl;

    return 0;
}



Measured memory_bytes: 4108
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod = 1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n, m;
const int maxn = 187;
char g[maxn][maxn];
int cnt[maxn][maxn];
int dp[maxn][maxn][maxn][16];

int main()
{
	getii(n, m);
	for (int i=1; i<=n; i++)
	{
		for (int j=1; j<=m; j++)
		{
			g[i][j] = getreal();
			cnt[i][j] = g[i][j]=='#';
		}
	}
	for (int i=1; i<n; i++) for (int j=1; j<=m; j++) cnt[i+1][j] += cnt[i][j];
	for (int xl=n; xl>=1; xl--)
	{
		for (int yl=m; yl>=1; yl--)
		{
			for (int xr=xl; xr<=n; xr++)
			{
				int c = cnt[xr][yl]-cnt[xl-1][yl];
				if (c==0||c==xr-xl+1)
				{
					dp[xl][yl][xr][0] = yl;
					if (yl<m&&g[xl][yl]==g[xl][yl+1])
					{
						dp[xl][yl][xr][0] = max(dp[xl][yl][xr][0], dp[xl][yl+1][xr][0]);
					}
				}
				else  dp[xl][yl][xr][0] = 0;
				for (int i=1; i<16; i++)
				{
					int &cur = dp[xl][yl][xr][i];
					//horizontal
					int tmp = dp[xl][yl][xr][i-1];
					if (tmp>0) cur = max(cur, max(tmp, dp[xl][tmp+1][xr][i-1]));
					//vertical
					if (xl<xr)
					{
						int l = xl, r = xr-1;
						while (l<=r)
						{
							int m = l+r>>1;
							int tl = dp[xl][yl][m][i-1];
							int tr = dp[m+1][yl][xr][i-1];
							cur = max(cur, min(tl, tr));
							if (tl>tr) l = m+1;
							else r = m-1;
						}
					}
//					cerr<<xl<<" "<<yl<<" "<<xr<<" "<<i<<":"<<dp[xl][yl][xr][i]<<endl;
				}
			}
		}
	}
	for (int i=0; i<16; i++)
	{
		if (dp[1][1][n][i]>=m)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	puts("16");
	return 0;
}


Measured memory_bytes: 406016
import bisect

n,k = map(int,input().split())
A = sorted([int(i) for i in input().split()])


zero = A.count(0)
inm = bisect.bisect_left(A,0)
inp = bisect.bisect_right(A,0)
mi = [-x for x in A[:inm]]
mi = mi[::-1]
pl = A[inp:]
numm = inm
nump = n-inp

def shaku(x,l):
    count = 0
    if len(l) <= 1:
        return 0
    ri = len(l)-1
    for i in range(len(l)):
        while ri >= 0 and l[ri]*l[i] > x:
            ri -= 1
        
        count += max(ri-i,0)
        
    return count 

def search(x):
    count = 0
    if x >= 0:
        count += zero*(n-zero)+numm*nump+(zero*(zero-1))//2
        count += shaku(x,pl)
        count += shaku(x,mi)
            
        return count
    else:
        ri = 0
        
        for i in pl[::-1]:
            while ri < numm and i*mi[ri] < -x:
                ri += 1
            count += numm-ri
        return count

left = -10**18-1
right = 10**18+1
while right > left+1:
    mid = (left+right)//2
    a = search(mid)
    
    if a >= k:
        right = mid
    else:
        left = mid
print(right)


Measured memory_bytes: 110680
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	string s[3];
	REP(i, 3) cin >> s[i];
	int k[3] = { 0, 0, 0 };
	int t = 0;
	while (k[t] < s[t].length()) {
		++k[t];
		t = s[t][k[t] - 1] - 'a';
	}
	cout << (char)('A' + t) << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from heapq import heapify, heappush, heappop

def main():
    n, m = MII()
    a_lst = MII()
    a_lst.sort()
    bc = []
    for i in range(m):
        b, c= MII()
        bc.append((b,c))
    bc.sort(key=lambda x: x[1], reverse=True)
    index = 0
    cnt = 0
    for i in range(n):
        if a_lst[i] > bc[index][1]: break
        a_lst[i] = bc[index][1]
        cnt += 1
        if cnt == bc[index][0]:
            cnt = 0
            index += 1
            if index == m:
                break
    print(sum(a_lst))

if __name__ == '__main__':
    main()


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

int main(){
    int N, M;
    cin >> N >> M;
    long long A;
    priority_queue<long long> que;
    rep(i, N){
        cin >> A;
        que.push(A);
    }
    rep(i, M){
        long long j = que.top();
        que.pop();
        que.push(j/2);
    }
    long long res = 0;
    while(!que.empty()){
        res += que.top();
        que.pop();
    }
    cout << res << endl;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INF = 2147483647;
const long long LINF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

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

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

int main(void){
    int N,K; cin >> N >> K;
    VI l(N); REP(i,N) cin >> l[i];
    int ans = 0;
    SORT(l); REVERSE(l);
    REP(i,K) ans += l[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

#define MAX_N (8+5)

int N;
double X[MAX_N];
double Y[MAX_N];

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> N;
	FOR(n,N) {
		cin >> X[n] >> Y[n];
	}

	double tot=0;
	for(int i=0;i<N;i++) {
		for(int j=i;j<N;j++) {
			tot += sqrt(pow(X[j]-X[i],2.0)+pow(Y[j]-Y[i],2.0));	
		}
	}

	double ans = tot*2/N;
	// double ans = tot*2.0f/comb;

	cout << setprecision(10) << ans << endl;

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k,s;
  cin>>k>>s;
  int count=0;
  for(int x=0;x<=k;x++){
    for(int y=x;y<=k;y++){
      for(int z=y;z<=k;z++){
        if(x+y+z==s){
          if(x==y&&y==z){count++;}
          else if(x==y||y==z||z==x){count+=3;}
          else{count+=6;}
        }
      }
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = list()
C = list()
for i in range(Q):
	b,c = map(int, input().split())
	B.append(b)
	C.append(c)

c = collections.Counter(A)
# print(c)

sum_a = sum(A)

for i in range(Q):
	b_num = c[B[i]]
	diff = (C[i]-B[i]) * b_num
	c[C[i]] = c[B[i]] + c[C[i]]
	c[B[i]] = 0
	sum_a = sum_a + diff
	print(sum_a)

Measured memory_bytes: 30072
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w;
	cin>>h>>w;
	char a[h][w];
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(a[i][j]=='#')
			{
				if(a[i+1][j]!='#'&&a[i][j-1]!='#'&&a[i][j+1]!='#'&&a[i-1][j]!='#')
				{
					cout<<"No\n";
					return 0;
				}	
			}
		}
	}
	cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#define endl '\n'
#define ll long long

using namespace std;

bool number[10];

bool ok(int ret)
{
        auto str = to_string(ret);
        for(int i = 0; i < str.size(); i++)
        {
                if(number[str[i] - '0']) return false;
        }

        return true;
}

int main(void)
{
        cin.tie(NULL); ios_base::sync_with_stdio(false);
        int N, K; cin >> N >> K;
        while(K--) { int temp; cin >> temp; number[temp] = true; }

        int ret = N;
        while(!ok(ret)) ret += 1;

        cout << ret << endl;


        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n; cin >> n;
	int w[101];
	for (int i = 0; i < n; i++) cin >> w[i];

	int ans = 999999999;
	for (int i = 0; i < n; i++) {
		int l = 0, r = 0;
		for (int j = 0; j < i; j++) {
			l += w[j];
		}
		for (int j = i; j < n; j++) {
			r += w[j];
		}

		ans = min(ans, abs(l - r));
	}

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

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

int main() {
  int N,a,b,c,d;
  cin >> N;
  d = N%10;
  c = N%100/10;
  b = N/100%10;
  a = N/1000;
  if((a==b && b==c)||(b==c && d==b))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
//54
#include<iostream>
#include<cstdlib>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int ans=1<<30;
    int a[20];
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    for(int i=0;i<1<<n;i++){
      int p[2]={};
      for(int j=0;j<n;j++){
	p[!(i&1<<j)]+=a[j];
      }
      ans=min(ans,abs(p[0]-p[1]));
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  string s;
  cin >> s;
  if(s=="ABC") cout << "ARC" << endl;
  else cout <<"ABC"<< endl;

  return 0;
}


Measured memory_bytes: 3624
count = 0
n = gets.chomp!.to_i
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

n.times do |i|
  power = bs[i]
  if power >= as[i]
    count += as[i]
    power -= as[i]
    if power >= as[i+1]
      count+=as[i+1]
      as[i+1]=0
    else
      count+=power
      as[i+1]-=power
    end
  else
    count += power
  end
end
  p count

Measured memory_bytes: 15376
import collections
import heapq

INF = 10 ** 18
MAX_S = 50*50+5

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

class edge:
    def __init__(self, to, cost, t): self.to, self.cost, self.t = to, cost, t

def main():
    N, M, S = ZZ()
    C, D = [0]*(N+1), [0]*(N+1)
    E = collections.defaultdict(list)
    dist = [[INF] * (MAX_S+1) for _ in range(N+1)]

    for _ in range(M):
        u, v, a, b = ZZ()
        E[u].append(edge(v, a, b))
        E[v].append(edge(u, a, b))

    for i in range(1, N+1): C[i], D[i] = ZZ()

    S = min(S, MAX_S)
    dist[1][S] = 0

    que = list()
    heapq.heapify(que)
    heapq.heappush(que, [dist[1][S], 1, S])

    while que:
        x, v, s = heapq.heappop(que)
        if dist[v][s] < x: continue

        #遷移
        ns = min(s+C[v], MAX_S)
        if dist[v][ns] > x + D[v]:
            dist[v][ns] = x + D[v]
            heapq.heappush(que, [x+D[v], v, ns])

        #遷移
        for e in E[v]:
            if s - e.cost < 0: continue
            if dist[e.to][s-e.cost] > x + e.t:
                dist[e.to][s-e.cost] = x + e.t
                heapq.heappush(que, [x+e.t, e.to, s-e.cost])

    for i in range(2, N+1):
        output = INF
        for j in range(MAX_S+1): output = min(output, dist[i][j])
        print(output)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 29108
r(int*a,int*b){return*b-*a;}c[99];char s[99];a;i;main(k){for(scanf("%*d%d\n",&k);gets(s);)c[*s-65]++;for(qsort(c,26,4,r);c[k-1];qsort(c,26,4,r),a++)for(i=0;i<k;i++)c[i]--;printf("%d\n",a);}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int[] map = new int[10010];
		for (int i = 1; i <= 100; i++) {
			for (int j = 1; j <= 100; j++) {
				for (int k = 1; k <= 100; k++) {
					int n = calc(i,j,k);
					if (n < 10010) {
						map[n]+=1;
					}
				}
			}
		}
		for (int i = 1; i <= m; i++) {
			System.out.println(map[i]);
		}

	}

	private static int calc(int i, int j, int k) {
		return i*i + j*j + k*k + i*j + i*k + j*k;
	}

}


Measured memory_bytes: 39028
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int a,b,k;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>

#define MAX 200000

using namespace std;

int price[MAX];
int main()
{
    // input
    int n, i, j;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &price[i]);
    }
    // main process
    int minNum = price[0];
    int maxNum = -2000000000;
    for (i = 1; i < n; i++) {
        maxNum = max(maxNum, price[i]-minNum);
        minNum = min(minNum, price[i]);
    }
    // output
    printf("%d\n", maxNum);
    return 0;
}

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

int main() {
  ll a;
  string b;
  cin >>a>>b;
  ll tmp1,tmp2,tmp3;
  tmp1=(ll)(b.at(0)-'0')*100;
  tmp2=(ll)(b.at(2)-'0')*10;
  tmp3=(ll)(b.at(3)-'0');
  ll b100=tmp1+tmp2+tmp3;
  ll ans=a*b100/100;
  cout <<ans<<endl;
}

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


int main() {
    long long m,n;
    scanf ("%lld %lld",&m,&n);
    long long y,z;
    y=1000000007;
    z=1;
    while(n>=1){
      if(n&1){
        z=(z*m)%y;
      }
      m=(m*m)%y;
      n=n>>1;
    }
    printf("%lld\n",z);

}



Measured memory_bytes: 3228