akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 305;
#define LL long long 
const int mod = 1e9 + 7;
int n, m, a[maxn], head[maxn], cnt = 1;
struct Node {int v, nxt, w;} G[maxn << 1];
void ins(int u, int v, int w) {G[cnt] = (Node) {v, head[u], w}; head[u] = cnt++;}
LL f[maxn][maxn][maxn];
bool check(int l, int r, int k) {
	int num = max(l, max(r, k));
	for (int i = head[num]; i; i = G[i].nxt) {
		int v = G[i].v;
		int cnt = (v <= l) + (v <= r) + (v <= k);
		if(cnt != G[i].w) return 0; 
	}
	return 1;
}
int DP() {
	f[0][0][0] = 1;
	int Ans = 0;
	for (int i = 0; i <= n; ++i) 
		for (int j = 0; j <= n; ++j)
			for (int k = 0; k <= n; ++k) {
				if(!f[i][j][k]) continue;
				if(!check(i, j, k)) {f[i][j][k] = 0; continue;}
				int p = max(i, max(j, k));
				f[p + 1][j][k] = (f[p + 1][j][k] + f[i][j][k]) % mod;
				f[i][p + 1][k] = (f[i][p + 1][k] + f[i][j][k]) % mod;
				f[i][j][p + 1] = (f[i][j][p + 1] + f[i][j][k]) % mod;
			}
	for (int i = 0; i <= n; ++i) 
		for (int j = 0; j <= n; ++j) {
			Ans = (Ans + f[i][j][n]) % mod;
			Ans = (Ans + f[n][i][j]) % mod;
			Ans = (Ans + f[i][n][j]) % mod;
		}
	return Ans;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		int l, r, x; 
		scanf("%d%d%d", &l, &r, &x);
		if(r - l + 1 < x) {puts("0"); return 0;}
		ins(r, l, x);
	}
	printf("%d\n", DP());
	return 0;
}

Measured memory_bytes: 221440
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<cmath>
using namespace std;
using Graph = vector<vector<int>>;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;

#define For(N,i) for(int i = 0; i < N; i++)


int main(){
	int A,B;
	cin>>A>>B;
	int ans = -1;
	if(A >= 10 or B >= 10){
		ans = -1;
	}else{
		ans = A*B;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
N, C = map(int, input().split())

# x = 0 に v = 0 の寿司があると考える
X = [0]
V = [0]

for _ in range(N):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)

# 0, v_1, v_1+v_2, v_1+v_2+v_3, ...
cumsum1 = [0]
for i in range(1, N + 1):
    cumsum1.append(cumsum1[-1] + V[i])

# 0, v_N, v_N+v_N-1, v_N+v_N-1+v_N-2, ...
cumsum2 = [0]
for i in range(N, 0, -1):
    cumsum2.append(cumsum2[-1] + V[i])

# 歩く範囲を弧ABと考える(A<=B)
# x_A = 0, x_1, x_2, ..., x_N
# x_B = x_A, ..., x_N

# 0, v_1-x_1, v_1+v_2-x_2, v_1+v_2+v_3-x_3, ...
f1 = [0]
# 0, v_1-2*x_1, v_1+v_2-2*x_2, v_1+v_2+v_3-2*x_3, ...
f2 = [0]
for i in range(1, N + 1):
    f1.append(cumsum1[i] - X[i])
    f2.append(cumsum1[i] - 2 * X[i])

f1_max = [0]
for i in range(1, N + 1):
    f1_max.append(max(f1_max[-1], f1[i]))
f2_max = [0]
for i in range(1, N + 1):
    f2_max.append(max(f2_max[-1], f2[i]))

ans = 0
# Bを全探索（固定する）
for i in range(N + 1):
    if i == 0:
        continue
    else:
        # 0 -> B(反時計回り、反転なし)
        ans = max(ans, cumsum1[i] - X[i])
        # 0 -> B(時計回り、反転なし)
        ans = max(ans, cumsum2[N + 1 - i] - (C - X[i]))
        # 0 -> A -> B(反転)
        ans = max(ans, f2_max[i - 1] + cumsum2[N + 1 - i] - (C - X[i]))
        # 0 -> B -> A(反転)
        ans = max(ans, f1_max[i - 1] + cumsum2[N + 1 - i] - 2 * (C - X[i]))

print(ans)


Measured memory_bytes: 123208
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=list(map(int,input().split()))
    mod=10**9+7
    max_n=len(format(max(A),'b'))
    C=[[0,0] for _ in range(max_n)]
    for a in A:
        ax=a
        for i in range(max_n):
            C[i][ax%2]+=1
            ax=ax//2
    ans=0
    for i,c in enumerate(C):
        ans+=c[0]*c[1]*2**i%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Measured memory_bytes: 124568
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define inf INT_MAX

int main(){
    FASTIO
    ll H, W; cin>>H>>W;
    char grid[H][W];
    ll dp[H][W];
    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j) {char c; cin>>c; grid[i][j]=c; dp[i][j] = 0;}
    }
    dp[0][0] = 1;
    for(int i=1; i<H; ++i){
        if(grid[i][0]=='.') dp[i][0] = dp[i-1][0];
    }
    for(int i=1; i<W; ++i){
        if(grid[0][i]=='.') dp[0][i] = dp[0][i-1];
    }
    for(int i=1; i<H; ++i){
        for(int j=1; j<W; ++j){
            if(grid[i][j]=='.'){
                dp[i][j] = (dp[i-1][j]%MOD + dp[i][j-1]%MOD)%MOD;
            }
        }
    }
    // for(int i=0; i<H; ++i){
    //     for(int j=0; j<W; ++j) cout<<dp[i][j]<<" "; cout<<endl;
    // }
    cout<<dp[H-1][W-1]%MOD<<endl;
}

