akhauriyash/Code-Regression huggingface dataset:
# frozen_string_literal: true

class Dice
  def initialize(params)
    @v = Array.new(6)
    (0..5).each do |i|
      @v[i] = params[i]
    end
    @phases = []
  end

  def faces
    @v
  end

  def slide(a, b, c, d)
    tmp = @v[a]
    @v[a] = @v[b]
    @v[b] = @v[c]
    @v[c] = @v[d]
    @v[d] = tmp
  end

  def rotate_atom(char)
    case char
    when 'N' then slide(0, 1, 5, 4)
    when 'E' then slide(0, 3, 5, 2)
    when 'W' then slide(0, 2, 5, 3)
    when 'S' then slide(0, 4, 5, 1)
    when 'D' then slide(1, 3, 4, 2)
    when 'U' then slide(1, 2, 4, 3)
    end
  end

  def rotate(string)
    string.chars.each do |c|
      rotate_atom(c)
    end
  end

  def top
    @v[0]
  end

  def register_phase
    4.times do
      @phases << Marshal.load(Marshal.dump(@v))
      rotate_atom('D')
    end
  end

  def register
    4.times do
      register_phase
      rotate_atom('S')
    end
    rotate_atom('W')
    register_phase
    rotate_atom('E')
    rotate_atom('E')
    register_phase
    rotate_atom('W')
  end

  def same_dice?(dice_y)
    register if @phases.empty?
    if dice_y.is_a?(Array)
      @phases.include?(dice_y)
    elsif dice_y.is_a?(Dice)
      @phases.include?(dice_y.faces)
    end
  end
end

dice = Dice.new(readline.split(' '))
dice.register
another = Dice.new(readline.split(' '))
puts(dice.same_dice?(another) ? 'Yes' : 'No')



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

int V, E;
int const max_v = 20;
const int INF = 100000000;
vector<int> G[max_v];
int C[max_v][max_v];

int main()
{
    int V, E;
    cin >> V >> E;

    //初期化
    for (int i = 0; i < max_v; i++)
    {
        for (int j = 0; j < max_v; j++)
        {
            if (i == j)
            {
                C[i][i] = 0;
            }
            else
            {

                C[i][j] = INF;
            }
        }
    }

    // グラフの入力
    for (int i = 0; i < E; i++)
    {
        int from, to, cost;
        cin >> from >> to >> cost;
        C[from][to] = cost;
    }

    // DPの初期化
    int dp[1 << V][V];
    for (int i = 0; i < (1 << V); i++)
    {
        for (int j = 0; j < V; j++)
        {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;

    // DP開始
    // S = 10010などすでに訪れた頂点を示す
    for (int S = 0; S < (1 << V); S++)
    {
        //v = 次に訪れる頂点
        for (int v = 0; v < V; v++)
        {
            for (int u = 0; u < V; u++)
            {
                if ((S & (1 << v)) == 0 || v == u)
                {
                    continue;
                }
                dp[S][v] = min(dp[S][v], dp[S & ~(1 << v)][u] + C[u][v]);
                /*
                if ((S & (1 << v)) == 0 && C[u][v] != INF)
                {
                    dp[S | (1 << v)][v] = min(dp[S | (1 << v)][v], dp[S][u] + C[u][v]);
                }
                */
            }
        }
    }

    if (dp[(1 << V) - 1][0] == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << dp[(1 << V) - 1][0] << endl;
    }
    return 0;
}


Measured memory_bytes: 5004
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
int main(void){
    IOS;
    int R; cin >> R;
    cout << setprecision(10) << fixed << 2*PI*R << endl;
    return 0;
}

Measured memory_bytes: 3808
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

const int N = 605;
const double INF = 1e14;

int n, m, u, v;

struct Edge{
	int nxt, to;
}edge[N*N];
int head[N], edgeNum, deg[N];
void addEdge(int from, int to){
	edge[++edgeNum] = (Edge){head[from], to};
	head[from] = edgeNum;
	deg[from]++;
}

double dp[N];
int tdeg[N];
double blockDP(int x){
	for(int i = 1; i <= n; i++){
		dp[i] = INF;
		tdeg[i] = deg[i];
	}
	dp[n] = 0;
	for(int i = n - 1; i >= 1; i--){
		double sumDP = 0, maxDP = 0;
		for(int k = head[i]; k; k = edge[k].nxt){
			maxDP = max(maxDP, dp[edge[k].to] == INF ? 0 : dp[edge[k].to]);
			sumDP += dp[edge[k].to];
		}
		if(i == x && tdeg[i] >= 2){
			sumDP -= maxDP;
			tdeg[i]--;
		}
		dp[i] = sumDP / tdeg[i] + 1;
	}
	return dp[1];
}

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++){
		scanf("%d%d", &u, &v);
		addEdge(u, v);
	}
	double ans = INF;
	for(int i = 1; i <= n; i++)
		ans = min(ans, blockDP(i));
	printf("%.10f\n", ans);
	return 0;
}


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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define pb push_back
#define PII pair <int, int>

