akhauriyash/Code-Regression huggingface dataset:
/* include */
#include <bits/stdc++.h>

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

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

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long
#define mp make_pair
#define r0 return 0

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    int a, b, sum = 0;
    cin >> a >> b;
    rep(i, 2)
    {
        if (a > b)
        {
            sum += a;
            a--;
        }
        else
        {
            sum += b;
            b--;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
from heapq import *
def input(): return sys.stdin.readline().strip()


def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A: d[a] += 1
    q = []
    for key in d: heappush(q, -d[key])
    for _ in range(k):
        if q: heappop(q)
    print(-sum(q))


if __name__ == "__main__":
    main()


Measured memory_bytes: 134164
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;

int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	int a,b;
	cin>>a>>b;
	if(a>=0&&a<=9&&b>=0&&b<=9){
		cout<<a*b<<endl;
	}else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #define cerr if(false)cerr
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb emplace_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
#define minel(a) *min_element(all(a))
#define maxel(a) *max_element(all(a))
#define pq(t) priority_queue<t, vector <t>, greater <t>>
#define pqd(t) priority_queue<t>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))      // Used to iterate over the types

const ll mod = 1e9 + 7;
const ll mx = 1e18;
const ll inf = 1e7;

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// For printing variables and their respective values

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}

template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

auto mods() { return 0; }

template<typename T, typename... Args>
auto mods(T a, Args... args) { return (a + mods(args...) + mod) % mod; }

auto modp() { return 1; }

template<typename T, typename... Args>
auto modp(T a, Args... args) { return ( a * modp(args...) )% mod; }
// ! inputs should be positive and less than `mod`.

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// !Taking `int` input

template<typename T>
T nxt(){
    T x;
    cin >> x;
    return x;
}

//  ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


inline void solve()
{
    int n = nxt<int>();
    int k = nxt<int>();
    vll arr(n);
    generate(all(arr), nxt<ll>);
    int low = 0, high = 1e9, mid;
    while (high - low > 1)
    {
        mid = low + high >> 1;
        ll temp = 0;
        rep(i, 0, n)
            temp += (arr[i] - 1) / mid;
        if (temp <= k)
            high = mid;
        else
            low = mid;
    }
    cout << high << endl;
}

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

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 4760
import numpy as np
n=int(input())

dp=[float("inf")]*(n+1)
dp[0]=0

for i in range(1,n+1):
  dp[i]=min(dp[i],dp[i-1]+1)
  for j in range(1,n+1):
    if i-6**j<0: break
    dp[i]=min(dp[i],dp[i-6**j]+1)
    if i-9**j<0: continue
    dp[i]=min(dp[i],dp[i-9**j]+1)
  #print("debug:",i,",",dp[i])

print(dp[n])

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

vi adj[100010];
map<pi, int> colors;

void dfs(int no, int pai, int cor_usada) {
    colors[MP(pai, no)] = cor_usada;
    int c = 1;
    for(int v : adj[no]) {
        if(v == pai) continue;
        if(c == cor_usada) c++;
        dfs(v, no, c);
        c++;
    }
}

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vpi arestas;
    int maxi = 0;
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].PB(b);
        adj[b].PB(a);
        arestas.PB(MP(a, b));
        maxi = max({maxi, (int) adj[a].size(), (int) adj[b].size()});
    }
    dfs(1, 1, 0);
    cout << maxi << "\n";
    for(pi a : arestas) {
        if(colors.count(a)) {
            cout << colors[a] << "\n";
        }else {
            cout << colors[MP(a.S, a.F)] << "\n";
        }
    }
}


Measured memory_bytes: 15996
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    n = getN()
    lis = getList()
    xo, su = 0, 0
    ans = 0
    l, r = 0, 0
    forward = True
    while True:
        # print(l, r, ans, xo, su)
        if r == n:
            print(ans)
            return
        if forward:
            xo = xo^lis[r]
            su += lis[r]
            if xo == su:

                ans += r - l + 1
                r += 1
            else:
                forward = False
        else:
            xo = xo^lis[l]
            su -= lis[l]
            if xo == su:
                forward = True
                ans += r - l
                r += 1
                l += 1
            else:
                l += 1

