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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,T,t[ohara],limitv[ohara],nowtime=0;
double v[ohara],ans;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n;

      rep(i,n){
        cin>>t[i];
        T+=t[i];
      }

        rep(i,ohara)v[i]=1000000000.0;

      rep(i,n){
        cin>>limitv[i];
        rrep(j,nowtime,nowtime+t[i]*2+1)v[j]=min(v[j],(double)limitv[i]);
        nowtime+=t[i]*2;
      }
    
      v[0]=0.0;v[2*T]=0.0;

      rrep(i,1,2*T+1){
        v[i]=min(v[i],v[i-1]+0.5);
      }

      v[0]=0.0;v[2*T]=0.0;
      rrrep(i,2*T,0){
        v[i]=min(v[i],v[i+1]+0.5);
      }

      v[0]=0.0;v[2*T]=0.0;

     rep(i,2*T){
       double up,down;
       up=v[i+1];
       down=v[i];
       ans+=(up+down)*0.5/2.0;
     }

     printf("%.15f\n",ans);
   


     

       
return 0;
}


Measured memory_bytes: 10496
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int k = sc.nextInt();
        ArrayList<String> list = new ArrayList<>();
        for (int i = 1; i <= k; i++) {
            for (int j = 0; j < s.length() - i + 1; j++) {
                try {
                    if (!list.contains(s.substring(j, j + i)))
                        list.add(s.substring(j, j + i));
                } catch (Exception e) {
                }
            }
        }
        Collections.sort(list);
        System.out.println(list.get(k - 1));
    }
}


Measured memory_bytes: 26068
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
// #define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N 102
#define MAX 200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"

const ll inf = (ll)1e18 + 10;
int l;
vec v;
int dp[102][10004][2] ;
int d;
int digitdp(int sum , int k , int t){
	int res = 0;
	if(k == l && sum % d == 0)
		return 1;
	else if(k == l && sum% d != 0)
		return 0;
	if(dp[sum][k][t] != -1)
		return dp[sum][k][t];
    int mx = (t == 1) ? v[k] : 9;
	for(int i = 0 ; i <= mx ; i++){
         int dt = (i == v[k]) ? t : 0;
         res += digitdp((sum + i) % d , k + 1 , dt);
         res %= mod;
	}

	dp[sum][k][t] = res;


	return dp[sum][k][t];

}
signed main(){
  fast;
   string s;
  cin >> s;
  l = s.length();
  for(int i = 0 ; i < s.length() ; i++){
  	int x = (int )s[i]  - '0';
  	v.pb(x);
  }
  
  memset(dp , -1 , sizeof(dp));
  cin >> d;

  int ans = digitdp(0 , 0 , 1) - 1 + mod;
  ans %= mod;
  
  cout << ans << endl;


}	

Measured memory_bytes: 9344
from sys import stdin
from collections import deque
n = int(stdin.readline())
d = [-1] * (n + 1)
def bfs():
    d[1] = 0
    dq = deque([1])
    while len(dq) != 0:
        v = dq.popleft()
        for c in G[v]:
            if d[c] != -1 : continue
            d[c] = d[v] + 1
            dq.append(c)
    for i, x in enumerate(d[1:], start=1):
        print(i, x)
