akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }



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

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  ll q;
  cin >> q;
  vector<ll> b(q), c(q);
  rep(i, 0, q) cin >> b[i] >> c[i];

  map<ll, ll> mp;
  rep(i, 0, n) mp[a[i]]++;

  ll sum = 0;
  rep(i, 0, n) sum += a[i];

  rep(i, 0, q){
    ll before = mp[b[i]] * b[i];
    mp[c[i]] += mp[b[i]];
    ll after = mp[b[i]] * c[i];
    mp[b[i]] = 0;

    //cout << before << ' ' << after << endl;
    sum += after - before;
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 11700
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	s1 := string([]rune(s)[0:len(s)/2])
	s2 := string([]rune(s)[(len(s)+1)/2:len(s)])

	s1s := strings.Split(s1,"")
	s2s := strings.Split(s2,"")

	count := 0
	for i := 0; i < len(s1s); i ++ {
		if s1s[i] != s2s[len(s2s)-1 -i] {
			count ++
		}
	}

	fmt.Println(count)
}

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

bool isVacantRange(int i, string s, pair<int, string> LR) {
    if((i - LR.first)%2 == 0) {
        if(s == LR.second) return false;
        else return true;
    } else {
        if(s != LR.second) return false;
        else return true; 
    }
}

int main() { 
    int n;
    cin >> n;
    pair<int, string> L = {0, ""}, R = {n-1, ""};
    cout << L.first << endl;
    cin >> L.second;
    if(L.second == "Vacant") return 0;
    cout << R.first << endl;
    cin >> R.second;
    if(R.second == "Vacant") return 0;
    string s;
    while(1) {
        int i = (R.first + L.first)/2;
        cout << i << endl;
        cin >> s;
        if(s == "Vacant") return 0;
        if(isVacantRange(i, s, L)) {
            R = make_pair(i, s);
        } else {
            L = make_pair(i, s);
        }
    }

    return 0;
}


Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <string>
#define INF (INT_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  string s;
  cin >> s;

  int n = s.length();

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

  if(m == INF) cout << n << endl;
  else cout << m << endl;

  return 0;
}


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

static const int MAX = 8;
static const int INF = 1e5;
int n, a, b, c, L[MAX], ans;

int rec(int cur, int rec_a, int rec_b, int rec_c) {
    int tmp_a, tmp_b, tmp_c, tmp_d;

    if ( cur == n ) {
        if ( rec_a > 0 and rec_b > 0 and rec_c > 0) {
            return abs(rec_a - a) + abs(rec_b - b) + abs(rec_c - c) - 30;
        } else {
            return INF;
        }
    }

    tmp_a = rec(cur+1, rec_a, rec_b, rec_c);
    tmp_b = rec(cur+1, rec_a+L[cur], rec_b, rec_c) + 10;
    tmp_c = rec(cur+1, rec_a, rec_b+L[cur], rec_c) + 10;
    tmp_d = rec(cur+1, rec_a, rec_b, rec_c+L[cur]) + 10;
    ans = min(tmp_a, tmp_b);
    ans = min(ans, tmp_c);
    ans = min(ans, tmp_d);
    return ans;
}

int main() {
    scanf("%d %d %d %d", &n, &a, &b, &c);
    
    for ( int i = 0; i < n; i++ ) {
        scanf("%d", &L[i]);
    }
    
    ans = INF;
    rec(0, 0, 0, 0);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int K = scan.nextInt();
		int A = scan.nextInt();
		int B = scan.nextInt();

		if(A / K == B / K) {
			if(A % K == 0) {
				System.out.println("OK");
			}else {
				System.out.println("NG");
			}
		}else {
			System.out.println("OK");
		}

	}
}

Measured memory_bytes: 27020
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli N;
	cin >> N;
/*
	if (N % 3 == 0) {
		lli type = N / 3;
		std::map<lli, lli> m;
		for (lli i = 0; i < N; i++) {
			lli a;
			cin >> a;
			m[a]++;
		}
		for (auto itr = m.begin(); itr != m.end(); itr++) {
			if (itr->second % type != 0) {
				COUT("No");
				return 0;
			}
		}

		COUT("Yes");

	}
	else {
		for (lli i = 0; i < N; i++) {
			lli a;
			cin >> a;
			if (a != 0) {
				COUT("No");
				return 0;
			}
		}
		COUT("Yes");

	}
	*/

	std::map<lli, lli> m;
	for (lli i = 0; i < N; i++) {
		lli a;
		cin >> a;
		m[a]++;
	}

	lli a = m.begin()->first;
	lli b = (--m.end())->first;

	m.begin()->second--;
	(--m.end())->second--;

	for (int i = 0; i < N - 2; i++) {
		if (m[a xor b] > 0) {
			m[a xor b]--;
			lli t = a xor b;
			a = b;
			b = t;
		}
		else {
			COUT("No");
			return 0;
		}
	}

	COUT("Yes");

	return 0;
}