def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 32200
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  int ans = -1;
  rep(i,n)rep(j,i){
    ans = max(ans, abs(a[i] - a[j]));
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder=new StringBuilder();
        while(true){
            String data[]=reader.readLine().split(" ");
            int x=Integer.parseInt(data[0]);
            int y=Integer.parseInt(data[1]);
            if(x==0 && y==0) break;
            builder.append(Integer.toString(x<y?x:y)).append(" ").append(Integer.toString(x<y?y:x)).append("\n");
        }
        System.out.print(builder);
    }
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  string s;cin>>s;

  if(s.size()==26){
    map<char,bool>mp;
    rep(i,0,s.size())mp[s[i]]=true;
    for(int i=s.size()-1;i>=0;i--){
      mp[s[i]]=false;
      rep(j,s[i]-'a'+1,26){
        if(!mp['a'+j]){
          out(s.substr(0,i)+char('a'+j));
          return 0;
        }
      }
    }
    out(-1);
  }
  else{
    rep(i,0,26){
      if(s.find('a'+i)==string::npos){
        out(s+char('a'+i));
        return 0;
      }
    }
  }


  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;

template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO  

  string s;
  map<string, int> cnt;
  int N, M, opt = 0; 
  cin >> N;
  for(int rep = 0; rep < N; ++rep){
    cin >> s;
    cnt[s]++;
  }
  cin >> M; 
  for(int rep = 0; rep < M; ++rep){
    cin >> s;
    cnt[s]--;
  }

  for(auto ele : cnt) max_self(opt, ele.S);

  cout << opt << "\n";
  return 0;
}

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

     public static void main(String []args) throws IOException{
       
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       
       int n = Integer.parseInt(br.readLine());
       
       String a[] = br.readLine().split(" ");
       
       int array[] = new int[n];
       int i=0;
      long left[] = new long[n];
    // Set<Integer> st = new HashSet<>();
       Map<Long,Integer> map = new HashMap<>();
       for(String x: a) {
           array[i] = Integer.parseInt(x); 
           left[i] = array[i]+i;
           long t =(i-array[i]);
           if(map.get(t)==null)
            map.put(t,0);
           map.put(t,map.get(t)+1);
           i+=1;
       }
       
       long count= 0;
       for(long x: left) {
           if(map.get(x)!=null)
           count+=map.get(x);
       }
       
       System.out.println(count);
       
     }
}


Measured memory_bytes: 79588
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
char name[100];
int t;
} P;

P Q[LEN];
int head,tail,n;
void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

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

int main(){
    int elaps = 0,c;
    int i,q;
    P u;
    scanf("%d %d",&n,&q);

    for(i = 1;i <= n;i++){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
        }
        head = 1;
        tail = n + 1;
        while(head != tail){
            u = dequeue();
            c = min(q,u.t);
            u.t -= c;
            elaps += c;
            if(u.t > 0)enqueue(u);
            else{
                printf("%s %d\n",u.name,elaps);
        }
    }
    return 0;
}