G = [0] + [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
bfs()

Measured memory_bytes: 8092
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author CompuWare
 */

#include <bits/stdc++.h>

using namespace std;

class CMultiplication3 {
public:
    void solve(std::istream &in, std::ostream &out) {
        long double a, b;
        in >> a >> b;
        long double res = a * b;
        out << (int64_t) (floor((res * 100) + 0.5) / 100);
    }
};


int main() {
    CMultiplication3 solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3732
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    cycle = 0
    flag = True
    visited = [0] * N
    visited[0] = 1
    visited_num = [0] * N
    before_city = 0
    visited_city = 0
    periodic = 0
    while flag:
        next_city = A[before_city] - 1
        cycle += 1
        if cycle >= K:
            flag = False
        if visited[next_city] == 1:
            visited_city = next_city
            periodic = cycle - visited_num[next_city]
            flag = False
        else:
            visited[next_city] = 1
            visited_num[next_city] = cycle
            before_city = next_city
    #print(periodic)
    #print(visited_city)
    if cycle < K:
        K_new = (K - cycle) % periodic
        before_city = visited_city
        for i in range(K_new):
            next_city = A[before_city] - 1
            before_city = next_city
        print(next_city+1)
    else:
        print(next_city+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 92388
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  long long k;
  cin >> k;
  char crr = s[0];
  long long cnt = 0;
  long long sum = 0;
  bool flag = true;
  int first_cnt = 0;
  int last_cnt = 0;
  for(int i = 1; i < s.length(); ++i){
    if(crr == s[i]) cnt++;
    else {
      if(flag){
        first_cnt = cnt;
        flag = false;
      }
      sum += (cnt + 1) / 2;
      crr = s[i];
      cnt = 0;
    }
  }
  if(cnt == s.length() - 1){
    cout << (cnt + 1) * k / 2 << endl;
    return 0;
  }
  sum += (cnt + 1) / 2;
  long long minus = 0;
  if(s[0] == s[s.length() - 1]){
    char temp = s[s.length() - 1];
    for(int i = s.length() - 2; i >= 0; --i){
      if(temp == s[i]) last_cnt++; 
      else break;
    }
    minus = ((first_cnt + 1) / 2 + (last_cnt + 1) / 2 - (first_cnt + last_cnt + 2) / 2) * (k - 1);
  }
  cout << sum * k - minus << endl;
}

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

int main(){
  char num[100000];
  int l,count_zero,count_one,ans;
  count_zero = count_one = 0;
  scanf("%s",num);
  l = strlen(num);

  for(int i = 0; i < l; i ++){
    if(num[i] == '0'){
      count_zero ++;
    }else{
      count_one ++;
    }
  }

  if(count_zero < count_one){
    ans = count_zero * 2;
  }else{
    ans = count_one * 2;
  }

  printf("%d",ans);

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {

	int W, H, x, y, r;
	
	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);

	if (W <= x || H <= y || x < 0 || y < 0 || W - x < r || H - y < r) printf("No\n");
	else if (x < W && y < H && W - x >= r && H - y >= r) printf("Yes\n");

	return 0;

}


Measured memory_bytes: 2112
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#include<bits/stdc++.h>
#define fr first
#define sc second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define forn(i,n) for(int i =1;i<= (n);++i)
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
const int inf = 1e9+7;
const int nmax = 500005;
const ll linf = LLONG_MAX;
const ll mod = 1000000007;

ll n , a[200005] , b[200005] , ax[200005] , bx[200005] , cnt[200005] , sp[200005] , hashb , hasha;
int nx(int i){
    return i%n + 1;
}
ll m = 999999733;

int main(){
    fast;
    ll im = 1 , s = m;
    for(ll i = 0 ; (1<<i) <= (mod-2) ; i++){
        if((mod-2)&(1<<i)){
            im *= s;
            im %= mod;
        }
        s *= s;
        s%= mod;
    }
    cin >> n;
    forn(i,n){
        cin >> a[i];
    }
    forn(i,n){
        cin >> b[i];
    }
    forn(i,n){
        ax[i] = a[i]^a[nx(i)];
        bx[i] = b[i]^b[nx(i)];
    }
    sp[0] = 1;
    forn(i,n){
        sp[i] = sp[i-1] * m;
        sp[i] %= mod;
    }
    forn(i,n){
        hashb += bx[i]*sp[i-1];
        hashb %= mod;
    }
    //
    forn(i,n){
        hasha += ax[i]*sp[i-1];
        hasha %= mod;
    }
    //
    //cout << "HASHB "   << hashb << '\n';
    if(hasha == hashb){
        cout << 0 <<' '<< ll(a[1]^b[1]) << '\n';
    }
    //
    //cout << "HASHES:\n";
    //cout << 1 << ' ' << hasha << '\n';
    forn(i,n-1){
        hasha -= ax[i];
        hasha = (hasha + mod)%mod;
        hasha *= im;
        hasha %= mod;
        hasha += sp[n-1]*ax[i];
        hasha %= mod;
        //cout << i+1 << ' ' << hasha << '\n';
        if(hasha == hashb){
            cout << i << ' ' << ll(a[i+1]^b[1]) << '\n';
        }
    }
    // 10^9 10^5 * 10^9
    // choose k
    // a[i+k] xor b[i] - same for all i
    // a[i+k] xor a[i+k+1] = b[i] xor b[i+1]
    // a[i] xor a[i+1] - cyclic shift of b[i] xor b[i+1]
}


Measured memory_bytes: 12416
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
ans=0
ans1=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+ans1,n):
      ans1=0
      if l[i]+l[j]>l[-1]:
        ans+=n-j-1
        break
      elif l[i]+l[j]<=l[k] :
        ans+=k-j-1
        ans1+=k-j-1
        break
      
      
print(ans)
      
        
        


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

int main()
{
	int a, b, x;
	char op;

	while (true){

		cin >> a >> op >> b;

		if (op == '+')
		{
			x = a + b;
			cout << x << endl;
		}

		else if (op == '-')
		{
			x = a - b;
			cout << x << endl;
		}

		else if (op == '*')
		{
			x = a * b;
			cout << x << endl;
		}

		else if (op == '/')
		{
			x = a / b;
			cout << x << endl;
		}

		else if (op == '?')
		{
			break;
		}
	}
}

Measured memory_bytes: 1164
#include <iostream>
#include <queue>
#include <vector>
#include <utility>

#define rep(i,n) REP(i,0,n)
#define REP(i,a,n) for(int i = a; i < (int)n; i++)
#define pb push_back
#define NIL - 1
#define MAX 100001

using namespace std;

struct Node{
  int id;
  int parent;
  vector<int> child;
  int depth;

  void addChild(int a){
    child.pb(a);
}

  void print(){
    cout << "node " << id << ": ";
    cout << "parent = " << parent << ", ";
    cout << "depth = " << depth << ", ";
    cout << (parent == -1?"root":child.size() == 0?"leaf":"internal node") << ", ";
    cout << "[";
    if(child.size() != 0){
      rep(i,child.size()-1){
	cout << child[i] << ", ";
      }
      cout << child[child.size()-1];
    }
    cout << "]" << endl;
  }
};

Node node[MAX];

void init(int n){
  rep(i,n){
    node[i].depth = NIL;
    node[i].parent = NIL;
    node[i].child.clear();
  }
}

signed main(){
  int n;
  int id, k, a, root;
  cin >> n;
  init(n);
  root = NIL;

  rep(i,n){
    cin >> id >> k;
    node[id].id = id;
    rep(j,k){
      cin >> a;
      node[id].addChild(a);
      node[a].parent = id;
      node[a].depth = node[id].depth + 1;
    }
  }

  rep(i,n){
    if(node[i].parent == NIL){
      root = i;
      break;
    }
  }

  queue<pair<Node,int> > q;
  q.push(make_pair(node[root], -1));
  while(!(q.empty())){
    pair<Node, int> p = q.front(); q.pop();
    node[p.first.id].depth = p.second + 1;
    rep(i, p.first.child.size()){
      q.push(make_pair(node[p.first.child[i]], p.second + 1));
    }
  }

  rep(i,n){
    node[i].print();
      }
}



Measured memory_bytes: 12572
import java.util.Scanner;

public class Main{
  static int x, a, b;

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

    x = sc.nextInt();
    a = sc.nextInt();
    b = sc.nextInt();

    if(b <= a){
      System.out.println("delicious");
    }
    else if(a + x >= b){
      System.out.println("safe");
    }
    else{
      System.out.println("dangerous");
    }
  }
}


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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;




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

    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if (!a)         cout << 1;
    else if (!b)    cout << 2;
    else if (!c)    cout << 3;
    else if (!d)    cout << 4;
    else            cout << 5;




    return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,Q,c[300010],ans[300010];