const int N = 1e5 + 7;
const int MX = 1e9 + 7;
const LL INF = 1e18 + 7LL;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	
	cout << max(max(a, b), c) - min(a, min(b, c));
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e3;
vector<string> s;
vector<vector<int>> mem;
const int mod = 1e9+7;

int dp(int i, int j) {
	if(i==0 && j==0) return 1;
	if(mem[i][j]!=-1) return mem[i][j];
	int a=0, b=0;
	if(i>0 && s[i-1][j]=='.') a=dp(i-1, j);
	if(j>0 && s[i][j-1]=='.') b=dp(i, j-1);
	return mem[i][j] = (a+b)%mod;
}
int main(){
	ios_base::sync_with_stdio(0);
	int a,b,r,c,n,T,cas=0;
	cin>>r>>c;
	s.resize(r);
	mem.resize(r, vector<int> (c, -1));
	for(int i=0;i<r;++i) {
		cin>>s[i];
	}
	int res = dp(r-1, c-1);
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 5376
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
set<char> S;

int main() {
  INCANT;
  cin >> N;
  char a;
  rep(i, N) {
    cin >> a;
    S.insert(a);
  }
  string ans = S.size()==4?"Four":"Three";
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {                                                                
    int data[101] = {};                                                         
    int x, max = -1;                                                            
    while (scanf("%d", &x) != EOF) {                                            
        data[x]++;                                                              
        max = data[x] > max ? data[x] : max;                                    
    }                                                                           
    int i = 1;                                                                  
    while (i++ < 101) {                                                         
        if (data[i] == max)                                                     
            printf("%d\n", i);                                                  
    }                                                                           
    return 0;                                                                   
}

Measured memory_bytes: 596
// -*- mode:c++; coding:utf-8; indent-tabs-mode:nil; -*-
// ALDS1_4-B: Binary Search

#include <cstdio>

const int NOT_FOUND = -1;
static int binary_search(const int as[], int f, int t, const int target) {
  while (f < t) {
    int m = (f+t)/2; // f+(t-f)/2
    if (target < as[m]) {
      t = m;
    } else if (as[m] < target) {
      f = m+1;
    } else { // as[m] == target
      return m;
    }
  }
  return NOT_FOUND;
}

int main(void) {
  int n;
  std::scanf("%d", &n);
  int ss[n];
  for (auto i = 0; i < n; ++i) {
    std::scanf("%d", &ss[i]);
  }

  int q;
  std::scanf("%d", &q);
  int c = 0;
  for (auto i = 0; i < q; ++i) {
    int t;
    std::scanf("%d", &t);
    auto j = binary_search(ss, 0, n, t);
    if (j != NOT_FOUND) ++c;
  }

  std::printf("%d\n", c);

  return 0;
}
// end

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

signed main() {
  int n;
  cin >> n;

  vi a(n), b(n);
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];

  int ans = 1e9;
  rep(mask, 0, 1<<n){
    vector<P> v[2];
    rep(i, 0, n){
      if(mask>>i & 1){
        v[(i+1)%2].emplace_back(b[i], i);
      }else{
        v[i%2].emplace_back(a[i], i);
      }
    }

    if(sz(v[1]) != n/2) continue;

    sort(all(v[0]));
    sort(all(v[1]));

    vector<P> w;
    rep(i, 0, n) w.emplace_back(v[i%2][i/2]);

    bool ok = true;
    rep(i, 0, n-1){
      if(w[i].first > w[i+1].first) ok = false;
    }
    if(!ok) continue;

    vi sorted(n);
    rep(i, 0, n){
      sorted[w[i].second] = i;
    }

    int tmp = 0;
    rep(i, 0, n){
      rep(j, i+1, n){
        if(sorted[i] > sorted[j]) tmp++;
      }
    }

    chmin(ans, tmp);
  }

  if(ans == 1e9) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}


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

int main(){
//srandom((unsigned long)time(NULL));
long long n,m;
cin>>n>>m;
vector<tuple<long long,long long>> v;
for(long long i=0;i<n;i++){
    long long a,b;
    cin>>a>>b;
    v.emplace_back(a,b);
}
sort(v.begin(),v.end());
long long now=0;
long long muny=0;
for(tuple<long long,long long> t:v){
    //cout<<"muny="<<muny<<endl;
    long long a,b;
    tie(a,b)=t;
    if(now+b<m){
        now+=b;
        muny+=a*b;
        continue;
    }
    if(now+b>=m){
        muny+=(m-now)*a;
        cout<<muny<<endl;
        return 0;
    }
}

return 0;
}

Measured memory_bytes: 2420
#include <set>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    string S; int n;
    
    set<string> T;
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
    {
        cin >> S;
        
        if(i % 20 == 0 || i % 20 == 1 || i % 20 == 2)
        {
            printf("1\n");
        }
        else
        {
            T.clear();
            
            for(int j = 1; j < S.size(); j++)
            {
                string A = S.substr(0, j);
                string B = S.substr(j, S.size() - j);
                
                string C = A; reverse(C.begin(), C.end());
                string D = B; reverse(D.begin(), D.end());
                
                T.insert(A + B);
                T.insert(B + A);
                T.insert(A + D);
                T.insert(D + A);
                T.insert(C + B);
                T.insert(B + C);
                T.insert(C + D);
                T.insert(D + C);
            }
            
            printf("%d\n", T.size());
        }
    }
    
    return 0;
}