Measured memory_bytes: 11864
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<bitset>
#define z(x) x+8000
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
char c[10000];
bool f[8001][16001],g[8001][16001];
int a[10000];
int main()
{	scanf("%s",c+1);
	int now=0,n=strlen(c+1),tot=0,x,y; scanf("%d%d",&x,&y);
	f[0][z(0)]=g[0][z(0)]=1;
	int p=1;
	while(p<=n)
	{	if(c[p]=='F')
		{	while(c[p]=='F') p++,now++;
			a[++tot]=now; now=0;
		}
		else
		{	while(c[p]=='T') p++,now++;
			a[++tot]=-(now&1); now=0;
		}
	}
//	for(rint i=1;i<=tot;i++) cout<<a[i]<<" ";cout<<endl;
	rint i=0; now=0;
	if(a[1]>0) f[1][z(a[1])]=g[1][z(0)]=1,i=1;
	for(;i+2<=tot;i+=2)
	{	for(rint j=-n;j<=n;j++)
		if(a[i+1]==0)
		{	if(!now)
			{	if(j+a[i+2]<=n)f[i+2][z(j+a[i+2])]|=f[i][z(j)];
				if(j-a[i-2]>=-n)f[i+2][z(j-a[i+2])]|=f[i][z(j)];
				g[i+2][z(j)]=g[i][z(j)];
			}
			else
			{	if(j+a[i+2]<=n)g[i+2][z(j+a[i+2])]|=g[i][z(j)];
				if(j-a[i+2]>=-n)g[i+2][z(j-a[i+2])]|=g[i][z(j)];
				f[i+2][z(j)]=f[i][z(j)];
			}
		}
		else
		{	if(now)
			{	if(j+a[i+2]<=n)f[i+2][z(j+a[i+2])]|=f[i][z(j)];
				if(j-a[i-2]>=-n)f[i+2][z(j-a[i+2])]|=f[i][z(j)];
				g[i+2][z(j)]=g[i][z(j)];
			}
			else
			{	if(j+a[i+2]<=n)g[i+2][z(j+a[i+2])]|=g[i][z(j)];
				if(j-a[i+2]>=-n)g[i+2][z(j-a[i+2])]|=g[i][z(j)];
				f[i+2][z(j)]=f[i][z(j)];
			}
		}
		if(a[i+1]) now^=1;
	}
	if(f[i][z(x)]&&g[i][z(y)]) cout<<"Yes\n";
	else cout<<"No\n"<<endl;
 	return 0;
}


Measured memory_bytes: 249472
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxN = 1e5 + 10;
map < int, int > mp[maxN];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
   	int res;
    cin >> res;
    mp[res % m][res]++;
  }
  int ans = 0;
  for (int t = 0; t <= m - t; t++) {
    if (t == (m - t) % m) {
		int gg = 0;
    	for (auto& it : mp[t]) gg += it.second;
      	ans += gg / 2;
    }
    else {
    	vector < int > sz0, sz1;
      	int x = 0, y = 0;
      	for (auto& it : mp[t]) {
          	x += it.second;
        	sz0.emplace_back(it.second);
        }
      	for (auto& it : mp[m - t]) {
          	y += it.second;
         	sz1.emplace_back(it.second); 
        }
      	if (x > y) {
        	swap(x, y);
          	swap(sz0, sz1);
        }
 //     	cout << x << " " << y << " " << t << " " << ans << endl;
      	for (auto& it : sz1) {
        	if (it % 2 == 1 && x > 0) {
            	x--;
              	y--;
              	ans++;
              	it--;
            }
        }
      	if (x > 0) {
          ans += (x + y) / 2;
        }
      	else {
      		for (auto& it : sz1) ans += it / 2;
        }
    }
  }
  cout << ans;	
}

Measured memory_bytes: 13060
S = input()
y, m, d = S.split("/")

def f(y, m, d):
    h = "Heisei"
    t = "TBD"
    if y > 2019:
        print(t)
        return
    if y < 2019:
        print(h)
        return
    if m > 4:
        print(t)
    else:
        print(h)

f(int(y), int(m), int(d))

Measured memory_bytes: 3060
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define LL long long
#define mp make_pair
#define fr first
#define sc second
#define pb push_back
#define lc (x<<1)
#define rc ((x<<1)|1)
const int N=100005;
int main(){
  //  freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,n,y,f=0,ans=1;
    scanf("%d",&n);
    for (i=1;i<=n;i++){
        int x;scanf("%d",&x);
        if (i==1||x==y) {y=x;continue;}
        if (y<x) {if (f==1||f==0) f=1; else ans++,f=0;}
         else {if (f==2||f==0) f=2; else ans++,f=0;}
        y=x;
    }
    printf("%d\n",ans);
  //  system("pause");
    return 0;
}