int p[601];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>Q;
	rep(i,N)cin>>c[i];
	sort(c,c+N);
	
	fill(p+1,p+601,N-1);
	for(int i=300000;i>=601;i--){
		rep2(j,1,601){
			while(p[j]>=0 && c[p[j]] >= i*j) p[j]--;
			if(p[j]>=0) ans[i]=max(ans[i],c[p[j]]%i);
		}
	}
	
	rep2(i,1,601){
		rep(j,N)ans[i]=max(ans[i],c[j]%i);
	}
	
	rep(i,Q){
		int q;
		cin>>q;
		cout<<ans[q]<<endl;
	}
}

Measured memory_bytes: 3560
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

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

	N /= 100;
	printf("ai1333");

	for(int i = 0; i < N; i++)printf("3");

	printf("\n");

	return 0;
}



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

# 有向グラフで優先度付きキューで探索

from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')

def dijkstra(s,n,g):
    seen = [False]*n
    cost = [INF]*n
    cost[s] = 0 #スタートはコスト0
    next_q = [(0,s)]
    heapify(next_q)
    while len(next_q)>0:
        c, i = heappop(next_q)
        if cost[i] < c:
            continue
        for nedge, ncost in g[i]:
            nc = cost[i]+ncost
            if cost[nedge]>nc:
                cost[nedge] = nc
                heappush(next_q,(nc, nedge))
    return cost

def main():
    N, M, S, T = map(int, input().split())
    graph_F = [[] for _ in range(N)]
    graph_R = [[] for _ in range(N)]
    #リストの作成
    for i in range(M):
        a, b, c, d = map(int, input().split())
        a -= 1
        b -= 1
        graph_F[a].append((b,c))
        graph_F[b].append((a,c))
        graph_R[a].append((b,d))
        graph_R[b].append((a,d))

    F = dijkstra(S-1,N,graph_F)
    R = dijkstra(T-1,N,graph_R)

    ret = [i+j for (i, j) in zip(F, R)]
    X = 10**15
    for r in range(N-2,-1,-1):
        ret[r] = min(ret[r+1], ret[r])
    for r in ret:
        print(X-r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 81352
n = int(input())
d = {}
for i in range(n):
    order, num = input().split()
    num = int(num)
    if order not in d:
        d[order] = num
    else:
        d[order] += num
# tupleにして、keyの長さでソートできるようにする。
d = sorted(d.items())
d = sorted(d, key=lambda x: len(x[0]))

for line in d:
    print(line[0], line[1])



Measured memory_bytes: 5624
#include<iostream>
#include<algorithm>
#include<string> 
#include<map>
#include<set>
#include<vector>
#include<string.h> 
#include<math.h>
#include<stdio.h> 
#include<queue>
using namespace std; 
int a[105]; 
int main()
{int n,d,x;cin>>n>>d>>x;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)
x+=1+(d-1)/a[i];
cout<<x;
system("pause");
return 0;
}

Measured memory_bytes: 504
from collections import deque
import sys
#sys.setrecursionlimit(200000)
#input = sys.stdin.readline
#n = int(input())
#x,y = map(int,input().split())
#a = list(map(int,input().split()))
s = input()
for i in range(len(s)):
    for j in range(len(s)):
        if i > j:
            continue
        if s[:i] + s[j:] == "keyence":
            print("YES")
            exit()
print("NO")

