akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int n;
bool f[105][15];
int p[105][15];
int ans=-1e9;

void dfs(int d,vector<bool> v,bool ok){
    if(d==10){
        if(!ok)return;
        int c[105]={0};
        int res=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<10;j++){
                if(f[i][j]==v[j]&&v[j]==1)c[i]++;
            }
            res+=p[i][c[i]];
        }
        if(res>ans){
            ans=res;
        }
        return;
    }
    v.push_back(0);
    dfs(d+1,v,ok);
    v[v.size()-1]=1;
    dfs(d+1,v,true);
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++){
            int t;
            cin>>t;
            f[i][j]=(t==1?true:false);
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=10;j++){
            cin>>p[i][j];
        }
    }
    vector<bool> v;
    dfs(0,v,0);
    cout<<ans<<endl;

    return 0;
}

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

s = []

for i in range(n):
    s.append(list(map(str,input())))

s_ord = [[0]*(l) for i in range(n)]

for i in range(n):
    for j in range(l):
        s_ord[i][j] += ord(s[i][j])

s_ord_sorted = sorted(s_ord)

s_sorted = ""

for i in range(n):
    for j in range(l):
        s_sorted += chr(s_ord_sorted[i][j])

print(s_sorted)

Measured memory_bytes: 3188
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    x = LI() + [INF]
    L = NI()
    m = N.bit_length()
    f = [[N-1] * N for _ in range(m)]
    j = 1
    for i in range(N-1):
        while x[i] + L >= x[j+1]:
            j += 1
            if j >= N-1: break
        f[0][i] = j
    for k in range(1,m):
        for i in range(N):
            f[k][i] = f[k-1][f[k-1][i]]

    for _ in range(NI()):
        ans = 0
        a,b = _LI()
        if a > b: a,b = b,a

        for k in range(m-1,-1,-1):
            if f[k][a] < b:
                a = f[k][a]
                ans += 2**k
        print(ans+1)



if __name__ == '__main__':
    main()

Measured memory_bytes: 84252
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front

#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)

#define mp make_pair
#define ff first
#define ss second
#define null NULL

#define all(c) (c).begin(),(c).end()
#define nl "\n"

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;

const double pi = 3.1415926535897;

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

    ll r;
    cin>>r;

    double ans = 2*pi*r;

    printf("%0.6lf",ans);
    
    
    return 0;
}

Measured memory_bytes: 3720
n = gets.chomp.to_i
a = gets.split(" ")
a.map!{|item| item.to_i}
cnt = 0
j = 1
for i in 0..(n-1)
    if a[i] == j
        j += 1
        cnt += 1
    end
end
if cnt == 0
    puts -1
else
    puts n-cnt
end

Measured memory_bytes: 13828
import random
import time
import copy
start=time.time()
d=int(input())
c=list(map(int, input().split()))
s=[]
solution=[]
last=[0]*26
sco=0
for i in range(d):
  s.append(list(map(int, input().split())))
for day in range(1,d+1):
  man=[]
  for i in range(26):
    man.append(s[day-1][i]+last[i]*c[i])
  con=man.index(max(man))
  sco+=s[day-1][con]
  last[con]=day
  for (i,j) in zip(last,c):
    sco-=i*j
  solution.append(con)

while time.time()-start<1.9:
  sc=0
  sol=copy.deepcopy(solution)
  sol[random.randrange(d)]=random.randrange(26)
  last=[0]*26
  for (day,i) in zip(range(1,d+1),sol):
    sc+=s[day-1][i]
    last[i]=day
    for (i,j) in zip(last,c):
      sc-=i*j
  if sc>sco:
    solution=sol
    sco=sc
for i in solution:
  print(i+1)

Measured memory_bytes: 10080
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int d[5];
   int k;
   for(int i = 0; i < 5 ;i++)
   {
       cin>>d[i];
   }
   
    cin>>k;

    if (d[4]-d[0]<=k) {
        cout<<"Yay!"<<endl;
    }
    else 
    {
        cout<<":("<<endl;
    }
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,r=0;
    cin>>n;
    int V[n],C[n];
    for(int i=0; i<n; i++)
    {
        cin>>V[i];
    }
    for(int i=0; i<n; i++)
    {
        cin>>C[i];
    }
    for(int i=0; i<n; i++)
    {
        if(V[i]>C[i])
            r += (V[i]-C[i]);
    }
    cout<<r<<endl;
}



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

int main() {
    int a, b;

    scanf("%d %d", &a, &b);

    int d, r;
    double f;
    d = a / b;
    r = a % b;
    f = 1.0 * a / b;

    printf("%d %d %.8f\n", d, r, f);

    return 0;

}


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