Measured memory_bytes: 12324
#include <stdio.h>

int	 main(void)
{
	int	a,b,c;

	scanf("%d%d%d",&a,&b,&c);

	if(a<b){
		if(b<c)
			puts("Yes");
		else
			puts("No");
	}
	else
		puts("No");

	return(0);
}

Measured memory_bytes: 1008
#include <iostream>

using namespace std;

int main()
{
 string n,m="Sunny",l="Cloudy",k="Rainy";
 cin>>n;

 if(n==m)
 {
     cout<<"Cloudy"<<endl;
 }
 else if(n==l)
 {
     cout<<"Rainy"<<endl;
 }
 else{
    cout<<"Sunny"<<endl;
 }
    return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

vector<int>f(vector<int>a, vector<int>b) {
	vector<int>c(a.size());
	rep(i, 0, a.size()) {
		c[i] = a[b[i]];
	}
	return c;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	string S; cin >> S;

	int n = S.size();
	vector<int>I(n);
	iota(all(I), 0);
	dump(I);
	vector<int>x(n);
	rep(i, 0, n) {
		if (S[i] == 'L') {
			x[i] = i - 1;
		}
		else {
			x[i] = i + 1;
		}
	}

	loop(100) {
		auto y = x;
		rep(i, 0, n) {
			y[i] = x[x[i]];
		}
		swap(y, x);
	}

	vector<int>ans(n);
	rep(i, 0, n) {
		ans[x[i]]++;
	}

	rep(i, 0, n) {
		cout << ans[i] << (i == n - 1 ? '\n' : ' ');
	}

	return 0;
}


Measured memory_bytes: 2896
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if (a1+a2+a3 >= 22)
        cout << "bust" << endl;
    else
        cout << "win" << endl;
    return 0;
}


Measured memory_bytes: 256
def solve():
    S = input()
    N = len(S)

    left = 0
    right = N-1

    ans = 0
    while right - left > 0:
        if S[left] == S[right]:
            left += 1
            right -= 1
        else: 
            if S[left] == 'x':
                left += 1
                ans += 1
            elif S[right] == 'x':
                right -= 1
                ans += 1
            else:
                print('-1')
                return
    
    print(ans)
                
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {
        for (int i = 1;; i++) {
            String x = br.readLine();
            if(x.equals("0")) break;
            out.println("Case "+i+": "+x);
        }
        out.flush();
    }
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[n + 1];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        a[n] = x;
        Arrays.sort(a);
        long ans = a[1] - a[0];
        for (int i = 0; i < n; i++) {
            long dif1 = a[i + 1] - a[i];
            ans = gcd(ans, dif1);
        }
        System.out.println(ans);

    }

    private static long gcd(long m, long n) {
        if (m < n)
            return gcd(n, m);
        if (n == 0)
            return m;
        return gcd(n, m % n);
    }

}

Measured memory_bytes: 49520
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))

visited = [0]
visitedSet = {0}
flag = False
loopStart = 0
loopCycle = 0
currentTown = 0

for i in range(n):
    currentTown = a[visited[-1]]-1
    if currentTown in visitedSet:
        flag = True
        loopStart = visited.index(currentTown)
        loopCycle = i + 1 - loopStart
        break
    if i == k - 1:
        print(currentTown+1)
        break

    visited.append(currentTown)
    visitedSet.add(currentTown)

if flag:
    print(visited[loopStart + (k - loopStart) % loopCycle]+1)

Measured memory_bytes: 35220
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long
   // #define ll unsigned long long
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define be begin()
    #define en end()
    #define le length()
    #define all(x) (x).begin(), (x).end()
    #define rep(i, n) for (ll i = 0; i < n; i++)
    #define repo(i, n) for (ll i = 1; i <= n; i++)
    #define fastIO                        \
        ios_base::sync_with_stdio(false); \
        cin.tie(NULL);                    \
        cout.tie(NULL)
    #define eps 1e-6
    #define pi 3.141592653589793
    #define c(a) cout << a << "\n";
    #define ao(a)        \
        for (auto i : a) \
            cout << i << " ";
    #define endl '\n'        
    typedef vector<int> vii;
    typedef vector<ll> vll;
    typedef pair<int, int> pii;
    typedef pair<ll, ll> pll;
    const int MOD = 1e9 + 7;
    const int INF = 1e9;
    const int N = 1e6 + 6;
 
    ll powmod(ll a, ll b, ll mod)
    {
        ll res = 1;
        a %= mod;
        for (; b; b >>= 1)
        {
            if (b & 1)
                res = (res * a) % mod;
            a = (a * a) % mod;
        }
        return res;
    }
 
    ll gcd(ll a, ll b)
    {
        while (b > 0)
        {
            ll t = a % b;
            a = b, b = t;
        }
        return a;
    }
 
    ll lcm(ll a, ll b)
    {
        return (a / gcd(a, b)) * b;
    }
 
    ll is_prime(ll n)
    {
        if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
            return 0;
        for (ll i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
            if (n % i == 0)
                return 0;
        return 1;
    }
    // long long bit[1000005], a[1000005];
    // ll N1 = 200005;
 
    // void update(int x, int del)
    // {
    //     for (; x <= N1; x += x & -x)
    //     {
    //         bit[x] += del;
    //     }
    // }
 
    // int query(int x)
    // {
    //     int sum = 0;
    //     for (; x > 0; x -= x & -x)
    //     {
    //         sum += bit[x];
    //     }
    //     return sum;
    // }
    /*************************************************************************************************************/
    int main(){
    ll n;
    cin>>n;
    vector<ll> p,q,a;
    ll x,l=0,r=0,k=0;
    for(int i=1;i<=n;i++) {a.pb(i);}
    rep(i,n) {cin>>x;p.pb(x);}
    rep(i,n) {cin>>x;q.pb(x);}
    do{
        k++;
        if(a==p) l=k;
        if(a==q) r=k;
    }while(next_permutation(all(a)));
    
    cout<<abs(l-r);
    return 0;   
    }
        
 
 
 

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n; cin >> n;
  vector<int> A(n), B(n);
  loop(i,0,n) cin >> A[i];
  loop(i,0,n) B[i] = A[i];
  sort(B.rbegin(), B.rend());
  loop(i,0,n) {
    if (A[i] == B[0] and B[0] != B[1]) {
      cout << B[1] << endl;
      continue;
    }
    cout << B[0] << endl;
  }
  return 0;
}


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