Measured memory_bytes: 3444
#include<stdio.h>
int main(){
    int n,a[1000];
    int i,tmp=0;
    scanf("%d",&n);

    for(i=0;i<n;i++)
        scanf("%d",&a[i]);

        for(i=0;i<n/2;i++){
                tmp=a[n-1-i];
                a[n-1-i]=a[i];
                a[i]=tmp;
            }
        for(i=0;i<n-1;i++)
            printf("%d ",a[i]);
        printf("%d\n",a[n-1]);
            


    return 0;
}




Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n-1; i++) {
    if(a[i+1]==a[i]){
      cout << "NO" << endl;
      exit (0);
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 1792
#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 = 1007;

bool used[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    string s;
    cin >> s;
    int k;
    cin >> k;

    bool c = 1;
    for (int i = 0; i + 1 < s.size(); ++i)
        c &= s[i] == s[i + 1];
    if (c) {
        int len = s.size() * k;
        cout << len / 2 << endl;
    }   
    else {
        if (s[0] != s.back()) {
            int ans = 0;
            for (int i = 0; i + 1 < s.size(); ++i) {
                if (s[i] == s[i + 1]) {
                    ++i;
                    ++ans;
                }   
            }   
            cout << ans * k << endl;
        }   
        else {
            vector <int> seg;
            int cur = 1;
            for (int i = 1; i < s.size(); ++i) {
                if (s[i] != s[i - 1]) {
                    seg.app(cur);
                    cur = 1;
                }   
                else {
                    ++cur;
                }
            }
            seg.app(cur);

            int ans = 0;
            for (int i = 1; i < seg.size() - 1; ++i) {
                ans += (seg[i] / 2) * k;
            }   
            ans += seg[0] / 2;
            ans += seg.back() / 2;
            ans += ((seg[0] + seg.back()) / 2) * (k - 1);

            cout << ans << endl;
        }   
    }   

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string a;
int main()
{
	cin>>a;
	for(int i=1;i<a.size();i++)
		if(a[i]==a[i-1])
		{
			cout<<i<<" "<<i+1<<"\n";
			return 0;
		}
	for(int i=2;i<a.size();i++)
		if(a[i]==a[i-2])
		{
			cout<<i-1<<" "<<i+1<<"\n";
			return 0;
		}
	cout<<-1<<" "<<-1<<"\n";
}

Measured memory_bytes: 512
def main():
	n,a=map(int,input().split())
	y=[a-int(x) for x in input().split()]
	dp={0:1}
	for i in y:
		for k,v in list(dp.items()):
			dp[i+k]=dp.get(i+k,0)+v
	print(dp[0]-1)
if __name__=="__main__":
	main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
const int N=1e5+7;
struct edge{
	int to,nx;
}e[N*2];
int n,e0[N],ep=2,f[N];
void f1(int w,int pa){
	for(int i=e0[w];i;i=e[i].nx){
		int u=e[i].to;
		if(u!=pa)f1(u,w);
	}
	int v1=0,v2=0,v3=1;
	for(int i=e0[w];i;i=e[i].nx){
		int u=e[i].to;
		if(u!=pa){
			int x=f[u];
			v2|=v1&x;
			v1|=x;
		}
	}
	for(;v3<=v2||(v3&v1);v3<<=1);
	f[w]=(v1|v3)&~(v3-1);
}
int main(){
	scanf("%d",&n);
	for(int i=1,a,b;i<n;++i){
		scanf("%d%d",&a,&b);
		e[ep]=(edge){b,e0[a]};e0[a]=ep++;
		e[ep]=(edge){a,e0[b]};e0[b]=ep++;
	}
	f1(1,0);
	int ans=0;
	for(;f[1]>1;f[1]>>=1,++ans);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6016
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, Read};
use std::usize;

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, a: [usize; n]);
    if a[0] != 0 {
        println!("{}", -1);
        return;
    }
    let mut ret = 0;
    let mut prev = 0;
    for &ai in &a[1..] {
        if prev + 1 < ai {
            println!("{}", -1);
            return;
        } else if prev + 1 != ai {
            ret += prev;
        }
        prev = ai;
    }
    println!("{}", ret + prev);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

class Program {
  static void Main() {
    int L;
    while ((L = int.Parse(Console.ReadLine())) != 0) {
      int s = 0;
      int a = 0;
      for (int i = 1; i <= 12; i++) {
        s += Console.ReadLine().Split().Select(int.Parse).Aggregate((m, n) => m - n);
        if (s >= L && a == 0) a = i;
      }
      Console.WriteLine(a == 0 ? "NA" : a.ToString());
    }
  }
}


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

int main() {
	// your code goes here
	int x,i=1;
	
	while( 1 ){
	   cin >>x	;
	   if ( x==0 ){ break ; }
	
     	cout<<"Case "<<i<<": "<<x<<endl;
     	i++;
    }
	
	
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main() {
    int bill;
    scanf("%d", &bill);

    while(bill > 0) {
        bill -= 1000;
    }

    if(bill == 0) {
        printf("0\n");
    } else {
        printf("%d", bill * -1);
    }

    return 0;
}

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

int main(void)
{
	int n, rui, out, score;
	char ive[30];
	
	scanf("%d", &n);
	if (n == 0)return (0);
	while (n != 0){
		n--;
		rui = 0;
		out = 0;
		score = 0;
		while (out < 3){
			scanf("%s", ive);
			
			if (strcmp(ive, "HIT") == 0){
				rui++;
				if (rui > 3){
					score += rui - 3;
					rui--;
				//	printf("%d\n", score);
				}
			}
			else if (strcmp(ive, "HOMERUN") == 0){
				score += rui + 1;
				rui = 0;
			//	printf("%d\n", score);
			}
			else if (strcmp(ive, "OUT") == 0){
				out++;
			//	printf("%d\n", score);
			}
		}
		printf("%d\n", score);
	}
	
	return (0);
}

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

int main(void)
{
   int a, b;
   cin >> a >> b;

   if(a==b){
      for (int i = 0; i < a;i++){
         cout << a;
      }
      cout << endl;
      return 0;
   }
   else if(a<b){
      for (int i = 0; i < b;i++){
         cout << a;
      }
      cout << endl;
      return 0;
   }
   else {
      for (int i = 0; i < a; i++)
      {
         cout << b;
      }
      cout << endl;
      return 0;
   }
   return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
a = int(input())
l = []
for i in range(a):
    t,T = map(int,input().split())
    l.append((t,T))
l = sorted(l, key=itemgetter(1), reverse=False)
# print(l)
E = 0
S = 0 
s = 0
for i , j in l :
    E += abs(E-j)
    S += i
    if S>E:
        s=1 
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')

y(s)

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

#define int long long

#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()

#define debug1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

#define INF (int)10000000000000000
#define PI (double)3.14159265358979
// #define M 421412341324321
#define MOD 1000000007


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

   	int n, k, c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    int pre = -1;
    vector <int> a(sz(s), LLONG_MAX);
    int cnt = 0;
    for (int i=0;i<n;++i)
    {
        if (cnt==k)
            break;
        if (s[i]=='x')
            continue;
        else
        {
            if (pre==-1)
            {
                a[i] = cnt;
                cnt++;
                pre = i;
            }
            else
            {
                if (i-pre>c)
                {
                    // debug1(i);
                    a[i] = cnt;
                    cnt++;
                    pre = i;
                }
            }
        }
    }
    vector <int> ans;
    cnt = 0, pre = -1;
    for (int i=n-1;i>=0;--i)
    {
        if (cnt==k)
            break;
        if (s[i]=='x')
            continue;
        else
        {
            if (pre==-1)
            {
                pre = i;
                if (a[i]==k-cnt-1){
                    ans.pb(i+1);
                }
                cnt++;
            }
            else
            {
                if (pre-i>c)
                {
                    if (a[i]==k-cnt-1)
                        ans.pb(i+1);
                    cnt++;
                    pre = i;
                }
            }
        }
    }
    sort(all(ans));
    // reverse(all(ans));
    for (auto j:ans)
        cout<<j<<"\n";

    return 0;
}

Measured memory_bytes: 5000
#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <iostream> 
#include <cstdlib>

using namespace std;

int main()
{
int N, M;
 cin >> N >> M;

 const int NMMAX = 50;
 int A[NMMAX], B[NMMAX];

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

 int road[NMMAX];
 for (int i = 0; i < N; ++i) {
 road[i] = 0;
 }

 for (int i = 0; i < M; ++i) {
 road[A[i] - 1] += 1;
 road[B[i] - 1] += 1;
 }

 for (int i = 0; i < N; ++i) {
 cout << road[i] << endl;
 }
}

Measured memory_bytes: 256
while 1:
    zero=0
    number=1
    n=int(input())
    if n==0:break
    for i in range(1,n+1):
        number*=i
        while len(str(number))>7:number=int(str(number)[1:])
        while number%10==0:
            zero+=1
            number=int(number/10)
    print(zero)


Measured memory_bytes: 5596
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            //日付を入力する
            string[] input = Console.ReadLine().Split(' ');
            int x = int.Parse(input[0]);
            int k = int.Parse(input[1]);
 
            //月が同じなら月末、それ以外は別
            if(x*500 >= k)
                Console.WriteLine("Yes");
            else
            {
                Console.WriteLine("No");
            }
                
        }
    }


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
int main(){
   ll a,b,n;
   cin>>n>>a>>b;
   ll s=n/(a+b);
   ll f=n%(a+b);
   if(f>a)cout<<s*a+a<<endl;
   else cout<<s*a+f<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char cd;
  int i,j,n,rank;
  int card[4][13];
  char buf[512];
  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      card[i][j] = 0;
    }
  }
  fgets(buf,512,stdin);
  sscanf(buf, "%d",&n);
  for(i=0;i<n;i++){
    fgets(buf, 512, stdin);
    sscanf(buf, "%c %d", &cd, &rank);
    switch(cd){
    case 'S':
      card[0][rank-1] = 1;
      break;

    case 'H':
      card[1][rank-1] = 1;
      break;

    case 'C':
      card[2][rank-1] = 1;
      break;

    case 'D':
      card[3][rank-1] = 1;
      break;
    }
  }

  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      if(card[i][j] == 0){
	switch(i){
	case 0:
	  printf("S %d\n",j+1);
	  break;

	case 1:
	  printf("H %d\n",j+1);
	  break;

	case 2:
	  printf("C %d\n",j+1);
	  break;

	case 3:
	  printf("D %d\n",j+1);
	  break;
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
#define ld long double

using namespace std;

const int MAXN = 100010;
map <int, ll> dp1, dp2, ma1, ma2; 
ll dist[MAXN], val[MAXN];

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

  int n;
  ll c;
  cin >> n >> c;
  REP(i, n) {
  	cin >> dist[i] >> val[i];
  }

  ll s = 0;
  REP(i, n) {
  	s += val[i];
  	dp1[i] = s - dist[i];
  	ma1[i] = dp1[i];
  	if (i) ma1[i] = max(ma1[i], ma1[i - 1]);
//  	cout << dp1[i] << " ";
  }
//  cout << endl;

  s = 0;
  FORd(i, n - 1, 0) {
  	s += val[i];
  	dp2[i] = s - (c - dist[i]);
  	ma2[i] = max(dp2[i], ma2[i + 1]);
//  	cout << dp2[i] << " ";
  }
//  cout << endl;

  ll out = 0;
  REP(i, n) {
  	out = max(out, dp1[i] + max(0LL, -dist[i] + ma2[i + 1]));
  	out = max(out, dp2[i] + max(0LL, -(c - dist[i]) + ma1[i - 1]));
  }
  cout << out << "\n";


  return 0;
}

Measured memory_bytes: 26880
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define F  first
#define S  second
#define ff(i,n) for(i=0;i<n;i++)
ll bg = 1000000007;
ll power(ll x,ll y)
{
	if(y==0)
		return 1;
	ll h=power(x,y/2)%bg;	
	h=(h*h)%bg;
	if(y%2==1)
	  return (x*h)%bg;
	else
	  return h%bg;  
}
ll modinv(ll m)
{
	return power(m,bg-2)%bg;
}
vector<ll> z_func(vector<ll> a)
{
	ll n = a.size();
	vector<ll> z(n);
	ll l=0,r=0;
	for(ll i=1;i<n;i++)
	{
		if(i<=r)
			z[i] = min(r-i+1,z[i-l]);
		else
			z[i]=0;
		while(i+z[i]<n && a[z[i]]==a[i+z[i]])
		   z[i]++;
		if(i+z[i]-1>r)
		{
			l = i;
			r = i+z[i]-1;	
		}   		
	}
	return z;
}
string s;
ll arr[600000];
vector<vector<ll> >adj(600000);
int main()
{ 
	ll t;
	t=1;
	while(t--)
	{
		ll i,n;
		cin>>n;
	    ll a,b;
	    cin>>a>>b;
	    if(abs(a-b)%2==0)
	        cout<<"Alice";
	    else
		    cout<<"Borys";    
	}	    
	return 0;
}

Measured memory_bytes: 14336
#pragma warning (disable:4996)
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <stack>
#include <queue>
#define inf 0X7f7f7f7f
#define MS_I(x) memset(x,-inf,sizeof(x))
#define MS(x) memset(x,0,sizeof(x))
#define MSI(x) memset(x,inf,sizeof(x))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5 + 5;

int main()
{
	int N, k, h;
	int ans = 0;
	scanf("%d%d", &N, &k);
	while (N--)
	{
		scanf("%d", &h);
		if (h >= k)
			ans++;
	}
	printf("%d\n", ans);
}

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

using namespace std;
typedef long long ll;

bool check_dist(const vector<ll>& x, const vector<ll>& y){
    ll sum = 0;
    for(int i = 0; i < x.size(); ++i){
        sum += (x.at(i) - y.at(i)) * (x.at(i) - y.at(i));
    }
    long double dist = sqrt((long double)sum);
    dist = round(dist);
    return dist * dist == (long double)sum;
}

int main(){
    ll n, d;
    cin >> n >> d;
    vector<vector<ll>> xs(n, vector<ll>(d, 0));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < d; ++j){
            cin >> xs.at(i).at(j);
        }
    }

    ll count = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            if(check_dist(xs.at(i), xs.at(j))){
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    int n; cin >> n;

    int cnt[8] = {};
    int rainbow = 0;
    int boundary[] = {400, 800, 1200, 1600, 2000, 2400, 2800, 3200};
    for(int i=0; i<n; i++){
        int temp; cin >> temp;

        for(int j=0; j<8; j++){
            if(temp < boundary[j]){
                cnt[j] = 1;
                break;
            }
        }
        if(temp >= 3200) rainbow++;

    }

    int fixed = accumulate(cnt, cnt+8, 0);

    if(fixed == 0){
        cout << 1 << " " << rainbow;
    }
    else{
        cout << fixed << " " << fixed + rainbow;
    }


    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
MOD = 998244353
dp = [0 for _ in range(N+1)]
dp[1] = 1
R = [tuple(map(int,input().split())) for _ in range(K)]
S = [0 for _ in range(K)]
for i in range(2, N+1):
	s = 0
	for k in range(K):
		S[k] += dp[max(0, i - R[k][0])] - dp[max(0, i - R[k][1] - 1)]
		S[k] %= MOD
		s = (s + S[k]) % MOD
	dp[i] = s
print(dp[N])

Measured memory_bytes: 16980
let fib_dp n =
  if n < 2 then 1
  else
    let rec doit i x y =
      if i = n then y
      else doit (i + 1) y (x + y) in
    doit 2 1 2

let () = read_int () |> fib_dp |> Printf.printf "%d\n"

Measured memory_bytes: 2272
#include<stdio.h>

int main(){
    int n,x;
    int i,j,k,posi=0,counter[10000];
    
    for(i=0;i<10000;i++){
        counter[i]=0;
    }
    
    while(1){
        
        scanf("%d %d",&n,&x);
        
        if(n==0&&x==0){
            counter[posi]=-1;
            break;
        }
        
        for(i=1;i<n-1;i++){
            for(j=i+1;j<n;j++){
                k=x-i-j;
                if(k<=j){
                    break;
                }else if(k>n){
                    continue;
                }else{
                    counter[posi]++;
                }
            }
        }
        posi++;
    }
    
    posi=0;
    while(counter[posi]!=-1){
        printf("%d\n",counter[posi]);
        posi++;
    }
    
    return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n;
	cin>>n;
	map<string,lli> d;
	lli maxCnt=0;
	REP(i,0,n){
		string s;
		cin>>s;
		d[s]++;
		maxCnt = max(maxCnt,d[s]);
	}

	for(auto e:d){
		if(e.second == maxCnt)cout<<e.first<<endl;
	}






	return 0;
}

Measured memory_bytes: 25216
n=int(input())
s=input()
r,g,b=0,0,0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1
m=0
for i in range(n):
    for j in range(n):
        if i-j<0 or i+j>=n:
            break
        if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:
            m+=1
print(r*g*b-m)


Measured memory_bytes: 68328
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double DA = ((H * 60 + M) / (60 * 12) * 360);
    double DB = (M / 60.0 * 360);
    double D = abs(DA - DB);
    if (D > 180) D = 360 - D;
    double sui = abs(A * sin(D * M_PI / 180.0)); 
    double hen = abs(A * cos(D * M_PI / 180.0));
    if (D < 90) B -= hen; else B += hen;
    double res = sqrt(sui * sui + B * B);
    cout << fixed << setprecision(20);
    cout << res << endl;
}


Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
// #include <cmath>
// #include <math.h>
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int a;
    vector<int> v(N+10, 0);
    for(int i=0; i<N; ++i){
        cin >> a;
        v[a] += 1;
    }
    sort(v.begin(), v.end(), greater<int>());
    int sum = 0;
    for(int i=K; i<=N; ++i){
        sum += v[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>

using namespace std;

int main(void){
    int n;
    cin >> n;
    int res = 1;
    int box;
    int k = (int)sqrt((double)n);
    for(int i=2;i<=k;i++){
        box = 1;
        while(1){
            box = box * i;
            if(box * i > n)break;
        }
        if(res < box)res = box;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
struct Point{int x,y,a,d;};
int w,h;
bool in(Point a){
  if(a.x<0||a.x>=w||a.y<0||a.y>=h) return false;
  return true;
}
int main(){
  cin >> w >> h;
  while(w!=0){
    int i,j,k;
    int st[30][30]={{}};
    int wfs[31][31][4]={{{}}};
    int c[4]={};
    int inf = 1 << 30;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	cin >> st[j][i];  
      }
    }
    fill(wfs[0][0],wfs[30][30],inf);
    //memset(wfs,inf,sizeof(wfs));
    for(i=0;i<4;i++)
      cin >> c[i];
    
    queue<Point> q;
    Point p,b;
    p.x=0;p.y=0;p.a=0;p.d=0;
    
    q.push(p);
    int ax[]={1,0,-1,0},ay[]={0,1,0,-1};
    while(!q.empty()){
      p=q.front();q.pop();
      
      if(wfs[p.x][p.y][p.a]>p.d) wfs[p.x][p.y][p.a]=p.d;
      else continue;
      //cout << p.x << ":" << p.y << ":" << p.d << endl;
      if(st[p.x][p.y]==4) {
	for(i=0;i<4;i++){
	  b.x=p.x+ax[i];b.y=p.y+ay[i];b.a=i;b.d=p.d+c[(4-p.a+i)%4];
	  if(in(b)) q.push(b);
	}
      }else{
	for(i=0;i<4;i++){
	  b.x=p.x+ax[i];b.y=p.y+ay[i];b.a=i;b.d=p.d;
	  if((p.a+st[p.x][p.y])%4!=i) b.d+=c[(4-p.a+i)%4];
	  if(in(b)) q.push(b);
	}
      }
    }
    
    int o=inf;
    
    for(i=0;i<4;i++)
      o=min(o,wfs[w-1][h-1][i]);
    
    cout << o << endl;
    cin >> w >> h;
  }
  return 0;
}

Measured memory_bytes: 1740
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=2e5+4;
const int lim=61;

int dp[N][64];

int main()
{
	int n; ll k;

	scn(n); lscn(k);

	rep(i,1,n+1)
	scn(dp[i][0]);

	rep(i,1,lim)
	{
		rep(node,1,n+1)
		dp[node][i]=dp[dp[node][i-1]][i-1];
	}

	int cur=1;

	rep(i,0,lim)
	if(k&(1LL<<i))
	cur=dp[cur][i];

	pri(cur);

    return 0;
}


Measured memory_bytes: 53868
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define all(a) (a).begin(), (a).end()
#ifdef LOCAL
	#define dbg(x) cout << #x << " = " << x << endl;
#else 
	#define dbg(x)
#endif 

using namespace std;

void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stderr);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();
}