Measured memory_bytes: 5120
#include <stdio.h>
#include <math.h>
int main()
{
    int i ,h ,m ,num;
    double l ,s ,d;
    scanf("%d",&num);
    for(i=0;i<num;i++){
        scanf("%d:%d",&h ,&m);
        l = h * 30 + m * 0.5;
        s = m * 6;
        d = fabs(l - s);
        if(d > 180){
            d = 360 - d;
        }
        
        if(90<=d&&d<=180){
            puts("safe");
        }else if(30<=d&&d<=90){
            puts("warning");
        }else{
            puts("alert");
        }
    }
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <algorithm>

using namespace std;

class PandC{
public:
    long p;
    long c;
};

int main(){
    long N, M;
    cin >> N >> M;
    PandC pc_list[N];
    for(int i = 0; i < N; i++){
        cin >> pc_list[i].p >> pc_list[i].c;
    }
    
    long answer = 0;
    
    sort(pc_list, pc_list + N,
         [](const PandC& x, const PandC& y) { return x.p < y.p;});
    
    int count = 0;
    for(int i = 0; i < N; i++){
        long M_remain = M - count;
        if(M_remain > pc_list[i].c){
            answer += pc_list[i].p * pc_list[i].c;
            count += pc_list[i].c;
        }else{
            answer += pc_list[i].p * M_remain;
            break;
        }
    }
    cout << answer;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	int ans=(n-1)*n/2+(m-1)*m/2;
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    int N, K;
    cin>>N>>K;
    vector<int> h(N);
    for (int &t: h)
        cin>>t;
    vector<int> T(N, 1000000000);
    T[0] = 0;
    for (int i=1; i<N; i++)
        for (int k=1; k<=K; k++)
            if (i-k>=0)
                T[i] = min(T[i], T[i-k]+abs(h[i]-h[i-k]));
    cout<<T[N-1]<<endl;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc105/editorial.pdf
　　　http://drken1215.hatenablog.com/entry/2018/08/13/125300
　　　https://www.hamayanhamayan.com/entry/2018/08/12/010816
・左端固定で右端動かすループの累積和だけ取れば、
　(右端の累積和)-(左端-1の累積和)で、どこでも分かるようになる。
・B-AがMの倍数 → BとAのmod Mが等しい(やってみれば分かる)
・各ループ内で、それまでに集計した累積和mod Mから左端として使える場所を数える。
"""

from collections import defaultdict

N, M = map(int, input().split())
aN = list(map(int, input().split()))

# 累積和を一時的に格納する変数
sm = 0
ans = 0
# 累積和のmod Mを格納するdict
d = defaultdict(int)
# 何もない累積和0の分を足しておく
d[0] = 1
for i in range(N):
    sm += + aN[i]
    # 今回のsm%Mを右端として、mod Mが同値になる左端候補の数を答えに加算
    ans += d[sm%M]
    # 今回のsm%Mはこの後左端候補として使うので+1
    d[sm%M] += 1
print(ans)


Measured memory_bytes: 14628
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int calc(int x){
  int res = 0;

  while(x){
    res += x%10;
    x/=10;
  }

  return res;
}

int main(){
  int n, ans = INF;

  cin >> n;

  for(int i=1;i<n;i++){
    ans = min(ans, calc(i) + calc(n-i));
  }

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



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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n;cin>>n;
  cout<<"ABC"<<n<<endl;

  return 0;
}

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

int ans;
int h, w;
int ttm[30][30];
int c;

bool ok(int x, int y){
    return x==0 ||
        y==0 ||
        ttm[y][x]==ttm[y][x-1] ||
        ttm[y][x-1]==ttm[y-1][x-1] ||
        ttm[y-1][x-1]==ttm[y-1][x] ||
        ttm[y-1][x]==ttm[y][x];
}

void dfs(int x, int y){
    if(x==w){
    if(y==h-1){
            ans++;
            return;
        }
        else dfs(0,y+1);
        return;
    }

    if(ttm[y][x]) dfs(x+1,y);
    else{
        if(x+1!=w && ttm[y][x+1]==0){
            ttm[y][x] = ttm[y][x+1] = c++;
            if(ok(x,y)) dfs(x+2,y);
            ttm[y][x] = ttm[y][x+1] = 0;
        }
        if(y+1!=h && ttm[y+1][x]==0){
            ttm[y][x] = ttm[y+1][x] = c++;
            if(ok(x,y)) dfs(x+1,y);
            ttm[y][x] = ttm[y+1][x] = 0;
        }
    }
}
int main(){
    while(cin >> h >> w && h){
        ans = 0;
        c = 1;
        memset(ttm,0,sizeof(ttm));
        dfs(0, 0);
        cout << ans << endl;
    }
}

Measured memory_bytes: 1172
import java.util.*;
import java.awt.geom.Line2D;

public class Main{
    int n;
    int xa,ya,xb,yb;
    int xs,ys,xt,yt,o,l;
    Line2D a,b;
    Intersection[] inter;

    class Intersection{
	double dist;
	int owner,height;
	public Intersection(double dist,int owner,int height){
	    this.dist = dist;
	    this.owner = owner;
	    this.height = height;
	}
    }

    void solve(){
	Scanner sc = new Scanner(System.in);
	int T = sc.nextInt();
	while(T--!=0){
	    xa = sc.nextInt(); ya = sc.nextInt();
	    xb = sc.nextInt(); yb = sc.nextInt();
	    n = sc.nextInt();

	    inter = new Intersection[n];
	    for(int i=0; i<n; i++){
		xs = sc.nextInt(); ys = sc.nextInt();
		xt = sc.nextInt(); yt = sc.nextInt();
		o = sc.nextInt(); l = sc.nextInt();
		a = new Line2D.Double(xa,ya,xb,yb);
		b = new Line2D.Double(xs,ys,xt,yt);
		if(a.intersectsLine(b)){
		    double d = calcDist(xa,ya,xb,yb,xs,ys,xt,yt);
		    inter[i] = new Intersection(d,o,l);
		}else{
		    inter[i] = new Intersection(-1,-1,-1);
		}
	    }

	    Comparator<Intersection> cmp = new Comparator<Intersection>(){
		public int compare(Intersection i1, Intersection i2){
		    if(i1.dist<i2.dist) return -1;
		    if(i1.dist>i2.dist) return 1;
		    return 0;
		}
	    };
	    Arrays.sort(inter, cmp);
	    
	    int ans = Math.min(countGate(0),countGate(1));
	    
	    System.out.println(ans);
	}
    }
    
    double calcDist(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4){
	double bx = x4-x3;
	double by = y4-y3;
	double d1 = Math.abs(bx*(y1-y3)-by*(x1-x3));
	double d2 = Math.abs(bx*(y2-y3)-by*(x2-x3));
	double t = d1/(d1+d2);	
	double x = x1+(x2-x1)*t;
	double y = y1+(y2-y1)*t;
	
	return (xa-x)*(xa-x)+(ya-y)*(ya-y);
    }
    
    int countGate(int nowHeight){
	int count = 0;
	for(int i=0; i<n; i++){
	    if(inter[i].dist==-1)continue;
	    if(inter[i].owner==0){
		if(inter[i].height==nowHeight){
		    nowHeight = 1 - nowHeight;
		    count++;
		}
	    }else{
		if(inter[i].height!=nowHeight){
		    nowHeight = 1 - nowHeight;
		    count++;
		}
	    }
	}
	return count;
    }
    
    public static void main(String[] args){
	new Main().solve();
    }
}

Measured memory_bytes: 13000
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
# from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
# from heapq import heappop, heappush, heappushpop
# from collections import Counter,defaultdict,deque
# from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
# from bisect import bisect_left,bisect_right
# from copy import deepcopy
from fractions import gcd
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))

def main():
    N=I()
    A=LI()
    l = 1
    for a in A:
        l *= a//gcd(l,a)
    ans = 0
    l%=mod
    for a in A:
        ans += l * pow(a,mod-2,mod)
        ans %= mod
    print(ans)
if __name__ == '__main__':
    main()



Measured memory_bytes: 69084
#include <iostream>
#include <string>
#include <cassert>
#include <cctype>
#include <cstdio>

using namespace std;

int array[100];
int size;

int to_i(const string& num) {
    int res = 0;
    for (int i = 0; i < num.size(); ++i) {
        res = res * 10 + (num[i] - '0');
    }
    return res;
}

int main(void) {

    int n;
    cin >> n;
    size = n;

    for (int i = 0; i < n; ++i) {
        string num;
        cin >> num;
        array[i] = to_i(num);
    }

    for (int i = 1; i < size; ++i) {
        for (int j = 0; j < size - 1; ++j) {
            printf("%d ", array[j]);
        }
        printf("%d\n", array[size - 1]);
        int key = array[i], j = 0;
        for (j = i - 1; j >= 0 && array[j] > key; --j) {
            array[j + 1] = array[j];
        }
        array[j + 1] = key;
    }
    for (int j = 0; j < size - 1; ++j) {
        printf("%d ", array[j]);
    }
    printf("%d\n", array[size - 1]);

    return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define y1 y11
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define skip continue
#define all(x) x.begin(), x.end()
#define NAME "code"
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
 
const ll inf = 1e9;
const int maxn = 1e5 + 11;

ll n, sum, a[maxn];

int main(){

cin >> n;

for(int i = 1; i <= n; ++i){
	cin >> a[i];
	sum += a[i];
}

if(sum & 1){
	cout << "NO";
}
else{
	cout << "YES";
}



return 0;
}

Measured memory_bytes: 1024
import sys

import collections

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
D = inl()
M = ini()
T = inl()


def solve():
    cd = collections.Counter(D)
    ct = collections.Counter(T)
    for t, cnt in ct.items():
        if cd[t] >= cnt:
            cd[t] -= cnt
        else:
            return False
    return True


print("YES" if solve() else "NO")


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

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

signed main(){
	fastio
	int n;
	cin >> n;
	int a[n];
	for(auto &x : a) cin >> x;
	int mx = -1, ans = 0;
	for(auto x : a){
		mx = max(mx, x);
		ans += mx-x;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 5216
import java.util.*;
import static java.lang.Math.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double x[] = new double[n];
        String u[] = new String[n];
        for(int i=0; i<n; i++){
            x[i] = sc.nextDouble();
            u[i] = sc.next();
        }
        double sum = 0.0;
        for(int i=0; i<n; i++){
            if(u[i].equals("JPY")){
                sum += x[i]; 
            }else{
                sum += x[i]*380000.0;
            }
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 23252
#include <stdio.h>

int main()
{
	int S, h, m, s;

	scanf(" %d", &S);

	h = S / 3600;
	S %= 3600;
	m = S / 60;
	s = S % 60;

	printf("%d:%d:%d\n", h, m, s);
	return 0;
}

Measured memory_bytes: 2752
import sys


N,M=map(int,input().split())

sw=[list(map(int,input().split())) for i in range(M)]

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

ans=0
for i in range(2**N):
    tmp=[p[i] for i in range(M)]
    s=bin(i)[2:].zfill(N)
    state=[int(s[i]) for i in range(N)]

    for j in range(M):
            for k in range(1,sw[j][0]+1):
                if state[sw[j][k]-1]==1:
                    tmp[j]=(tmp[j]+1)%2
    
    if max(tmp)==0: ans+=1

print(ans)


Measured memory_bytes: 3064
x = int(input())
# 1 <= x <= 10^9
a, b = 0, 0

def make_divisors(n):
    '''約数のリストを返す
    '''
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

d = make_divisors(x)
d.sort()

for i in d:
    #print("div:",i)
    a, b = i, 0
    while(b != -1000):
        #print("sw:",a, b)
        if x == pow(a,5) - pow(b,5):
            print(a, b)
            exit()
        else:
            a -= 1
            b -= 1


Measured memory_bytes: 65256
<?php
  fscanf(STDIN, "%d", $n);
  fscanf(STDIN, "%d %d", $d, $x);

  $ans = $x;
  for ($i=0; $i<$n; $i++) {
    fscanf(STDIN, "%d", $a);
    $ans += (int)(($d+$a-1)/$a);
  }

  echo $ans . "\n";
?>

Measured memory_bytes: 4604
#M番目が1/4M以下ならだめ

N, M = map(int, input().split())
A = list(map(int, input().split()))
total = 0
A.sort(reverse=True)

for i in range(N):
  total += A[i]

if A[M-1] < total/(4*M):
  print('No')
  
else:
  print('Yes')
 

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,a,n) for(int i=a;i<=n;i++)
#define repb(i,a,n) for(int i=a;i>=n;i--)
#define trav(a,x) for(auto a=x.begin();a!=x.end();a++)
#define all(x) x.begin(),x.end()
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
typedef long double ld;
typedef pair <int,int> pii;
typedef vector <int> vi;
typedef long long ll;


void pre(){

}

void solve(){
  ll n; cin>>n;
  ll temp=1;
  ll kemp=26;
  int ans=0;

  while(temp<=n){
    ans++;
    temp+=kemp;
    kemp=kemp*26;
  }

  temp=1;
  kemp=26;

  for(int i=1;i<ans;i++){
    temp+=kemp;
    kemp=kemp*26;
  }

  ll a[ans];
  int ch[ans];

  for(int i=ans-1;i>=0;i--){
    if(i==ans-1) a[i]=1;
    else a[i]=a[i+1]*26;
  }

  for(int i=0;i<ans;i++){
    for(int j=0;j<26;j++){
      if(temp+(j*a[i])<=n){
        ch[i]=j;
      }
      else break;
    }
    temp+=(ch[i]*a[i]);
  }

  string str="abcdefghijklmnopqrstuvwxyz";

  for(int i=0;i<ans;i++){
    cout<<str[ch[i]];
  }
  cout<<"\n";
}

int main(){
  // #ifndef ONLINE_JUDGE
  //   freopen("in.txt","r",stdin);
  // #endif
  ios_base::sync_with_stdio(0); cin.tie(0);
  pre();
  int t; t=1;
  rep(i,t) solve();
  return 0;
}


Measured memory_bytes: 3652
def main():
    s = int(input())

    y = s//10**9
    x = s%10**9
    if x == 0:
        result = [0,0,10**9,1,x,y]
    else:
        result = [0,0,10**9,1,10**9-x,y+1]
    print(*result)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
// 1_abc132_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

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++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<char> s(4);
    rep(i, 4){
        cin >> s[i];
    }
    sort(s.begin(), s.end());

    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <cmath>

int main() 
{
    int n, k;
    std::vector<int> vi;

    scanf("%d %d", &n, &k);
    int sum = 0;
    for (int i = 0; i < n; ++i)
    {
        int x;
        scanf("%d", &x);
        vi.push_back(x);
        sum += x;
    }

    auto check = [&](int x) -> bool 
    {
        std::vector<int> rem;
        std::transform(vi.begin(), vi.end(), 
            std::back_inserter(rem), 
            [x](int i) { return i % x; });

        std::stable_sort(rem.begin(), rem.end());

        int l = 0, r = rem.size() - 1;
        int t = 0, m = 0;
        while (l <= r) 
        {   
            if (m <= 0) 
            {
                m += rem[l];
                t += rem[l];
                ++l;
            }
            else
            {
                m -= x - rem[r];
                t += x - rem[r];
                --r;
            }
        }
        if (t > 2 * k) 
        {
            return 0;
        }
        if (m != 0) 
        {
            return 0;
        }

        return 1;
    };

    int ret = -1;
    for (int i = 1; i <= std::sqrt(sum); ++i)
    {
        if (sum % i != 0) 
        {
            continue;
        }

        if (check(i)) 
        {
            ret = std::max(ret, i);
        }
        if (check(sum / i)) 
        {
            ret = std::max(ret, sum / i);
        }
    }
    printf("%d\n", ret);
    return 0;
}               

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int sx = stdIn.nextInt();
		int sy = stdIn.nextInt();
		int tx = stdIn.nextInt();
		int ty = stdIn.nextInt();
		
		for(int i = sy; i <ty; i++) {
			System.out.print("U");
		}
		for(int i = sx; i < tx; i++) {
			System.out.print('R');
		}
		for(int i = ty; i > sy; i--) {
			System.out.print('D');//
		}
		for(int i = tx; i > sx; i--) {
			System.out.print('L');
		}
		//ここまでで1週
		System.out.print('L');//
		
		for(int i = sy; i < ty; i++) {
			System.out.print('U');
		}
		System.out.print('U');
		System.out.print('R');
		
		for(int i = sx; i < tx; i++) {
			System.out.print('R');
		}
		System.out.print('D'); //tx,tyに到着
		
		System.out.print('R');
		
		for(int i = ty; i > sy; i--) {
			System.out.print('D');
		}
		System.out.print('D');
		System.out.print('L');
		
		for(int i = tx; i > sx; i--) {
			System.out.print('L');
		}
		System.out.print('U');
		
		
	}

}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n), a(n);
  rep(i,n,0){
    cin >> p[i];
    a[i] = p[i];
  }
  sort(a.begin(), a.end());
  int x = 0;
  rep(i,n,0){
    if(a[i] != p[i]) x++;
  }
  if(x > 2) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  int num = 0;
  cin >> S >> T;
  for(int i=0;i<S.size();i++){
    if( S.at(i) != T.at(i)){
      num += 1;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 3836
N = int(input())
a = [int(i) for i in input().split()]
ans = [0]*8
count = 0
for i in a:
    if i < 400:
        ans[0] += 1
    elif i < 800:
        ans[1] += 1
    elif i < 1200:
        ans[2] += 1
    elif i < 1600:
        ans[3] += 1
    elif i < 2000:
        ans[4] += 1
    elif i < 2400:
        ans[5] += 1
    elif i < 2800:
        ans[6] += 1
    elif i < 3200:
        ans[7] += 1
    else:
        count += 1
count1 = 0
for i in ans:
    if i!=0:
        count1 += 1
mn = count1
mx = count1 + count
print(max(1,mn),mx)

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

int main()
{
    int a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    int t = 0;
    for (int i = a; i < b + 1; i++) {
        if (c % i == 0) {
            t = t + 1;
        }
    }
    cout << t << endl;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int N,K;
	map<int,int> cnt;
	cin>>N>>K;
	rep(i,N){
		int x;
		cin>>x;
		cnt[x]++;
	}
	vector<int> vc;
	for(auto it:cnt) vc.pb(it.sc);
	sort(all(vc));
	if(vc.size()<=K){
		puts("0");
		return 0;
	}
	int a =0;
	rep(i,vc.size()-K){
		a+=vc[i];
	}
	cout<<a<<endl;
}


Measured memory_bytes: 10748
import java.util.*;
import java.io.*;

class Main {

	void solve() {
		
		int a = inint(), b = inint(), c = inint();
		
		if (a == b) out.println(c);
		else if (a == c) out.println(b);
		else out.println(a);
		
	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

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

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}
	
	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}
	
	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

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

int main() {
 int N;
  cin >> N;
  
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
 
  for( int i=0; i<N; i++ )
    cin >> A.at(i);
  
  for( int i=0; i<N; i++ )
    cin >> B.at(i);
  
  for( int i=0; i<N-1; i++)
    cin >> C.at(i);
  
  int sum = 0;
  for( int i=0; i<N; i++ ){
    
    int m;
    
    m = A.at(i);
    
    sum += B.at(m-1); 
    
    if( i >= 1 ){
      if( m-1 == A.at(i-1) ){
        sum += C.at(m-2);
      }
    }
   
  }
  
  cout << sum;
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ans,b[16]={67,79,68,69,70,69,83,84,73,86,65,76,50,48,49,54};//CODEFESTIVAL2016的ASCII码值 
char a[16]; 
int main()
{
	for(int i=0;i<16;i++)
	{
		cin>>a[i];
		if(a[i]!=b[i])
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;	
}


Measured memory_bytes: 256
#if 0
2020.03.26

由于 a 是升序的，那么任意大小为 k + 1 的子集和大于任意大小为 k 的子集和等价于：
a[1] + a[2] + ... + a[k + 1] > a[n] + a[n - 1] + ... + a[n - k + 1]
而只要 k = floor((n - 1) / 2) 满足上述条件，任意 k 就能满足。

众所周知升序序列考虑差分，令 a[i] = 1 + x[1] + x[2] + ... + x[i] ，
那么上述限制等价于 x[1] >= x[2] * 0 + x[3] * 1 + ... + x[n - 1] * 2 + x[n] * 1 。
另外还要有 sum(x) < n 。
设 a = x[2] + x[3] + ... + x[n - 1] + x[n] ，
b = x[2] * 0 + x[3] * 1 + ... + x[n - 1] * 2 + x[n] * 1 。
那么有 b <= x[1] < n - a ，也就是说确定了 x[2] 到 x[n] 后 x[1] 有恰好 n - a - b 种选择。
不难发现需要关注的只是 a + b ，而 a + b 等于下式：
x[2] * 1 + x[3] * 2 + ... + x[n - 1] * 3 + x[n] * 2 。

DP 设 f[i][j] 表示考虑前 i 个 x 后 a + b = j 的方案数，前缀和优化即可。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
} read;

const int maxn = 5050;
ll f[maxn][maxn];
int g[maxn];

int main () {
	int n = read, mod = read;

	for (int i = 1; i < n; i ++)
		g[i] = std::min(i, n - i + 1);

	f[0][0] = 1;
	for (int i = 1; i < n; i ++) {
		for (int j = 0; j < g[i]; j ++)
			f[i][j] = f[i - 1][j];
		for (int j = g[i]; j < n; j ++)
			f[i][j] = (f[i][j - g[i]] + f[i - 1][j]) % mod;
	}

	ll ans = 0;
	for (int j = 0; j < n; j ++)
		(ans += (n - j) * f[n - 1][j]) %= mod;
	printf("%lld\n", ans);
}


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

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

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

int main() {
	int N, M; cin >> N >> M;
	int l = 1;
	int r = N;
	rep(i, M) {
		int L, R; cin >> L >> R;
		if (l < L)l = L;
		if (r > R)r = R;
	}
	
	cout << max(0, r - l + 1);
}

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

typedef long long ll;

int n;
int a[16][16];
ll dp[1<<16];
ll pre[1<<16];

int main(){

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

    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    for(int s=0;s<1<<n;s++){
        dp[s]=-1e18;
        for(int i=0;i<n;i++)if(s>>i&1){
            for(int j=i+1;j<n;j++)if(s>>j&1){
                pre[s]+=a[i][j];
            }
        }
    }
    dp[0]=0;
    for(int s=0;s<1<<n;s++){
        int rs=s^((1<<n)-1);
        for(int t=rs;t;t=(t-1)&rs){
            dp[s|t]=max(dp[s|t],dp[s]+pre[t]);
        }
    }
    cout<<dp[(1<<n)-1]<<endl;

    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N;
ll A[202000];

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    ll min_h = A[0];
    ll sum = 0;
    for (int i = 1; i < N; i++)
    {
        if (min_h > A[i])
        {
            sum += min_h - A[i];
        }
        else
        {
            min_h = A[i];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 5184
#include <vector>
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;


void solve(long long A, long long B, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> x, std::vector<long long> y, std::vector<long long> c){
    vector<int> cost;
    for(int i = 0; i < M; i++) {
        long long solve_c = a[x[i]-1] + b[y[i]-1] - c[i];
        cost.push_back(solve_c);
    }

    long long min_c = 999999999;
    for(int i = 0; i < cost.size(); i++) {
        if(min_c > cost[i]) {
            min_c = cost[i];
        }
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    if(a[0] + b[0] < min_c) {
        std::cout << a[0] + b[0] << endl;
        return;
    }

    std:cout << min_c << endl;
    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(A);
    for(int i = 0 ; i < A ; i++){
        scanf("%lld",&a[i]);
    }
    std::vector<long long> b(B);
    for(int i = 0 ; i < B ; i++){
        scanf("%lld",&b[i]);
    }
    std::vector<long long> x(M);
    std::vector<long long> y(M);
    std::vector<long long> c(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
        scanf("%lld",&c[i]);
    }
    solve(A, B, M, std::move(a), std::move(b), std::move(x), std::move(y), std::move(c));
    return 0;
}


Measured memory_bytes: 4860
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<tuple>

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

int main(){

    while(1){
        int N, M;
        cin>> N>> M;
        if(!(N||M)) break;
        int r;
        cin>> r;

        int t[r], n[r], m[r], s[r];
        for(int i=0; i<r; i++){
            cin>> t[i]>> n[i]>> m[i]>> s[i];
            m[i]--;
        }
        int Q;
        cin>> Q;
        for(int i=0; i<Q; i++){
            int ss, ee, mm;
            cin>> ss>> ee>> mm;
            mm--;
            int a[1270]={};
            for(int i=0; i<r; i++){
                if(m[i]==mm){
                    if(s[i]) a[t[i]]+=1;
                    else a[t[i]]-=1;
                }
            }
            for(int i=1; i<1270; i++){
                a[i]+=a[i-1];
            }
            int k=0;
            for(int j=ss; j<ee; j++){
                k+=(a[j]>0);
            }
            cout<< k<< endl;
        }
    }

    return 0;
}

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

int main(void)
{
	int n;
	int i, j, k;
	int len, ch_len;
	int cnt = 0;
	char check[11];
	char str[21];
	
	scanf("%s", check);
	scanf("%d", &n);
	
	ch_len = strlen(check);
	
	for (i = 0; i < n; i++){
		scanf("%s", str);
		
		len = strlen(str);
		strcat(str, str);
		
		for (j = 0; j < len * 2; j++){
			if (check[0] == str[j]){
				for (k = 0; k < ch_len; k++){
					if (check[k] != str[k + j]){
						break;
					}
				}
			}
			if (k == ch_len){
				cnt++;
				k = 0;
				break;
			}
		}
	}
	
	printf("%d\n", cnt);
	
	return (0);
}

Measured memory_bytes: 604
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		PriorityQueue<Structure> pq = new PriorityQueue<Structure>();
		for(int i = 0; i < m; i++){
		    int p = sc.nextInt();
		    int y = sc.nextInt();
		    String s = String.format("%06d", p);
		    pq.add(new Structure(i, p, y, s));
		}       
		
		// 計算
		String[] result = new String[m];
		int oldP = 0;
		int num = 0;
		for(int i = 0; i < m; i++){
		    Structure struct = pq.poll();
		    if(struct.p != oldP){
		        oldP = struct.p;
		        num = 1;
		        result[struct.id] = struct.s + String.format("%06d", num);
		    }else{
		        num++;
		        result[struct.id] = struct.s + String.format("%06d", num);
		    }
		}

		// 出力
		for(int i = 0; i < m; i++){
		    System.out.println(result[i]);
		}
	}
}

class Structure implements Comparable<Structure> {
	int id;
	int p;
	int y;
    String s;

	Structure(int id, int p, int y, String s) {
		this.id = id;
		this.p = p;
		this.y = y;
		this.s = s;
	}

	@Override
	public int compareTo(Structure obj) {
	    // this > obj => 1
	    // this < obj => -1
	    // this == obj => 0
	    int order = 0;
	    
		// 第1ソートキー
	    order = Integer.compare(this.p, obj.p);
	    // 第2ソートキー
		if(order == 0){
	        order = Integer.compare(this.y, obj.y);
	    }

		return order;
	}

	public String toString() {
		return "id:" + this.id + "p:" + this.p + " y:" + this.y + " s:" + this.s;
	}
}


Measured memory_bytes: 168332
fun main(args : Array<String>) {
    val s = readLine()!!
    val t = readLine()!!

    val map = mutableMapOf<Char, MutableList<Long>>()

    s.forEachIndexed { index, c ->
        if (map.contains(c)) {
            map[c]!!.add(index.toLong())
        } else {
            map[c] = mutableListOf()
            map[c]!!.add(index.toLong())
        }
    }
    var ans = 0L
    var prev = -1L
   t.forEach {
       val indexes = map[it]
       if (indexes == null) {
           println(-1)
           return
       }
       val next = lowerBound(indexes, prev + 1)
       val nextIdx = if(next >= indexes.size) indexes.first() else indexes[next]
       ans += if(nextIdx > prev) nextIdx - prev else s.length - prev + nextIdx
       prev = nextIdx
   }
   println(ans)
}
fun lowerBound(sortedList: List<Long>, key: Long) : Int {
    var ng = - 1 // left
    var ok = sortedList.size  // right

    fun isOk(mid: Int) : Boolean {
        return sortedList.get(mid) >= key
    }

    while (Math.abs(ok - ng) > 1) {
        var mid = (ok + ng) / 2
        if (isOk(mid)) {
            ok = mid
        } else {
            ng = mid
        }
    }
    return ok
}


Measured memory_bytes: 41512
n=int(input())
d= [list(map(int, input().split())) for d in range(n)]

yes=0
for i in range(n-2):
    if d[i][1]==d[i][0] and d[i+1][1]==d[i+1][0] and d[i+2][1]==d[i+2][0]:
        yes+=1
    else:
        pass

if yes==0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,x[105],y[105],xx,yy;
  int fl=0;
  cin>>n>>m>>xx>>yy;

  for(int i=0; i<n; i++){
    cin>>x[i];
  }

  for(int i=0; i<m; i++){
    cin>>y[i];
  }

  sort(x,x+n);
  sort(y,y+m);

  for(int i=xx+1; i<=yy; i++){

    if(x[n-1]<i){
      if(y[0]>=i){
	fl=1;
      }
    }
  }
  
  if(fl)cout<<"No War"<<'\n';
  else cout<<"War"<<'\n';

  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
data=[list(map(int,input().split())) for i in range(m)]
import sys
input = lambda: sys.stdin.readline()[:-1]
l,r=0,10**6
for i,j in data:
	l=max(l,i)
	r=min(r,j)
print(max(0,r-l+1))



Measured memory_bytes: 60120
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=5e5+5;
int n,m,i,a[N],d[N];
long long mn;bool ans[N];
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
int main(){
	for (n=read(),d[0]=read(),i=1;i<=n;i++)
		d[i]=min(d[i-1],abs(d[i-1]-(a[i]=read())));
	for (mn=1,i=n;i;i--){
		if (d[i-1]>=mn) ans[i]=1;
		if (2*mn>a[i]) mn=mn+a[i];
	}
	for (i=read();i--;) puts(ans[read()]?"YES":"NO");
}

Measured memory_bytes: 6272
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define sh short int
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const ll inf = 1e18;
const ll mod = 1e9+7;
int main(){
    ll n; cin>>n;
    ll x = log2(n);
    cout<<(1ll<<(x+1))-1<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i=0; i < n; i++)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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 INF = 1LL << 60;
//cout << fixed << setprecision(10);
//M_PI

int main() {
    string x;
    cin>>x;
    stack<char> st;
    rep(i,x.size()){
        if(x[i] == 'S') st.push('S');
        else if(st.empty() || st.top() == 'T') st.push('T');
        else st.pop();
    }
    cout << st.size() <<endl;
}


Measured memory_bytes: 644
let () = Scanf.scanf "%d %d %s" @@ fun a b s ->
  Array.init (a + b + 1) (fun i ->
    if i = a then s.[i] = '-' else s.[i] <> '-')
  |> Array.fold_left ( && ) true
  |> (function true -> "Yes" | false -> "No")
  |> print_endline

Measured memory_bytes: 4480
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
#define MOD 1000000007
#define EPS 10e-8
int main(){
  int N,A;
  cin >> N >> A;
  if(N%500<=A) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 504
n,m = map(int,input().split())
o = set(int(input()) for _ in range(m))
#print(o)
mod = (10**9)+7
dp = [0]*(n+1)
dp[0] = 1

for i in range(1,n+1):
  dp[i] = (dp[i-1]+dp[i-2])%mod
  if i in o:
    dp[i] = 0
  #print(i,dp)
#print(dp)
print(dp[-1])


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  string s,t;
  cin >> s >> t;

  if(s.size() + 1 == t.size() && s == t.substr(0,s.size())){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3628
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int is(int x){
	if(x==0 || x==1) return 0;
	if(x==2 || x==3 || x==5) return 1;
	if(x%2==0 || x%3==0 || x%5==0) return 0;
	for(int i=6, l=sqrt(x+1); i<=l; i+=6){
		if(x%(i+1)==0 && l+1<x) return 0;
		if(x%(i+5)==0 && l+5<x) return 0;
	}
	return 1;
}

int main(void){
	int q, i;
	char d[100001];
	for(i=0; i<=100000; i++){
		d[i]=is(i);
	}
	int e[100000];
	e[1]=0;
	for(i=3; i<100000; i+=2){
		if(d[i]!=0 && d[(i+1)/2]!=0){
			e[i]=e[i-2]+1;
		}else{
			e[i]=e[i-2];
		}
	}
	scanf("%d", &q);
	for(i=0; i<q; i++){
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", l==1?e[r]:e[r]-e[l-2]);
	}
}


Measured memory_bytes: 1024