int  main()
{
   int n;
   cin>>n;
   int num[n];
   map<int,int> m;
   for(int i=2;i<=n;i++){
      int a;
      cin>>a;
      if(a<i)
       m[a]++;
   }
   int count=0, total_count=0;
   
     for(int i=1;i<=n;i++){
        cout<<m[i]<<endl;
     }
     
   
  
}

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

using namespace std;

int row, col,jmlJalan;
char lintasan[10][10];
bool hasil;

void floodFill(int row1 , int col1){
	if(row1==row&&col==col1){
		hasil=true;
		return;
	}else{
		if(lintasan[row1][col1]!='#'){
			return;
		}else{
			floodFill(row1+1,col1);
			floodFill(row1,col1+1);
		}
	}
}

int main(){

	cin>>row>>col;
	for(int x=1;x<=row;x++){
		for(int y=1;y<=col;y++){
			cin>>lintasan[x][y];
			if(lintasan[x][y]=='#'){
				jmlJalan++;
			}
		}
	}
	if(jmlJalan!=(row+col-1)){
		cout << "Impossible"<<endl;
		return 0;
	}
	floodFill(1,1);
	if(hasil==true){
		cout << "Possible"<<endl;
	}else{
		cout << "Impossible"<<endl;
	}



	return 0;
}


Measured memory_bytes: 256
void throwdice_N(int x[6]){
    int tmp;
    tmp = x[0];
    x[0] = x[1];
    x[1] = x[5];
    x[5] = x[4];
    x[4] = tmp;
}
void throwdice_E(int x[6]){
    int tmp;
    tmp = x[0];
    x[0] = x[3];
    x[3] = x[5];
    x[5] = x[2];
    x[2] = tmp;
}
void throwdice_S(int x[6]){
    int tmp;
    tmp = x[0];
    x[0] = x[4];
    x[4] = x[5];
    x[5] = x[1];
    x[1] = tmp;
}
void throwdice_W(int x[6]){
    int tmp;
    tmp = x[0];
    x[0] = x[2];
    x[2] = x[5];
    x[5] = x[3];
    x[3] = tmp;
}

#include <stdio.h>
int main(int argc, const char * argv[]) {
    int i, q, top, front;
    int x[6];
    for(i=0; i<6; i++) {
        scanf("%d",&x[i]);
    }
    scanf("%d",&q);
    for (i=0; i<q; i++) {
        scanf("%d %d",&top,&front);
        while (x[1] != front) {
            if (x[2] == front || x[3] == front) {
                throwdice_E(x);
            }
            throwdice_N(x);
        }
        while (x[0] != top) {
            throwdice_E(x);
        }
        printf("%d\n", x[2]);
    }
    return 0;
}