const int INF = 1e9, MAXN = 1e5 + 10;                 	

bool check(string &s, string &t) {
 	vector<int> a(26), b(26);
 	for (int i = 0; i < len(s); ++i) {
 	    a[s[i] - 'a']++;
 	}	
 	for (int i = 0; i < len(t); ++i) {
 	 	b[t[i] - 'a']++;
 	}

 	for (int i = 0; i < 26; ++i) {
 	 	if (a[i] == 0 && b[i] != 0) {
 	 	    return false;
 	 	}	
 	}
 	return true;
}

void solve() {                         
	string s, t;
	cin >> s >> t;
	int n = len(s), m = len(t);

	if (!check(s, t)) {
		cout << -1 << endl;
		return;	
	}
	s.insert(0, "#");
	
	vector<vector<int>> f(n + 1, vector<int>(26, -1));
	int ans = 0;
	for (char ch = 'a'; ch <= 'z'; ++ch) {
		int i = 0;
		while (i <= n) {
		 	int prev = i;
		 	i++;
		 	while (i <= n && s[i] != ch) {
		 	 	i++;
		 	}
		 	if (i == n + 1) {
		 	    break;
		 	}
		 	for (int j = prev; j < i; ++j) {
		 		f[j][ch - 'a'] = i;
		   	}
		   	
	 	}    	
	}
	
	int j = 0, k = 0;
	for (int i = 0; i < m; ++i) {
		j = f[j][t[i] - 'a'];
		if (j == -1) {
		 	k++;
		 	j = f[0][t[i] - 'a'];
		}
		else {
		 	ans = j;
		}
	}	

	cout << k * n + j << endl;
}	


