akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[2];
            string[] s = Console.ReadLine().Split(' ');
            a[0] = int.Parse(s[0]);
            a[1] = int.Parse(s[1]);

            int ga = 0;
            int gb = 0;
            int gc = 0;

            for(int i = 0; i < 2; i++)
            {
                switch(a[i])
                {
                    case 1:
                        ga++;
                        break;
                    case 2:
                        gc++;
                        break;
                    case 3:
                        ga++;
                        break;
                    case 4:
                        gb++;
                        break;
                    case 5:
                        ga++;
                        break;
                    case 6:
                        gb++;
                        break;
                    case 7:
                        ga++;
                        break;
                    case 8:
                        ga++;
                        break;
                    case 9:
                        gb++;
                        break;
                    case 10:
                        ga++;
                        break;
                    case 11:
                        gb++;
                        break;
                    case 12:
                        ga++;
                        break;
                }
            }

            if (ga == 2 || gb == 2 || gc == 2)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
int main(){
  
  string s,str1,str2;
  map<string,int> mp;

  while(cin >> s){

    if(mp.find(s) == mp.end()) mp[s] = 1;
    else mp[s]++;

    if(mp[s] > mp[str1]) str1 = s;
    if(s.size() > str2.size()) str2 = s;

  }
  
  cout << str1 << ' ' << str2 << endl;
  return (0);
}

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