Measured memory_bytes: 768
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    string s, t; cin >> s >> t;

    const ll alpnum = 'z' - 'a' + 1;
    vector<vector<ll>> cindex(alpnum);
    REP(i, s.size()) {
        cindex[s[i] - 'a'].push_back(i);
    }

    ll ans = 0;
    ll j = -1;
    REP(i, t.size()) {

        ll v = t[i] - 'a';
        if (cindex[v].empty()) {
            cout << -1 << endl;
            return 0;
        }

        auto vitr = upper_bound(ALL_OF(cindex[v]), j);
        if (vitr == cindex[v].end()) { // to front
            ans += cindex[v].front() + s.size() - j;
            j = cindex[v].front();
        } else {
            ll d = *vitr;
            ans += d - j;
            j = d;
        }

    }
    cout << ans << endl;
    
}

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

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

	//string s;
	int n;

	//cin >> n >> k;
	cin >> n;
	
	//string ans="Yes";
	
	int ans=0;
	vector<int> a(n+1);
	vector<int> b(n+1);
	vector<int> c(n);

	rep(i,n){
		cin >> a[i+1];
	}
	rep(i,n){
		cin >> b[i+1];
	}
	rep(i,n-1){
		cin >> c[i+1];
	}
	
	rep(i,n){
		int num=a[i+1];
		ans+=b[num];
		//cout << b[num] << endl;
		if(i>0 && a[i+1]==a[i]+1){
			ans+=c[num-1];
			//cout << c[num] << endl;
		}
	}
	
	cout << ans << "\n";
	
	
	return 0;

    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char arr[3][3];
    char result[3];
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<3; j++)
        {
            cin>>arr[i][j];
            if(i==j)
            {
                result[i]=arr[i][j];
            }

        }
    }
    for(int i=0; i<3; i++)
        cout<<result[i];
    return 0;
}


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

using namespace std;

//#define FILE_IO

const int mod = 1e9 + 7;

int N, M;
int X, Y, ans;
int v[100005];

int add(int x, int y) { x += y; if(x >= mod) x -= mod; return x; }
int mul(int x, int y) { return (1LL * x * y) % mod; }

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

    scanf("%d%d", &N, &M);
    for(int i = 1; i <= N; i++)
        scanf("%d", &v[i]);
    N--;
    for(int i = 1; i <= N; i++)
    {
        int d = v[i + 1] - v[i];
        X = add(X, mul(d, mul(i, N - i + 1)));
    }

    for(int i = 1; i <= M; i++)
        scanf("%d", &v[i]);
    M--;
    for(int i = 1; i <= M; i++)
    {
        int d = v[i + 1] - v[i];
        Y = add(Y, mul(d, mul(i, M - i + 1)));
    }

    ans = mul(X, Y);
    printf("%d\n", ans);


    return 0;
}


Measured memory_bytes: 640
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

class UnionFind:
    def __init__(self, size=None, nodes=None):
        """
        size か nodes どっちか指定。
        nodes は set、size は list を使う。
        :param int size:
        :param collections.Iterable nodes:
        """
        assert size is not None or nodes is not None
        if size is not None:
            self._parents = [i for i in range(size)]
            self._ranks = [0 for _ in range(size)]
            self._sizes = [1 for _ in range(size)]
        else:
            self._parents = {k: k for k in nodes}
            self._ranks = {k: 0 for k in nodes}
            self._sizes = {k: 1 for k in nodes}

    def unite(self, x, y):
        """
        x が属する木と y が属する木を併合
        :param x:
        :param y:
        """
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return

        # rank が小さい方が下
        if self._ranks[x] > self._ranks[y]:
            # x が root
            self._parents[y] = x
            self._sizes[x] += self._sizes[y]
        else:
            # y が root
            self._parents[x] = y
            self._sizes[y] += self._sizes[x]
            if self._ranks[x] == self._ranks[y]:
                self._ranks[y] += 1

    def root(self, x):
        """
        x が属する木の root
        :param x:
        """
        if self._parents[x] == x:
            return x
        self._parents[x] = self.root(self._parents[x])
        return self._parents[x]

    def size(self, x):
        """
        x が属する木のノード数
        :param x:
        """
        return self._sizes[self.root(x)]


N, M, K = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
CD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(K)]

uf = UnionFind(size=N + 1)
for a, b in AB:
    uf.unite(a, b)

friends = [0] * (N + 1)
blocks = [0] * (N + 1)
for a, b in AB:
    if uf.root(a) == uf.root(b):
        friends[a] += 1
        friends[b] += 1
for a, b in CD:
    if uf.root(a) == uf.root(b):
        blocks[a] += 1
        blocks[b] += 1

ans = []
for i in range(1, N + 1):
    cnt = uf.size(i) - friends[i] - blocks[i] - 1
    ans.append(cnt)
