akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

func main() {
	k, a, b := ScanInt(), ScanInt(), ScanInt()

	P(solve(k, a, b))

	close(O)
	oWg.Wait()
}
func solve(k, a, b int) string {
	for i := a; i <= b; i++ {
		if i%k == 0 {
			return "OK"
		}
	}
	return "NG"
}

/*********************** I/O ***********************/

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}


Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		{
			fh=-1;
			jp=getchar();
		}
	while (jp>='0'&&jp<='9')
		{
			out=out*10+jp-'0';
			jp=getchar();
		}
	return out*fh;
}
const int MAXN=1e6+10;
int cnt[MAXN],n,m;
struct Q{
	int p,y,id;
	char ans[20];
}q[MAXN];
int cmp1(const Q &x,const Q & y)
{
	return x.y<y.y;
}
int cmp2(const Q &x,const Q & y)
{
	return x.id<y.id;
}
int main()
{
  	//freopen(".in","r",stdin);
  	//freopen(".out","w",stdout);
  	n=read(),m=read();
  	for(int i=1;i<=m;++i)
  		{
  			q[i].p=read(),q[i].y=read();
  			q[i].id=i;
		}
	sort(q+1,q+1+m,cmp1);
	for(int i=1;i<=m;++i)
		{
			cnt[q[i].p]++;
			int th=cnt[q[i].p];
			int p1=q[i].p,x1=th;
			for(int j=5;j>=0;--j)
				{
					q[i].ans[j]=p1%10+'0';
					p1/=10;
				}
			for(int j=11;j>=6;--j)
				{
					q[i].ans[j]=x1%10+'0';
					x1/=10;
				}
		}
	sort(q+1,q+1+m,cmp2);
	for(int i=1;i<=m;++i)
		cout<<q[i].ans<<endl;
	return 0;
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a,b;
	cin >> a >> b;
	b.pop_back();
	if(a.compare(b)==0) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 3620
N, K = map(int, input().split())
MOD = 10 ** 9 + 7

def C(N, p):
  min_p = p * (p - 1) // 2
  max_p = p * (2 * N - p + 1) // 2
  return max_p - min_p + 1

ans = 0

for i in range(K, N + 2):
  ans += C(N, i) % MOD
  
print(ans % MOD)

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>
using namespace std;

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
#define MAX_V 100005

struct edge{
    int to;
    long long cost;
    edge(int i, long long j) {to = i, cost = j; };
};

class Dijkstra{
    public:
typedef pair<long long, int> P; // firstは最短距離、secondは頂点の番号

int V;
vector<edge> G[MAX_V];
long long d[MAX_V];
int pv[MAX_V];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, LLONG_MAX);
    fill(pv, pv + V, -1);
    d[s] = 0;
    que.push(P(0,s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first ) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost ) {
                d[e.to] = d[v] + e.cost;
                pv[e.to] = v;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

vector<int> get_path(int t){
    vector<int> path;
    for(; t != -1; t = pv[t]) path.push_back(t);
    reverse(path.begin(), path.end());
    return path;
}

};



int main() {

    ll money = 1000000000000000LL;

    int n, m, s, t; cin >> n >> m >> s >> t;
    s--; t--;

    vi u(m), v(m);
    vll a(m), b(m);

    Dijkstra yen, snuuke;
    yen.V = n;
    snuuke.V = n;

    REP(i, m) {
        cin >> u[i] >> v[i] >> a[i] >> b[i];
        u[i]--;
        v[i]--;

        yen.G[u[i]].push_back(edge(v[i], a[i]));
        yen.G[v[i]].push_back(edge(u[i], a[i]));
        snuuke.G[u[i]].push_back(edge(v[i], b[i]));
        snuuke.G[v[i]].push_back(edge(u[i], b[i]));
    }

    yen.dijkstra(s);
    snuuke.dijkstra(t);

    vector<pair<ll, int>> ryogae(n);
    REP(i, n) {
        ryogae[i] = make_pair(yen.d[i] + snuuke.d[i], i);
    }

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

    int j = 0;
    REP(i, n) {
        while (ryogae[j].second < i) j++;
        cout << money - ryogae[j].first << endl;
    }

    return 0;
}


Measured memory_bytes: 23036
#include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
#include<stack>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int main(void){
  ll L;
  while(cin>>L,L){
    bool ans = false;
    ll sum = 0 ;
    for(int i = 0 ; i < 12 ; i ++){
      ll M,N;
      cin>>M>>N;
      sum += M - N;
      if(sum >= L && !ans){
	ans = true;
	cout<<i+1<<endl;
      }
    }
    if(!ans)cout<<"NA"<<endl;
  }

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

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;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  int N,K;cin>>N>>K;vi D(K);rep(i,K)cin>>D[i]; 
  for(int i=N; i<100000;i++){
    int num=i;
    bool ok=true;
    while(num>0){
       rep(j,K){
         if(D[j] ==num%10)ok=false;
       }
      num /=10;
    }
    if(ok){
      cout<<i<<endl;
      break;
    }
  }
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i<b; i++)
#define dep(i,a,b) for(int i = a-1; i>=b; i--)
#define makeUnique(vec) sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin())
#define LOG_vec(vec, sep) for (int fl = 0; fl < vec.size(); fl++) { cout << vec[fl]<< sep; } cout << "\n";
#define LOG_ints(vec, sep) for (int fl = 0; fl < MAXSIZE; fl++) { cout << vec[fl]<< sep; } cout << "\n"
#define all(x) (x).begin(), (x).end()
#define ll long long
#define LSB(i) ((i) & -(i))
#define vvi vector<vector<int>>
#define vi vector<int>
#define MAXSIZE 100000000
using namespace std;