Measured memory_bytes: 24656
n = gets.to_i
a = gets.chomp.split.map(&:to_i)

gl = a[0]
gr = a[-1]
l = [0]
r = [0]

n.times do |i|
  gl = gl.gcd(a[i])
  gr = gr.gcd(a[n - 1 - i])
  l << gl
  r.unshift(gr)
end

m = []
n.times do |i|
  if l[i] == 0
    m << r[i + 1]
  elsif r[i + 1] == 0
    m << l[i]
  else
    m << l[i].gcd(r[i + 1])
  end
end
puts m.max

Measured memory_bytes: 24476
#include<bits/stdc++.h>
using namespace std;
int main(){
int H,W;
  cin>>H>>W;
  vector<vector<char>>M(H+2,vector<char>(W+2,'#'));
  for(int i=1;i<=H;i++){
  string S;
    cin>>S;
    for(int j=1;j<=W;j++){
    M.at(i).at(j)=S.at(j-1);
    
    }
  }for(int i=0;i<H+2;i++){
  for(int j=0;j<W+1;j++){
  cout<<M.at(i).at(j);
  } cout<<M.at(i).at(W+1)<<endl;
  
  }
  
  
  
  
   return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
hList = []
for i in range(N):
  hList.append(int(input()))
hList_sorted = sorted(hList)
kList = []
for i in range(N - K + 1):
  dis = abs(hList_sorted[i] - hList_sorted[i + K - 1])
  kList.append(dis)
print(min(kList))


Measured memory_bytes: 12060
#include "bits/stdc++.h"
using namespace std;

void North(int Dice[]) {
	int p = Dice[0];
	Dice[0] = Dice[1];
	Dice[1] = Dice[5];
	Dice[5] = Dice[4];
	Dice[4] = p;
}

void South(int Dice[]) {
	int p = Dice[0];
	Dice[0] = Dice[4];
	Dice[4] = Dice[5];
	Dice[5] = Dice[1];
	Dice[1] = p;
}

void East(int Dice[]) {
	int p = Dice[0];
	Dice[0] = Dice[3];
	Dice[3] = Dice[5];
	Dice[5] = Dice[2];
	Dice[2] = p;
}

void West(int Dice[]) {
	int p = Dice[0];
	Dice[0] = Dice[2];
	Dice[2] = Dice[5];
	Dice[5] = Dice[3];
	Dice[3] = p;
}

void Left(int Dice[]) {
	int p = Dice[1];
	Dice[1] = Dice[2];
	Dice[2] = Dice[4];
	Dice[4] = Dice[3];
	Dice[3] = p;
}

void Right(int Dice[]) {
	int p = Dice[1];
	Dice[1] = Dice[3];
	Dice[3] = Dice[4];
	Dice[4] = Dice[2];
	Dice[2] = p;
}

bool same1(int Dice1[], int Dice2[]) {
	for (int i = 0; i < 6; i++) {
		if (Dice1[i] != Dice2[i]) return false;
	}
	return true;
}

bool same2(int Dice1[], int Dice2[]) {
	bool check = false;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 4; j++) {
			if (same1(Dice1, Dice2)) check = true;
			Left(Dice2);
		}
		North(Dice2);
		for (int j = 0; j < 4; j++) {
			if (same1(Dice1, Dice2)) check = true;
			Left(Dice2);
		}
		East(Dice2);
	}
	return check;
}

int main() {
	int Dice[100][6], N;
	bool check = true;
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 6; j++) {
			cin >> Dice[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (same2(Dice[i], Dice[j])) check = false;
		}
	}
	if (check) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3108