akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
typedef long long ll;

vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];
int main() {
    
    int n,k;
    cin >> n >> k;
    vector<int>a(n+1,0);
    set<int>sa;
    rep(i,0,n){
        int tmp;
        cin >> tmp;
        sa.insert(tmp);
        a[tmp]++;
    }
    if (sa.size() == k){
        cout << 0 << endl;
        return 0;
    }
    ll cnt = 0;
    sort(a.begin(), a.end());
    
    rep(i,1,a.size()-k){
        cnt+=a[i];
    }
    cout << cnt  << endl;
    return 0;
    
    
    return 0;
}


Measured memory_bytes: 15492
#include <iostream>
using namespace std;
int main(void){
    string card_t, card_h;
    int n, point_t, point_h;
    point_t = 0;
    point_h = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> card_t >> card_h;
        if (card_t > card_h) {
            point_t += 3;
        } else if (card_t < card_h) {
            point_h += 3;
        } else {
            point_t++;
            point_h++;
        }
    }
    cout << point_t << " " << point_h << endl;
    return 0;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define pi 3.1415926535897
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000000
#define inf1 1000000000
#define endl '\n'
ll dp[3005][3005];
int main()
{
	fastio;
	#ifdef APNA_IO
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n;
	cin>>n;
	string s;
	getline(cin,s);
	getline(cin,s);
	dp[1][1]=1;
	for(ll i=1;i<n;i++)
	{
		for(ll j=1;j<=i;j++)
		{
			if(s[i-1]=='<')
				dp[i+1][j+1]=(dp[i+1][j+1]+dp[i][j])%mod;
			else
			{
				dp[i+1][1]=(dp[i+1][1]+dp[i][j])%mod;
				dp[i+1][j+1]=(dp[i+1][j+1]+mod-dp[i][j])%mod;
			}
		}
		for(ll j=1;j<=i;j++)
			dp[i+1][j+1]=(dp[i+1][j+1]+dp[i+1][j])%mod;
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
		ans=(ans+dp[n][i])%mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 69120
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>

using namespace std;

queue<pair<int, int>> q;
bool is_rechable(vector<string>& grid, vector<vector<int>>& dis,pair<int,int> &x) {
    int H = grid.size(), W = grid[0].size();
    if (x.first < 0 || x.first >H - 1 || x.second < 0 || x.second > W - 1)return false;
    if (grid[x.first][x.second] == '#') return false;
    if (dis[x.first][x.second])return false;
    return true;
}
void from_dis(vector<string>& grid, vector<vector<int>>& dis, pair<int, int> x) {
    q.pop();
    vector<int> tate = { -1,0,1,0 }, yoko = { 0,1,0,-1 } ;

    for (int i = 0; i < 4; i++) {
        pair<int, int> y = make_pair(x.first + tate[i], x.second + yoko[i]);
        if (is_rechable(grid, dis, y)) {
            q.push(y);
            dis[y.first][y.second] = dis[x.first][x.second] + 1;
        }
    }
    if (q.empty()) return;
    pair<int, int> z = q.front();
    from_dis(grid, dis, z);
}
int main() {
    int H, W;
    cin >> H >> W;

    vector<string> grid(H);
    vector<vector<int>> dis(H, vector<int>(W));
    vector<vector<pair<int, int>>> history(H, vector<pair<int, int>>(W));
    for (int i = 0; i < H; i++)
        cin >> grid[i];
       
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '.')
                continue;          
            q.push(make_pair(i, j));
            history[i][j] = make_pair(i, j);
        }
    }
    from_dis(grid, dis, q.front());
    int ans = -1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ans = max(ans, dis[i][j]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 185360
# Problem: https://atcoder.jp/contests/abc067/tasks/abc067_b
# Python 3rd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(allNumber, selectNum, eachLength):
    result = 0
    # algorithm
    sortedStickLength = sorted(eachLength, reverse=True)
    #    print("{}:{}".format(sortedStickLength, eachLength))
    for j in range(0, selectNum, +1):
        result = result + sortedStickLength[j]
    return result


if __name__ == "__main__":
    N, K = MI()
    StickList = LI()
    print("{}".format(solver(N, K, StickList)))


Measured memory_bytes: 3064
#include <stdio.h>
#define N 100


int min(int a,int b){
	if(a<b){
		return a;
	}
	
	return b;
}


int main(void){
	int n;
	int p[N+1],m[N+1][N+1];
	scanf("%d",&n);
	
	for(int i=1;i<=n;i++){
		scanf("%d %d",&p[i-1],&p[i]);
	}
	
	for(int i=1;i<=n;i++){
		m[i][i]=0;
	}
	
	for(int l=2;l<=n;l++){
		for(int i=1;i<=n-l+1;i++){
			int j=i+l-1;
			m[i][j]=(1<<21);
			for(int k=i;k<=j-1;k++){
				m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	}
	
	
	
	printf("%d\n",m[1][n]);
	
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <string>
#include <fstream>
#include <algorithm>
#include <complex>
using namespace std;

typedef long long ll;
const int NMAX=2*1e5+2;

string s;
int n,dp[2][NMAX]; //1 si i est dans une pair et 0 sinon osef du reste


int main(){
	ios::sync_with_stdio(false);
	
	cin >> s;
	
	n=s.size();
	
	dp[0][0]=1;
	dp[1][0]=0;
	dp[1][1]=1;
	
	if(n>=2 && s[1]!=s[0])
		dp[0][1]=2;
	
	
	for(int i=2;i<n;i++){
		
		if(s[i]!=s[i-1]){ //on alterne sans pb 
			dp[0][i]=max(dp[0][i],1+dp[0][i-1]);
		}
		dp[0][i]=max(dp[0][i],1+dp[1][i-1]);
		
		dp[1][i]=max(dp[1][i],1+dp[0][i-2]);
		
		if( i>=3 && (s[i]!=s[i-2] || s[i-1]!=s[i-3]) )
			dp[1][i]=max(dp[1][i],1+dp[1][i-2]);
		
		
		
	}
	
	cout << max(dp[0][n-1],dp[1][n-1]) << '\n';
	
	return 0;
}



Measured memory_bytes: 2196
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program
{

    static void Main(string[] args)
    {

        //var NX = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = long.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        long cum = A.Sum();
        long ans = 0;
        long bef = 0;
        for (int i = 0; i <= N; i++)
        {
            if(i > 0 && 2*bef < A[i])
            {
                ans = -1;
                break;
            }
            cum -= A[i];
            bef = Math.Min(2 * bef - A[i], cum);
            if (i == 0) bef = A[i] == 1 ? 0 : 1;
            ans += (bef+A[i]);
        }
        if (A[0] > 1) ans = -1;
        Console.WriteLine(ans);
    }
}


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

#define ll long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define all(v) (v.begin(),v.end())
#define vi vector<int>

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
    int n,k,r,s,p;
    string t;

    cin >> n >> k >> r >> s >> p >> t;
    vector<bool> cool(n);
    int score = 0;
    for(int i = 0;i < n; ++i){
        if(i >= k){
            if(t[i] == t[i - k] && cool[i - k]){
                cool[i] = false;
                continue;
            }
        }

        cool[i] = true;

        switch(t[i]){
            case 'r':
                score += p;
                break;
            case 's':
                score += r;
                break;
            case 'p':
                score += s;
                break;
            default:
                break;
        }
    }

    cout << score;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define all(v)    ((v.begin()),(v.end()))
#define sz(v)     ((int)(v.size()))
#define forv(i, v) for(int i = 0; i < sz(v); ++i)
#define forn(i,n)   for(int i = 0; i < (int)(n); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector< vi >    vii;
typedef vector< vd >    vdd;
typedef vector<string>  vs;

ll coose2(ll n) {
	return (ll)(n * (n - 1) / 2);
}

int main()
{
	fast;
	ll n;
	cin >> n;
	ll ar[n + 2];
	forn(i, n) cin >> ar[i];
	forn(i, n) ar[i]--;
	ll cnt[n + 2] = {0};
	forn(i, n) cnt[ar[i]]++;
	ll tot = 0;
	forn(i, n) {
		tot += coose2(cnt[i]);
	}
	forn(i, n) {
		ll ans = tot;
		ans -= coose2(cnt[ar[i]]);
		ans += coose2(cnt[ar[i]] - 1);
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 5760
N = int(input())
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
    d[input()] += 1
m = max(d.values())
l = []
for a,b in d.items():
  if b == m:
    l.append(a)
l.sort()
for i in l:
  print(i)

Measured memory_bytes: 32488
import std;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto X = BigInt(sread());
    auto v = BigInt(100);
    foreach (i; 0 .. 1_000_000)
    {
        if (X <= v)
        {
            writeln(i);
            return;
        }
        v = (v * 101) / 100;
    }
}


Measured memory_bytes: 3828
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(void){
    double N,p,q;
    int tmp;
    scanf("%lf",&N);
    tmp = (int)sqrt(N);
    for(int i=1;i<=tmp;i++){
        if(fmod(N,i) == 0) p = i;
    }
    q = N / p;
    printf("%.0lf",p+q-2);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

int n;
vector<int> inorder;
vector<int> ans;
void dfscreate(int p,int from,int to){//親と区間
    if(from>to){return;}
    //区間の最小値が親
    int newp;
    for(int i=from;i<=to;i++){
        if(i==from)newp=i;
        if(inorder.at(newp)>inorder.at(i)){
            newp=i;
        }
    }
    dfscreate(inorder.at(newp),from,newp-1);
    dfscreate(inorder.at(newp),newp+1,to);
    ans.pb(inorder.at(newp));
    return;
}

int main() {
    cin>>n;
    vector<int> change(n+1),rchange(n+1);
    inorder.resize(n);
    rep(i,n){
        cin>>rchange.at(i+1);
        change.at(rchange.at(i+1))=i+1;
    }
    rep(i,n){
        int a;
        cin>>a;
        inorder.at(i)=change.at(a);
    }
    //入力2行目が123...の時3行目がinorder

    dfscreate(0,0,n-1);

    rep(i,n){
        if(i)cout<<" ";
        cout<<rchange.at(ans.at(i));
    }
    cout<<endl;
}


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

int main(){
   int D,T,S;
   cin >> D >> T >> S;

   if(S*T >= D){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }
}

Measured memory_bytes: 3640
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	nb := b - a
	hb := hight(nb)
	fmt.Println(hb - b)
	return
}

func hight(n int) int {
	return (n*n + n) / 2
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define MOD 1000000007
#define endl "\n"
#define deb(n) cout<<"[ "#n<<" = "<<n<<" ]"<<endl;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const long long  MAX = 1 << 18;
int case_no=1;
#define w(x) int x; cin>>x; while(x--)

int main() {
	FIO
	int n; cin >> n;
	cout << (int)pow(n, 3) << endl;
	return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
    
#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a)  for(int i = 0; i < n; i++) cin >> a[i];
#define print(a)  for(int i = 0; i < n; i++) cout << a[i] << " ";
#define pb push_back
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
#define endl '\n'
#define N 10000002
#define MOD 1000000007

signed main() {
    int n;
    cin >> n;
    vi a(n);
    int sum = 0, cnt = 0, mn = INT_MAX;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        sum += abs(a[i]);
        if(a[i] < 0)    cnt++;
        mn = min(mn, abs(a[i]));
    }
    if(cnt % 2) sum -= (2 * mn);
    cout << sum << endl;
}

Measured memory_bytes: 1024
//Accumlation.
#include<iostream>
#include<vector>
#define REP(i,n) for(int i=0;i<(n);++i)
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long   llong;
typedef vector<int> vi;

int main(){
	int n;
	cin>>n;
	
	vi a(n);
	REP(i,n) cin>>a[i];
	
	llong ans=1;//point.
	int hat[3]={};
	REP(i,n){
		int cnt=0;
		int id=0;
		REP(j,3){
			if(hat[j]==a[i]){
				cnt++;
				id=j;
			}
		}
		ans*=cnt;
		ans%=MOD;
		hat[id]++;
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>

int gcd(int x, int y);
int main()
{
    int x, y;
    std::cin >> x;
    std::cin >> y;
    std::cout << gcd(x, y) << std::endl;
    return 0;
}
int gcd(int x, int y)
{
    if(x < y){
        std::swap(x, y);
    }
    if(x%y == 0){
        return y;
    }
    return gcd(x%y, y);
}

Measured memory_bytes: 3064
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> s;
  rep(i, Size(s)) {
    if (s[i] == '9') {
      Cout("Yes");
      return 0;
    }
  }
  Cout("No");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>

using namespace std;

#define ll long long
#define MOD 1000000007
#define rep(i, n) for(int i = 0;i < n;i++)

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

int main()
{
    int n,m;
    cin >> n >> m;

    vector<pair<int,int> > pairs;
    int a,b;
    rep(i,n)
    {
        pair<int,int> mypair;
        cin >> a >> b;
        mypair = make_pair(a,b);
        pairs.push_back(mypair);
    }

    priority_queue<int> q;

    sort(pairs.begin(),pairs.end());


    ll sum = 0;
    int index = 0;
    for (int i = 1; i < m+1; i++)
    {
        
        
        for (int j = index; j < n; j++)
        {
            if (pairs[j].first == i)
            {
                q.push(pairs[j].second);
            }else
            {
                index = j;
                break;
            }
            
        }
        
        if(q.empty()==false)
        {
            sum+=q.top();
            q.pop();
        }
        
    }

    cout << sum << endl;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
  int N;
  cin >> N;
  llong sum = 0;
  vector<llong> A(N);
  for(int i=0; i<N; ++i){
    cin >> A[i];
    sum += A[i];
    sum %= MOD;
    if(sum < 0) sum += MOD;
  }
  llong ans = 0;
  for(int i=0; i<N-1; ++i){
    sum -= A[i];
    if(sum < 0) sum += MOD;
    ans += A[i] * sum;
    ans %= MOD;
    if(ans < 0) ans += MOD;
  }
  ans %= MOD;
  if(ans < 0) ans +- MOD;
  cout << ans << endl;
}

Measured memory_bytes: 4788
#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 c[10][10];
int h, w;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> h >> w;
	rep(i, 10) rep(j,10){
		cin >> c[i][j];
	}
	rep(k, 10)rep(i, 10)rep(j, 10) {
		if (c[i][j] > c[i][k] + c[k][j]) {
			c[i][j] = c[i][k] + c[k][j];
		}
	}
	int ans = 0;
	rep(i, h)rep(j, w) {
		int a; cin >> a;
		if (a >= 0)ans += c[a][1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long ans=0;
		for(int i=1;i<=1000000;i++) {
			ans+=n/i;
			int b=n/i;
			if(b*i==n)
				ans--;
		}
		System.out.println(ans);
	}
}

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

  int main(){
    int a,b,c,r=1;
    cin >> a >> b >> c;
    if (a!=b){
      r+=1;
    }
    if (a!=c){
      r+=1;
    }
    if (b==c){
      r-=1;
    }
    if (r==0){
      r=1;
    }
    cout << r << endl;
  }


Measured memory_bytes: 256
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const llint mod=1000000007;
const llint big=1e9+1e8;
const llint red=0xE869120;
const llint pro=1002001;
llint n,k,q;
vector<llint> wa;
llint solve(llint st,llint en){
	llint i;
	if(en-st==1){if(wa[en]-wa[st]>=0){return 1;}else{return 0;}}
	llint gen=(st+en)/2,ans=0;
	ans+=solve(st,gen);
	ans+=solve(gen,en);
	vector<llint> sl;
	//vector<llint> el;
	for(i=st;i<gen;i++){sl.pub(wa[i]);}
	sort(sl.begin(),sl.end());
	for(i=gen+1;i<=en;i++){
		ans+=upper_bound(sl.begin(),sl.end(),wa[i])-sl.begin();
	}
	//cout<<st<<" "<<en<<" "<<ans;
	return ans;
	
}
int main(void){
	cin>>n>>k;
	wa.res(n+1);
	for(int i=1;i<=n;i++){cin>>q;q-=k;wa[i]=wa[i-1]+q;}
	cout<<solve(0,n)<<endl;
	return 0;
}


Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	scanf("%d",&n);
	int arr[2*n];
	for(int i=0;i<2*n;i++)
	{
		scanf("%d",&arr[i]);
	}
	int ans=0;
	sort(arr,arr+2*n);
	for(int i=0;i<=2*n-1;i+=2)
		ans+=arr[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    import collections
    input = sys.stdin.readline
    N = int(input())
    S = [input() for i in range(N)]
    c = collections.Counter(S)
    max_num = c.most_common(1)[0][1]
    c_most = list(c.most_common())
    ss = [cc[0] for cc in c_most if cc[1] == max_num]
    ss.sort()
    print("".join(ss))


main()

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

int main() {
    char c; cin>>c;
    if(c == 'A') cout<<'T';
    if(c == 'T') cout<<'A';
    if(c == 'G') cout<<'C';
    if(c == 'C') cout<<'G';
}

Measured memory_bytes: 256
#! -*- coding:utf-8 -*-
# ?´???°??????
# ???????????§????????°??????????????????????¢????????´???°?????????????????????????????§????????????
def is_prime(num):
    if num==2 or num==3:
        return True
    for x in xrange(2,int(num**0.5)+1):
        if num%x ==0:
            return False
    return True

count = 0
for i in xrange(input()):
    input_prime_candidate = input()
    if is_prime(input_prime_candidate):
        count+=1
print count

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


void solve(string S){
    int n0 = count(S.cbegin(), S.cend(), '0');
    int n1 = count(S.cbegin(), S.cend(), '1');

    std::cout << 2*min(n0,n1) << endl;
}

int main(){
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#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;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N; cin >> N;
  int a[N]; rep(i,N) { cin >> a[i]; a[i]--; }
  vector<int> in(N,N-1); rep(i,N) in[a[i]]--;
  set<int> count[N+1]; rep(i,N) count[in[i]].insert(i);
  set<int> left; rep(i,N) left.insert(i);
  // rep(i,N+1) cout << count[i].size() << " "; cout << endl;

  vector<int> result;
  if (count[0].size()>=2) { cout << -1 << endl; return 0; }
  int now = count[0].size()==1 ? *count[0].begin() : 0;

  rep(i,N) {
    // cout << now << endl;
    result.push_back(now);
    if (i!=N-1) {
      count[in[now]].erase(now); left.erase(now);
      if (left.count(a[now])) {
        count[in[a[now]]].erase(a[now]); count[in[a[now]]+1].insert(a[now]);
        in[a[now]]++;
      }
      // rep(i,N+1) cout << count[i].size() << " "; cout << endl;
      int to;
      if (count[i+1].size()==1) to = *count[i+1].begin();
      else {
        to = *left.begin();
        if (a[now]==to) to = *(++left.begin());
      }
      if (i==N-4) {
        auto p = left.begin();
        int t1 = *p, t2 = *(++p), t3 = *(++p);
        // cout << t1 << " " << t2 << " " << t3 << endl;
        if (a[now]!=t1&&a[t1]!=t2&&a[t2]!=t3) { 
          result.push_back(t1); result.push_back(t2); result.push_back(t3); 
        } 
        else if (a[now]!=t1&&a[t1]!=t3&&a[t3]!=t2) { 
          result.push_back(t1); result.push_back(t3); result.push_back(t2); 
        } 
        else if (a[now]!=t2&&a[t2]!=t1&&a[t1]!=t3) { 
          result.push_back(t2); result.push_back(t1); result.push_back(t3); 
        } 
        else if (a[now]!=t2&&a[t2]!=t3&&a[t3]!=t1) { 
          result.push_back(t2); result.push_back(t3); result.push_back(t1); 
        } 
        else if (a[now]!=t3&&a[t3]!=t1&&a[t1]!=t2) { 
          result.push_back(t3); result.push_back(t1); result.push_back(t2); 
        } 
        else if (a[now]!=t3&&a[t3]!=t2&&a[t2]!=t1) { 
          result.push_back(t3); result.push_back(t2); result.push_back(t1); 
        } 
        break;
      }
      now = to;
    }
  }
  // debug(all(result));
  
  rep(i,N) cout << result[i]+1 << " "; cout << endl;
  return 0;
}

Measured memory_bytes: 15744
#include <bits/stdc++.h>
//#define int long long
using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n, greater<int>());
    int alice = 0, bob = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) alice += a[i];
        else bob += a[i];
    }
    
    int ans = alice - bob;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

typedef vector<double> VD;
typedef vector< VD > VVD;

int weight( int flag, VI boxes )
{
	const int N = boxes.size();

	int res = 0;

	REP( i, 0, N )
	{
		if ( !( ( flag >> i ) & 1 ) )
		{
			continue;
		}

		res += boxes[i];
	}

	return res * 20;
}

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

	int n;
	cin >> n;

	VI num( n ), dists( n ), boxes( n );

	REP( i, 0, n )
	{
		cin >> num[i] >> dists[i] >> boxes[i];
	}

	VVD dp( 1 << n, VD( n, DBL_MAX ) );

	REP( i, 0, n )
	{
		dp[ 1 << i ][i] = 0;
	}

	VVI prev( 1 << n, VI( n ) );

	REP( flag, 1, 1 << n )
	{
		REP( i, 0, n )
		{
			if ( dp[ flag ][i] == DBL_MAX )
			{
				continue;
			}

			REP( j, 0, n )
			{
				if ( ( flag >> j ) & 1 )
				{
					continue;
				}

				int nflag = flag | ( 1 << j );
				double time = abs( dists[i] - dists[j] ) / ( 2000. / ( 70 + weight( flag, boxes ) ) );

				if ( dp[ nflag ][j] <= dp[ flag ][i] + time )
				{
					continue;
				}

				dp[ nflag ][j] = dp[ flag ][i] + time;
				prev[ nflag ][j] = i;
			}
		}
	}

	int flag = ( 1 << n ) - 1, cur = -1;
	
	REP( i, 0, n )
	{
		if ( cur == -1 || dp[ flag ][i] < dp[ flag ][ cur ] )
		{
			cur = i;
		}
	}
	
	VI seq;

	while ( 0 < flag )
	{
		seq.PB( cur );

		int nflag = flag ^ ( 1 << cur );
		int next = prev[ flag ][ cur ];

		flag = nflag;
		cur = next;
	}
	
	reverse( ALL( seq ) );

	REP( i, 0, n )
	{
		if ( i )
		{
			cout << ' ';
		}

		cout << num[ seq[i] ];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,y,i;
    cin>>x>>y;
    int leg=2*x;
    
    for(i=0; i<=x; i++){
        if(leg==y){
            cout<<"Yes"<<endl;
            return 0;
        }
        leg+=2;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3616
q = int(input())
l = []
r = []
for i in range(q):
    x,y = map(int, input().split())
    l.append(x)
    r.append(y)

num = [0]*100010

def is_prime(n):
    # nが素数かどうか判定
    if n == 1:
        return False

    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
    
    return True

for i in range(1,100010):
    if i%2 == 1 and is_prime(i) and is_prime((i+1)/2):
        num[i] = num[i-1]+1
    else:
        num[i] = num[i-1]

for i in range(q):
    print(num[r[i]]-num[l[i]-1])


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll i,j,k,l,m,n,t;

	for(i=0;i<5;i++)
	{
		cin >> k;
		if(k==0)
		{
			l = i+1;
		}
	}

	cout << l << '\n';

}

Measured memory_bytes: 3604
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int a2 =  a*a;
      int a3 =  a*a*a;
      int ans = a+a2+a3;
      System.out.println(ans);
	}
}

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

int main(){

    list<int> l;

    list<int>::iterator it;

    int n,tmp,count;

    cin >> n;

    for(int i=0;i<n;i++){
      cin >> tmp;
      l.push_back(tmp);
    }

    l.sort();

    it = l.end();

    it--;

    list<int>::iterator itbegin = l.begin();

    count = 0;

    while(it!=itbegin){

      count++;

      if(count > *it){
        if(count != *it){
          count--;
        }
        break;
      }

      it--;

    }

    if(it==itbegin){
      if(count+1<=*it){
        count++;
      }
    }

    cout << count << endl;




    return 0;
}

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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    
    for (int i = 0; i <= a; i++) {
        for (int ii = 0; ii <= b; ii++) {
            for (int iii = 0; iii <= c; iii++) {
                if ((500 * i + 100 * ii + 50 * iii) == x) {
                    ans++;
                }
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import Data.List
import Data.Int

modulus :: Int64
modulus = 10^9 + 7

addMod, subMod, mulMod, remMod :: Int64 -> Int64 -> Int64
addMod x y
  | x + y >= modulus = x + y - modulus
  | otherwise        = x + y

subMod x y
  | x < y     = x - y + modulus
  | otherwise = x - y

mulMod x y = (x * y) `rem` modulus

remMod x y = x `mulMod` invMod y

powMod :: Int64 -> Int64 -> Int64
powMod n p
  | p == 0    = 1
  | odd p     = n * powMod n (p-1) `mod` modulus
  | otherwise = let t = powMod n (p `div` 2)
                 in (t^2) `mod` modulus

invMod :: Int64 -> Int64
invMod n = powMod n (modulus - 2)

prodMod :: [Int64] -> Int64
prodMod = foldr mulMod 1

nCrMod :: Int64 -> Int64 -> Int64
nCrMod n r = prodMod [(n-r+1)..n] `remMod` prodMod [1..r]

main :: IO ()
main = do
    [n,a,b] <- map read . words <$> getLine :: IO [Int64]
    print $ (powMod 2 n - 1) `subMod` nCrMod n a `subMod` nCrMod n b

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

long long dp[1000010][2];

int main() {
    long long n; cin >> n;
    vector<long long> c(2*n+2, 0);
    long long ans = 0;
    dp[0][0] = 1;
    for (long long i = 0; i < n; i++) {
        c[i+1] = (c[i+1] + c[i]) % mod;
        dp[i+1][0] = (dp[i][0] + c[i+1]) % mod;
        dp[i+1][1] = dp[i][0];
        c[i+2] = (c[i+2] + dp[i][1]) % mod;
        c[i+n+1] = (c[i+n+1] + (mod - dp[i][1])) % mod;
        if (i > 0) ans += (dp[i][1] * ((n-1) * (n-1) % mod)) % mod;
        ans %= mod;
    }
    ans += dp[n][0] + dp[n][1] * (n-1) % mod;
    ans %= mod;
    for (long long i = n; i < 2*n+1; i++) {
        c[i+1] = (c[i+1] + c[i]) % mod;
        ans = (ans + c[i+1]) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 31488
import java.util.*;

public class Main {
    public static int ans[] ;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
       for(int i=1;i<=n;i++){
           ans += i;
       }
       System.out.println(ans);
    }
}


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

int main()
{
    int N, K;
    int ans = 0;
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        if (K / 2 >= x)
        {
            ans += x;
        }
        else
        {
            ans += K - x;
        }
    }
    cout << ans * 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    
    int main(){
        ll h , w;
        string s;
        cin >> s;
        if(s[0] == s[1] && s[0] != s[2] && s[2] == s[3]){
            cout << "Yes" << endl;
        }else if(s[0] == s[2] && s[0] != s[1] && s[1] == s[3]){
            cout << "Yes" << endl;
        }else if(s[0] == s[3] && s[0] != s[1] && s[1] == s[2]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        
        return 0;
        
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    string T, ans;
    cin >> T;

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

    }
    cout << ans << endl;

    return 0;
            
}

Measured memory_bytes: 3924
/* You can't connect the dots looking forward 
   you can only connect them looking backwards. */

/* Nothing is impossible; impossible itself says "I'm possible" */

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;
#define dbset(x) for(int i=0 ; i<x.size(); i++) cerr << x[i] << " "; cerr << endl;
#define inf 1000000007
#define INF 1000000000000000000LL
#define PI 3.14159265358979323846
#define mod 1000000007
#define mod1 1000696969
#define flusz fflush(stdout);
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define BIT bitset<N>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

#define int long long
#define N 500007

int test;

int n;

VI g[N];

int h[N],par[N];

int cou1;

void dfs(int v,int p){
    h[v] = h[p]+1;
    par[v] = p;

    for(auto it:g[v]){
        if (it!=p){
            dfs(it,v);
        }
    }

    return;
}

void dfs1(int v,int p){
    cou1++;

    for(auto it:g[v]){
        if (it!=p){
            dfs1(it,v);
        }
    }

    return;
}

void solve()
{
    cin >> n;

    FOR(i,1,n-1){
        int a,b;
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }

    dfs(1,1);

    int a = n;
    int cou = 2;

    while(cou<h[a]-1){
        cou++;
        a = par[a];
    }

    dfs1(a,par[a]);

    int cou2 = n-cou1;
    if (cou1>=cou2){
        cout << "Snuke";
    }else{
        cout << "Fennec";
    }

    return;
}

int32_t main()
{
    boost

    test=1;

    while(test--)
    {
        solve();
    }

  return 0;
}


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

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    int ca = 0, cb = 0, cc = 0;
    rep(i, n)
    {
        if (s[i] == 'a')
        {
            if (a + b > ca + cb)
            {
                cout << "Yes" << endl;
                ca++;
            }
            else
            {
                cout << "No" << endl;
                ca++;
            }
        }
        else if (s[i] == 'b')
        {

            if (a + b > ca + cb && b > cb)
            {
                cout << "Yes" << endl;
                cb++;
            }
            else
            {
                cout << "No" << endl;
            }
        }
        else if (s[i] == 'c')
        {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)


int main(){
	stack<ll> st;
	string s;
	getline(cin,s);
	ll i=0;
	while(i<s.size()){
		char c = s[i];
		if(c==' '){
			i++;
			continue;
		}
		if(c=='+'||c=='-'||c=='*'){
			ll x,y,z;
			x = st.top();
			st.pop();
			y = st.top();
			st.pop();
			if(c=='+')z = x+y;
			else if(c=='-')z=y-x;
			else z=x*y;
			st.push(z);
		}else{
			ll x = c - '0';
			while(s[i+1]<='9'&&s[i+1]>='0'){
				i++;
				x *= 10;
				x += s[i] - '0';
			}
			st.push(x);
		}
		i++;
	}
	cout<<st.top()<<endl;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e5 + 5;
int cnt[N], a[N];
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
 
    int n, q;
    cin >> n;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i]; 
        cnt[a[i]]++;
        sum += 1ll * a[i];
    }
    cin >> q;
    while (q--) {
        int b, c;
        cin >> b >> c;
        sum = sum - 1ll * cnt[b] * b + 1ll * cnt[b] * c;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << '\n';
    }
}

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

int main(){
    string s;
    cin>>s;
    string ans="No";
    for(ll i=0;i<s.size();++i){
        if(s[i]=='7'){
            ans="Yes";
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

int main() {
#ifdef LOCAL
  freopen("b.in", "r", stdin);
  freopen("b.out", "w", stdout);
#endif

  int n, k;
  while (scanf("%d%d", &n, &k) == 2) {
    vector<int> v(n);
    for (int& x : v) scanf("%d", &x);
    set<int> s;
    int ans = n - k + 1;
    for (int i = 0; i < k; i++) {
      s.insert(v[i]);
    }
    int sorted = 0;
    vector<bool> sorted_seg(n);
    if (k == 1) sorted_seg[0] = true;
    for (int i = 1; i < n; i++) {
      if (v[i] > v[i-1]) {
        sorted++;
      }
      if (i >= k && v[i - k + 1] > v[i - k]) {
        sorted--;
      }
      if (sorted == k - 1) sorted_seg[i] = true;
    }

    bool have_sorted = sorted_seg[k - 1];

    for (int i = k; i < n; i++) {
      s.insert(v[i]);
      if ((v[i] == *--s.end() && v[i - k] == *s.begin()) || (sorted_seg[i] && have_sorted)) ans--;
      have_sorted |= have_sorted || sorted_seg[i];
      s.erase(v[i - k]);
    }


#ifdef LOCAL
    set<vector<int>> ss;
    for (int i = k; i <= n; i++) {
      vector<int> u = v;
      sort(u.begin() + i - k, u.begin() + i);
//      for (int j = 0; j < n; j++) eprintf("%d ", u[j]);
      if (!ss.insert(u).second) {
//        eprintf("!!!!");
      }
//      eprintf("\n");
    }
//    eprintf("%d %d\n", n, k);
//    assert((int)ss.size() == ans);
#endif
    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 10368
while str = STDIN.gets
  n = str.split(" ")
  a = n[0].to_i
  b = n[1].to_i

  if a == 0 && b == 0
    break
  else
    for h in 1..a do
      for w in 1..b do
        print "#"
      end
      print "\n"
    end
  end
  print "\n"
end


Measured memory_bytes: 6868
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long int
int main()
{
  ll n;
  cin >> n;

  string ans = "";
  if(n == 0){cout << "0" << endl; return 0;}
  while(n != 0){
    if(n&1){
      --n;
      ans+="1";
      n /= -2;
    }
    else{
      ans+="0";
      n /= -2;    
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
package main

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

func main() {
	N := nextInt()
	K := nextInt()

	c := 0

	for i := 0; N != 0; i++ {
		c++
		N /= K
	}

	fmt.Println(c)
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


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

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

    uint64_t power = 1;
    uint64_t div = (uint64_t)pow(10, 9) + 7;
    for (auto i = 1; i <= n; i++) {
        power *= i;
        power %= div;
    }
    cout << power << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::collections::VecDeque;

const MOD: i64 = 1_000_000_007;
const INV2: i64 = MOD - MOD/2;

fn solve(g: &Vec<Vec<usize>>, pos: usize) -> VecDeque<(i64, i64)> {
    if g[pos].is_empty() {
        return VecDeque::from(vec![(INV2, INV2)]);
    }
    let mut update_idx = 0;
    let mut res = solve(g, g[pos][0]);
    for i in 1..g[pos].len() {
        let mut cur = solve(&g, g[pos][i]);
        if res.len() < cur.len() {
            update_idx = std::cmp::max(update_idx, res.len());
            for j in 0..res.len() {
                cur[j].1 = (cur[j].0 * res[j].1 + cur[j].1 * res[j].0) % MOD;
                cur[j].0 = cur[j].0 * res[j].0 % MOD;
            }
            res = cur;
        } else {
            update_idx = std::cmp::max(update_idx, cur.len());
            for j in 0..cur.len() {
                res[j].1 = (res[j].0 * cur[j].1 + res[j].1 * cur[j].0) % MOD;
                res[j].0 = res[j].0 * cur[j].0 % MOD;
            }
        }
    }
    for i in 0..update_idx { res[i].0 =  (1 + MOD - res[i].1) % MOD }
    res.push_front((INV2, INV2));
    return res;
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap() + 1;
    let mut g = vec![Vec::new(); n];
    for i in 1..n {
        let p = it.next().unwrap().parse::<usize>().unwrap();
        g[p].push(i);
    }
    let all = solve(&g, 0);
    let mut res = 0;
    for &t in &all { res = (res + t.1) % MOD }
    for _ in 0..n { res = 2 * res % MOD }
    println!("{}", res);
}


Measured memory_bytes: 73720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a%b);
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    ll a, b; cin >> a >> b;
    cout << a * b /gcd(a, b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;

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

int N;
vector<int> w;
vector<vector<int>> dp;

int rec(int l = 0, int r = N) {
    if ((r - l) <= 1) return 0;
    if ((r - l) == 2) {
        if (abs(w[l] - w[l + 1]) <= 1) {  // 隣り合う2つの差が1以下
            return 2;
        } else {
            return 0;
        }
    }
    int &ret = dp[l][r];
    if (ret != -1) return ret;  // 既に計算済みならその値を使う

    if (abs(w[l] - w[r-1]) <= 1 && rec(l + 1, r - 1) == r - l - 2) chmax(ret, r - l);
    for (int i = l + 1; i <= r - 1; i++) {
        chmax(ret, rec(l, i) + rec(i, r));
    }

    return ret;
}

int main() {
    vector<int> ans;
    while (true) {
        cin >> N;
        if (N == 0) break;
        w.resize(N);
        for (int i = 0; i < N; i++) {
            cin >> w.at(i);
        }

        dp.assign(N + 2, vector<int>(N + 2, -1));  // 初期化

        ans.push_back(rec());
    }

    for (auto i : ans) {
        cout << i << endl;
    }

    return 0;
}



Measured memory_bytes: 3264