int main() {
  ll n, t;
  cin >> n >> t;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  ll ans = t;
  for (int i = 0; i < n - 1; i++) {
    ans += min(t, a[i + 1] - a[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
const int N = 1e5+5;
ll n,m;
ll down[N];
ll up[N];
ll pref[N];
ll suff[N];
vector<ll> tree[N];

void down_dfs(ll u, ll par){
    down[u] = 1;
    for(int i=0;i<tree[u].size();++i){
        int to = tree[u][i];
        if(to!=par){
            down_dfs(to,u);
            down[u] = (down[u]*((down[to]+1)%m))%m;
        }
    }
}

void up_dfs(ll u, ll par){
    pref[0] = 1;
    ll x = 1;
    for(int i=0;i<tree[u].size()-1;++i){
        int child = tree[u][i];
        if(child!=par){
            x = (x*(down[child]+1))%m;
            pref[i+1] = x;
        }else{
            pref[i+1] = x;
        }
    }
    suff[tree[u].size()-1] = 1;
    x = 1;
    for(int i=tree[u].size()-1;i>0;--i){
        int child = tree[u][i];
        if(child!=par){
            x = (x*(down[child]+1))%m;
            suff[i-1] = x;
        }else{
            suff[i-1] = x;
        }
    }
    for(int i=0;i<tree[u].size();++i){
        int child = tree[u][i];
        if(child!=par){
            up[child] = (pref[i]*suff[i])%m;
            up[child] = (up[child]*(up[u]+1))%m;
        }
    }
    for(int i=0;i<tree[u].size();++i){
        int child = tree[u][i];
        if(child!=par){
            up_dfs(child,u);
        }
    }
}

int main(){
    ll x, y;
    cin >> n>> m;
    for(ll i=0;i<n-1;++i){
        cin >> x>> y;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }
    down_dfs(1,0);
    up[1] = 0;
    if(n>1)
        up_dfs(1,0);
    for(ll i=1;i<=n;++i){
        cout << (down[i]*(up[i]+1))%m <<endl;
    }
    return 0;
}


Measured memory_bytes: 14464
#!/usr/bin/env python3
# -*- coding: utf-8 -*-*-

from sys import stdin


def main():
    N, K = map(int, stdin.readline().split())
    # N, K = 7, 4

    a = N % K
    b = abs(a - K)
    if a < b:
        print(a)
    else:
        print(b)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import math
from functools import reduce
def gcd(numbers):
    return reduce(math.gcd, numbers)
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.append(a[1])
c = sorted(b)
d = []
for i in range(a[0]):
  d.append(c[i+1]-c[i])
print(gcd(d))

Measured memory_bytes: 20520
n = int(input())
data = []
for i in range(n-1):
    c,s,f = map(int,input().split())
    s //= f
    data.append((c,s,f))
for i in range(n):
    if i == n-1:
        print(0)
        break
    for j in range(i,n-1):
        if j == i:
            ans = data[j][0]+data[j][1]*data[j][2]
            continue
        ans = (max((ans-1)//data[j][2]+1,data[j][1])*data[j][2]) + data[j][0]
    print(ans)

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;

  double ans = 0.0;

  FOR(i, 1,(n + 1)){
      double t = (double)k / i;
      int roll = ceil(log2(t));
      if(roll < 0) roll = 0;
      ans += pow(0.5,(double)roll);
    }
    cout << fixed;
    cout << setprecision(16) << (ans / n) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long ans = 1;
        HashMap<Long, Long> map = new HashMap<>();
        map.put(0L, 0L);
        map.put(1L, 0L);
        map.put(2L, 0L);
        for (int i = 0; i < N; i++) {
            long A = scan.nextLong();
            long count = 0;
            long index = 0;
            for (long j = 0; j < 3; j++) {
                if (map.get(j) == A) {
                    count += 1;
                    index = j;
                }
            }
            ans *= count;
            ans %= 1000000007;
            map.put(index, map.get(index) + 1);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 48688
// .\code.exe
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define UN unsigned
#define pb push_back
#define mod 1000000007
#define mt make_tuple
#define f first
#define s second
typedef tuple<int, int> tii;
typedef pair<int, int> pii;

int root(vector<int>& u, int i){
    if(u[i] == i)
        return i;
    else{
        u[i] = root(u, u[i]);
        return u[i];
    }
}

void onion(vector<int>& u, int a, int b){
    int ra = root(u, a);
    int rb = root(u, b);
    u[ra] = rb;
}

void solve(void){
    int n, m;
    cin >> n >> m;

    vector<int> a(n+1), u(n+1, -1);
    
    for(int i=1; i<=n; i++){
        cin >> a[i];
        u[i] = i;
    }

    while(m--){
        int x, y;
        cin >> x >> y;
        onion(u, x, y);
    }
 
    int ans = 0;

    for(int i=1; i<=n; i++){
        if(a[i] == i || root(u, a[i]) == root(u, i)){
            ans++;
            continue;
        }
    }
    cout << ans;
}

int main(void){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
#include <limits>
using namespace std;
int gcd(int a, int b)//最大公約数
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}
vector<int> divisor(int n) {//約数発見
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    std::sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    //std::stack<int> stack;
    int n,k;
    cin >> n >> k;
    long ans = 0;
    vector<long> max(n+1);
    vector<long> min(n+1);
    min[0] = 0;
    max[0] = n;
    for(int i = 1; i <= n; i++){
        max[i] = max[i-1] + n-i;
        min[i] = min[i-1] + i;
    }
    for(int i = k-1; i <= n; i++){
        ans += max[i]+1 - min[i];
        ans %= mod;
    }
    
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 6344
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int x,a,b;
    cin>>x>>a>>b;
    
    x=x-a;
    
    cout<<x%b<<endl;
    
    
   
    
    return 0;
   
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 1e5 + 7;

int n, k;
int p[N];
int ans = 0;
vector <int> tree[N];
int h[N];
void dfs(int u) {
    for (int v : tree[u]) {
        dfs(v);
        if (h[v] >= k - 1 && u != 1) {
            ++ans;
        }   
        else {
            h[u] = max(h[u], h[v] + 1);
        }   
    }   
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }   
    ans += p[1] != 1;
    p[1] = 1;
    for (int i = 2; i <= n; ++i) {
        tree[p[i]].app(i);
    }   
    dfs(1);
    cout << ans << endl;
}

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

using namespace std;

int main(){
	int n, m;
	while(cin >> n >> m, n || m){
		vector<int> data(n);
		for(int i = 0; i < n; i++){//input
			cin >> data[i];
		}

		int max = 0;
		for(int i = 0; i < n; i++){
			for(int j = i+1; j < n; j++){
				int tmp = data[i] + data[j];
				if(tmp <= m && tmp > max){
					max = tmp;
				}
			}
		}

		if(max == 0){//output
			cout << "NONE" << endl;
		} else {
			cout << max << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3072
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int sum = 0;
		int[] line = new int[3];

		for (int i = 0; i < 3; i++) {
			line[i] = sc.nextInt();
			sum += line[i];
		}

		int min = Integer.MAX_VALUE;

		for (int i = 0; i < 3; i++) {
			min = Math.min(min, sum-line[i]);
		}

		System.out.println(min);
		
	}

}


Measured memory_bytes: 27104
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18;

int A,B,C,N,M,K,X,Y,Z;
string t[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};

signed main(){
	int N;
	cin>>N;
	string s;
	cin>>s;
	REP(i,s.size()){
		int t = s[i]-'A';
		t = (t + N) % 26;
		s[i]='A'+t;
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n ;
	scanf("%d",&n);
	int v[n],c[n];
	for (int i = 0;i < n;i++){
		scanf("%d",&v[i]);
	}
	for (int i = 0;i < n;i++){
		scanf("%d",&c[i]);
	}
	int vt = 0;
	int ct = 0;
	for (int i = 0;i < n;i++){
		if(v[i]-c[i] > 0){
			vt += v[i];
			ct += c[i];
		}
	}
	int ans = vt -ct;
	printf("%d",ans);
	
}

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

#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define FORD(i, b, e) for (int i = (b); i >= (int)(e); i--)
#define ll long long
#define st f
#define nd s
#define pb PB
#define eb emplace_back
#define mp make_pair
#define siz(c) SIZ(c)
const int inf = 1e9 + 7;
const LL INF = 1e18L + 7;

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type
{int o = 0; p << "{"; for (auto c : y) {if (o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if (p > y) p = y;}
sim, class s> void maxi(n &p, s y) {if (p < y) p = y;}

#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "

#define int ll
const int N = 1 << 20;
const int mod = 1e9 + 7;

int n, ans, all, zer;

int dp[N][2]; //dodaj zera
int ile[N];

void dodaj(int s)
{	
	for(int i = 1; i < N; ++i)
	{
		dp[i][0] += (all - ile[i]) * dp[i][1];
		dp[i][0] %= mod;
		ile[i] = all;
	}

	for(int i = 1; i < N; ++i)
	{
		ans += s * dp[i][0];
		ans += s * dp[i][1];
		ans %= mod;
	}
}

int pot(int a, int w)
{
	int res = 1;

	while(w--)
	{
		res *= a;
		res %= mod; 
	}

	return res;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	for(int i = 1; i < N; ++i)
	{
		dp[i][0] = 1;
	}

	cin >> n;

	if(n == 1)
	{
		cout << 1 << endl;
		return 0;
	}

	int pref = 0;

	for(int i = 1; i <= n; ++i)
	{
		int a;
		cin >> a;
		pref ^= a;

		if(pref == 0)
		{
			if(i != n)
				++zer;

			++all;
		}
		else
		{
			dp[pref][0] += (all - ile[pref]) * dp[pref][1];
			dp[pref][0] %= mod;
			ile[pref] = all;

			dp[pref][1] += dp[pref][0];
			dp[pref][1] %= mod;
		}

		if(i == n - 1)
			dodaj(-1);
	}

	dodaj(1);
	debug(ans);

	if(!pref)
		ans += pot(2, zer);

	ans %= mod;
	ans += mod;
	ans %= mod;

	cout << ans << endl;
}

Measured memory_bytes: 24960
import java.math.*;import java.util.*;public class Main{public static void main(String[]a){for(Scanner s=new Scanner(System.in);s.hasNext();){BigInteger x=s.nextBigInteger(),y=s.nextBigInteger();System.out.println(x.gcd(y)+" "+x.multiply(y).divide(x.gcd(y)));}}}

Measured memory_bytes: 12000
n=int(input())
a=list(map(int,input().split()))
sumd=abs(a[0])
a.append(0)
for i in range(n):
    sumd+=abs(a[i]-a[i+1])
print(sumd-abs(a[0])+abs(a[1])-abs(a[1]-a[0]))
for i in range(1,n):
    print(sumd+abs(a[i-1]-a[i+1])-abs(a[i-1]-a[i])-abs(a[i]-a[i+1]))

Measured memory_bytes: 14048
using System;
using System.Collections.Generic;

class main
{
	static void Main(string[] args)
	{
		int[] Arry = IntArr();
		Console.Write((Arry[0] + Arry[1] - 1)/ Arry[1] * Arry[2]);
	}

	static string[] StrArr()
	{
		return Console.ReadLine().Trim().Split(' ');
	}
	static int[] IntArr()
	{
		string[] strArr = StrArr();
		int len = strArr.Length;

		int[] intArr = new int[len];
		for(int i = 0;i < len; i++)
		{
			intArr[i] = Int(strArr[i]);
		}

		return intArr;
	}

	static int Int(string Str)
	{
		return int.Parse(Str);
	}
}



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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

void dump(int i, int j){
  if(!!( i & (1<<j) )) cout << '+';
  else cout << '-';
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d,g;
  cin >> d >> g;
  VLL p(d);
  VLL c(d);

  rep(i,d){
    cin >> p[i] >> c[i];
  }
  ll minCnt = 1e9;
  rep(i,1<<d){
    //全完する問題
    ll ans = 0;
    ll cnt = 0;
    rep(j,d){
      if(!!(i&(1<<j))){
        cnt+= p[j];
        ans += c[j];
        ans += 100LL * (j+1) * p[j];
      }
    }
    if(ans >= g){
      minCnt = min(minCnt,cnt);
    }

    for(ll j = d-1; j >= 0; j --){
      if(!(i&(1<<j))){
        int x = (g - ans + (100LL*(j+1)) - 1) / (100LL*(j+1));
        if(x > p[j]) break;
        if(x < 0) break;
        if(ans + 100L * (j +1) * x < g) break;
        else{
          minCnt = min(minCnt,cnt+x);
        }
      }
    }
  }
  cout << minCnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <cstring>
#include <map>
#include <queue>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
int const maxn = 2e5+10;
map<int, int>mmp;
int main(){
	int n, i, num;
	int flag = 1;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d", &num);
		if(mmp.count(num)){
			flag = 0;
			break;
		}
		mmp[num]++;
	}
	if(flag == 0)
		printf("NO\n");
	else printf("YES\n");
}

Measured memory_bytes: 9600
const main = (input) => {
  input = input.split(' ');
  const A = input[0];
  const B = input[1];
  const C = input[2];
  
  const bigA = A.toUpperCase();
  const bigB = B.toUpperCase();
  const bigC = C.toUpperCase();
  const result = bigA.slice(0,1)+bigB.slice(0,1)+bigC.slice(0,1);
  
  console.log(result);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<stdio.h>
#include<string.h>
int main(){
    char s[10+1];
    char t[11+1];
    scanf("%s",s);
    scanf("%s",t);
    for(int i=0;i<strlen(s);i++){
        if(s[i]==t[i]){

        }else{
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main() { //xor sum of all numbers up to 2^n is 0 which gives k when xor with k
  int n,k;
  scanf ("%d %d",&n,&k);
  if (k >= (1 << n) || (k == 1 && n == 1)) return 0 * printf ("-1\n");
  if (n == 1) return 0 * printf ("0 0 1 1\n"); //1 is a special case
  for (int x = 0; x < (1 << n); x++) if (x!=k) printf ("%d ",x);
  printf ("%d ",k);
  for (int x = (1<<n)-1; x >= 0; x--) if(x!=k) printf ("%d ",x);
  printf ("%d\n",k);
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x-r < 0 || x+r > W || y-r < 0 || y+r > H){
        printf("No\n");
    }else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;





signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE x(n), y(n), h(n);
	rep(i, n)cin >> x[i] >> y[i] >> h[i];
	rep(i, 101) {
		rep(j, 101) {
			int tmp = 0;
			rep(k, n) {
				if (h[k]) {
					tmp = h[k] + abs(i - x[k]) + abs(j - y[k]);
					break;
				}
			}
			bool ok = true;
			rep(k, n) {
				if (h[k] != max(0LL, tmp - abs(i - x[k]) - abs(j - y[k]))) {
					ok = false; break;
				}
			}
			if (ok)cout << i << " " << j << " " << tmp << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto S = readln.chomp.to!(wchar[]);

    int i;
    long r;
    foreach (j, s; S) {
        if (s == 'W') {
            r += j - i;
            ++i;
        }
    }
    writeln(r);
}

Measured memory_bytes: 2616
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
 
map<string, int> dp;
int direction[4] = { 1, -1, 4, -4 };
 
//************************************
// Method:    bfs
// FullName:  bfs
// Access:    public 
// Returns:   void
// Qualifier: ???0????????´?????????
//************************************
void bfs()
{
	queue<string> que;
	que.push("01234567");
	dp["01234567"] = 0;
	while (!que.empty())
	{
		string now = que.front(); que.pop();
		// p???'0'?????????
		int p = 0;
		for (int j = 0; j < 8; ++j)
		{
			if (now[j] == '0')
			{
				p = j;
				break;
			}
		}
 
		for (int i = 0; i < 4; ++i)
		{
			int n = p + direction[i];
			if (0 <= n && n < 8 && 
				!(p == 3 && i == 0) && // ???????§???????????????????
				!(p == 4 && i == 1))   // ???????§???????????????????
			{
				string next = now;
				swap(next[p], next[n]);
				if (dp.find(next) == dp.end())
				{
					dp[next] = dp[now] + 1;
					que.push(next);
				}
			}
		}
	}
}
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
	bfs();
	string line;
	while (getline(cin, line))
	{
		line.erase(remove(line.begin(), line.end(), ' '), line.end());
		cout << dp[line] << endl;
	}
 
	return 0;
}
///////////////////////////End Sub//////////////////////////////////

Measured memory_bytes: 3436
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
ll a,b,c;

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

  cin >> a >> b >> c;
  if (c<=a+b) {
    cout << "No" << "\n";
    return 0;
  }
  string ans = c*(c-2*a-2*b) +pow(max(a, b)-min(a,b),2) > 0?"Yes":"No";
  cout << ans << "\n";
  return 0;
}


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

int main(){
    ll N;
    string S;
    cin >> N >> S;
    map<char,ll> mp;
    rep(i,N){
        mp[S[i]]++;
    }
    ll cnt = 1;
    for(auto& e:mp){
        cnt *= (e.second+1);
        cnt %= mo;
    }
    cnt--;
    cnt %= mo;
    cout <<cnt<<endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>
#define REP(i,p,n) for(int i=p;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()

using namespace std;
template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

int main() {
	int S,T;
	int a,b,c,d;	
	cin >> a >> b >> c >> d;
	S = a + b + c + d;
	cin >> a >> b >> c >> d;
	T = a + b + c + d;

	if (S > T) {
		cout << S << endl;
	}
	else {
		cout << T << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

class Main {
    static StringBuilder sb = new StringBuilder("");
    static int index = 0;

    public static void main (String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] preorder = new int[n];
        int[] inorder = new int[n];
        for (int i = 0; i < n; i++) {
            preorder[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            inorder[i] = sc.nextInt();
        }
        Node[] nodes = new Node[n];
        reconstruct(nodes, preorder, inorder, 0, n);
        sb.deleteCharAt(0);
        System.out.println(sb);
    }

    public static int reconstruct(Node[] nodes, int[] preorder, int[] inorder, int right, int left) {
        if (left == right) return -1;

        // find root
        int root = 0;
        outside: for (int i = 0; i < preorder.length; i++) {
            for (int j = right; j < left; j++) {
                if (preorder[i] == inorder[j]) {
                    root = j;
                    break outside;
                }
            }
        }

        int tempIndex = index;
        index++;

        nodes[tempIndex] = new Node(inorder[root], -1, -1);
        nodes[tempIndex].left = reconstruct(nodes, preorder, inorder, right, root);
        nodes[tempIndex].right = reconstruct(nodes, preorder, inorder, root + 1, left);

        sb.append(" ").append(nodes[tempIndex].id);

        return tempIndex;
    }
}

class Node {
    public int id;
    public int left;
    public int right;

    public Node(int id, int left, int right) {
        this.id = id;
        this.left = left;
        this.right = right;
    }
}

Measured memory_bytes: 26440
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
}
 int dp[403][403];
 vi arr(403);
 int n;
 int sum(int l,int r)
    {  int s=0;
        for(int i=l;i<=r;i++)
        s+=arr[i];
        return s;
    }
    
int memo(int s,int e)
 {
     if(s>=e)
     return dp[s][e]=0;
     
     if(dp[s][e]!=-1)
     return dp[s][e];
     int ans=1e18+5;
     for(int i=s;i<=e-1;i++)
     {
         ans=min(ans,memo(s,i)+memo(i+1,e)+sum(s,e));
     }
  return dp[s][e]=ans;   
 }
int32_t main()
{
    c_p_c();
    
    cin>>n;
     
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    
    cout<<memo(0,n-1);
    
    //cout<<dp[0][n-1];
    return 0;
}

Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharp_AtCoder
{
    class MinHeap<T> where T : struct, IComparable<T>
    {
        int H;  //heap配列の最後の有効インデックス
        T[] heap;  //heap[1]が最小、heap[0]はダミー
        const int MAX = 2000000;

        public MinHeap()
        {
            H = 0;
            heap = new T[MAX];
        }

        public MinHeap(int size, T[] array)
        {
            H = size;
            heap = new T[size + 1];
            array.CopyTo(heap, 1);
            BuildMinHeap();
        }

        public void MinHeapfy(int p)
        {
            while (2 * p <= H)
            {
                int son_n = 2 * p;
                T son = heap[2 * p];
                if (2 * p + 1 <= H && son.CompareTo(heap[2 * p + 1]) == 1)
                {
                    son = heap[2 * p + 1];
                    son_n++;
                }

                if (son.CompareTo(heap[p]) == -1)
                {
                    T tmp = heap[p];
                    heap[p] = son;
                    heap[son_n] = tmp;
                }
                else
                {
                    break;
                }

                p = son_n;
            }
        }

        public void BuildMinHeap()
        {
            for (int s = H / 2; s >= 1; s--)
            {
                MinHeapfy(s);
            }
        }

        public void Insert(T key)
        {
            H++;
            heap[H] = key;

            int son = H;

            while (son != 1)
            {
                int p = son / 2;
                if (heap[son].CompareTo(heap[p]) == -1)
                {
                    T tmp = heap[p];
                    heap[p] = heap[son];
                    heap[son] = tmp;
                    son /= 2;
                }
                else
                {
                    break;
                }
            }

        }

        public T ExtractMin()
        {
            T min = heap[1];
            heap[1] = heap[H];
            H--;

            MinHeapfy(1);

            return min;
        }

    }

    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            double[] v = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();

            MinHeap<double> mh = new MinHeap<double>(N, v);
            for (int i = 0; i < N - 1; i++)
            {
                double a = mh.ExtractMin();
                double b = mh.ExtractMin();
                double ab = (a + b) / 2;
                mh.Insert(ab);
            }

            Console.WriteLine(mh.ExtractMin());
        }
    }
}


Measured memory_bytes: 13396
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

ll a, b, c, d;

unordered_map<ll, ll> memo;

ll f(ll n){
	if (memo.find(n) != memo.end()) return memo[n];
	if (n == 0) return 0;
	if (n == 1) return d;
	ll res = LINF;
	if ((ld)n * d <= 1e18) chmin(res, n * d);

	if (n % 2 == 0) chmin(res, a + f(n / 2));
	else{
		chmin(res, d + a + f((n + 1) / 2));
		chmin(res, d + a + f((n - 1) / 2));
	}

	if (n % 3 == 0) chmin(res, b + f(n / 3));
	else{
		ll rest = n - n / 3 * 3;
		chmin(res, d * rest + b + f((n - rest) / 3));
		chmin(res, d * (3 - rest) + b + f((n - rest) / 3 + 1));
	}

	if (n % 5 == 0) chmin(res, c + f(n / 5));
	else{
		ll rest = n - n / 5 * 5;
		chmin(res, d * rest + c + f((n - rest) / 5));
		chmin(res, d * (5 - rest) + c + f((n - rest) / 5 + 1));
	}
	return memo[n] = res;
}

void solve() {
	ll n;
	cin >> n >> a >> b >> c >> d;
	memo.clear();

	ll ans = f(n);
	co(ans);
}

int main(void){
	ll t;
	cin >> t;
	rep(i, t) solve();

	return 0;
}


Measured memory_bytes: 4112
Program ABC065_A;
const   finput='ABC065_A.inp';
        foutput='ABC065_A.out';
var     a,b,x:longint;

begin
    read(x,a,b);
    if b>a+x then write('dangerous')
    else
        if b<=a then write('delicious')
        else
            write('safe');
end.

Measured memory_bytes: 128
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.lang.StringBuilder
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)
    val h = sc.nextInt()
    val w = sc.nextInt()
    val grid = Array(h) { Array(w) { '.' } }
    var count = 0
    for (i in 0 until h) {
        val s = sc.nextLine()
        for (j in 0 until w) {
            grid[i][j] = s[j]
            if (s[j] == '#') count++
        }
    }
    println(if (count == h + w - 1) "Possible" else "Impossible")
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 31264
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

char s[10];
int a[10];

int main(){
  cin>>s;
  rep(i,3){
    a[s[i]-'a']++;
  }

  rep(i,3){
    if(a[i]==0){
      cout<<"No"<<endl;
      return 0;
    }
  }

  cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include	<stdio.h>
int main(){
int a=0,b=0,c=0;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
if(a+b>=c){
if(a<=c){
printf("YES");
}else{
printf("NO");
}
}else{printf("NO");}
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int main(){
    LL n,m,v,p;
    scanf("%lld %lld %lld %lld\n",&n,&m,&v,&p);
    v=n-v;
    LL a[100005];
    for(int i = 1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    sort(a+1,a+n+1);
    LL pre[100005];
    pre[0]=0;
    for(int i = 1;i<=n;i++){
        pre[i]=pre[i-1]+a[i];
    }
    int ans=0;
    for(int i = 1;i<=n;i++){
        if(i>n-p)ans++;
        else{
            if(a[n-p+1]-a[i]>m)continue;
            LL need=pre[n-p+1]-pre[i]-a[i]*(n-p+1-i);
            //printf("%lld\n",need);
            if(need<=m*v)ans++;
        }
    }
    printf("%d\n",ans);
}
/*
*/

Measured memory_bytes: 1792
// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const int MaxN=5050;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
struct state
{
    int last;
    int len[MaxN<<1],jook[MaxN<<1];
    int ch[MaxN<<1][26],cnt;
    int ans;
	int size[MaxN<<1];
    state()
    {
        last=1;
        cnt=1,ans=0;
        len[1]=0;
        jook[1]=0;
        size[cnt]=1;
    }
    inline int new_node()
    {
        ++cnt;
        len[cnt]=jook[cnt]=size[cnt]=0;
        for(reg int i=0;i<26;++i)
            ch[cnt][i]=0;
        return cnt;
    }
    inline void insert(int c)
    {
        int cur=new_node(),p=last;
        size[cur]=1;
        len[cur]=len[last]+1;
        while(p&&!ch[p][c])
        {
            ch[p][c]=cur;
            p=jook[p];
        }
        if(!p)
            jook[cur]=1;
        else
        {
            int q=ch[p][c];
            if(len[p]+1==len[q])
                jook[cur]=q;
            else
            {
                int clone=new_node();
                for(reg int i=0;i<26;++i)
                    ch[clone][i]=ch[q][i];
                len[clone]=len[p]+1;
                jook[clone]=jook[q];
                while(p&&ch[p][c]==q)
                {
                    ch[p][c]=clone;
                    p=jook[p];
                }
                jook[q]=jook[cur]=clone;
            }
        }
        last=cur;
    }
}sam;
int n,l1,l2,ans;
char str[MaxN],s[MaxN],t[MaxN],kmp[MaxN];
signed main(void)
{
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n;
	cin>>str+1;
	for(reg int i=0;i<n;++i)
	{
		if(i)
			sam.insert(str[i]-'a');
		reg int pos=1,res=0;
		for(reg int j=i+1;j<=n;++j)
		{
			pos=sam.ch[pos][str[j]-'a'];
			if(!pos)
				res=0,pos=1;
			else
				++res;
			ans=max(ans,res);
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

typedef long long ll;
struct RollingHash {
	static const ll mo0 = 1000000007, mo1 = 1000000009;
	static ll mul0, mul1;
	static const ll add0 = 1000010007, add1 = 1003333331;
	static vector<ll> pmo[2];
	vector<int> s; int l; vector<ll> hash_[2];
	void init(vector<int> s) {
		this->s = s; l = s.size(); int i, j;
		hash_[0] = hash_[1] = vector<ll>(1, 0);
		if (!mul0) mul0 = 10009 + (((ll)&mul0) >> 5) % 259, mul1 = 10007 + (((ll)&mul1) >> 5) % 257;
		if (pmo[0].empty()) pmo[0].push_back(1), pmo[1].push_back(1);
		for (int i = 0; i < l; i++) hash_[0].push_back((hash_[0].back()*mul0 + add0 + s[i]) % mo0);
		for (int i = 0; i < l; i++) hash_[1].push_back((hash_[1].back()*mul1 + add1 + s[i]) % mo1);
	}
	pair<ll, ll> hash(int l, int r) { // s[l..r]
		if (l>r) return make_pair(0, 0);
		while (pmo[0].size()<r + 2)
			pmo[0].push_back(pmo[0].back()*mul0%mo0), pmo[1].push_back(pmo[1].back()*mul1%mo1);
		return make_pair((hash_[0][r + 1] + (mo0 - hash_[0][l] * pmo[0][r + 1 - l] % mo0)) % mo0,
			(hash_[1][r + 1] + (mo1 - hash_[1][l] * pmo[1][r + 1 - l] % mo1)) % mo1);
	}
};
vector<ll> RollingHash::pmo[2]; ll RollingHash::mul0, RollingHash::mul1;

int N, M;

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

	while (cin >> N >> M)
	{
		string s; cin >> s;

		RollingHash rh;
		vector<int> v(s.length());
		rep(i, 0, s.length()) v[i] = s[i] - 'a';
		rh.init(v);

		int l = 0, r = 0;
		vector<pair<ll, ll> > vp;
		rep(i, 0, M)
		{
			string q; cin >> q;
			if (q == "L++")
				l++;
			else if (q == "L--")
				l--;
			else if (q == "R++")
				r++;
			else
				r--;

			vp.push_back(rh.hash(l,r));
		}

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

		int ans = 1;
		pair<ll, ll> back = vp[0];

		rep(i, 1, M)
		{
			if (back != vp[i]) ans++;
			back = vp[i];
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 24384
// https://atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_c
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
struct fast_ios {
    fast_ios() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    };
} fast_ios_;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    double n, m, d;
    cin >> n >> m >> d;
    if (d == 0) {
        cout << (m - 1) / n << endl;
    } else {
        cout << (m - 1) * 2.0 * (n - d) / (n * n) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size())cout << a[i] << " ";cout << "\n"
#define vecvec(a) vector<vector<(a)>>
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);
struct edge{ll to,cost;};
ll N;const ll NMAX = 100005LL;
vector<edge> G[NMAX];
vector<ll> dist(NMAX,INF);
void dfs(ll from,ll par,ll d){
    dist[from] = d;
    for(auto x : G[from]){
        if(x.to != par){
            dfs(x.to,from,d + x.cost);
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c;
    cin >> N;
    rep(i,N - 1){
        cin >> a >> b >> c;
        a--;b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    ll Q,K;
    cin >> Q >> K;
    dist[K - 1] = 0;
    dfs(K - 1,-1,0);
    ll A,B;
    rep(i,Q){
        cin >> A >> B;
        cout << dist[A - 1] + dist[B - 1] << "\n";
    }
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using namespace std;

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

    int n; cin >> n;
    vector<int> vc;
    vc.push_back(0);
    for(int i = 0; i < n; i++){
        int x; cin >> x;
        vc.push_back(x);
    }
    sort(vc.begin(), vc.end());

    for(int i = 0; i <= n; i+=2){
        vc[i] = (24 - vc[i]) % 24;
    }

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

    int minimum = 100;

    for(int i = 1; i <= n; i++){
        minimum = min(vc[i] - vc[i - 1], minimum);
    }
    cout << minimum;
}


Measured memory_bytes: 256
n = int(input())
info = {}
point = {}
for i in range(n):
  s, p = input().split()
  point[int(p)] = i+1
  if s not in info:
    info[s] = [int(p)]
  else:
    info[s].append(int(p))
   
for city in sorted(info.keys()):
  for p in sorted(info[city], reverse=True):
    print(point[p])


Measured memory_bytes: 3060