print(*ans)


Measured memory_bytes: 113500
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define N 3

int map[N][N];
int x0,y0;
int lim;
bool check(void){
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(i==N-1&&j==N-1) break;
			if(map[i][j]!=i*N+j+1) return false;
		}
	}
	if(map[N-1][N-1]!=0)return false;
	return true;
}

bool swapping(int x,int y,int dep){
	int temp=map[x0+x][y0+y];
	map[x0+x][y0+y]=map[x0][y0];
	map[x0][y0]=temp;
	x0+=x;
	y0+=y;
	if(check()){
		printf("%d\n",dep);
		exit(0);
		return true;
	}
	if(dep<=lim){
		if(x!=1&&x0-1!=-1) swapping(-1,0,dep+1);
		if(x!=-1&&x0+1!=N) swapping(1,0,dep+1);
		if(y!=1&&y0-1!=-1) swapping(0,-1,dep+1);
		if(y!=-1&&y0+1!=N) swapping(0,1,dep+1);
	}
	temp=map[x0-x][y0-y];
	map[x0-x][y0-y]=map[x0][y0];
	map[x0][y0]=temp;
	x0-=x;
	y0-=y;
	return false;
}
int main(void){
	time_t t;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			scanf("%d",&map[i][j]);
			if(map[i][j]==0){
				x0=i;
				y0=j;
			}
		}
	}
	if(check()){
		printf("0\n");
		return 0;
	}
	time_t t0=time(NULL);
	for(lim=1;lim<46;lim++){
		t=time(NULL);
//		printf("lim:%d:%lld\n",lim,t-t0);
		t0=t;
		if(x0-1!=-1) swapping(-1,0,1);
		if(x0+1!=N) swapping(1,0,1);
		if(y0-1!=-1) swapping(0,-1,1);
		if(y0+1!=N) swapping(0,1,1);
	}
//	printf("Unsolved\n");
	return 0;
}

Measured memory_bytes: 2748
var
 a,b,c,i,j,k:longint;
 f:array[0..500,0..500,0..500]of longint;
begin 
 readln(a,b,c);
 f[0,1,0]:=1;
 for i:=0 to a do
  for j:=1 to b do
   for k:=i downto 0 do
    if f[i,j,k]<>0 then
     begin
      if k<>0 then
       begin
        f[i,j,k]:=f[i,j,k] mod c;
        f[i,j,k-1]:=f[i,j,k-1]+f[i,j,k];
       end
      else
       f[i,j+1,i]:=(f[i,j+1,i]+f[i,j,k])mod c;
      f[i+1,j,k]:=(f[i+1,j,k]+(k+1)*f[i,j,k])mod c;
     end;
 writeln(f[a,b+1,a]);
end.

Measured memory_bytes: 296192
// https://beta.atcoder.jp/contests/abc079
// status:

#define SUBMIT

#include <bits/stdc++.h>
using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const int N = 3;

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    stringstream stream(R"(3242
)");
#endif
    char cs[4];
    int v[4];
    for (int i = 0; i < 4; ++i) stream >> cs[i];
    for (int i = 0; i < 4; ++i) v[i] = cs[i] - '0';

    for (int bit = 0; bit < (1 << N); ++bit) {
        string ans = to_string(v[0]);
        int sum = v[0];
        for (int i = 0; i < N; ++i) {
            if (bit & (1 << i)) {
                sum += v[i + 1];
                ans += "+";
            }
            else {
                sum -= v[i + 1];
                ans += "-";
            }
            ans += to_string(v[i + 1]);
        }
        if (sum == 7) {
            ans += "=7";
            cout << ans << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import javax.lang.model.util.ElementScanner6;
import java.lang.Math;

public class Main {

    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);

        // 入力
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        //String s = sc.next();

        // 処理
        int[] c = new int[n];
        int[][] a = new int[n][m];

        for(int i = 0; i < n; i++){
            c[i] = sc.nextInt();
            for(int j = 0; j < m; j++){
                a[i][j] = sc.nextInt();
            }
        }

        int out = 0;

        //不可能チェック
        boolean check = true;
        for(int i = 0; i < m; i++){
            int tmp = 0;
            for(int j = 0; j < n; j++){
                tmp += a[j][i];
            }
            if(tmp < x){
                check = false;
                break; 
            }
        }
        if(check == false){
            out = -1;
        } else {
            //最小金額の初期値
            int min = 0;
            for(int i = 0; i < n; i++){
                min += c[i];
            }

            //全組み合わせ
            int ptn = (int)Math.pow(2, n);
            for(int i = 0; i < ptn; i++){
                int kingaku = 0;
                int[] score = new int[m];
                for(int j = 0; j < n; j++){
                    if(((i)&((int)Math.pow(2,j))) != 0){
                        kingaku += c[j];
                        for(int k = 0; k < m; k++){
                            score[k] += a[j][k];
                        }
                    }
                }
                //scoreチェック
                boolean scheck = true;
                for(int l = 0; l < m; l++){
                    if(score[l] < x){
                        scheck = false;
                        break;
                    }
                }
                if(scheck == true){
                    if(kingaku < min) {
                        min = kingaku;
                    }
                }
            }
            out = min;
        }

        // 出力
        System.out.println(out);
    }
}