Measured memory_bytes: 596
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    H, W = map(int, input().split())
    S_lsit = [input() for i in range(H)]

    INF = 401

    node_list = []
    for i in range(H):
        node_list += [(i, j) for j in range(W)]

    dist_table = [[INF for j in range(H*W)] for i in range(H*W)]
    for i in range(H*W):
        dist_table[i][i] = 0
    #print(dist_table)

    path_list = [[] for i in range(H*W)]
    for k in range(H*W):
        node = node_list[k]
        i, j = node[0], node[1]
        if i >= 1 and S_lsit[i-1][j] == ".":
            path_list[k].append((i-1)*W + j)
        if i <= H-2 and S_lsit[i+1][j] == ".":
            path_list[k].append((i+1)*W + j)
        if j >= 1 and S_lsit[i][j-1] == ".":
            path_list[k].append(i*W + j-1)
        if j <= W-2 and S_lsit[i][j+1] == ".":
            path_list[k].append(i*W + j+1)
        for next_node in path_list[k]:
            dist_table[k][next_node] = 1
    #print(path_list)

    for k in range(H*W):
        for i in range(H*W):
            for j in range(H*W):
                dist_table[i][j] = min(
                    dist_table[i][j],
                    dist_table[i][k] + dist_table[k][j]
                )
    #print(dist_table)

    max_dist = 0
    for i in range(H*W):
        if S_lsit[i//W][i%W] == ".":
            for j in range(H*W):
                if S_lsit[j//W][j%W] == ".":
                    max_dist = max(max_dist, dist_table[i][j])
    print(max_dist)

if __name__ == "__main__":
    main()



Measured memory_bytes: 75040
#include <stdio.h>
int main(void)
{
  int a,b,max=0;
  scanf("%d%d",&a,&b);
  max=a+a-1;
  if(b+b-1>max)
    max=b+b-1;
  if(a+b>max)
    max=a+b;
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#define N 100

int main(){
  int M[N][N],i,j;
  int n,u,k,v;
  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    for(j=0 ; j<n ; j++){
      M[i][j]=0;
    }
  }
  for(i=0 ; i<n ; i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0 ; j<k ; j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  for(i=0 ; i<n ; i++){
    for(j=0 ; j<n ; j++){
      if(j) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2104
apples =str(input())
apples_list = apples.split(" ")
N = int(apples_list[0])
L = int(apples_list[-1])
pai_values = []
 
for i in range(1,N+1):
    pai_value = i + L -1
    pai_values.append(pai_value)
    
min_pai = abs(pai_values[0])
target_number = 0
 
for j in range(N):
    if min_pai > abs(pai_values[j]):
        min_pai = abs(pai_values[j])
        target_number = j
        
pai_values.pop(target_number)
 
answer = sum(pai_values)
 
print(int(answer))

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll T[100005];
ll P[100005];

ll func(ll a, ll m) {
    return a * a % m;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, X, M;
    cin >> N >> X >> M;
    N--;

    memset(P, 0, sizeof(P));
    memset(T, -1, sizeof(T));
    P[X]++;
    T[X] = 0;

    REP(i, N) {
        X = func(X, M);
        if (T[X] < 0) {
            T[X] = i + 1;
            P[X]++;
            continue;
        }

        //! ループを始める
        ll x = i + 1 - T[X];
        ll n = N - i;
        REP(j, x) {
            ll p = n / x;
            if (n % x > j)
                p++;
            P[X] += p;
            X = func(X, M);
        }
        break;
    }

    ll ans = 0;
    REP(i, M) {
        ans += i * P[i];
    }

    cout << ans << endl;

    return 0;
}

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

bool solve(vector<bool> &As)
{
    // 横
    for(int i=0; i<9; i+=3)
    {
        if(As.at(i) && As.at(i+1) && As.at(i+2))
        {
            return true;
        }
    }

    // 縦
    for(int i=0; i<3; i++)
    {
        if(As.at(i) && As.at(i+3) && As.at(i+6))
        {
            return true;
        }
    }

    // ななめ
    if(As.at(0) && As.at(4) && As.at(8))
    {
        return true;
    }
    if(As.at(2) && As.at(4) && As.at(6))
    {
        return true;
    }

    return false;
}

int main()
{
    vector<int> As(9);
    for(int i=0; i<9; i++)
    {
        cin >> As.at(i);
    }

    int n;
    cin >> n;

    vector<int> Bs(n);
    for(int i=0; i<n; i++)
    {
        cin >> Bs.at(i);
    }


    for(int i=0; i<9; i++)
    {
        int& a = As.at(i);
        for(const int& b : Bs)
        {
            if(a == b)
            {
                a = 0;
            }
        }
    }

    vector<bool> mat;
    for(const int& a : As)
    {
        if(a == 0)
        {
            mat.push_back(true);
        }
        else
        {
            mat.push_back(false);
        }
    }

    if(solve(mat))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    int W,H,N,sum=0;
    cin >> W >> H >> N;

    int a[W][H];
    REP(i,H){
        REP(j,W){
            a[j][i] = 1;
        }
    }

    REP(o,N){
        int x,y,c;
        cin >> x >> y >> c;

        if(c==1){
            for(int i=0;i<H;i++){
                for(int j=0;j<x;j++){
                    a[j][i] = 0;
                }
            }
        }else if(c==2){
            for(int i=0;i<H;i++){
                for(int j=x;j<W;j++){
                    a[j][i] = 0;
                }
            }
        }else if(c==4){
            for(int i=y;i<H;i++){
                for(int j=0;j<W;j++){
                    a[j][i] = 0;
                }
            }
        }else{
            for(int i=0;i<y;i++){
                for(int j=0;j<W;j++){
                    a[j][i] = 0;
                }
            }
        }
    }

    REP(i,H){
        REP(j,W){
            sum +=a[j][i];
        }
    }

    

    
    cout << sum << endl;

}

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

int main(){
  int n,i;
  long long int a,sum[200000]={},min=200000000000000;
  scanf("%d",&n);
  scanf("%lld",&a);
  sum[0]=a;
  for(i=1;i<n;i++){
    scanf("%lld",&a);
    sum[i]=sum[i-1]+a;
  }
  for(i=0;i<n-1;i++){
    if(min>llabs(sum[n-1]-2*sum[i]))
      min=llabs(sum[n-1]-2*sum[i]);
  }
  printf("%lld\n",min);
}

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

using namespace std;

#define int long long
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
typedef tuple<int,int> T1;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

int N,D;
int V[35],W[35];
int dat[16777216*2-1];
int ans=0;
vector<T1> P1,P2;

class Segment{
public:
    int n;
    inline void init(int _n){
        n=1;
        while(n<_n)n*=2;
        for(int i=0;i<2*n-1;++i)dat[i]=-INF;
    }
    inline void update(int k,int a){
        k+=n-1;
        dat[k]=a;
        while(k>0){
            k=(k-1)/2;
            dat[k]=max(dat[k*2+1],dat[k*2+2]);
        }
    }
    inline int query(int a,int b,int k,int l,int r){
        if(r<=a||b<=l)return -INF;
        if(a<=l&&r<=b)return dat[k];
        int vl=query(a,b,k*2+1,l,(l+r)/2);
        int vr=query(a,b,k*2+2,(l+r)/2,r);
        return max(vl,vr);
    }
};


void half(int n,int End,int v,int w,vector<T1> &S){
    if(n==End){
        S.push_back(make_tuple(v,w));
        return ;
    }
    half(n+1,End,v+V[n],w+W[n],S);
    half(n+1,End,v-V[n],w-W[n],S);
    half(n+1,End,v,w,S);
}

signed main(){
    cin>>N>>D;
    for(int i=0;i<N;++i)cin>>V[i]>>W[i];
    half(0,N/2,0,0,P1);
    half(N/2,N,0,0,P2);
    sort(P1.begin(),P1.end());
    sort(P2.begin(),P2.end());
    Segment seg;
    seg.init(P2.size());
    for(int i=0;i<P2.size();++i)seg.update(i,get<1>(P2[i]));
    for(int i=0;i<P1.size();++i){
        int x,y;
        int a,b;
        tie(x,y)=P1[i];
        a=min(D-x,-D-x);
        b=max(D-x,-D-x);
        int lit=lower_bound(P2.begin(),P2.end(),make_tuple(a,-INF))-P2.begin();
        int rit=upper_bound(P2.begin(),P2.end(),make_tuple(b,INF))-P2.begin();
        if(rit==P2.size()||lit==rit)continue;
        if(lit>rit)continue;
        ans=max(ans,abs(y+seg.query(lit,rit,0,0,seg.n)));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 713372
#include<iostream>
#include<vector>
#define INF 1500000000

using namespace std;


int main(){
	int n;
	while(cin>>n && n){
		vector<int >data;
		data.push_back(0);
		for(int i=0;i<n;i++){
			int x;
			cin>>x;
			data.push_back(x+data.back());
		}
		int ans=-1*INF;
		for(int i=0;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				ans=max(ans,data[j]-data[i]);
			}
		}
		cout<<ans<<endl;
	}
}

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

int main() {
	int x;
	int y;
	int p;

	cin >> x >> y;
	if(y%2>0){
		cout << "No" << endl;
		return 0;
	}
	y=y/2;
	if(y<x){
		cout << "No" << endl;
		return 0;
	}
	if(y>2*x){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 3640
#include "iostream"
#include "vector"
#include "string"
#include <iomanip>
#include <algorithm>
#define rep(i,n) for (int i= 0; i < (n); ++i)
using ll = long long;
using namespace std;
const double PI = 3.14159265358979323846;

int main() {
	int D1, D2 = 0;
	int N = 0;
	cin >> N;
	
	int conti = 0;
	int max_conti = 0;

	for (int i = 0; i < N; i++) {

		cin >> D1 >> D2;

		if (D1 == D2) {
			conti++;
		}
		else {
			if (conti > max_conti) {
				max_conti = conti;
			}
			conti = 0;
		}
	}

	if (conti > max_conti) {
		max_conti = conti;
	}

	if (max_conti >= 3) {
		cout << "Yes" <<endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;

}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define Maxn 200007
using namespace std;
int n;
long long d,a;
pair<long long,long long> q[Maxn];
int main()
{
    scanf("%d%lld%lld",&n,&d,&a);
    for (int i=1;i<=n;i++)
        scanf("%lld%lld",&q[i].first,&q[i].second);
    sort(q+1,q+n+1);
    for (int i=n;i>1;i--)
        q[i].second-=q[i-1].second;
    long long ans=0LL;
    for (int i=1;i<=n;i++)
    {
        q[i].second+=q[i-1].second;
        if (q[i].second>0LL)
        {
            long long tmp=(q[i].second+a-1)/a;
            ans+=tmp;
            tmp=1LL*tmp*a;
            q[i].second-=tmp;
            if (q[n].first>q[i].first+2LL*d)
            {
                int lx=i+1,rx=n,now;
                while (rx-lx>1)
                {
                    int mid=(lx+rx)/2;
                    if (q[mid].first>q[i].first+2LL*d) rx=mid; else lx=mid;
                }
                if (q[lx].first>q[i].first+2LL*d) now=lx; else now=rx;
                q[now].second+=tmp;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define elif else if
#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define vint vector<int>
#define vvint vector<vector<int>>
#define vtr vector<string>
#define vvtr vector<vector<string>>
#define vhar vector<char>
#define vvhar vector<vector<char>>
#define mod 100000007
#define elif else if
#define str string

signed main(){
  int N,M,O,P=0,c=0,c2=0,crash=0,nowtab=1;
  double D,D2;
  char C;
  str S,T,U;
  vint v(0);
  cin>>N>>S;
  rep(0,N){
    if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
      c++;
    }
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
n = int(input())

score = [list(map(lambda x: int(x) - 1 , input().split())) for _ in range(int(n*(n-1)/2))]

points = [0 for _ in range(n)]

for a,b,c,d in score:
    if c > d:
        points[a] += 3
    elif c < d:
        points[b] += 3
    else:
        points[a] += 1
        points[b] += 1

rank = sorted(points, reverse=True)

for p in points: 
    print(rank.index(p) + 1)

Measured memory_bytes: 7496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000007;
ll arr[10000005],ans[10000005];
int main ()
{
    ll n, k;
    cin>>n>>k;
    
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    //ans[0]=0;
    for (int i=0;i<n;i++)
    {
        ans[i]=INF;
    }
    ans[0]=0;
    for (int i=0;i<n;i++)
    {
        for (int j=i+1;j<=i+k;j++)
        {
            if(j<n)
            {
            ans[j]=min(ans[j],ans[i]+abs(arr[j]-arr[i]));
            }
        }
    }
    cout<<ans[n-1]<<'\n';

}



Measured memory_bytes: 5076
#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N = int(input())
    f = [{} for _ in range(N+1)] # [{arg:k}]
    if len(f) > 6:
        f[6] = {(1,1,1):1}
    for i in range(N):
        args = f[i]
        for (x,y,z),k in args.items():
            index = i + 2*x + y + z + 1
            arg = (x+1,y,z)
            if index < N+1:
                f[index][arg] = 1
            index = i + x + 2*y + z + 1
            arg = (x,y+1,z)
            if index < N+1:
                f[index][arg] = 1
            index = i + x + y + 2*z + 1
            arg = (x,y,z+1)
            if index < N+1:
                f[index][arg] = 1

    for i in range(1,N+1):
        print(sum(f[i].values()))


main()


Measured memory_bytes: 35076
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 0;

char c;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> c;
	if(c >= 'a'){
		cout << 'a' << '\n';
	}
	else{
		cout << 'A' << '\n';
	}
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> s;
typedef long long int ll;

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}

char c[2][4];

int main(){
  scanf("%s",c[0]);
  scanf("%s",c[1]);
  REP(i,3){
    if(c[0][i] == c[1][2-i]) continue;
    printf("NO\n");
    return 0;
  }
  printf("YES\n");
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int INF = 1001001001;

int main() {
    ll N;
    cin >> N;
    vl n(N);
    bool is_zero = false;
    rep (i, N) {
        cin >> n[i];
        if (n[i] == 0) is_zero = true;
    }

    ll max = 1000000000000000000;
    ll ans = 1;
    rep (i, N) {
        if (max/ans < n[i]) {
            ans = -1;
        } else {
            ans *= n[i];
        }
    }

    if (is_zero) ans = 0;

    cout << ans << endl;
}


Measured memory_bytes: 4024
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from itertools import accumulate
def main():
    n, *a = map(int, read().split())
    large_p = 10 ** 9 + 7
    aac = tuple(accumulate(a))
    r = 0
    for i1 in range(n):
        t1 = aac[-1] - aac[i1]
        r += (t1 * a[i1]) % large_p
    r = r % large_p
    print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 108744
// 解説後
#include <algorithm>
#include <iostream>
#include <vector>

constexpr uint32_t MAX_LENGTH = 1000;

uint32_t counts[MAX_LENGTH + 1];
uint32_t prefix_sums[MAX_LENGTH + 1];

int main() {
  size_t N;
  std::cin >> N;

  // 棒の長さをインデックスとした棒の個数のリストを作る
  for (size_t i = 0; i < N; ++i) {
    size_t L_i;
    std::cin >> L_i;
    counts[L_i]++;
  }

  // 棒の長さをインデックスとした棒の個数の累積和のリストを作る
  prefix_sums[0] = counts[0];
  for (size_t i = 1; i < MAX_LENGTH + 1; ++i) {
    prefix_sums[i] = prefix_sums[i - 1] + counts[i];
  }

  // 取り得るすべての三角形の個数を計算する
  int64_t result = 0;
  for (uint32_t a = 1; a <= MAX_LENGTH; ++a) {
    const int64_t a_count = counts[a];

    // a == b != cの場合の組み合わせの数を計上する
    const int64_t c_sum = prefix_sums[std::min(a + a - 1, MAX_LENGTH)] - prefix_sums[a];  //　a < c < 2aの範囲の棒の数
    const int64_t ab_comb = a_count * (a_count - 1) / 2;  // a_count個から2つ選ぶときの組み合わせの数
    result += c_sum * ab_comb;

    // a == b == cの場合の組み合わせの数を計上する
    const int64_t abc_comb = ab_comb * (a_count - 2) / 3;  // a_count個から3つ選ぶときの組み合わせの数
    result += abc_comb;

    // a < bのときに取り得る三角形の個数を計算する
    for (uint32_t b = a + 1; b <= MAX_LENGTH; ++b) {
      const int64_t b_count = counts[b];

      // a != b != cの場合の組み合わせの数を計上する
      const int64_t c_sum = prefix_sums[std::min(a + b - 1, MAX_LENGTH)] - prefix_sums[b];  //　b < c < a+bの範囲の棒の数
      const int64_t ab_comb = a_count * b_count;  // a_count個とb_count個から1つずつ選ぶときの組み合わせの数
      result += c_sum * ab_comb;

      // a != b == cの場合の組み合わせの数を計上する
      const int64_t abc_comb = ab_comb * (b_count - 1) / 2;  // a_count個から1つ、b_count個から2つを選ぶときの組み合わせの数
      result += abc_comb;
    }
  }

  std::cout << result;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
xy=[]
for i in range(n):
  x,y=map(int,input().split())
  xy.append((x,y))
pq=[]
for i in range(n):
  for j in range(n):
    if i==j:continue
    x1,y1=xy[i]
    x2,y2=xy[j]
    pq.append((x2-x1,y2-y1))
ans=n
for p,q in pq:
  t=0
  for x,y in xy:
    if (x+p,y+q) not in xy:
      t+=1
  ans=min(ans,t)
print(ans)







Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    //素数なら、Nが1でないかぎり答えは1になる
    //M=x*(N以上の整数)
    int n, m;
    cin >> n >> m;

    //for (int i = n; i <= m; i++) {
    //    if (m % i == 0) {
    //        cout << m / i << endl;
    //        exit(0);
    //    }
    //}
    int r = 1;
    int t = (int)sqrt(m);
    for (int i = 1; i <= t; i++) {
        if (m % i == 0) {
            int a = m / i;
            int b = i;
            if (a > b) swap(a, b);
            if (b >= n) {
                r = max(r, a);
                if (a >= n) r = max(r, b);
            }
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<deque>
using namespace std;

struct pro {
    char name[10];
    int time;
};

int main(){

    int n, q;
    scanf("%d %d", &n, &q);

    deque<pro> Pro;
    for(int i=0; i<n; i++){
        pro tmp;
        scanf("%s %d", tmp.name, &tmp.time);
        Pro.push_back(tmp);
    }

    int sum_time = 0;
    while(!Pro.empty()){
        pro tmp;
        tmp = Pro.front();
        if((tmp.time - q)>0){
            tmp.time-=q;
            Pro.pop_front();
            Pro.push_back(tmp);
            sum_time += q;
        }else{
            printf("%s %d\n", Pro.front().name, sum_time+Pro.front().time);
            sum_time += Pro.front().time;
            Pro.pop_front();
        }
    }
    return 0;
}


Measured memory_bytes: 3180
from math import gcd
N = int(input())
A = list(map(int,input().split()))

g = 0
for a in A:
    g = gcd(g,a)
if g > 1:
    print('not coprime')
    exit()

sa = set()
for a in A:
    if a==1: continue
    if a in sa:
        print('setwise coprime')
        exit()
    sa.add(a)

MAXN = 10**6+10
sieve = [0,0] + [1]*MAXN
p = 2
small_primes = []
while p*p <= MAXN:
    if sieve[p]:
        small_primes.append(p)
        for q in range(2*p,MAXN+1,p):
            sieve[q] = 0
    p += 1

st = set()
for a in A:
    for p in small_primes:
        found = False
        while a%p==0:
            a //= p
            found = True
        if found:
            if p in st:
                print('setwise coprime')
                exit()
            st.add(p)
        if a==1: break
    else:
        if a in st:
            print('setwise coprime')
            exit()
        st.add(a)

print('pairwise coprime')

Measured memory_bytes: 241520
#
# panasonic2020b d
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1"""
        output = """a"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2"""
        output = """aa
ab"""
        self.assertIO(input, output)


def resolve():
    global N
    N = int(input())

    T = []
    func("a", "a", T)

    for t in T:
        print(t)


def func(mw, s, T):
    if len(s) == N:
        T.append(s)
        return

    for i in range(ord(mw)-ord("a")+2):
        mw = max(mw, chr(ord("a")+i))
        ns = s + chr(ord("a")+i)
        func(mw, ns, T)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 24432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,l;
  cin >> n >> l;
  ll s = 0,ps = 0,delta = INT_MAX;
  for(ll i = 1; i <= n; ++i) s += l+i-1;
  for(ll i = 1; i <= n; ++i){
    if(abs(l+i-1) < delta){
      delta = abs(l+i-1);
      ps = s - (l+i-1);
    }
  }
  cout << ps;
  return 0;
}


Measured memory_bytes: 256
import java.util.*; 
import java.lang.*; 

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		long N = scan.nextLong();
		long K = scan.nextLong();
		
		long r = N%K;
		System.out.println(Math.min(r,K-r));
	}
}

Measured memory_bytes: 21844
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

DP = [0 for s in range(S+1)]
ans = 0
for i in range(N):
  a = A[i]
  for s in range(S,-1,-1):
    if s+a <= S:
      DP[s+a] += DP[s]
  if a <= S:
    DP[a] += i+1 #始点がiの列
  ans += DP[S]
  #print(DP, ans)
  
print(ans % MOD)
  
    
  

Measured memory_bytes: 88732
fn func(input_str: &str) -> i32 {
    let mut iter = input_str.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    if n >= m {
        return 0;
    }
    let mut x_s: Vec<i32> = iter.take(m).map(|x| x.parse().unwrap()).collect();
    x_s.sort();
    let x_s = x_s;
    let mut d_s = x_s[0..x_s.len()-1].iter().zip(x_s[1..].iter())
        .map(|(x0, x1)| x1 - x0)
        .enumerate()
        .collect::<Vec<_>>();
    d_s.sort_by_key(|k| k.1);
    d_s.reverse();
    let idx_s = d_s[0..n - 1].iter().map(|k| k.0);
    let mut p_idx = 0;
    let mut ans = 0;
    for c_idx in idx_s {
        ans += x_s[c_idx] - x_s[p_idx];
        p_idx = c_idx + 1;
    }
    ans += x_s.last().unwrap() - x_s[p_idx];
    ans
}

use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    println!("{}", func(&buf[..]));
}

Measured memory_bytes: 8444
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    string s, t;
    cin >> s>> t;
    map<char, ll> sm;
    map<char, vector<int>> ss;
    map<char, ll> tm;
    
    for(int i=0, n=s.size(); i<n; i++){
        sm[s[i]]++;
        ss[s[i]].emplace_back(i);
    }
    for(auto &c: t) tm[c]++;
    bool ok = true;
    for(auto &c: t) if(!sm.count(c)) ok = false;
    if(!ok){
        cout << -1 << endl;
        return 0;
    }
    ll cnt = 0;
    ll idx = -1;
    for(int i=0, n=t.size(); i<n; i++){
        auto itr = upper_bound(ALL(ss[t[i]]), idx);
        if(itr==ss[t[i]].end()){
            cnt++;
            idx = ss[t[i]][0];
        }
        else{
            idx = *itr;
        }
    }
    ll res = s.size()*cnt + idx+1;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1220
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli x, a, b, y;
    cin >> x >> a >> y >> b;
    if(x==y){
        out(0);
    }
    else{
        out(1);
    }
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define li long long int
#define ld long double
#define F first
#define S second
const li M = 1000000007;
#define ld long double
li dx[]={-1,1,0,0};
li dy[]={0,0,-1,1};

li p26[13];

int main()
{
	li N,K,i,j; cin>>N;
	p26[0]=1;
	for(i=1;i<13;i++)
	{
		p26[i]=p26[i-1]*26;
	} //p26[0]=0;
	li s=0;
	for(i=1;i<13;i++)
	{
		s+=p26[i];
		if(s >= N)
		break;
	}
	li len=i;
	//cout<<len<<" \n";
 	li ct=0;
	for(i=1;i<len;i++)
	{
		ct+=p26[i];
	}
	ct=N-ct;
	//cout<<ct<<" \n";
	vector<char> ss(len,'a');
	/*for(i=0;i<len;i++)
	{
		cout<<ss[i];
	}cout<<"\n";
	*/
	li x=p26[len-1];
	for(i=0;i<len;i++)
	{
		j=0;
		while(x*j < ct)
			j++;
		j--;
		li pp=x*j; ct=ct-pp; x=x/26;
		ss[i]='a'+j;
	}
	for(i=0;i<len;i++)
	{
		cout<<ss[i];
	}
	
}



Measured memory_bytes: 3624
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input!{
        n: usize,
        v: [f64; n],
    }
    let mut w = v;
    w.sort_by(|a, b| a.partial_cmp(b).unwrap());

    // for x in w {
        // println!("{}", x);
    // }
    let mut sum = 0.0;
    for (i, x) in w.into_iter().enumerate() {
        if i == 0 {
            sum = x;
        } else {
            sum = (x + sum) / 2.0;
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define N 100000
using namespace std;
typedef long long ll;
bool used[N];

ll SumD(ll a,ll d,ll n){return (n*(2*a+(n-1)*d))/2;}

bool mark(ll n){
  bool res=1;
  for(ll i=1;i*i<=n;i++){
    if(n%i)continue;
    if(i<N)res&=!used[i],used[i]=1;
    if(i!=n/i&&n/i<N)res&=!used[n/i],used[n/i]=1;
  }
  return res;
}

int main(){
  while(1){
    ll n,m,p[21];
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<m;i++)cin>>p[i];
    sort(p,p+m);
  
    ll sum=0,cnt=0;
    for(int i=0;i<m;i++){
      sum+=SumD(p[i],p[i],n/p[i]);
      cnt+=n/p[i];
      memset(used,0,sizeof(used));
      for(int j=0;j<i;j++){
	ll lcm=(p[i]/__gcd(p[i],p[j]))*p[j];
	if(!mark(lcm))continue;
	sum-=SumD(lcm,lcm,n/lcm);
	cnt-=(n/lcm);
      }
    }

    printf("%.8f\n",(p[0]!=1)*(1.0*SumD(1,1,n)-sum)/max(1LL,(n-cnt)));
  }
  return 0;
}

Measured memory_bytes: 3380
#include "cstdio"
int max(int x,int y){
	return x>y?x:y;
}
int s,n,ss1,ss2,i,ss[10];
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&s);
		if(s>=3200)ss2++;
		else ss[s/400]=1;
	}
	for(i=0;i<8;i++)if(ss[i])ss1++;
	printf("%d %d\n",max(ss1,1),ss1+ss2); 
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/practice2/tasks/practice2_a

#include <atcoder/all>

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N, Q;
  cin >> N >> Q;

  dsu d(N);

  rep(i, Q) {
    ll t, u, v;
    cin >> t >> u >> v;

    if (t == 0) {
      d.merge(u, v);
    } else {
      if (d.same(u, v)) {
        cout << 1 << "\n";
      } else {
        cout << 0 << "\n";
      }
    }
  }
}


Measured memory_bytes: 3960
#include <iostream>
#include <cstdio>

using namespace std;

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

	long long int res;
	res=n/11*2;
	n=n%11;

	if(n>6){res+=2;}
	else if(n>0){res++;}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256