Measured memory_bytes: 3364
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  ll mod=1000000007;
  ll s; cin>>s;
  ll ans[2001]; ans[1]=0; ans[2]=0;
  for(int i=3;i<=2000;i++){
    ans[i]=1;
    for(int j=3;j<=i-3;j++){
      ans[i]+=ans[j];
      ans[i]%=mod;
    }
  }
  cout<<ans[s];
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;



int main(int argc, const char * argv[]) {
    
    int n;
    
    cin >> n;
    
    int hour =n/3600;
    int amari=n-hour*3600;
    
    int min =amari/60;
    int amari2=amari-min*60;
    
    cout << hour<< ":"<< min<< ":" << amari2<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[])
{
        double r;
        double s, l;

        scanf("%lf", &r);

        s = r * r * M_PI;
        l = 2 * r * M_PI;

        printf("%f %f\n", s, l);

        return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}


int main() {
    int x,y;
    cin >> x >> y;
    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            if(i+j != x) continue;
            if(i*2+j*4 == y){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	int diff = a - b;
	if (c > diff)cout << c - diff << endl;
	else cout << "0" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N, C;
    cin >> N >> C;
    vector<vector<P>> G(C);
    rep(i,N){
        int a, b, c;
        cin >> a >> b >> c;
        --c;
        G[c].push_back(P(a, b));
    }
    rep(i,C){
        sort(G[i].begin(), G[i].end());
    }
    int chanel[100010]{};
    rep(i,C){
        int tmp = -1;
        for(auto e : G[i]){
            int st = e.first;
            if(st == tmp) st++;
            int en = e.second;
            for(int i=st;i<=en;i++){
                chanel[i]++;
            }
            tmp = en;
        }
    }
    int ans = 0;
    rep(i,100010){
        chmax(ans, chanel[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string j="No";
  int n;
  cin>>n;
  for(int a=0; a<10; a++){
    for(int b=0; b<10; b++){
   		if(n==a*b){
          j="Yes";
        }
     }
  }
  cout<<j<<endl;
}
      

Measured memory_bytes: 3616
n, k = map(int, input().split())
d = set(map(int, input().split()))
inf = 10 * n + 1
stop = len(str(n))
num = []
for i in range(10):
    if i in d:
        pass
    else:
        num.append(i)


def dfs(pos, x):
    if pos == stop:
        if x >= n:
            return x
        else:
            return inf

    ret = [
        dfs(pos + 1, 10 * x + num_i) for num_i in num
    ]

    return min(ret)


if dfs(0, 0) != inf:
    print(dfs(0, 0))
else:
    stop += 1
    print(dfs(0, 0))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, D;
	in >> N >> D;
	std::vector<std::vector<LL>>X(N, std::vector<LL>(D));
	rep(i, N) rep(j, D) in >> X[i][j];

	LL ans = 0;
	rep(i, N)
	{
		for (LL j = i + 1; j < N; ++j)
		{
			LL dist = 0;
			rep(k, D) dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			LL res = sqrt(dist);
			if (res * res == dist) ++ans;
		}
	}

	out << ans << std::endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    int[] A=new int[N];
	    boolean[] f=new boolean[9];
	    int c=0;
	    for (int i=0; i<N;i++) {
	    	A[i]=gi();
	    	f[Math.min(Math.floorDiv(A[i], 400), 8)]=true;
	    	if(A[i]>=3200) c++;
	    }
	    
	    int min=0;
	    for (int i=0; i<8;i++) {
	    	if(f[i])min++;
	    }
	    int max=min+c;
	    if(min==0)min++;

       System.out.print(min + " " + max);
//
//        if (f) {
//    	    System.out.print("Yes");
//        }else{
//        	 System.out.print("No");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

const int STRING_LEN = 10;
const int ALPHABET = 26;

using namespace std;


int main() {
	int n;
	cin >> n;
	
	
	vector<int> h;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		h.emplace_back(tmp);
		
	}

	
	h[0]--;
	bool nonDecrese = true;

	for (int i = 1; i < n; i++) {
		if (h[i] > h[i - 1]) {
			h[i]--;
		}
		else if (h[i] < h[i - 1]) {
			nonDecrese = false;
			break;
		}
		
	}
	
	cout << (nonDecrese ? "Yes" : "No") << endl;

}

Measured memory_bytes: 892
n = gets.chomp.to_i
s = gets.chomp

if (n%2 == 0)
  s1 = s[0..(n/2-1)]
  s2 = s[(n/2)..(n-1)]
  if s1 == s2
    puts "Yes"
  else
    puts "No"
  end
else
  puts "No"
end


Measured memory_bytes: 1788
a, b, c, x, y = map(int, input().split())
A = x * a + y * b
if x >= y:
    B = y * 2 * c + (x - y) * a
else:
    B = x * 2 * c + (y - x) * b

C = max(x, y) * 2 * c
print(min(A, B, C))


Measured memory_bytes: 2940
N = int(input())
S = input()

ans = 0
for i in range(10):
    for j in range(10):
        f = 0
        used = [0]*10
        for k in range(N):
            if f == 0 and S[k] == str(i):
                f = 1
            elif f == 1 and S[k] == str(j):
                f = 2
            elif f == 2 and used[int(S[k])] == 0:
                ans += 1
                used[int(S[k])] = 1
                
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
  int N;
  int V[50], C[50];

  cin >> N;
  for(int i = 0; i < N; i++) cin >> V[i];
  for(int i = 0; i < N; i++) cin >> C[i];

  int sub = 0;

  for(int i = 0; i < N; i++){
    if(V[i] > C[i]) sub += V[i] - C[i];
  }

  cout << sub << endl;
}
    


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.IO.Pipes;
using System.Linq;

class Program
{ 
	public static int Main()
	{
		Scanner cin = new Scanner();
	  while (true)
	  {
	    int s = cin.nextInt();
	    if (s == 0)
	    {
	      break;
	    }
	    for (int i = 0; i < 9; i++)
	    {
	      s -= cin.nextInt();
	    }
      Console.WriteLine(s);
	  }
		return 0;
	}

}

class Scanner {
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner() {
		s = new string[0];
		i = 0;
	}

	public string next() {
		if (i < s.Length) return s[i++];
		do {
			s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
		} while ((s.Length == 1 && s[0] == "") || s.Length == 0);
		i = 0;
		return s[i++];
	}

	public int nextInt() {
		return int.Parse(next());
	}

	public long nextLong() {
		return long.Parse(next());
	}

	public double nextDouble() {
		return double.Parse(next());
	}

}

Measured memory_bytes: 5604
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
b = []
for i in range(n):
    x = int(input())
    b.append(x)


for i in b:
    if i in a1:
        a1[a1.index(i)] = 'X'
    if i in a2:
        a2[a2.index(i)] = 'X'
    if i in a3:
        a3[a3.index(i)] = 'X'

if len(set(a1)) == 1 and a1[0] == 'X' or len(set(a2)) == 1 and a2[0] == 'X' or len(set(a3)) == 1 and a3[0] == 'X':
    print('Yes')
elif a1[0] == 'X' and a1[0] == a2[0] == a3[0] or a1[1] == 'X' and a1[1] == a2[1] == a3[1] or a1[2] == 'X' and a1[2] == a2[2] == a3[2]:
    print('Yes')
elif a1[0] == 'X' and a1[0] == a2[1] == a3[2] or a1[2] == 'X' and a1[2] == a2[1] == a3[0]:
    print('Yes')
else:
    print('No')



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  ll n,k;cin>>n>>k;
  vector<ll> h(n);
  rep(i,n)cin>>h[i];
  sort(h.rbegin(), h.rend());
  ll sum = 0;
  rep(i,n){
    if(i>=k)sum+=h[i];
  }
  cout<<sum;

  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std; 

//しゃくとり方でとく//
int main(void){
 int N,K;

 char S[100050];
 vector<int> A;

 cin>>N>>K;
 cin>>S;

 int cnt=0;
 int now=0;

 for(int i=0; i<strlen(S);i++){
  if(S[i]==('1'-now)){
   cnt++;
  }
  else{
   now=1-now;
   A.push_back(cnt);
   cnt=1;
  }
 }
 A.push_back(cnt);          
 
 if(A.size()%2==0)A.push_back(0);
 
 int sum,left,right,ans,nowleft,nowright;
 sum=0;
 left=0;
 right=0;
 nowleft=0;
 nowright=0;
 ans=0;

 while(left<A.size()){
  right=min(left+2*K+1,(int)A.size());

  while(nowleft<left){
   sum-=A[nowleft];
   nowleft++;
  }
  while(nowright<right){
   sum+=A[nowright];
   nowright++;
  }
  left+=2;
  ans=max(sum,ans);
 }

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

Measured memory_bytes: 1020
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 1000001;
const int MOD =1000000007;
const int INV2 = (MOD+1)/2;



     signed main(){
 int n,m,x,y;
 cin>>n>>m>>x>>y;
 int a[n],b[m];
 for(int i=0;i<n;i++)cin>>a[i];
 for(int i=0;i<m;i++)cin>>b[i];
 sort(a,a+n);sort(b,b+m);
 if(a[n-1]<b[0]&&x<b[0]&&a[n-1]<y)cout<<"No War";
 else cout<<"War";



}


        


Measured memory_bytes: 256
def has_duplicates(words):
  if len(words) == len(set(words)):
    return False
  return True

a = int(input())
words = []
for i in range(a):
  words.append(input())
if has_duplicates(words) == True:
  print('No')
  exit()
for i in range(a-1):
  if words[i][len(words[i])-1] != words[i+1][0]:
    print('No')
    exit()
print('Yes')

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

int main(){
    int N;
    cin >> N;
    long tmp = 0;
    int count = 0;
    long update = 1000000001;
    long total = 0;

    for(int i = 0; i < N; i++){
        cin >> tmp;
        total += abs(tmp);
        if(tmp < 0) count++;
        if(update > abs(tmp)) update = abs(tmp);
    }

    if(count%2 == 0){
        cout << total << '\n';
    }
    else{
        total -= 2*update;
        cout << total << '\n';
    }

    return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
#define INF 1e18
#define int long long
using namespace std;
typedef pair<int,int> P;
 
struct Graph{
  Graph(int n):E(n),d(n){};
  vector<vector<P>>E;
  vector<int>d;
  void add_edge(int a,int b,int c){
    E[a].push_back({b,c});
  }
  bool bellmanFord(int s,int t){
    int sz=d.size();
    fill(d.begin(),d.end(),INF);
    d[s]=0;
    for(int i=0;i<sz;++i)
      for(int j=0;j<sz;++j)
        for(P& p:E[j])
          if(d[j]!=INF&&d[j]+p.second<d[p.first]){
            d[p.first]=d[j]+p.second;
            if(i==sz-1&&p.first==t)return false;
            //if check after destination route
            // if(i==sz-1)return false;
          }
    return true;
  }
};
 
main(){
  int n,m,a,b,c;
  cin>>n>>m;
  Graph E(n);
  for(int i=0;i<m;++i){
    cin>>a>>b>>c;
    E.add_edge(a-1,b-1,-c);
  }
  if(E.bellmanFord(0,n-1))cout<<-E.d[n-1]<<endl;
  else cout<<"inf"<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  string s;
  cin >> s;
  if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int nPi = 0;
        for (int i = 1; i <= n; i++) {
            nPi += l + i - 1;
        }
        int minDiff = Integer.MAX_VALUE;
        int result = 0;
        for (int i = 1; i <= n; i++) {
            int n1Pi = nPi - (l + i - 1);
            int diff = Math.abs(nPi - n1Pi);
            if (minDiff > diff) {
                minDiff = diff;
                result = n1Pi;
            }
        }
        System.out.println(result);
    }

}


Measured memory_bytes: 23764
n,m = map(int, input().split())

if m <=1:
    print("Yes")
    exit()

from collections import defaultdict
V = defaultdict(list)
 
for _ in range(m):
    a, b,c = map(int, input().split())
    V[a].append([b,c])
    V[b].append([a,-c])

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

def dfs(source):
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b[0]]!=inf:
                if dist[b[0]] != dist[a] +b[1]:
                    print("No")
                    exit()
            else:
                dist[b[0]] = dist[a] + b[1]
                q.append(b[0])

for i in range(n):
    if dist[i] ==inf:
        dfs(i)

print("Yes")

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

const int64_t MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n,k;
  cin >> n >> k;
  
  double p = 0;
  if(k-1<n){
  // (n-k+1)/n
    p += ((double)(n-(k-1)))/(double)n;
  }
  for(int i=1;i<=k-1&&i<=n;i++){
    double pTmp = 1.0/(double)n;
    int value = i;
    while(value < k){
      value *= 2;
      pTmp /= 2.0;
    }
    p += pTmp;
  }
  cout << fixed << setprecision(12) << p << endl;
  return 0;
}



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

int main(void){
	char a[12];
	for(int i=0;i<12;i++)cin >> a[i];
	for (int i = 0; i<4; i++)cout<< a[i];

	cout <<" ";
	for (int i = 4; i<12; i++)cout << a[i];
	cout << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h = sorted(h)
dif = 10**9

for i in range(n-k+1):
    if dif > h[i+k-1] - h[i]:
        dif = h[i+k-1] - h[i]

print(dif)

Measured memory_bytes: 8280
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let _n: i32 = read();
    let v: Vec<i64> = read_vec();
    println!("{} {} {}",
        v.iter().min().unwrap(),
        v.iter().max().unwrap(),
        v.iter().sum::<i64>()
     );
}



Measured memory_bytes: 5036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
int main(){
    ll N, M; cin >> N >> M;
    if(abs(N-M)>1) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    if(N==M) ans *= 2;
    for (int i = 2; i <= N; i++) 
    {
        ans *= i;
        ans %= mod;
    }
     
    for (int i = 2; i <= M; i++) 
    {
        ans *= i;
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict as ddic, deque
from itertools import combinations, permutations, product
import sys
sys.setrecursionlimit(10**6)
stdout = sys.stdout
rr = lambda: raw_input().strip()
rri = lambda: int(raw_input())
rrm = lambda: list(map(int, raw_input().strip().split()))


def solve(N, A):
    dp0 = [0] * (N+1)
    dp1 = [0] * (N+1)
    for i in xrange(N-1, -1, -1):
        for color in (0, 1):
            if color == 1:
                ans = dp1[i+1] + (A[i] != color)
            else:
                ans = min(dp0[i+1], dp1[i+1]) + (A[i] != color)

            if color == 0:
                dp0[i] = ans
            else:
                dp1[i] = ans

    return min(dp0[0], dp1[0])

###
N = rri()
S = rr()
A = [1 if c == '#' else 0 for c in S]
print solve(N, A)


Measured memory_bytes: 37916
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
 long long int i,k,l,n,mo;
 cin >> n;
 mo=n-1;
 for(i=2;i<=sqrt(n);i++)
 {
  if(n%i==0)
  {
   k=min(i,(n/i));
   l=max(i,(n/i));
   if((l+k-2)<mo)
   mo=l+k-2;
  }
 }
 cout << mo;
 return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

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

	int N, M, K;
	cin >> N >> M >> K;

	bool ok = [&]() {
		for( int i = 0; i <= N; ++i ) {
			for( int j = 0; j <= M; ++j ) {
				int x = i * (M - j);
				int y = j * (N - i);
				if( x+y == K ) {
					return true;
				}
			}
		}
		return false;
	}();
	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include <numeric>
using namespace std;

int main()
{	
	long long int N;
	scanf("%lld", &N);
	long long int A[N];
	for(long long int i=0;i<N;i++){
		scanf("%lld", &A[i]);
	}
	long long int P, Q, R, S, l, r;
	l=0;
	r=2;
	P=A[0]; 
	Q=A[1];
	R=A[2];
	S=0;
	for(long long int i=3; i<N; i++){
		S+=A[i];
	}

	long long int answer;

	for(long long int i=1;i<N-1;i++){
		
		while((l<i-1)&&(P+A[l+1]<=Q-A[l+1]))
		{	
			P+=A[l+1];
			Q-=A[l+1];
			l++;
		}
		while((r<N-1)&&(R+A[r+1]<S-A[r+1]))
		{
			R+=A[r+1];
			S-=A[r+1];
			r++;
		}
		answer=min(answer, max(max(max(P,Q),R),S)-min(min(min(P,Q),R),S));
		answer=min(answer, max(max(max(P+A[l+1],Q-A[l+1]),R),S)-min(min(min(P+A[l+1],Q-A[l+1]),R),S));
		answer=min(answer, max(max(max(P+A[l+1],Q-A[l+1]),R+A[r+1]),S-A[r+1])-min(min(min(P+A[l+1],Q-A[l+1]),R+A[r+1]),S-A[r+1]));
		answer=min(answer, max(max(max(P,Q),R+A[r+1]),S-A[r+1])-min(min(min(P,Q),R+A[r+1]),S-A[r+1]));
		
		Q+=A[i+1];
		R-=A[i+1];
	}
	
	printf("%lld", answer);
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int cnt;
int main(){
	int n,x,y,a,b,c,d,e;
	cin>>n>>x>>y;
	for(int i=0;i<n+1;i++){
		a=i/10000;
		b=i/1000-i/10000*10;
		c=i/100-i/1000*10;
		d=i/10-i/100*10;
		e=i%10;
		//cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;
		if(x<=(a+b+c+d+e)&&(a+b+c+d+e)<=y){
			cnt+=i;
		}
		//cout<<cnt<<endl;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int ans;
void solve(int n, int k=0) {
    if(n <= 3) ans = k+1;
    else solve((n-1)/3+1, ++k);
}

signed main() {
    int n; cin >> n;
    solve(n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int a,b,ans=0;
int main()
{
    cin>>a>>b;
    for(int i=0;i<=a;i++)
    {
        for(int j=0;j<=a;j++)
        {
            if(b-i-j>=0 && b-i-j<=a) ans++;
        }
    }
    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n; cin >> n;
    vector<ll> A(n); rep(i, n) cin >> A[i];
    vector<ll> AS = A; sort(all(AS));
    ll L = AS[n/2-1], R=AS[n/2];
    
    vector<ll> res;
    rep(i, n){
        ll tmp = A[i];
        if(tmp <= L)res.push_back(R);
        else res.push_back(L);
    }
    rep(i, n){
        cout << res[i] << ln;
    }
}


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

char b[3][3];

bool check(char c) {
	for (int i = 0; i < 3; i++) {
		if (b[i][0] == c && b[i][0] == b[i][1] && b[i][0] == b[i][2]) return true;
		if (b[0][i] == c && b[0][i] == b[1][i] && b[0][i] == b[2][i]) return true;

	}
	if (b[0][0] == c && b[0][0] == b[1][1] && b[0][0] == b[2][2]) return true;
	if (b[0][2] == c && b[0][2] == b[1][1] && b[0][2] == b[2][0]) return true;
	return false;
}

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

	while (true) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				cin >> b[i][j];
				if (b[i][j] == '0') return 0;
			}
		}

		if (check('b')) {
			cout << 'b' << endl;
		}
		else if (check('w')) {
			cout << 'w' << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 1168
N=input()
A=map(int, raw_input().split())
B=range(1,N+1)
 
C=[]
for x,y in zip(A,B):
	C.append(x-y)

C.sort()

m=0
if len(C)%2==1:
	m=C[len(C)/2]
else:
	m=(C[len(C)/2-1]+C[len(C)/2])/2

	
t=0
for x in C:
	t+=abs(-1*m+x)
print t


Measured memory_bytes: 68060
#include <stdio.h>

int main(){
    
    int S;
    
    scanf("%d",&S);
    
    int a,b;
    
    a = S / 100;
    b = S % 100;
    
    if(1 <= a && a <= 12){
        if(1 <= b && b <= 12)printf("AMBIGUOUS\n");
        else printf("MMYY\n");
    }
    else{
        if(1 <= b && b <= 12)printf("YYMM\n");
        else printf("NA\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
//#define int long long
#define all(vec) vec.begin(),vec.end()

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

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

	int N;
	cin >> N;
	int t[110000], x[110000], y[110000];
	t[0] = x[0] = y[0] = 0;
	for (int i = 0; i < N; i++) {
		cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
	}
	bool can = true;
	for (int i = 0; i < N; i++) {
		int dt = t[i + 1] - t[i];
		int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		if(dt<dist){
			can = false;
		}
		if(dist%2!=dt%2){
			can = false;
		}
	}

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

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
#define MOD 1000000007
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	ans = k * pow(k - 1, n - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int A, B; cin >> A >> B;

    string ans;
    if (A == B) {
        ans = "Draw";
    } else if (A == 1) {
        ans = "Alice";
    } else if (B == 1) {
        ans = "Bob";
    } else if (A > B) {
        ans = "Alice";
    } else {
        ans = "Bob";
    }

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

Measured memory_bytes: 256
import bisect
S=input()
T=input()
N=len(S)
M=len(T)
chardict=dict()
for i in range(26):
    chardict[chr(i+97)]=[]
for i in range(2*N):
    chardict[S[i%N]].append(i)
dp=[0 for i in range(M+1)]
dp[0]=-1
for i in range(M):
    nowpoint=dp[i]%N
    cycle=dp[i]//N
    #cycle 周していて　nowpoint番目にいる
    if len(chardict[T[i]])==0:
        print(-1)
        exit()
    tmp=bisect.bisect_right(chardict[T[i]],nowpoint)
    dp[i+1]=cycle*N+chardict[T[i]][tmp]
print(dp[M]+1)


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

#define int long long

int N, M;
int K[10];
int S[10][10];
int P[10];

signed main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++)
    {
        cin >> K[i];
        for(int j = 0; j < K[i]; j++)cin >> S[i][j];
    }
    for(int i = 0; i < M; i++)cin >> P[i];

    int ans = 0;
    for(int i = 0; i < (1 << N); i++)
    {
        int cnt = 0;
        for(int j = 0; j < M; j++)
        {
            int tmp = 0;
            for(int k = 0; k < K[j]; k++)
            {
                if(i & (1 << (S[j][k] - 1)))tmp++;
            }
            if((tmp % 2) == P[j])cnt++;
        }
        if(cnt == M)ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const int N =  1e5 + 10;
 
struct IOsetup{
  IOsetup(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   cout << fixed << setprecision(20);
  }
}IO;

int32_t main(){
  int n, k;
  cin >> n >> k;
  int ret = (int)(floor(log(n) / log(k)) + 1);
  cout << ret << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    string S;
    cin >> S;
    int n = S.size();

    vector<vector<int>> rl(n, vector<int>(2, 0));

    for (int i = n-2; i >= 0; i--) {
        if(S[i] == 'L' && S[i+1] == 'R') continue;
        if(S[i] == 'L' && S[i+1] == 'L') continue;

        if(S[i] == 'R' && S[i+1] == 'L'){
            rl[i][0] = 1;
        }else{
            rl[i][0] = rl[i+1][0]+1;
        }
    }
    for (int i = 1; i < n; i++) {
        if(S[i] == 'R' && S[i-1] == 'L') continue;
        if(S[i] == 'R' && S[i-1] == 'R') continue;

        if(S[i] == 'L' && S[i-1] == 'R'){
            rl[i][1] = 1;
        }else{
            rl[i][1] = rl[i-1][1]+1;
        }
    }

    vector<int> ans(n, 0);
    REP(i, n){
        if(S[i]=='R'){
            if(rl[i][0]&1){ //奇数
                ans[i+rl[i][0]-1]++;
            }else{
                ans[i+rl[i][0]]++;
            }
        }else{
            if(rl[i][1]&1){ //奇数
                ans[i-rl[i][1]+1]++;
            }else{
                ans[i-rl[i][1]]++;
            }
        }
    }

    REP(i, n){
        pr(ans[i]);
    }
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = a; i < (b + a); i++)
#define W1 while (1)
#define COUT(x) cout << x << endl
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define mod 1000000007
#define PB push_back
#define F first
#define S second

int main() {
  int k;
  int num = 7;
  int plus = 70;
  int ans = 1;
  cin >> k;
  rep(i, k + 1) {
    if (num % k == 0) break;
    if (i == k) {
      ans = -1;
      break;
    }
    num = (num + plus) % k;
    plus = (plus * 10) % k;
    ans++;
  }
  COUT(ans);

  return 0;
}


Measured memory_bytes: 3620
from collections import defaultdict
N, M = map(int, input().split())
section = [list(map(int, input().split())) for i in range(N)]

# 区間の大きさごとに分類
D = defaultdict(list)
for sec in section:
    D[sec[1] - sec[0] + 1].append(sec)


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= (i & -i)
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += (i & -i)

    def reset(self):
        self.bit = [0] * (self.size + 1)


BIT = BinaryIndexedTree(M)

for d in range(1, M + 1):
    for l, r in D[d - 1]:
        N -= 1
        BIT.add(l, 1)
        BIT.add(r + 1, -1)

    ans = N
    for i in range(d, M + 1, d):
        ans += BIT.sum(i)
    print(ans)


Measured memory_bytes: 131288
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var blackBoardList = Console.ReadLine().Split(' ');
            var resultCount = 0;

            var blackBoardIntegerList = new List<int> { };
            foreach (var item in blackBoardList)
            {
                blackBoardIntegerList.Add(int.Parse(item));
            }

            bool isEven = true;
            while (isEven)
            {
                var list = new List<int>();
                foreach (var item in blackBoardIntegerList)
                {

                    if ((item % 2) != 0)
                    {
                        isEven = false;
                        break;
                    }
                    list.Add(item / 2);
                }
                if (isEven)
                {
                    blackBoardIntegerList = list;
                    resultCount++;
                }
            }

            Console.WriteLine(resultCount);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    string s[3];
    REP(i,3) cin >> s[i];
    int x = 0;
    while(1){
        if (s[x].length() > 0){
            int y = s[x][0] - 'a';
            s[x].erase(0,1);
            x = y;
        }else{
            printf("%c\n", 'A'+x);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>

int main(){

  int K, N;
  scanf("%d", &N);
  scanf("%d", &K);
  std::vector<int > h(N);
  for (int i=0; i<N; i++){
    scanf("%d", &h[i]);
  }
  std::sort(h.begin(), h.end());
  int ans = 1000000007;
  for (int i=0; i<N-K+1; i++){
    ans = std::min(ans, h[i+K-1]-h[i]);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640