Measured memory_bytes: 37640
#include<stdio.h>
int main()
{
	int i,n,j;
	int min_i;
	int count=0;
	char temp;
	char a[36][2];
	char b[36][2];
	char c[2];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s",c);
		a[i][0]=b[i][0]=c[0];
		a[i][1]=b[i][1]=c[1];
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n-1-i;j++)
		{
			if(a[j][1]-a[j+1][1]>0)
			{
				temp=a[j][1];
				a[j][1]=a[j+1][1];
				a[j+1][1]=temp;

				temp=a[j][0];
				a[j][0]=a[j+1][0];
				a[j+1][0]=temp;
			}
		}
	}

	for(i=0;i<n;i++)
	{
		min_i=i;
		for(j=i;j<n;j++)
		{
			if(b[j][1]-b[min_i][1]<0)
			{
				min_i=j;
			}
		}

		temp=b[i][1];
		b[i][1]=b[min_i][1];
		b[min_i][1]=temp;

		temp=b[i][0];
		b[i][0]=b[min_i][0];
		b[min_i][0]=temp;
	}

	for(i=0;i<n;i++)
	{
		if(i!=n-1)
			printf("%c%c ",a[i][0],a[i][1]);
		else
			printf("%c%c\n",a[i][0],a[i][1]);
	}

	printf("Stable\n");

	for(i=0;i<n;i++)
	{
		if(i!=n-1)
			printf("%c%c ",b[i][0],b[i][1]);
		else
			printf("%c%c\n",b[i][0],b[i][1]);

		if(a[i][0]==b[i][0])
			count++;
	}

	if(count==n)
		printf("Stable\n");
	else
		printf("Not stable\n");
	return 0;
}

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

int main(){
int N;
cin >> N;
bool A=1;
vector<int> vec(N,0);
for(int i=0;i<N;i++){cin>>vec.at(i);
;}
for(int i=0;i<N;i++){
if(vec.at(i)%2==0&&vec.at(i)%3!=0&&vec.at(i)%5!=0)A=0
;}
if(A)cout<<"APPROVED"<<endl;
else cout<<"DENIED"<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


ll dp[1111][22222];

int main(void) {
  ll H, N;
  cin >> H >> N;
  ll i, j;
  ll a[1111], b[1111];
  ll max=0;
  
  for(i=0; i<N; i++) {
    cin >> a[i] >> b[i];
    chmax(max, a[i]);
  }
  
  
  for(i=0; i<N; i++) {
    for(j=0; j<H+max; j++) {
      dp[i][j]=INF;
    }
  }
  dp[0][0]=0;
  
  for(i=0; i<N; i++) {
    for(j=0; j<H+max; j++) {
      chmin(dp[i+1][j], dp[i][j]);
      chmin(dp[i][j+a[i]], dp[i][j]+b[i]);
    }
  }
  
  ll ans=INF;
  for(j=H; j<H+max; j++) {
    chmin(ans, dp[N-1][j]);
  }
  
  pt(ans);
}



Measured memory_bytes: 173312
#include <bits/stdc++.h>
#define ll long long
const ll MOD=1e9+7;
using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> ans(N,-1);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    if(ans[a-1]==-1||ans[a-1]==b) ans[a-1]=b;
    else{
      cout<<"-1"<<endl;
      return 0;
    }
  }
  if(N!=1&&ans[0]==0){
    cout<<"-1"<<endl;
    return 0;
  }
  if(N==1&&M==0){
    cout<<"0"<<endl;
    return 0;
  }
  for(int i=0;i<N;i++){
    if(ans[i]!=-1) cout<<ans[i];
    else if(i==0) cout<<"1";
    else cout<<"0";
  }
  cout<<endl;
}