int A, P;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> A >> P;
    cout << (3*A+P)/2 << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	int x = a[0];
	repn(i, 1, n) x ^= a[i];
	rep(i, n) cout << (x ^ a[i]) << " ";
	cout << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3948
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll A, ll B) {
  if (A == 1) A = 14;
  if (B == 1) B = 14;
  if (A > B) cout << "Alice" << endl;
  else if (A < B) cout << "Bob" << endl;
  else cout << "Draw" << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll B;
	ll A;
	scanf("%lld", &A);
	scanf("%lld", &B);
	solve(A, B);
	return 0;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	In := readLineInt()
	fmt.Println((In[0] - 1) * (In[1] - 1))
}

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

func readLineInt() []int {
	result := make([]int, 0)
	for _, v := range strings.Split(readLine(), " ") {
		i, _ := strconv.Atoi(v)
		result = append(result, i)
	}
	return result
}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}


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

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = INF;
vl flag, color; vll path; ll start = 0;
//***********//
vl Ans;
void dfs(ll now, vl V, ll num) {
	stack<ll> S;
	S.push(now);
	flag[now] = 1;
	V.emplace_back(now + 1);
	while (!S.empty()) {
		ll u = S.top();
		S.pop();
		for (ll i = 0; i < path[u].size(); i++) {
			ll v = path[u][i];
			if (v == start) {
				debug(start, V);
				if (num < ans) {
					ans = num;
					Ans = V;
				}
			}
			if (flag[v] == 0) {
				dfs(v, V, num + 1);
			}
		}
	}
}
int main() {
	cin >> N >> M;
	flag.resize(N);
	path.resize(N);
	for (i = 0; i < M; i++) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		path[a].push_back(b);
	}
	//始点でDFS
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			flag[j] = 0;
		}
		vl A = {};
		start = i;
		dfs(i, A, 1);
	}
	if(ans==INF) cout << -1;
	else {
		cout << ans << endl;
		for (i = 0; i < Ans.size(); i++) {
			cout << Ans[i] << endl;
		}
	}
}


Measured memory_bytes: 12544
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

class Dice {
    enum { TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM }
    char v[6];
    override bool opEquals(Object o) const {
        Dice d = cast(Dice)o;
        foreach (i; 0 .. 6) {
            if (v[i] != d.v[i]) return false;
        }
        return true;
    }
    void rollX() { roll(TOP, FRONT, BOTTOM, BACK); }
    void rollY() { roll(TOP, LEFT, BOTTOM, RIGHT); }
    void rollZ() { roll(FRONT, RIGHT, BACK, LEFT); }
    void roll() (int a, int b, int c, int d) {
        char t = v[a];
        v[a] = v[b]; v[b] = v[c]; v[c] = v[d]; v[d] = t;
    }
    Dice dup() const {
        Dice ret = new Dice;
        foreach (i; 0 .. 6) {
            ret.v[i] = v[i];
        }
        return ret;
    }
    Dice[] allState() const {
        Dice[] Ret;
        Dice d = this.dup;
        foreach (i; 0 .. 6) {
            if (i % 2 == 0) d.rollX();
            else            d.rollY();
            foreach (j; 0 .. 4) {
                d.rollZ();
                Ret ~= d.dup;
            }
        }
        return Ret;
    }
    bool isSameDice(in Dice d) const {
        Dice[] states = allState;
        return states.any!((a) => a == d);
    }
    override string toString() const {
        return "Dice: " ~ v.to!string;
    }
}
 
void main() {
    int N;
    Dice[] Ds;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        Ds = new Dice[N];
        foreach (i; 0 .. N) {
            Ds[i] = new Dice;
            auto F = readln.chomp.split(" ");
            foreach (j; 0 .. 6) {
                Ds[i].v[j] = F[j][0];
            }
        }
        return true;
    }
    void solve() {
        auto dup = new bool[N];
        int A = 0;
        foreach (i; 0 .. N) {
            if (dup[i]) continue;
            foreach (j; i + 1 .. N) {
                if (!dup[j] && Ds[i].isSameDice(Ds[j])) {
                    dup[j] = true;
                    A++;
                }
            }
        }
        writeln(dup.count!"a");
    }
    while (input) solve;
}

Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
int const nax = 1e6 + 10;
char s[nax];
int n;
int dp[nax][2];