int main(){

	string s1;
	cin >> s1;
	cout << (s1[2] == s1[3] && s1[4] == s1[5] ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int A, B;
    char c;
    int ctr = 0;
    
    
    scanf("%d%c%d%c", &A, &c, &B, &c);
    
    
    B -= 1;
    
    while(B > 0)
    {
        B += 1;
        B -= A;
        
        ctr++;
    }
    
    
    printf("%d\n", ctr);
    
    
    //system("pause");
    
    return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> h(N);
  rep(i,N){
    cin >> h[i];
  }
  
  int ans=0;
  int active=0;
  rep(i,N){
    if(active>=h[i]){
      active=h[i];
    }else{
      ans += h[i]-active;
      active = h[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
data = {
        'S': [int(x) for x in range(1,14)],
        'H': [int(x) for x in range(1,14)],
        'C': [int(x) for x in range(1,14)],
        'D': [int(x) for x in range(1,14)]
        }
 
count = int(input())
 
for c in range(count):
    (s, r) = input().split()
    r = int(r)
 
    del data[s][data[s].index(r)]
 
 
for i in ('S', 'H', 'C', 'D'):
    for v in data[i]:
        print(i, v)

Measured memory_bytes: 6724
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n, k, q;
    cin >> n >> k >> q;
    vll a(n);
    rep(i, n) cin >> a[i];
    ll ans = INFL;
    vll b = a;
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    for(int i = 0; i < b.size(); ++i) {
        vll sel, tmp;
        for(int j = 0; j < n; ++j) {
            if(a[j] >= b[i]) {
                tmp.push_back(a[j]);
                continue;
            }
            sort(tmp.begin(), tmp.end());
            for(int l = 0; l + k <= tmp.size(); ++l) sel.push_back(tmp[l]);
            tmp.clear();
        }
        if(tmp.size() > 0) {
            sort(tmp.begin(), tmp.end());
            for(int l = 0; l + k <= tmp.size(); ++l) sel.push_back(tmp[l]);
        }
        if(sel.size() < q) continue;
        sort(sel.begin(), sel.end());
        chmin(ans, sel[q-1] - sel[0]);
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

int main () {

    int N, M;

    scanf("%d %d", &N, &M);

    ll x[N], y[N], z[N];

    for (int i = 0; i < N; i++) {
        scanf("%lld %lld %lld", &x[i], &y[i], &z[i]);
    }

    ll ans = LONG_MIN;

    for (int i = 0; i < (1 << 3); i++) {

        ll array[N];

        for (int j = 0; j < N; j++) {

            ll value = 0LL;

            if (i >> 0 & 1) value += x[j]; else value -= x[j];
            if (i >> 1 & 1) value += y[j]; else value -= y[j];
            if (i >> 2 & 1) value += z[j]; else value -= z[j];

            array[j] = value;
        }

        sort(array, array + N, greater<ll>());

        ll gain = 0;

        for (int j = 0; j < M; j++) {
            gain += array[j];
        }
        
        ans = max(ans, gain);
    }

    printf("%lld\n", ans);

    return 0;
}

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

using namespace std;

#define int long long

const int MOD = 1e9 + 7;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i; j++) {
            if (A[j] > A[i]) {
                ans += K;
                ans %= MOD;
            }
        }
        for (int j = 0; j < N; j++) {
            if (A[j] > A[i]) {
                ans += K * (K - 1) / 2 % MOD;
                ans %= MOD;
            }
        }
    }
    cout << ans;
    return 0;
}


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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
char a[5]="PWGY";
int  vis[5];
char s[6][6]={"One","Two","Three","Four"};
int main()
{
     int ans=0,n;
     cin>>n;
     for(int i=1;i<=n;i++)
     {
     	char ch;
     	cin>>ch;
     	for(int j=0;j<4;j++)
     	{
     		if(ch==a[j]&&vis[j]==0)
     		{
     			vis[j]=1;
     			ans++;
     		
     		}
     	}
     }
     cout<<s[ans-1];
	 return 0;
}

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

int main(){
  int n;
  cin>>n;
  
  map<int,int> memo;
  
  rep(i,0,n){
    int tmp;
    cin>>tmp;
    if(memo[tmp]==0){memo[tmp]++;}
    else{memo[tmp]--;}
  }
  
  int ans=0;
  for(auto x:memo){ans += x.second;}
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using std::cout;
using std::cin;
using std::endl;

std::vector<std::string> split(const std::string &str, char sep)
{
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

int Stoi(const std::string &str)
{
    int num=0, i=0;
    std::string s = str;
    while (i<s.size())
    {
        if (s[i]<'0'||s[i]>'9')
            break;
        num = num * 10 + (str[i] - '0');
        i++;
    }

    return num;
}

std::string replace(const std::string &str1, int a, int b, const std::string &str2)
{
    std::string s1, s2;
    s1 = str1; s2 = str2;

    s1 = s1.erase(a, b-a+1);
    //cout << s1 << endl;
    s1 = s1.insert(a, s2);
    //cout << s1 << endl;
    return s1;
}

int main(){
    int a, b, count=1;
    long long n;
    std::string str, line, doubt, s;
    cin >> str;
    cin >> n;
    std::getline(cin, doubt);

    std::vector<std::string> Priope, v;
    std::vector<int> num(n);


    for (int i = 0; i < n; i++)
    {
        std::getline(cin, line);
        v = split(line, ' ');

        a = Stoi(v[1]); b = Stoi(v[2]);
        
        if (v[0] == "print")
        {
            s = str.substr(a, b-a+1);
            Priope.push_back(s);
            num.push_back(i);
            //cout << s << endl;
        }
        else if (v[0] == "reverse")
            {std::reverse(str.begin()+a, str.begin()+b+1); }//cout << str << endl;}
        else if(v[0] == "replace")
            str = replace(str, a, b, v[3]);
        else
        {
            cout << "Wrong Command:" << v[0] << endl;
            i--;
        }
         
    }
/*
    for (int i = 0; i < num.size(); i++)
        cout << Priope(i) << endl;
*/
    std::vector<std::string>::iterator itr;
    itr = Priope.begin();
    while (itr != Priope.end())
    {
        cout << *itr << endl;
        itr++;
    }
        
    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 1;

char s[N];
int ans;

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


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

using namespace std;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

unordered_set<string> vis;

int main(){

    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("input.txt", "r", stdin);

    int n;
    string s, t;

    cin >> n >> s >> t;

    for(int i = 0; i < n; ++i){
        vis.insert(s.substr(i));
    }

    int best = 0;

    for(int i = 1; i <= n; ++i){
        if(vis.find(t.substr(0, i)) != vis.end()){
            best = i;
        }
    }

    cout << 2 * n - best;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
static const int MAX = 100;

// 各計算ステップで1つの最小値を「選択」していく

void printLine (int A[], int N) {
    for (int i = 0; i < N; i++) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n");
}

int selectionSort(int A[], int N, int idx, int acc) {
    int min = -1;
    int minIdx = -1;
    for (int i = idx; i < N; i++) {
        if (i == idx) {
            min = A[i];
            continue;
        }
        int right = A[i];
        if (right < min) {
            min = right;
            minIdx = i;
        }
    }
    
    int cnt = 0;
    if (minIdx > -1 && minIdx != idx) {
        int v = A[idx];
        A[idx] = min;
        A[minIdx] = v;
        cnt = 1;
    }
    
    idx++;
    if (idx < N-1) {
        cnt = selectionSort(A, N, idx, cnt);
    }
    return acc + cnt;
}

int main() {
    int N;
    scanf("%d", &N);
    
    int A[MAX];
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    int r = selectionSort(A, N, 0, 0);
    printLine(A, N);
    printf("%d\n", r);
   
    return 0;
}



Measured memory_bytes: 3204
#include <cstdio>
#include <utility>
#include <vector>
#include <complex>
#include <cmath>

using namespace std;

static const double EPS=1e-12;
static const double INF=1e24;

using Point=complex<double>;
using Plane=vector<Point>;

bool operator<(const Point &a, const Point &b) {
    return real(a)!=real(b)? real(a)<real(b) : imag(a)<imag(b);
}

double cross_prod(const Point &a, const Point &b) {
    return imag(conj(a)*b);
}

double dot_prod(const Point &a, const Point &b) {
    return real(conj(a)*b);
}

struct Line: public vector<Point> {
    Line() {}
    Line(const Point &a, const Point &b) {
        push_back(a);
        push_back(b);
    }
};

struct Circle {
    Point p;
    double r;
    Circle() {}
    Circle(const Point &p, const double r): p(p), r(r) {}
};

enum {
    ONLINE_FRONT=-2,
    CLOCKWISE,
    ON_SEGMENT,
    COUNTER_CLOCKWISE,
    ONLINE_BACK,
};    

int ccwise(Point a, Point b, Point c) {
    b -= a; c -= a;

    if (cross_prod(b, c) > 0) {
        return COUNTER_CLOCKWISE;
    } else if (cross_prod(b, c) < 0) {
        return CLOCKWISE;
    } else if (dot_prod(b, c) < 0) {
        return ONLINE_BACK;
    } else if (norm(b) < norm(c)) {
        return ONLINE_FRONT;
    } else {
        return ON_SEGMENT;
    }
}

int main() {
    double x, y;
    scanf("%lf %lf", &x, &y);
    Point p0(x, y);

    scanf("%lf %lf", &x, &y);
    Point p1(x, y);

    size_t q;
    scanf("%zu", &q);
    for (size_t i=0; i<q; ++i) {
        double x, y;
        scanf("%lf %lf", &x, &y);
        Point p2(x, y);

        int state=ccwise(p0, p1, p2);
        if (state == ONLINE_FRONT) {
            printf("ONLINE_FRONT\n");
        } else if (state == CLOCKWISE) {
            printf("CLOCKWISE\n");
        } else if (state == ON_SEGMENT) {
            printf("ON_SEGMENT\n");
        } else if (state == COUNTER_CLOCKWISE) {
            printf("COUNTER_CLOCKWISE\n");
        } else if (state == ONLINE_BACK) {
            printf("ONLINE_BACK\n");
        }
    }

    return 0;
}

Measured memory_bytes: 2724
/*
	
	????¨??????§?°???????????????????????????????????°??????????????????°?????????????????°?????????????±??????????
	??????x1??¨y1???????????§?????????????????´??????x2(>x1)??¨??????????????????y2???y2>y1???????????????x1+y1<x2+y2??¨??????????????§?????????
*/

#include<stdio.h>

int Main();

int main(int argc, char *argv[]){
	while( Main() == 0 );
	return 0;
}

int Main(){
	int n = 0, m = 0, st = 0, sh = 0, *card[2], *num[2], d = 0, i = 0, j = 0, k = 0;	//????????¨??±???????????????????????°??????????????????????????????????¨???????????????¨?????°????????°?????????????????????(0???????¨?????°??????????)???????¨??????????
	if( scanf("%d %d", &n, &m) != 2 ){ return -1; }
	if( n == 0 && m == 0 ){ return 1; }
	int taro[n], hana[m];
	//??????????????\??????
	for( i = 0; i < n; i++ ){
		if( scanf("%d", &taro[i]) != 1 ){ return -1; }
		st += taro[i];
	}
	for( i = 0; i < m; i++ ){
		if( scanf("%d", &hana[i]) != 1 ){ return -1; }
		sh += hana[i];
	}
	if( st <= sh ){
		card[0] = taro;
		card[1] = hana;
		num[0] = &n;
		num[1] = &m;
		d = sh - st;
	}else{
		card[0] = hana;
		card[1] = taro;
		num[0] = &m;
		num[1] = &n;
		d = st - sh;
	}
	//????¨???????????\???°???????????¶??????????????????????????¨????????????
	if( d % 2 == 1 ){
		printf("-1\n");
		return 0;
	}
	//?????????????°???????????????????????????????
	for( i = 0; i < 2; i++ ){
		for( j = 0; j < *num[i] - 1; j++ ){
			for( k = j + 1; k < *num[i]; k++ ){
				if( card[i][j] > card[i][k] ){
					int t = card[i][j];
					card[i][j] = card[i][k];
					card[i][k] = t;
				}
			}
		}
	}
	//????¨?????°??????????????????????????????????????????????
	for( i = 0; i < *num[0]; i++ ){
		for( j = 0; j < *num[1]; j++ ){
			if( card[1][j] - card[0][i] == d / 2 ){
				//??????????????????????????????????????§???????????§????????????????????????????????????????????????????????????????????????
				printf("%d %d\n", card[(st<=sh?0:1)][(st<=sh?i:j)], card[(st<=sh?1:0)][(st<=sh?j:i)]);
				return 0;
			}else if( card[1][j] - card[0][i] > d ){
				break;
			}
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 612
from collections import deque, Counter

INF = float("inf")

N, X, Y = map(int, input().split())

E = [[] for _ in range(N + 1)]
for i in range(1, N):
    E[i].append(i + 1)
    E[i + 1].append(i)
E[X].append(Y)
E[Y].append(X)

C = Counter()
for s in range(1, N + 1):
    dist = [INF] * (N + 1)
    dist[s] = 0
    Q = deque([s])
    while Q:
        p = Q.popleft()
        for c in E[p]:
            if dist[c] > dist[p] + 1:
                dist[c] = dist[p] + 1
                Q.append(c)
    C.update(dist)

for k in range(1, N):
    print(C[k] // 2)

Measured memory_bytes: 54364
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7
N = 10**6 +1


# def seive():
#     for i in range(2*2,N+1,2):
#         prime[i] = False
#     # for j in range(divceil(l,2)*2 ,r+1,2):
#     #         divisor[j-l].append(2)
    
#     p= 3
#     while(p*p <= N):
#         if prime[p]:
#             for i in range(p*p,N+1,p):
#                 prime[i]  = False
#             # for j in range(divceil(l,p)*p ,r+1,p):
#             #     # if j == 18:
#             #     #     print("fs")
#             #     divisor[j-l].append(p)
#         p+=2

def solve(cnt):
    val = (-1+sqrt(1+8*cnt))/2
    return floor(val)


# prime = [True]*(N+1)
n = int(ri())

ans = 0
if n == 1:
    print(0)
else:
    p = 2
    while p*p <= n:
        cnt = 0
        while(n%p == 0):
            cnt+=1
            n= n//p
        if cnt != 0:
            # print(p)
            ans+=solve(cnt)
        p+=1
    if n != 1:
        ans +=1

    print(ans)



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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	ll a, b, d;
	while (true) {
		cin >> a >> b >> d;
		if (a == 0 && b == 0 && d == 0) break;
		ll x = INF, y = INF;
		for (int i = -100000; i < 100000; i++) {
			if ((d - a*i) % b == 0) {
				ll xtmp = abs(i), ytmp = abs((d - a*i) / b);
				if (x + y >= xtmp + ytmp && a*x + b*y >= a*xtmp + b*ytmp) {
					x = xtmp; y = ytmp;
				}
			}
		}
		cout << x << " " << y << endl;
	}
}

Measured memory_bytes: 3008
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define ll long long int
int main(){
  ll n,k;
  cin>>n>>k;
  vector<double>a(n);
  vector<double>v(n);
  for(ll i=0;i<n;i++){
    cin>>v[i];
    a[i]=(v[i]+1)/2;
  }
  //for(ll i=0;i<n;i++)
    //cout<<a[i]<<" ";
  double sum=0,ans=0;
  for(ll i=0;i<n;i++){
    sum+=a[i];
    if(i>=k)
      sum-=a[i-k];
    ans=max(ans,sum);
  }
  cout<<setprecision(6)<<fixed<<ans;
  return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  string color;
  cin >> N;
  int counter = 0;
  
  for(int i = 0; i < N ; i++){
    cin >> color;
  
    if(color == "Y"){
      counter  += 1;
    }
  }
  
  if(counter != 0){
    cout << "Four" << endl;
  }
  else{
    cout << "Three" << endl;
  }
  
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,Z,W,a[2001];
  cin >> N >> Z >> W;
  REP(i,N)cin >> a[i];
  
  cout << (max(abs(a[N-1]-W),abs(a[N-2]-a[N-1]))) << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


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


int main()
{
    int N;
    cin >> N;
    vector<int> vec(N);

	for(int i = 0; i < N; i++) {
      cin >> vec.at(i);
    }
  
  for(int i = 0; i < N; i ++) cin >> vec.at(i);
      sort(vec.begin(), vec.end());

    int count = 0;
    
    for(int i = 0; i < N-1; i++){
        if(vec.at(i) == vec.at(i + 1)){
            count ++;
        }
    }


    cout << N - count << endl;






    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back

#define START 0
#define GOAL 1

#define int ll

signed main(){
    ll t,n;
    cin>>t>>n;
    set<ll> st;
    vector<pll> data;
    rep(i,n){
        ll s,t;
        cin>>s>>t;
        data.pb(pll(s,START));
        data.pb(pll(t,GOAL));
    }
    
    sort(all(data));
    map<ll,int> zip;
    map<int,ll> unzip;
    
    rep(i,data.size()){
        zip[data[i].first] = i;
        unzip[i] = data[i].first;
    }
    
    static ll rui[1000000];
    rep(i,1000000)rui[i] = 0;
    
    for(int i=0;i<data.size();i+=2){
        assert(data[i].second==START);
        rui[i+1] = data[i+1].first - data[i].first;
    }
    
    ll ans = 0;
    
    rep(i,1000000-1)rui[i+1] += rui[i];
    
    for(int i=0;i<data.size();i+=2){
        assert(data[i].second==START);
        
        ll end_time = data[i].first + t;
        
        int pos = upper_bound( all(data) , pll(end_time,-1) )-1-data.begin();
        
        
        
        if(pos==-1){
            cout<<0<<endl;  //???
        }else if(data[pos].second==START){
            int r = rui[pos] - rui[i];
//            cout<<r<<endl;
            ans = max(ans,r+(end_time - data[pos].first));
        }else if(data[pos].second==GOAL){
            int r = rui[pos]-rui[i];
//            cout<<r<<endl;
            ans = max(ans,r);
        }
        
    }
    cout<<ans<<endl;
    
    
    
    
}

Measured memory_bytes: 38676
#include <iostream>

using namespace std;

static const int N = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, m[N][N];

int prim()
{
	int d[N], p[N], color[N];

	for (int i = 0; i < n; ++i)
	{
		d[i] = INFTY;
		p[i] = -1;
		color[i] = WHITE;
	}

	d[0] = 0;

	while (1)
	{
		int u = -1;
		int minv = INFTY;
		for (int i = 0; i < n; ++i)
		{
			if (minv > d[i] && color[i] != BLACK)
			{
				minv = d[i];
				u = i;
			}
		}

		if (u == -1) break;
		color[u] = BLACK;

		for (int v = 0; v < n; ++v)
		{
			if (m[u][v] != INFTY && color[v] != BLACK && m[u][v] < d[v])
			{
				d[v] = m[u][v];
				p[v] = u;
				color[v] = GRAY;
			}
		}
	}

	int s = 0;
	for (int i = 0; i < n; ++i)
	{
		if (p[i] != -1) s += m[p[i]][i];
	}

	return s;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			int e; cin >> e;
			m[i][j] = (e == -1) ? INFTY : e;
		}
	}

	cout << prim() << endl;
	return 0;
}

Measured memory_bytes: 3124
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    string s;
    cin>>s;
    if(s=="AKIHABARA")cout<<"YES"<<endl;
    else if(s=="KIHARABA")cout<<"YES"<<endl;
    else if(s=="AKIHBARA")cout<<"YES"<<endl;
    else if(s=="AKIHABRA")cout<<"YES"<<endl;
    else if(s=="AKIHABAR")cout<<"YES"<<endl;
    else if(s=="KIHBARA")cout<<"YES"<<endl;
    else if(s=="KIHABRA")cout<<"YES"<<endl;
    else if(s=="KIHABAR")cout<<"YES"<<endl;
    else if(s=="AKIHBRA")cout<<"YES"<<endl;
    else if(s=="AKIHBAR")cout<<"YES"<<endl;
    else if(s=="AKIHABR")cout<<"YES"<<endl;
    else if(s=="KIHBRA")cout<<"YES"<<endl;
    else if(s=="KIHBAR")cout<<"YES"<<endl;
    else if(s=="KIHABR")cout<<"YES"<<endl;
    else if(s=="AKIHBR")cout<<"YES"<<endl;
    else if(s=="KIHBR")cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>

using namespace std;

int main()
{
    int W,H,x,y,r;
     cin>>W>>H>>x>>y>>r;
     if((x+r)>W||(x-r)<0||(y+r)>H||(y-r)<0||x<0||y<0)
        cout<<"No"<<endl;
     else
        cout<<"Yes"<<endl;
     return 0;
}




Measured memory_bytes: 3116
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;

int main(){
    ll n;
    cin >> n;
    map<ll,ll> m;
    rep(i,n){
        ll a;
        cin >> a;
        if(m[a]){
            m[a]--;
        }
        else{
            m[a]++;
        }
    }
    ll ans=0;
    for(auto x:m){
        ans+=x.se;
    }
    cout << ans << endl;
}

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

int main() {
  int k; cin >> k;
  vector<int> nums = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << nums.at(k-1);
}

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

int main() {

    string S;
    cin >> S;

    int N = S.length();
    for (int i = 0; i < ceil(N/2.0); ++i) {
        // cout << i << " " << N-i-1 << endl;
        if (S[i] != S[N-i-1]) {
            cout << "No" << endl;
            return 0;
        }
    }

    string A = S.substr(0, (N-1)/2);
    string B = S.substr((N+1)/2, (N-1)/2);

    for (string s : {A, B}) {
        int n = s.length();
        for (int i = 0; i < ceil(n/2.0); ++i) {
            // cout << i << " " << n-i-1 << endl;
            if (S[i] != S[n-i-1]) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
List = list(map(int,input().split()))
result = [(1+i)/2 for i in List]
Answer = 0
if N == 1:
  print(result[0])
  exit()
elif N == K:
  print(sum(result))
  exit()
base = [sum(result[0:K])]
for i in range(N-K):
  counter = base[i]-result[i]+result[i+K]
  if counter > Answer:
    Answer = counter
  base.append(counter)
print(Answer)

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef queue<int> qi;

int main(){
    ll a,b,c,ans=0;
    cin >> a >> b >> c;
    if(a==b&&b==c&&a%2==0){
        cout << -1 << endl;
        return 0;
    }
    while(a%2==0&&b%2==0&&c%2==0){
        ll A=a,B=b,C=c;
        a=B/2+C/2;
        b=A/2+C/2;
        c=A/2+B/2;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */
int main() {
    int h,m;
    cin>>h>>m;
    char s[55][55]; //迷路
    int dist[55][55]; //距離
    rep(i,h)rep(j,m){
        cin>>s[i][j];
        dist[i][j]=-1;
    }
    int f[]={1,0,-1,0},g[]={0,1,0,-1}; //移動方向４通り
    dist[0][0]=0;
    queue<P> que;
    que.push(make_pair(0,0));
    int x,y;
    while(!que.empty()){
        P p=que.front();
        que.pop();
        rep(i,4){
            x=p.first+f[i],y=p.second+g[i];
            if(x<0||x>=h||y<0||y>=m)continue;
            if(dist[x][y]==-1&&s[x][y]=='.'){
                dist[x][y]=dist[p.first][p.second]+1;
                que.push(make_pair(x,y));
            }
        }
    }
    if(dist[h-1][m-1]==-1){
        cout<<-1<<endl;
        return 0;
    }
    int ans=h*m-dist[h-1][m-1]-1;
    rep(i,h)rep(j,m)if(s[i][j]=='#')ans--;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
///Nahid Hasan Raju
#include <bits/stdc++.h>

#define MS(ARRAY,VALUE) memset(ARRAY,VALUE,sizeof(ARRAY))
#define Fin freopen("input.txt","r",stdin)
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define Fout freopen("output.txt","w",stdout)
#define rep(i,a,b) for(i=a;i<=b;i++)
#define EPS 0.00000001
#define INF INT_MAX
#define PI 2*acos(0.0)
#define P1(XX) cout<<"db1: "<<XX<<endl
#define P2(XX,YY) cout<<"db2: "<<XX<<" "<<YY<<endl
#define P3(XX,YY,ZZ) cout<<"db3: "<<XX<<" "<<YY<<" "<<ZZ<<endl
#define set(XX,POS) XX|=(1<<POS)
#define reset(XX,POS) XX&=(~(1<<POS))
#define check(XX,POS) (bool)(XX&(1<<POS))
#define toggle(XX,POS) (XX^(1<<POS))
#define SORT(v) sort(v.begin(),v.end())
#define REVERSE(V) reverse(v.begin(),v.end())
#define VALID(X,Y,R,C) X>=0 && X<R && Y>=0 && Y<C
#define SIZE(ARRAY) sizeof(ARRAY)/sizeof(ARRAY[0])
#define RT printf("Run Time : %0.3lf seconds\n", clock()/(CLOCKS_PER_SEC*1.0))
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>


using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree< pair<int,int> , null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> odrst;

#define MOD 1000000007LL
#define MX 200005


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

ll m, n;
ll a[MX];
map<ll,int>mp;
int main()
{
    int test, tc=0, i, j;
    ll q,b,c,ans=0,s=0;
    //scanf("%d", &test);
    test=1;
    while(test--)
    {
       cin>>n;
       for(i=0;i<n;i++){
            scanf("%lld", &a[i]);
            mp[a[i]]++;
            ans+=a[i];
       }
       cin>>q;
       for(i=0;i<q;i++){
            scanf("%lld %lld", &b, &c);
            mp[c]+=mp[b];
            ans+=(mp[b]*(c-b));
            cout<<ans<<endl;
            mp[b]=0;
       }

       //cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 10364
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

class mint {
public:
    long long x;
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    //mint operator-() const{ return mint(-x);}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

};

ll gcd(ll x, ll y){
  if (y == 0) return x;
  return gcd(y, x % y);
}
int main(){
  int N; cin >> N;
  int zero = 0;
  map<pair<ll, ll>, P> mp;
  rep(i, N){
    ll x, y; cin >> x >> y;
    if (x == 0 && y == 0) {
      zero++;
      continue;
    }
    ll g = gcd(x, y);
    x /= g;
    y /= g;
    if (y < 0) x = -x, y = -y;
    if (y == 0 && x < 0) x = -x, y = -y;
    bool rot90 = (x <= 0);
    if (rot90) {
      ll tmp = x;
      x = y, y = -tmp;
    }
    if (rot90) mp[{x, y}].first++;
    else mp[{x, y}].second++;
  }

  mint ans = 1;
  for (auto p : mp){
    int s = p.second.first;
    int t = p.second.second;
    mint now = 1;
    now += mint(2).pow(s) - 1;
    now += mint(2).pow(t) - 1;
    ans *= now;
  }
  ans -= 1;
  ans += zero;
  cout << ans.x << endl;
}


Measured memory_bytes: 19024
n = input()
s = input()
# n：スライムの数
# s：スライムの色情報

# 最終的に存在するスライムの数を答える
judge_str = s[0]
ans=1
for i in s:
    if i != judge_str:
        ans+=1
        judge_str = i
print(ans)

Measured memory_bytes: 9136
#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int main()
{
	int a, b; scanf("%d%d", &a, &b);
	int ans = 0;
	ans = max(2*a - 1, max(2*b - 1, a + b));
	printf("%d", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n;
bool rev = false;

bool query(vector<int> &a){
    cout << "?";
    rep(i, 0, n){
        cout << " " << a[i] + 1;
    }
    cout << endl;
    string t;
    cin >> t;
    bool res = (t == "Red" ? 0 : 1);
    if(rev) res = !res;
    return res;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<char> ans(2 * n);
    int l = 0, r = n;
    vector<int> a(n);
    {
        rep(i, 0, n) a[i] = i;
        bool tmp = query(a);
        if(tmp) rev = true;
        while(r - l > 1){
            int mid = (l + r) / 2;
            rep(i, 0, n) a[i] = mid + i;
            if(query(a)) r = mid;
            else l = mid;
        }
        ans[l] = 'R';
        ans[l + n] = 'B';
    }
    rep(i, 0, n) a[i] = l + i;
    for(int i = 0; i < l; i++){
        a[0] = i;
        if(query(a)) ans[i] = 'B';
        else ans[i] = 'R';
    }
    for(int i = l + n + 1; i < 2 * n; i++){
        a[0] = i;
        if(query(a)) ans[i] = 'B';
        else ans[i] = 'R';
    }
    a.clear();
    rep(i, 0, l) a.push_back(i);
    rep(i, l + n + 1, 2 * n) a.push_back(i);
    for(int i = l + 1; i < l + n; i++){
        a.push_back(i);
        if(query(a)) ans[i] = 'B';
        else ans[i] = 'R';
        a.pop_back();
    }
    if(rev){
        rep(i, 0, 2 * n){
            if(ans[i] == 'R') ans[i] = 'B';
            else ans[i] = 'R';
        }
    }
    cout << "! ";
    rep(i, 0, 2 * n) cout << ans[i];
    cout << endl;
}

Measured memory_bytes: 724