Measured memory_bytes: 256
def main():
  import math
  A, B, H, M = map(int, input().split())
  kaku = abs( 360*(H/12) + 30*(M/60)  - 360*(M/60) )
  
  nagasa = math.sqrt(A ** 2 + B ** 2 - 2*A*B*math.cos(math.radians(kaku)))
  print(nagasa)
main()

Measured memory_bytes: 62524
using System;
using System.Linq;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            string input2 = Console.ReadLine();

            string result = "APPROVED";

            var input2IntList = input2.Split(' ').Select(x => Convert.ToInt32(x)).Where(x => x % 2 == 0).ToList();

            

            foreach (var input2Int in input2IntList)
            {
                if (input2Int % 3 != 0 && input2Int % 5 != 0)
                {
                    result = "DENIED";
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int N; cin >> N;
  vector<ll> A(N);
  for (auto& a : A) { cin >> a; }
  vector<ll> sum(N);
  sum[0] = A[0];
  for (int i = 1; i < N; ++i) {
    sum[i] = sum[i-1] + A[i];
  }

  map<ll, int> mp{};
  ++mp[0];
  ll res{};
  for (int i = 0; i < N; ++i) {
    ll s = sum[i];
    res += mp[s];
    ++mp[s];
  }
  cout << res << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    Vec a(n);
    rep(i,n)cin>>a[i];

    ll ans=0;

    ll j = 0;
    ll x = 0;
    rep(i,n){
        while (((x+ a[j]) == (x^a[j])) && j < n){
            x += a[j];
            j++;
        }
        ans += j-i;
        if(j<i){
            j++;
        }else{
            x -= a[i];
        }
    }
    cout<<ans<<endl;
    return  0;
}


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

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
import java.util.TreeSet;

public class Main{
	public static void main(String[] args) throws IOException{
		Scanner in = new Scanner(System.in);
		while(true){
			int x = in.nextInt();
			int y = in.nextInt();
			int s = in.nextInt();
			if(s == 0) break;
			int res = 0;
			for(int i=1; i<s; i++){
				for(int j=1; j<s; j++){
					if(i*(100+x)/100 + j*(100+x)/100 != s
							|| i+j>s) continue;
					res = Math.max(res, i*(100+y)/100+j*(100+y)/100);
				}
			}
			System.out.println(res);
		}
	}
}

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

using namespace std;

#define all(x) begin(x), end(x)

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

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

    int n, m;
    cin >> n >> m;

    vector<vi> graph(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u; --v;

        graph[u].push_back(v);
    }

    int src, sink;
    cin >> src >> sink;
    --src; --sink;

    vector<int> dist(3 * n, -1);
    queue<int> q;
    dist[3 * src] = 0;
    q.push(3 * src);

    while (!q.empty()) {
        int uk = q.front();
        q.pop();

        int u = uk / 3;
        int k = uk % 3;
        int l = (k + 1) % 3;

        for (int v : graph[u]) {
            int vl = 3 * v + l;
            if (dist[vl] == -1) {
                dist[vl] = dist[uk] + 1;
                q.push(vl);
            }
        }
    }

    if (dist[3 * sink] == -1) {
        cout << -1 << '\n';
    } else {
        cout << (dist[3 * sink] / 3) << '\n';
    }

    return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vp task(N);
  rep(i,N) {
    int a,b;
    cin >> a >> b;
    task[i] = P(b,a);
  }
  int t = 0;
  sort(rng(task));
  rep(i,N) {
    t += task[i].second;
    if(t > task[i].first) {
      cout << "No" << endl;
      return 0;
    } 

  }
  cout << "Yes" <<endl; 
  return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
import java.io.*;

class Main {
    public static void main(String[] args)throws IOException{ 
    	InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader read = new BufferedReader(in);

        int num = Integer.parseInt(read.readLine());
        int count,p;
        double d1 = 0;
        double d2 = 0;
        double d22 = 0;
        double d3 = 0;
        double d33 = 0;
        double d4 = 0;
        double max = 0;
        
        
        String linex = read.readLine();
        String [] splix = linex.split(" ");
        double [] x = new double [num];        
        for(count = 0; count < num; count++){
            x[count] = Double.parseDouble(splix[count]);          //????????????x    
        }  
        
        String liney = read.readLine();
        String [] spliy = liney.split(" ");
        double [] y = new double [num];        
        for(count = 0; count < num; count++){
            y[count] = Double.parseDouble(spliy[count]);          //????????????y        
        }  
        
        for(p = 1; p <= 4; p++){
        	
        	if(p == 1){
        		for(count = 0; count < num; count++){
                    d1 = d1+Math.abs(x[count]-y[count]); 
                }
        		System.out.println(d1);
        	}
        	else if(p == 2){
        		for(count = 0; count < num; count++){
                    d2 = d2+Math.abs((x[count]-y[count])*Math.abs(x[count]-y[count]));
                    d22 = Math.sqrt(d2);
                }
        		System.out.println(d22);
        	}
        	else if(p == 3){
        		for(count = 0; count < num; count++){
        			d3 = d3+Math.abs(x[count]-y[count])*Math.abs(x[count]-y[count])*Math.abs(x[count]-y[count]);
                    d33 = Math.cbrt(d3);
        		}
        		System.out.println(d33);
        	}
        	else{
        		for(count = 0; count < num; count++){
        			d4 = Math.abs(x[count]-y[count]);
        			if(count == 0){
        				max = d4;
        			}
        			if(max < d4){
    					max = d4;
    				}   				       			       			
        	     }
        		System.out.println(max);
        	}
        }
        
    }
}

Measured memory_bytes: 24348
# -*- coding: utf-8 -*-
# 整数の入力
#a = int(input())
# スペース区切りの整数の入力
#b, c = map(int, input().split())
# 文字列の入力
#s = input()
# 出力
#print("{} {}".format(a+b+c, s))

n = int(input())
a = list(map(int, input().split()))

ans=0
pm=n+1
for i in range(0,n):
  if a[i] < pm:
    ans+=1
    pm=a[i]

print(ans)


Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
int main(){
int N; string S; cin >> N >> S; 
if(N%2){ cout << "No\n"; return 0; }
for(int i=0, T=N/2; i<T; i++){
if(S[i]!=S[T+i]){ cout << "No\n"; return 0; }
}
cout << "Yes\n";
}

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

long long a, b, c, d;

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

bool solve() {
  if (a < b) return false;
  if (d < b) return false;
  if (c >= b-1) return true;

  long long g = GCD(b, d);

  // g で割って a あまる数で、c より大きく b 未満な整数があるかどうか
  a %= g;
  long long val = c;
  if (val % g == a) val += g;
  else val += (a - val%g + g) % g;
  if (val < b) return false;
  else return true;
}

int main() {
  int T; cin >> T;
  for (int CASE = 0; CASE < T; ++CASE) {
	cin >> a >> b >> c >> d;
	if (solve()) cout << "Yes" << endl;
	else cout << "No" << endl;
  }
}


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

l,r,num,ans = 0,0,0,0

while r<N:
        if num + A[r] == num ^ A[r]:
                num ^= A[r]
                r += 1
                ans += r-l
        else:
                num ^= A[l]
                l += 1

print(ans)

Measured memory_bytes: 23560
import collections
def main():

    N = int(input())
    S = input()
    d = collections.defaultdict(set)
    for i in range(N):
        for v in d[2]:
            d[3].add(v + S[i])
        for v in d[1]:
            d[2].add(v + S[i])
        d[1].add(S[i])
        # print(d[1])
        # print(d[2])
        # print(d[3])
    return len(d[3])

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 41836