int main () {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    s[0] = '0';

    dp[n + 1][1] = 1;

    for (int i = n ; i >= 0 ; -- i) {
        int d = s[i] - '0';
        dp[i][0] = min(dp[i + 1][1] + 10 - d, dp[i + 1][0] + d);
        dp[i][1] = min(dp[i + 1][0] + d + 1, dp[i + 1][1] + 9 - d);
    }

    printf("%d\n", dp[0][0]);
}


Measured memory_bytes: 12612
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif
#define out(v) cout<<v<<"\n"
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, M; cin >> N >> M;

  cout << max(0, (4-N)*100000) + max(0, (4-M)*100000) + (N == 1 && M == 1 ? 400000 : 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;

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

typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
  int n;
  cin >> n;
  int hund = n/100;
  n = n%100;
  int ten = n/10;
  n = n%10;
  int one = n;

  cout << ((hund == 7 || ten == 7 || one == 7) ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define inf 1000000007000000007
typedef long long ll;
using namespace std;
#define N 100010
typedef pair<ll,ll> P;
typedef pair<ll,pair<ll,ll> >PP;
ll n,m,s,t;
vector<pair<ll,ll> >v[N];

priority_queue<PP,vector<PP>,greater<PP> >Q;
ll d[N][2],cnt[N][2];
void Dijkstra(ll start,ll flag){
	lol(i,n)d[i][flag]=inf,cnt[i][flag]=0;
	Q.push(make_pair(0,make_pair(start,-1)));
	while(!Q.empty()){
		ll a=Q.top().first,b=Q.top().second.first;
		ll from=Q.top().second.second;
		Q.pop();
		if(d[b][flag]<a)continue;
		if(d[b][flag]==a){
			cnt[b][flag]+=cnt[from][flag];
			cnt[b][flag]%=mod;
			continue;
		}
		d[b][flag]=a;
		if(from==-1)cnt[b][flag]=1;
		else cnt[b][flag]=cnt[from][flag];
		lol(i,v[b].size()){
			Q.push(make_pair(v[b][i].first+a,make_pair(v[b][i].second,b)));
		}
	}
}

int main(){
	cin>>n>>m>>s>>t;s--,t--;
	lol(i,m){
		ll a,b,c;cin>>a>>b>>c;a--,b--;
		v[a].push_back(make_pair(c,b));
		v[b].push_back(make_pair(c,a));
	}
	Dijkstra(t,1);
	Dijkstra(s,0);
	ll k=d[t][0];
	
	ll sum=0;
	lol(i,n){
		if(d[i][0]*2>k)continue;
		if(d[i][0]*2==k){
			ll tmp=cnt[i][0]*cnt[i][1]%mod;
			sum+=tmp*tmp;sum%=mod;
			continue;
		}
		//d[i][0]*2<kが成り立っている
		lol(j,v[i].size()){
			ll to=v[i][j].second,cost=v[i][j].first;
			if(cost+d[i][0]==d[to][0]&&d[to][0]*2>k&&cost+d[i][0]+d[to][1]==k){
				//cout<<"#"<<i+1<<" "<<to+1<<endl;
				ll tmp=cnt[i][0]*cnt[to][1]%mod;
				sum+=tmp*tmp;sum%=mod;
			}
		}
	}
	ll ans=(cnt[s][1]*cnt[t][0]-sum)%mod;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 23792
def main():
    h, w = map(int, input().split())
    s = [["." for _ in range(w + 2)]]
    for _ in range(h):
        s.append(["."] + list(input()) + ["."])
    s.append(s[0])
    delta = [[0, 1], [1, 0], [0, -1], [-1, 0]]
    count_black = 0
    count_possible = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if s[i][j] == "#":
                count_black += 1
                if any(s[dy + i][dx + j] == "#" for dy, dx in delta):
                    count_possible += 1
    print("Yes" if count_possible == count_black else "No")


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
import numpy as np
N = int(input())
A = np.zeros(N)
B = np.zeros(N)
for i in range(N):
    A[i], B[i] = map(int, input().split())

am = np.median(A)
bm = np.median(B)

if N % 2 == 0:
    print(int((bm - am) * 2 + 1))
else:
    print(int((bm - am) + 1))

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

int main() {
    int K, S, count;
    cin >> K >> S ;
  	for(int i = 0; i <= K; i++){
      for(int j = 0; j <= K; j++){
        int z = S - i - j; 
        if(z >= 0 && z <= K){
          count++;
        }
      }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main() {
    int n; cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];

    unordered_map<string, ll> cnt;
    rep(i, n) {
        sort(all(s[i]));
        cnt[s[i]]++;
    }

    ll ans = 0;
    for (auto e: cnt) {
        ans += e.second * (e.second - 1) / 2; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 17700
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template <typename T>
struct edge {
    int from, to;
    T cost;

    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}

    explicit operator int() const {return to;}
};

template <typename T>
vector<vector<T>> all_dijkstra(vector<vector<edge<T>> > &G){
    int n=G.size();
    const T INF = numeric_limits<T>::max();
    using P = pair<T, int>;
    vector<vector<T>> ans;
    for (int i = 0; i < n; ++i) {
        vector<T> d(n, INF);
        vector<int> b(n,-1);
        priority_queue<P,vector<P>,greater<> > Q;
        d[i]=0;
        Q.emplace(d[i],i);
        while(!Q.empty()){
            T cost;
            int j;
            tie(cost, j) = Q.top(); Q.pop();
            if(d[j] < cost) continue;
            for (auto &&e : G[j]) {
                auto cost2 = cost + e.cost;
                if(d[e.to] <= cost2) continue;
                d[e.to] = cost2;
                Q.emplace(d[e.to], e.to);
            }
        }
        ans.emplace_back(d);
    }
    return ans;
}

int main() {
    u32 n, m, r;
    cin >> n >> m >> r;
    vector<vector<edge<int>>> v(n);
    vector<int> R(r);
    for (int i = 0; i < r; ++i) {
        int x;
        cin >> x;
        R[i] = x-1;
    }
    sort(R.begin(), R.end());
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        v[a-1].emplace_back(b-1, c);
        v[b-1].emplace_back(a-1, c);
    }
    vector<vector<int>> p = all_dijkstra(v);
    ll ans = numeric_limits<ll>::max();
    do{
        ll x = 0;
        for (int i = 0; i < r - 1; ++i) {
            x += p[R[i]][R[i+1]];
        }
        ans = min(x, ans);
    }while(next_permutation(R.begin(), R.end()));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
using System;

class Program {
    //--------------------------------------------------
    static void Main( string[] args )
    {
        while ( true ) {
            string[] input = Console.ReadLine().Split();

            int h = int.Parse( input[ 0 ] );
            int w = int.Parse( input[ 1 ] );

            if ( 0 == h + w ) {
                break;
            }

            string odd = GetPattern( w, true );

            if ( h < 2 ) {
                Console.WriteLine( odd );

            } else {
                string even = GetPattern( w, false );

                bool order = true;

                for ( int i = 0; i < h; ++i ) {
                    Console.WriteLine( order ? odd : even );
                    order = !order;
                }
            }

            Console.WriteLine();
        }
    }

    //--------------------------------------------------
    public static string GetPattern( int width, bool order )
    {
        char[] pattern = new char[ width ];

        for ( int i = 0; i < width; ++i ) {
            pattern[ i ] = order ? '#' : '.';
            order = !order;
        }

        return new string( pattern );
    }
}

Measured memory_bytes: 8908
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int r, c, k;
  cin >> r >> c >> k;
  vector<vector<ll>> v(r + 5, vector<ll>(c + 5, 0));
  vector<vector<vector<ll>>> ans(r + 5, vector<vector<ll>>(c + 5, vector<ll>(4, 0)));
  for(int i = 0; i < k; i++) {
    ll x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    v[x][y] = z;
  }
  for(int i = 0; i <= r + 1; i++) {
    for(int j = 0; j <= c + 1; j++) {
      for(int l = 3; l >= 0; l--){
        ans[i][j][l + 1] =
            max(ans[i][j][l + 1], ans[i][j][l] + v[i][j]);
      }
      for(int l = 0; l < 4; l++) {
        if(l < 3) {
          ans[i + 1][j][0] = max(ans[i][j][l], ans[i + 1][j][0]);
        }
        ans[i][j + 1][l] = max(ans[i][j + 1][l], ans[i][j][l]);
        ans[i + 1][j][0] = max(ans[i + 1][j][0], ans[i][j][l]);
      }
    }
  }
  cout << max( {ans[r - 1][c - 1][0], 
                ans[r - 1][c - 1][1], 
                ans[r - 1][c - 1][2],
                ans[r - 1][c - 1][3]})
       << endl;

  /*
  for(int i = 0; i < r + 1; i++) {
    for(int j = 0; j < c + 1; j++) {
      cout << max({ans[i][j][0],
                   ans[i][j][1],
                   ans[i][j][2],
                   ans[i][j][3]});
      cout << " ";
    }
    cout << '\n';
  }
  */
  return 0;
}

Measured memory_bytes: 708992
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n - i; j++) {
                int k = n - i - j;
                int sum = (i * 10000) + (j * 5000) + (k * 1000);
                if(sum == y) {
                    System.out.println(i + " " + j + " " + k);
                    System.exit(0);
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}

Measured memory_bytes: 38944
#include <stdio.h>

int main(void)
{
	int n, a;//nは合計,aは端数
	scanf("%d", &n);
	scanf("%d", &a);


	if (a >= n % 500){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
    return 0;
}



Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.awt.geom.Point2D.Double;

import static java.lang.Integer.parseInt;

public class Main {

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

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int q = parseInt(br.readLine());

      String[] lines;
      Point2D[] p = new Point2D[4];
      StringBuilder buf = new StringBuilder();

      for(int i=0; i<q; i++) {
        lines = br.readLine().split(" ");
        int x, y;
        for(int j=0,k=0; j<p.length; j++) {
          x = parseInt(lines[k++]);
          y = parseInt(lines[k++]);
          p[j] = new Point2D(x, y);
        }

        Vector v = new Vector();
        if(v.isParallel(p[0], p[1], p[2], p[3]))
          buf.append(2).append("\n");
        else if(v.isOrthogonal(p[0], p[1], p[2], p[3]))
          buf.append(1).append("\n");
        else
          buf.append(0).append("\n");
      }

      System.out.print(buf);
    }
    catch(IOException e) {
      System.out.println(e);
    }
  }

  private class Point2D extends Double {
    private static final long serialVersionUID = 1L;
    double EPS = 1e-10;

    public Point2D() { super(); }
    public Point2D(double x, double y) { super(x, y); }

    public boolean equals (double a, double b) {
      return Math.abs(a-b) < EPS;
    }
    public Point2D sum(Point2D b) {
      return new Point2D(x+b.x, y+b.y);
    }
    public Point2D diff(Point2D b) {
      return new Point2D(x-b.x, y-b.y);
    }
  }

  private class Vector extends Point2D {

    private static final long serialVersionUID = 1L;

    public Vector() { super(); }
    public Vector(double x, double y) { super(x, y); }

    public double dot(Point2D a, Point2D b) {
      return a.x * b.x + a.y * b.y;
    }
    public double cross(Point2D a, Point2D b) {
      return a.x * b.y - a.y * b.x;
    }
    public boolean isOrthogonal(Point2D a, Point2D b) {
      return equals(dot(a,b) , 0.0);
    }
    public boolean isOrthogonal(Point2D a1, Point2D a2, Point2D b1, Point2D b2) {
      return isOrthogonal(a1.diff(a2), b1.diff(b2));
    }
    public boolean isParallel(Point2D a, Point2D b) {
      return equals(cross(a, b), 0.0);
    }
    public boolean isParallel(Point2D a1, Point2D a2, Point2D b1, Point2D b2) {
      return isParallel(a1.diff(a2), b1.diff(b2));
    }
  }
}


Measured memory_bytes: 28332
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;
// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

int dp[100010];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	rep(i, 100010)dp[i] = n;
	dp[0] = 0;
	FORR(i, 1, n) {
		for (int j = 1; j <= i; j *= 6) {
			chmin(dp[i], dp[i - j] + 1);
		}
		for (int j = 1; j <= i; j *= 9) {
			chmin(dp[i], dp[i - j] + 1);
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1024
import static java.lang.Math.*;
import static java.util.Arrays.*;

import java.util.*;
import java.io.*;

public class Main {
	int w, h, ans;
	int INF = 1<<28;
	boolean[][] m;
	int sx, sy, gx, gy;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			w = sc.nextInt(); h = sc.nextInt();
			if( (w|h) == 0 ) break;
			m = new boolean[h][w];
			
			for(int i=0;i<h;i++) for(int j=0;j<w;j++) {
				int v = sc.nextInt();
				m[i][j] = v == 1;
				if( v == 2 ) { sx = j; sy = i; }
				if( v == 3 ) { gx = j; gy = i; }
			}
			
			ans = INF;
			dfs(sx, sy, 0);
			System.out.println((ans == INF? -1: ans));
		}
	}
	int[] dx = {0,1,0,-1};
	int[] dy = {1,0,-1,0};
	void dfs(int x, int y, int cnt) {
		if( cnt == 10 ) return;
		for(int i=0;i<4;i++) {
			int nx = x, ny = y;
			for(;;) {
				nx += dx[i]; ny += dy[i];
				if( nx == gx && ny == gy ) { ans = min(ans, cnt+1); break; }
				if( nx < 0 || ny < 0 || nx >= w || ny >= h ) break;
				if( m[ny][nx] ) {
					if(( (nx-dx[i] == x) && (ny-dy[i] == y))) break;
					m[ny][nx] = false; dfs(nx-dx[i], ny-dy[i], cnt+1); m[ny][nx] = true;
					break;
				}
			}
		}
	}
	
	class P {
		int x, y, cnt;
		P(int x, int y) {
			this.x = x;
			this.y = y;
			cnt = 0;
		}
		
		P(int x, int y, int cnt) {
			this.x = x;
			this.y = y;
			this.cnt = cnt;
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

Measured memory_bytes: 37580
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;

char rot(char ch, int n)
{
    unsigned num = 0;
    if ('a' <= ch && ch <= 'z') {
        num = (ch - 'a' + n) % 26;
        return num + 'a';
    } else {
        num = (ch - 'A' + n) % 26;
        return num + 'A';
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        s[i] = rot(s[i], n);
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include<vector>
#include<algorithm>
#include<queue>
#include<stdio.h>
#include<vector>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s=="Sunny")puts("Cloudy");
  else if(s=="Cloudy")puts("Rainy");
  else if(s=="Rainy")puts("Sunny");
  return 0;
}

Measured memory_bytes: 256
n,m = list(map(int,input().split()))
x=[list(map(int,input().split())) for i in  range(n)]
#for i in range(n):
    #x.append(list(map(int,input().split())))
x.sort()
result=0
while 1:
    if x[0][1]>=m:
        result+=m*x[0][0]
        break
    else:
        result+=x[0][0]*x[0][1]
        m-=x[0][1]
        del x[0]
print(result)

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

using namespace std;

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

int main (){
    cin.tie(0);
    char C[2][3];
    cin >> C[0] >>C[1];
    REP (i,3){
        if( C[0][i] != C[1][2-i]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
def warshall_floyd(graph):
    num_v = len(graph)

    for k in range(num_v):
        for i in range(num_v):
            for j in range(num_v):
                if graph[i][j] > graph[i][k] + graph[k][j]:
                    graph[i][j] = graph[i][k] + graph[k][j]
    return graph

N = int(input())
graph = [[float("inf") for _ in range(N)] for _ in range(N)]
for i in range(N):
    a_list = list(map(int, input().split()))
    for j in range(N):
        if i == j:
            continue
        graph[i][j] = a_list[j]
import copy
a_list = copy.deepcopy(graph)
w_graph = warshall_floyd(graph)
result = 0
for i in range(N):
    for j in range(i+1, N):
        if i == j:
            continue
        if w_graph[i][j] != a_list[i][j]:
            print(-1)
            exit()
        d = []
        for k in range(N):
            d.append(w_graph[i][k] + w_graph[j][k])
        if min(d) > w_graph[i][j]:
            result += w_graph[i][j]
print(result)


Measured memory_bytes: 63708
N, M, C = map(int, input().split())

B = list(map(int, input().split()))

count = 0

for i in range(0, N):
    A = list(map(int, input().split()))

    sum_a = 0

    for j in range(0, M):

        sum_a += A[j] * B[j]

    sum_a += C

    if sum_a > 0:
        count += 1

print(count)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

class Node {
 public:
  int value = -1;
  int left = -1;
  int right = -1;
  explicit Node(int value)
    :value{value} {}
};

void print_inorder(vector<Node>&, int);
void print_preorder(vector<Node>&, int);

int main() {
  vector<Node> tree;
  cin.ignore(numeric_limits<streamsize>::max(), '\n');
  string line;
  while (getline(cin, line)) {
    if (line == "print") {
      if (!tree.size()) {
        cout << endl;
      } else {
        print_inorder(tree, 0); cout << endl;
        print_preorder(tree, 0); cout << endl;
      }
    } else {
      int value = stoi(line.substr(7));
      tree.push_back(Node(value));
      if (tree.size() == 1) continue;
      int curr = 0;
      int prev = 0;
      while (curr != -1) {
        if (value < tree[curr].value) {
          prev = curr;
          curr = tree[curr].left;
        } else if (value > tree[curr].value) {
          prev = curr;
          curr = tree[curr].right;
        }
      }
      if (value < tree[prev].value) {
        tree[prev].left = tree.size() - 1;
      } else {
        tree[prev].right = tree.size() - 1;
      }
    }
  }
}

void print_inorder(vector<Node>& tree, int curr) {
  if (tree[curr].left != -1) print_inorder(tree, tree[curr].left);
  cout << ' ' << tree[curr].value;
  if (tree[curr].right != -1) print_inorder(tree, tree[curr].right);
}

void print_preorder(vector<Node>& tree, int curr) {
  cout << ' ' << tree[curr].value;
  if (tree[curr].left != -1) print_preorder(tree, tree[curr].left);
  if (tree[curr].right != -1) print_preorder(tree, tree[curr].right);
}


Measured memory_bytes: 9128
import java.util.*;

public class  Main{
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);

        String userInput = sc.nextLine();

        String[] splitedUserInput = userInput.split("");
        String resultCd = "Good";
        for(int i = 0; i < splitedUserInput.length - 1; i++){
            if(splitedUserInput[i].equals(splitedUserInput[i+1])){
                resultCd = "Bad";
            }
        }

        System.out.println(resultCd);
    }
}

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

typedef long long ll;
const int N = 105, mod = 1000000007;
int n, h[N];

inline int qpow(int b, int p) {
  int r = 1;
  for (; p; p >>= 1) {
    if (p & 1) r = (ll) r * b % mod;
    b = (ll) b * b % mod;
  }
  return r;
}

pair<int, int> solve(int l, int r, int x) {
  int mn = mod;
  for (int i = l; i <= r; i++) {
    mn = min(mn, h[i]);
  }
  pair<int, int> p = make_pair(2, 1);
  for (int i = l; i <= r; i++) {
    if (h[i] == mn) {
      p.second = p.second * 2 % mod;
    } else {
      int j = i;
      for (; j < r && h[j + 1] > mn; j++);
      auto q = solve(i, j, mn);
      p.first = (ll) p.first * q.first % mod;
      p.second = (ll) p.second * (q.first * 2 % mod + q.second) % mod;
      i = j;
    }
  }
  p.second = (p.second + mod - p.first) % mod;
  p.first = (ll) p.first * qpow(2, mn - x - 1) % mod;
  return p;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &h[i]);
  }
  auto p = solve(1, n, 0);
  printf("%d\n", (p.first + p.second) % mod);
}


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

using namespace std;

const int MAXN = 100002;

int N,K;
bool dislike[10] = {false};
vector<int> likes;
vector<int> Ndgt;
bool overValued = false;
vector<int> rDgt(7,0);

void outRoutine(){
	int rVal = 0;
	for (int i=Ndgt.size()-1;i>=0;i--)
		rVal = rVal*10+rDgt[i];
	cout<<rVal<<endl;
}
void dfs(int step,bool overValued){
	if (step==0){
		if (overValued){
			rDgt[step] = likes.front();
			outRoutine();
			exit(0);
		}
		else{
			auto it = lower_bound(likes.begin(),likes.end(),Ndgt[step]);
			if (it!=likes.end()){
				rDgt[step] = *it;
				outRoutine();
				exit(0);
			}
		}
	}
	if (overValued){
		rDgt[step] = likes.front();
		dfs(step-1,true);
	}
	if (step==Ndgt.size()-1){ // search first digit to 0
		rDgt[step]=0;
		dfs(step-1,false);
	}
	auto it = lower_bound(likes.begin(),likes.end(),Ndgt[step]);
	if (it==likes.end())
		return;
	if (*it>Ndgt[step]){
		rDgt[step] = *it;
		dfs(step-1,true);
	}
	else{
		rDgt[step] = *it;
		dfs(step-1,false);
		if (next(it)!=likes.end()){
			rDgt[step] = *next(it);
			dfs(step-1,true);
		}
	}
}
void solve(){
	cin>>N>>K;
	for (int i=0;i<K;i++){
		int d;
		cin>>d;
		dislike[d] = true;
	}
	for (int i=0;i<=9;i++)
		if (!dislike[i])
			likes.push_back(i);

	int N0 = N;
	while (N0>0){
		Ndgt.push_back(N0%10);
		N0 /= 10;
	}
	Ndgt.push_back(0);
	dfs(Ndgt.size()-1,false);
}


int main(){
//	freopen("in.txt","r",stdin);
	std::ios::sync_with_stdio(false);

//	int TestCase;
//	cin>>TestCase;
//	for (int i=0;i<TestCase;i++){
		solve();
//	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    map<int,int> A;
    ll sum=0;
    for(int i=0;i<N;i++){
        int t; cin >> t;
        sum += t;
        A[t]++;
    }
    cerr << sum << endl;
    int Q; cin >> Q;
    for(int i=0;i<Q;i++){
        int B,C; cin >> B >> C;
        int sub = C-B;
        int cnt=A[B];
        //cerr << sub << "\t" << cnt << endl;
        if(A.count(C)!=0){
            A[C] = A[C]+A[B];
            A[B] = 0;
        }else{
            A[C] = A[B];
            A[B] = 0;
        }
        sum += sub*cnt;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 8088
#include <iostream>
using namespace std;
int x, n, a, ans, maxv = 1000,curdif;
int main(){
    cin >> x >> n;
    bool q[110];
    for (int i = 0;i<110;i++){
        q[i] = false;
    }
    for (int i = 0;i<110;i++){
        cin >> a;
        q[a] = true;
    }
    for(int i = 0;i<110;i++){
        if(q[i]){
            continue;
        }
        curdif = abs(x - i);
        if(maxv == curdif){
            cout << ans << endl;
            return 0;
        }
        if(maxv > curdif){
            maxv = curdif;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <algorithm>

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

int main()
{
    int n;
    cin >> n;
    
    while (n)
    {
        if (n % 10 == 7)
        {
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
    return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

string t = "ATCG";

int main() {
  string N;
  cin >> N;
  int ans = 0;
  int tmpans = 0;
  bool jg = false;
  
  rep(i,N.size()){
    jg = false;
    rep(j,t.size()){
        if(N[i] == t[j]) jg = true;
    }
    if(jg){
        tmpans+=1;
    }else{
        tmpans = 0;
    }
    ans = max(tmpans,ans);
 }
 cout << ans;
  

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    vector<ll> B(N,0);
    for(ll i=0;i<N;i++)cin>>A[i];
    for(ll i=0;i<N;i++)cin>>B[i];
    ll suma=0,sumb=0;
    for(ll i=0;i<N;i++){
        suma+=A[i];
        sumb+=B[i];
    }
    if(sumb>suma){print(-1)return 0;}
    vector<ll> D(N,0);
    ll minus=0;ll count=0;
    for(ll i=0;i<N;i++){D[i]=A[i]-B[i];if(D[i]<0){minus-=D[i];count++;}}
    sort(D.rbegin(), D.rend());
    ll sum=0;
    for(ll i=0;i<N;i++){
        if(sum>=minus)break;
        sum+=D[i];count++;
    }
    print(count)
    
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
typedef long long ll;
int a,b,c,ans,N,M,tt;
int main(){
	scanf("%d%d",&N,&a);
	int s=0;
	rep(i,1,N){
		scanf("%d",&b);
		s+=b;
		if (s<=a) ans++;
	}
	printf("%d\n",ans+1);
	return 0;
}


Measured memory_bytes: 256
//by tzupengwang™
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<iostream>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;

int n;
int s[100005], t[100005];

void init() {
  scanf("%d", &n);
  ll s1 = 0, s2 = 0;
  for (int i = 0; i < n; i ++) scanf("%d", &s[i]), s1 += s[i];
  for (int i = 0; i < n; i ++) scanf("%d", &t[i]), s2 += t[i];

  if (s1 > s2) printf("No\n");
  else {
    ll stp = s2 - s1;
    ll nd = 0, nd2 = 0;

    for (int i = 0; i < n; i ++) {
      ll tmp = s[i] - t[i];
      if (tmp > 0) nd2 += tmp;
      else {
        tmp = -tmp;
        if (tmp % 2) nd2 ++, tmp ++;
        nd += tmp / 2;
      }
    }
    if (stp >= nd && stp >= nd2) puts("Yes");
    else puts("No");
  }
}

void process() {
}

int main() {
/*
#ifdef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
  int Cases;
  scanf( "%d" , &Cases ) ;
  for ( int cases = 1 ; cases <= Cases ; cases ++ ) {
*/
    init() ;
    process() ;
/*
  }
*/
  return 0 ;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int start[10] = {0};
	int finish[10] = {0};
	int count, norma;
	int time;
	int i;
	
	while(1){
		time = 0;
		
		scanf("%d", &norma);
		if(norma == 0)    break;
		scanf("%d", &count);
		
		for(i = 0; i < count; i++){
			scanf("%d %d", &start[i], &finish[i]);
			time += (finish[i] - start[i]);
		}
		if(time >= norma)
			printf("OK\n");
		else
			printf("%d\n", (norma - time));
	}
	
	return 0;
}

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

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl

string n;

int main () {
    cin >> n;
    if (n[0]==n[1]) {
        cout << "Bad";
        return 0;
    }
    if (n[2]==n[1]) {
        cout << "Bad";
        return 0;
    }
    if (n[2]==n[3]) {
        cout << "Bad";
        return 0;
    }
    cout << "Good";
}


Measured memory_bytes: 256