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

int dis[205][205], R[10];

int main ()
{
    int n, m, r, x, y, z;
    scanf("%d%d%d",&n,&m,&r);
    for (int i=1; i<=r; ++i)
        scanf("%d",R+i);
    for (int i=1; i<=n; ++i)
        for (int j=1; j<=n; ++j)
            if (i!=j)
                dis[i][j]=1000000000;
    for (int i=1; i<=m; ++i) {
        scanf("%d%d%d",&x,&y,&z);
        dis[x][y]=dis[y][x]=z;
    }
    for (int k=1; k<=n; ++k)
        for (int i=1; i<=n; ++i)
            for (int j=1; j<=n; ++j)
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
    string ss;
    for (int i=1; i<=r; ++i)
        ss.push_back(i+'0');
    int ans=1000000000;
    do {
        int tmp=0;
        for (int i=1; i<r; ++i)
            tmp+=dis[R[ss[i]-'0']][R[ss[i-1]-'0']];
        ans=min(ans,tmp);
    }while (next_permutation(ss.begin(),ss.end()));
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int x; cin >> x; cout << !x << endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int T = sc.nextInt();

		System.out.println( ((int)(T+0.5)/A) * B);
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000],y,d;
pair<int,int> pp[220000];
string s,ss[220000];
char c;
queue<int> que;
signed main(){
    cin>>n;
    cout<<n+n*n+n*n*n;
}


Measured memory_bytes: 10472
import java.util.Scanner;

public class Main {

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

    boolean[] isZoromeList = new boolean[N];
    for (int i = 0; i < N; i++) {
      int n1 = scanner.nextInt();
      int n2 = scanner.nextInt();

      if (n1 == n2) {
        isZoromeList[i] = true;
      } else {
        isZoromeList[i] = false;
      }
    }

    boolean is3TimesZorome = false;
    for (int i = 0; i < isZoromeList.length - 2; i++) {
      if (isZoromeList[i] && isZoromeList[i + 1] && isZoromeList[i + 2]) {
        is3TimesZorome = true;
      }
    }

    System.out.println(is3TimesZorome ? "Yes" : "No");
  }
}


Measured memory_bytes: 27320
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

// 1 way is to find compute all the sorted permutations and find the 
// positions of the current permutation.

int _find(ll a,ll b){
    if(a<=0 && b>=0){
        return 0;
    }
    // a,b
    if(a>0){
        return 1;
    }
    
    return (b-a+1)%2==0 ? 1:-1;
    
}

int convert(int n){
    int rem=n%10;
    if(rem==0){
        return n;
    }
    int miss=10-rem;
    return n+miss;
}
int remain(int n){
    int r=n%10;
    int w = r==0 ? 10 : r;
    return w;
}
void solve(){
    vi arr(5);
    for(int i=0;i<5;i++){
        cin>>arr[i];
    }
    sort(all(arr),[&](int a,int b){
        
        return remain(a) > remain(b);
    });
    int tim=0;
    for(int i=0;i<4;i++){
        int t=convert(arr[i]);
        // cout<<arr[i]<<" "<<t<<" ";
        tim+=t;
        // cout<<tim<<endl;
    }
    tim+=arr[4];
    cout<<tim<<endl;
}



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

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,b) FOR(i,0,b)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,b) ROF(i,0,b)

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define MOD(x,m) ((x)%(m)+(m))%(m)
#define int long long

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((b-a)%2 == 0) cout << (b-a)/2;
	else cout << min((n-b)+1+(n-(a+(n-b)+1))/2, (a-1)+1+(b-a-1)/2);
}


Measured memory_bytes: 256
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1;
    if(key > A[mid]) left = mid + 1;
    else if(key < A[mid]) right = mid;
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll ai, ao, at, aj, al, as, az;
    cin >> ai >> ao >> at >> aj >> al >> as >> az;

    ll ans = 0;
    {
        ll num = ao;
        num += ai/2*2;
        num += aj/2*2;
        num += al/2*2;
        num += 3 * (ai%2) * (aj%2) * (al%2);
        chmax(ans, num);
    }
    if(ai>0 && aj>0 && al>0) {
        ai--, aj--, al--;
        ll num = 3;
        num += ai/2*2;
        num += aj/2*2;
        num += al/2*2;
        num += ao;
        chmax(ans, num);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cctype>
#include <cstdio>
#include <vector>
#include <numeric>
#include <algorithm>

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

using namespace std;

int idx;
char s[10001];

int dfs(){
	vector<int> a;
	if(isdigit(s[idx])){
		int b=0;
		while(isdigit(s[idx])) b=10*b+(s[idx++]-'0');
		a.push_back(b/2+1);
	}
	else{
		while(s[idx]=='['){
			idx++;
			a.push_back(dfs());
			idx++;
		}
	}
	sort(a.begin(),a.end());
	return accumulate(a.begin(),a.begin()+a.size()/2+1,0);
}

int solve(){
	scanf("%s",s);
	idx=0;
	return dfs();
}

int main(){
	int T; scanf("%d",&T);
	while(T--) printf("%d\n",solve());
	return 0;
}

Measured memory_bytes: 1092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

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

		solve(sc, out);

		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out) {
		double a = sc.nextDouble();
		double  b = sc.nextDouble();
		
		out.println(new BigDecimal((a+b)/2d).setScale(0, RoundingMode.HALF_UP));
		
	}
	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21332
program ABC095C
    implicit none
    integer(8)::A,B,C,X,Y
    read*,A,B,C,X,Y

    if(X<Y)then
        print'(i0)',min(A*X+B*Y,2*C*X+B*(Y-X),2*C*Y)
    else if(X>Y)then
        print'(i0)',min(A*X+B*Y,2*C*Y+A*(X-Y),2*C*X)
    else
        print'(i0)',min(A*X+B*Y,2*C*X)
    end if
end program ABC095C

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<pair<int,int>> vip;

#define ZOOM ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define LOOP_IT(s) for(auto it=(s).begin();it!=(s).end();++it)


int main(int argc,char* argv[])
{
    ZOOM

    ll h,n,sum=0;
    cin>>h>>n;
    vector<ll> v(n);
    for(ll i=0;i<n;++i)
    {
        cin>>v[i];
        sum+=v[i];
    }
    cout<<(sum>=h?"Yes":"No");

    return 0;
}



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

int sieve_of_eratosthenes(int n){
  int p = 0; //素数の数
  int primes[n];
  bool is_prime[n+1]; 
  for(int i=0;i<=n;i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false; //0,1は素数じゃない
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      primes[p++] = i;
      for(int j= i*2;j<=n;j+=i) is_prime[j] = false;
    }
  }
  return p;
}

int main(){
  int n;
  while(cin >> n){
    cout << sieve_of_eratosthenes(n) << endl;
  }
}

Measured memory_bytes: 3216
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
ans = 0
check_box = []
for s in S:
  s = sorted(s)
  s = ''.join(s)
  check_box.append(s)
C = Counter(check_box)
for i in C:
  ans += C[i]*(C[i]-1)//2
print(ans)

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

using namespace std;

void hawawa(){
  int n, a;
  cin >> n >> a;
  if (n % 500 <= a) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}

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

Measured memory_bytes: 256
import sys

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


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = [a - i - 1 for i, a in enumerate(A)]
    A.sort()
    i = N // 2
    b = A[i]
    ans = 0
    for a in A:
        ans += abs(a - b)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 25872
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	
	string s;
	cin>>s;
	bool flag = false;
	int ind1,ind2;
	for(int i = 0; i+1 < s.size(); i++){
		if(s[i] == s[i+1]) {flag = true; ind1 = i; ind2 = i+1;}
	}
	if(flag)  {cout<<ind1+1<<" "<<ind2+1<<"\n"; return 0;}
	for(int i = 1; i+1 < s.size(); i++){
		if(s[i-1] == s[i+1]) {flag = true; ind1 = i-1; ind2 = i+1;}
	}
	if(flag) {cout<<ind1+1<<" "<<ind2+1<<"\n"; return 0;}
	cout<<-1<<" "<<-1<<"\n";
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#define ll long long
using namespace std;
int main() {
	ll a, b,x;
	cin >> a >> b>>x;
	if (a + b >= x&&a<=x) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)

n = int(input())
G = [[] for _ in range(n)] 
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append([b, c])
    G[b].append([a, c])

vis = [False] * n
d = [-1] * n
def dfs(k, depth):
    vis[k] = True
    d[k] = depth
    for i in G[k]: # i: [to, cost]
        if not vis[i[0]]: dfs(i[0], depth + i[1])

q, k = map(int, input().split())
dfs(k - 1, 0)

for i in range(q):
    x, y = map(int, input().split())
    print(d[x - 1] + d[y - 1])

Measured memory_bytes: 138704
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main()
{
    int H, W;
    cin >> H >> W;
    string *str;
    str = new string[H];
    for(int i=0;i<H;i++){
        cin >> str[i];
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(str[i][j]=='#'){
                bool w = true;
                bool e = true;
                bool n = true;
                bool s = true;
                if(i==0)   w = false;
                if(i==H-1) e = false;
                if(j==0)   n = false;
                if(j==W-1) s = false;
                if(w) if(str[i-1][j]=='.') w = false;
                if(e) if(str[i+1][j]=='.') e = false;
                if(n) if(str[i][j-1]=='.') n = false;
                if(s) if(str[i][j+1]=='.') s = false;
                if(!(w|e|n|s)){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  long long N, input, ans;
  long long lcm (long long a, long long b);
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> input;
    if(i == 0) ans = input;
    else ans = lcm(ans, input);
  }
  cout << ans << endl;
  
  return 0;
}


long long lcm (long long a, long long b){
  long long gcd (long long a, long long b);
  return a  / gcd(a, b) * b;
}

long long gcd(long long a, long long b){
  if(a < b){
    long long temp = b;
    b = a;
    a = temp;
  }
  long long r = a % b;
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,Q;
    cin >> A >> B >> Q;
    vl s, t;
    s.emplace_back(-LINF);
    rep(i,A){
        ll d;cin >> d;
        s.emplace_back(d);
    }
    s.emplace_back(LINF);
    t.emplace_back(-LINF);
    rep(i,B){
        ll d;cin >> d;
        t.emplace_back(d);
    }
    t.emplace_back(LINF);
    rep(i,Q){
        ll x;cin >> x;
        auto s2 = lower_bound(s.begin(),s.end(),x);
        auto s1 = s2;
        --s1;
        auto t2 = lower_bound(t.begin(),t.end(),x);
        auto t1 = t2;
        --t1;

        ll ans = LINF;
        chmin(ans, abs(x - *s1) + abs(*s1 - *t1));
        chmin(ans, abs(x - *t1) + abs(*t1 - *s1));
        chmin(ans, abs(x - *s1) + abs(*s1 - *t2));
        chmin(ans, abs(x - *t2) + abs(*t2 - *s1));
        chmin(ans, abs(x - *s2) + abs(*s2 - *t1));
        chmin(ans, abs(x - *t1) + abs(*t1 - *s2));
        chmin(ans, abs(x - *s2) + abs(*s2 - *t2));
        chmin(ans, abs(x - *t2) + abs(*t2 - *s2));
        printf("%lld\n", ans);
    }
}

Measured memory_bytes: 3060
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
 
x, y = MAP()
 
if x == y:
	print(0)
 
elif x < y :
	print(min(y-x, abs(y+x)+1))
 
else:
	print(min(-y+x+2, abs(y+x)+1))

Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin >> s;
    ll n = SZ(s);
    rep(i, n){
        bool f2 = 0;
        for(char k = 'a'; k <= 'z'; k++){
            bool f = 1;
            rep(j, n-i){
                if(find(s.begin()+j, s.begin()+j+i+1, k) == s.begin()+j+i+1){
                    f = 0;
                }
            }
            if(f) f2 = 1;
        }
        if(f2){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    n,m=inpm()
    g=[[] for _ in range(n)]
    for _ in range(m):
        a,b=inpm()
        g[a-1].append(b-1)
        g[b-1].append(a-1)
    ans = 0
    for root in permutations(range(1,n)):
        if root[0] not in g[0]:
            continue
        key=0
        for i in range(n-2):
            if root[i] not in g[root[i+1]]:
                key=1
        if key==0:
            ans+=1
    print(ans)
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 41836
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;

int main(){
        ll n;
        scanf("%ld", &n);
        std::vector<P> links[n];
        for(ll i=0; i<n-1; i++){
                ll u, v, w;
                scanf("%ld %ld %ld", &u, &v, &w);
                links[u-1].push_back(P(v-1, w));
                links[v-1].push_back(P(u-1, w));
        }

        std::vector<bool> used(n, 0), ans(n);
        std::queue<P> que;
        que.push(P(0, 0));
        while(!que.empty()){
                ll from, dis;
                std::tie(from, dis) = que.front();
                que.pop();
                ans[from] = dis%2;
                used[from] = 1;
                for(P p: links[from]){
                        if(!used[p.first]) que.push(P(p.first, p.second+dis));
                }

        }

        for(bool i: ans) printf("%d\n", i);
        return 0;
}

Measured memory_bytes: 7936
#include<iostream>
#include<string>
using namespace std;
int main(){
long i,j;
string s[8],t[8]="        ";
for(i=0;i<8;i++)cin>>s[i];
for(i=0;i<8;i++)
for(j=0;j<8;j++)t[i][j]=s[7-j][i];
cout<<"90"<<endl;
for(i=0;i<8;i++)cout<<t[i]<<endl;
for(i=0;i<8;i++)
for(j=0;j<8;j++)t[i][j]=s[7-i][7-j];
cout<<"180"<<endl;
for(i=0;i<8;i++)cout<<t[i]<<endl;
for(i=0;i<8;i++)
for(j=0;j<8;j++)t[i][j]=s[j][7-i];
cout<<"270"<<endl;
for(i=0;i<8;i++)cout<<t[i]<<endl;
return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

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

int dp[1000][1000][16];
int h, w;
string str[1000];
int cost[1000][1000];

void update(int &a, int x) {
	a = min(a, x);
}

bool check(int x, int y) {
	return x >= 0 && x < w && y >= 0 && y < h;
}

int main() {
	cin >> h >> w;
	REP(i, h) cin >> str[i];
	REP(i, h) REP(j, w) {
		if (str[i][j] == '.') cost[i][j] = 0;
		else cost[i][j] = str[i][j] - '0';
	}
	
	fill(dp[0][0], dp[h][0], INF);
	
	dp[0][0][0] = 0;
	REP(i, h) REP(j, w) REP(k, 1<<4) {
		if (dp[i][j][k] == INF) continue;
		
		int c[3];
		int nextc, nextk, buy;
		
		// move down
		if (i < h - 1) {
			c[0] = check(j + 1, i + 1) ? cost[i + 1][j + 1] : 0; // right
			c[1] = check(j, i + 2)     ? cost[i + 2][j]     : 0; // down
			c[2] = check(j - 1, i + 1) ? cost[i + 1][j - 1] : 0; // left

			buy = 7; // ????????????????????? right, down, left
			if (!c[0]) buy -= 1;
			if (!c[1]) buy -= 2;
			if (!c[2] || k & 8) buy -= 4;
			
			nextc = dp[i][j][k] + (!(k & 4) ? cost[i + 1][j] : 0);
			nextk = k & 2 ? 1 : 0;
			
			if (buy == 0 || buy == 1 || buy == 2 || buy == 4) {
				update(dp[i + 1][j][nextk], nextc);
			}
			else if (buy == 3 || buy == 6 || buy == 5) {
				int tmp[3] = {2,4,0};
				REP(l, 3) if (1 << l & buy)
					update(dp[i + 1][j][nextk | tmp[l]], nextc + c[l]);
			}
			else if (buy == 7) {
				// right + left
				update(dp[i + 1][j][nextk | 2], nextc + c[0] + c[2]);
				// right + down
				update(dp[i + 1][j][nextk | 6], nextc + c[0] + c[1]);
				// down + left
				update(dp[i + 1][j][nextk | 4], nextc + c[1] + c[2]);
			}
			
		}
		
		// move right
		if (j < w - 1) {
			c[0] = check(j + 2, i)     ? cost[i][j + 2]     : 0; // right
			c[1] = check(j + 1, i + 1) ? cost[i + 1][j + 1] : 0; // down
			c[2] = check(j + 1, i - 1) ? cost[i - 1][j + 1] : 0; // up
			
			buy = 7; // right, down, up
			if (!c[0]) buy -= 1;
			if (!c[1]) buy -= 2;
			if (!c[2] || k & 1) buy -= 4;
			
			nextc = dp[i][j][k] + (!(k & 2) ? cost[i][j + 1] : 0);
			nextk = k & 4 ? 8 : 0;
			
			if (buy == 0 || buy == 1 || buy == 2 || buy == 4) {
				update(dp[i][j + 1][nextk], nextc);
			}
			else if (buy == 3 || buy == 6 || buy == 5) {
				int tmp[3] = {2,4,0};
				REP(l, 3) if (1 << l & buy)
					update(dp[i][j + 1][nextk | tmp[l]], nextc + c[l]);
			}
			else if (buy == 7) {
				// right + up
				update(dp[i][j + 1][nextk | 2], nextc + c[0] + c[2]);
				// right + down
				update(dp[i][j + 1][nextk | 6], nextc + c[0] + c[1]);
				// down + up
				update(dp[i][j + 1][nextk | 4], nextc + c[1] + c[2]); 
			}
		}
	}
	
	cout << dp[h - 1][w - 1][0] << endl;
	return 0;
}

Measured memory_bytes: 70480
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// typedef
typedef std::vector<int> VI;
typedef std::vector<VI> VII;
typedef std::vector<bool> VB;
typedef std::vector<VB> VBB;
typedef std::vector<std::string> VS;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  solve();
  return 0;
}

void solve() {
  int h, n;
  std::cin >> h >> n;
  int total = 0;
  int a;
  REP(i, n) {
    std::cin >> a;
    total += a;
  }
  if (total < h) {
    cout(no);
  } else {
    cout(yes);
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
int a[114];
signed main(){
	ic(n)ic(k)
	int sum=0;
	rep(0,i,n)cin>>a[i];
	rep(0,i,n)sum+=min(a[i],k-a[i]);
	c(sum*2)
}	


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<double> v(n);
	for (int i = 0; i < n; i++){
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	double ans = v[0];
	for (int i = 1; i < n; i++){
		ans = (ans + v[i])/2;
	}
	cout << setprecision(10) << ans << endl;
 	return 0;
}



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

using namespace std;

#define ll long long int
#define inf 0x3f3f3f3f
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define N 1000007 // 10e6 + 7

int n;
int a[N][4];
int dp[N][4];

int go(int curr, int p){
	int &ret=dp[curr][p];
	if(ret!=-1)return ret;
	if(curr>=n)return ret=0;
	ret = 0;
	for(int i=0; i<3; i++){
		if(i==p)continue;
		ret=max(ret, go(curr+1, i)+a[curr][i]);
	}
	return ret;
}

int main(int argc, char const *argv[]){
	memset(dp, -1, sizeof dp);

	cin >> n;

	for(int i=0; i<n; i++){
		cin >> a[i][0] >> a[i][1] >> a[i][2];

	}
	cout << go(0, 3) << endl;
	return 0;
}

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

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e5 + 10;
const int mod = (int)1e9 + 7;

int main(){

    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);

    ll n;
    cin >> n;

    ll res = n;

    for(ll i = 1; i * i <= n; ++i){
        if(n % i) continue;
        ll j = n / i;
        res = min(res, i + j - 2);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
int x[100];
signed main(){
	int n,ans=mod;
	cin>>n;
	f(i,n){
		cin>>x[i];
	}
	sort(x,x+n);
	for(int i=x[0];i<=x[n-1];i++){
		int z=0;
		f(j,n){
			z+=pow(x[j]-i,2);
		}
		ans=min(ans,z);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
INF = float("inf")


# update: node[x] を更新する
# getmin: 区間 [a, b) の最小値を返す
class SegmentTree:
    def __init__(self, arr):
        size = len(arr)
        n = 1 << size.bit_length()
        self.n = n
        self.node = [0]*(2*n - 1)
        for i in range(size):
            self.node[i+n-1] = arr[i]
        for i in reversed(range(n-2)):
            self.node[i] = max(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, x, val):
        x += (self.n - 1)
        self.node[x] = val
        while x > 0:
            x = (x - 1) // 2
            self.node[x] = max(self.node[2*x+1], self.node[2*x+2])
    
    def getmax(self, l, r):
        res = 0
        l += self.n - 1
        r += self.n - 1
        while l <= r:
            res = max(res, self.node[l])
            res = max(res, self.node[r])
            l  = l // 2
            r = r // 2 - 1
        return res
 

# 処理内容
def main():
    N, K = map(int, input().split())
    
    seg = SegmentTree([0]*300010)
    ans = 0
    for _ in range(N):
        A = int(input())
        a = max(A-K, 0)
        b = min(A+K, 300000)
        tmp = seg.getmax(a, b) + 1
        ans = max(ans, tmp)
        seg.update(A, tmp)
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 86876
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define pb push_back
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vint = vector<int>;
using vstr = vector<string>;
static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}
template<class T> inline map<T,T> factorization(T n){map<T,T>r;for(T i=2;i*i<=n;i++){while(n%i== 0){r[i]++;n/=i;}}if(n!=1)r[n]=1;return r;}

void solve(ll N, ll P) {
  ll ans = 1;
  for(auto p: factorization(P)) ans *= (ll)pow(p.first, p.second / N);
  cout << ans << endl;
}

int main() {
  ll N;
  ignore_ret(scanf("%lld",&N));
  ll P;
  ignore_ret(scanf("%lld",&P));
  solve(N, P);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define ll long long 
using namespace std;
const int maxn=5e5+10;
char c[maxn];
int len,head[maxn],num;
struct Le
{
	int nt,to;
}edge[maxn<<1];
bool vis[maxn];
int M[maxn];
void dfs(int u,int dis) {
	M[u]=max(M[u],dis);
	for(int i=head[u];i;i=edge[i].nt) {
		int v=edge[i].to;
		dfs(v,dis+1);
	}
}
ll ans;
void add(int f,int t) {
	edge[++num].nt=head[f];
	edge[num].to=t;
	head[f]=num;
}
int main() 
{
	scanf("%s",c+1);
	len=strlen(c+1);
	for(int i=1;i<=len;++i) {
		if(c[i]=='>') add(i+1,i),vis[i]=1;
		else add(i,i+1),vis[i+1]=1;
	}
	for(int i=1;i<=len+1;++i) {
	//	cout<<vis[i]<<"*";
		if(!vis[i]) dfs(i,0);
	}//puts("");
	for(int i=1;i<=len+1;++i) ans+=M[i];//,cout<<M[i]<<" ";
//	puts("");
	cout<<ans<<"\n";
	return 0; 
} 

Measured memory_bytes: 26624
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	string s;
	string t;

	cin >> s;
	cin >> t;

	vector<SINT32> SDATA(s.length());
	vector<SINT32> TDATA(t.length());
	
	rep(i,0,s.length()) {
		SDATA[i] = s[i] - '0';
	}
	rep(i,0,t.length()) {
		TDATA[i] = t[i] - '0';
	}
	sort(SDATA.begin(),SDATA.end());
	sort(TDATA.begin(),TDATA.end(),std::greater<SINT32>());

	rep(i,0,MIN(s.length(),t.length())) {
		if (SDATA[i] < TDATA[i]) {
			cout << "Yes" << endl;
			return 0;
		} else if (SDATA[i] > TDATA[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	if (s.length() < t.length()) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

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

int main() {
    int n;
    cin >> n;
    vector<int> height(n);
    for(int i=0; i<n; i++)cin >> height[i];
    vector<int> dp(n,0);
    dp[1] = abs(height[1]-height[0]);
    for(int i=2; i<n; i++)
    {
        int pos1 = dp[i-1]+abs(height[i]-height[i-1]);
        int pos2 = dp[i-2]+abs(height[i]-height[i-2]);
        dp[i] = min(pos1,pos2);
    }
    cout << dp[n-1];
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <string>

using namespace std;

int main(){
  std::string str;
  cin >> str;
  if(str.length()>=4&&str[0]=='Y'&&str[1]=='A'&&str[2]=='K'&&str[3]=='I'){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

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

typedef long long ll;

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

    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    int ans = 0;
    for(int l=0;l<=k;l++){
        for(int r=0;r<=k-l;r++){
            if(l+r>n) break;
            int waste = k - l - r;
            int now = 0;
            vector<int> s;
            for(int i=0;i<l;i++){
                now += v[i];
                s.push_back(v[i]);
            }
            for(int i=n-r;i<n;i++){
                now += v[i];
                s.push_back(v[i]);
            }
            sort(s.begin(),s.end());
            for(int i=0;i<waste;i++){
                if(i>=s.size()) break;
                if(s[i]>0) break;
                now -= s[i];
            }
            ans = max(ans,now);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <iostream>

using namespace std;

namespace {

struct Process {
  char name[10];
  // required time to process this task.
  int time;
};

// Ring-buffer based queue. Enqueue and dequeue run in O(1).
template <int N>
class Queue {
 public:
  // Note: leave one element empty so that we can distinguish
  // that the ring buffer is empty or full.
  Queue() : size_(N + 1), head_(0), tail_(0) {}

  void Enqueue(Process p) {
    assert(!IsFull());
    data_[tail_] = p;
    tail_ = next(tail_);
  }

  Process Dequeue() {
    assert(!Empty());
    auto p = data_[head_];
    head_ = next(head_);
    return p;
  }

  bool IsFull() const { return head_ == next(tail_); }

  bool Empty() const { return head_ == tail_; }

 private:
  int next(int a) const { return (a + 1) % size_; }

  Process data_[N + 1];
  const int size_;
  int head_;
  int tail_;
};

}  // namespace

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

  Queue<100000> queue;
  for (int i = 0; i < n; ++i) {
    Process p;
    scanf("%s %d", p.name, &p.time);
    queue.Enqueue(p);
  }

  int current_time = 0;
  while (!queue.Empty()) {
    auto p = queue.Dequeue();
    const int used = min(p.time, q);
    p.time -= used;
    current_time += used;

    if (p.time <= 0) {
      printf("%s %d\n", p.name, current_time);
      continue;
    }
    queue.Enqueue(p);
  }
  return 0;
}

Measured memory_bytes: 4644
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.FileReader;
import java.io.FileWriter;

import java.util.*;
import java.util.stream.LongStream;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /* 標準入力数値配列用 long */
    static long[] inputLongArr() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        long[] longarray = new long[strarray.length];
        for (int i = 0; i < longarray.length; i++) {
            longarray[i] = Long.parseLong(strarray[i]);
        }
        return longarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer 降順ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /*標準入力long*/
    static long inputLong() throws Exception {
        return Long.parseLong(br.readLine());
    }

    /*標準入力long*/
    static int inputInt() throws Exception {
        return Integer.parseInt(br.readLine());
    }



    public static void main(String[] args) throws Exception {
        // write your code here
        String s = br.readLine();
        int n = s.length()-1;
        char [] cl = s.toCharArray();
        for(int i=0; i< (Math.pow(2,n)); i++){
            long sum = 0;
            StringBuilder sb = new StringBuilder();
            for(int j=0; j<n; j++){
                sb.append(cl[j]);
                if ((1&i>>j) == 1) {
                    sb.append('+');
                }else{
                    sb.append('-');
                }
            }
            sb.append(cl[n]);
            String tmp = sb.toString();
            sum += Long.parseLong(tmp.substring(0,1));
            for(int k = 1; k<tmp.length()-1; k++){
                String val = tmp.substring(k+1,k+2);
                if(tmp.charAt(k) == '+'){
                    sum += Long.parseLong(val);
                }else if(tmp.charAt(k) == '-'){
                    sum -= Long.parseLong(val);
                }
            }
            if (sum == 7){
                System.out.println(tmp + "=7");
                break;
            }

        }




    }

}



Measured memory_bytes: 36564
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define Icin(s) ll (s);cin>>(s);
#define Scin(s) ll (s);cin>>(s);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
//ここから
int main() {
    string s,t;
    cin>>s>>t;
    ll n=s.size()+1;
    ll m=t.size()+1;
    VV dp(n,V(m));
    dp[0][0]=0;
    rep(i,n){
        rep(j,m){
            if(i==0){
                dp[0][j]=j;
            }else if(j==0){
                dp[i][0]=i;
            }else{
                dp[i][j]=dp[i-1][j]+1;
                chmin(dp[i][j],dp[i][j-1]+1);
                if(s[i-1]!=t[j-1]){
                    chmin(dp[i][j],dp[i-1][j-1]+1);
                }else{
                    chmin(dp[i][j],dp[i-1][j-1]);
                }
            }
        }
    }
    rep(i,n){
        rep(j,m){
     //       cout<<dp[i][j];
        }
      //  cout<<endl;
    }
    cout<<dp[n-1][m-1]<<endl;
}


Measured memory_bytes: 10868
S = input()
A = int(S[0:2])
B = int(S[2:])

if (A == 0 or A > 12) and (B == 0 or B > 12):
  print("NA")
else:
  if (A >= 1 and A <= 12) and (B >= 1 and B <= 12):
    print("AMBIGUOUS")
  elif A == 0 or A > 12:
    print("YYMM")
  else:
    print("MMYY")

Measured memory_bytes: 3064
if __name__ == '__main__':
    record = set()
    n = int(input())
    for _ in range(n):
        order, string = input().split()
        if order == 'insert':
            record.add(string)
        else:
            assert order == 'find', '输入错误'
            if string in record:
                print('yes')
            else:
                print('no')



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

using namespace std;

int main() {
    string a, b, c;
    cin >> a >> b >> c;

   if ((a.at(a.size()-1) == b.at(0)) && (b.at(b.size()-1) == c.at(0)))
       cout <<"YES" << endl;
   else cout << "NO" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

const ll MOD = 1e9 + 7;

int main() {
  int n;
  ll h;
  cin >> n >> h;
  V<ll> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  priority_queue<P> q;

  rep(i, n) {
    q.push({a[i], 1});
    q.push({b[i], 0});
  }

  int ans = 0;
  while (h > 0) {
    auto t = q.top();
    q.pop();
    if (t.second == 1) {
      ans += (h + t.first - 1) / t.first;
      break;
    } else {
      h -= t.first;
    }
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 9000
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a:usize = read();
    let b:usize = read();
    println!("{}", a*b);
}


Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
signed main(){
long long  n,k,h[1000000],sum=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
	cin>>h[i];
  }
  if(n<=k){
    cout<<"0\n";
  }else{
    sort(h,h+n,greater<int>());
    for(int i=0;i<k;i++){
	h[i]=0;
    }
    for(int i=0;i<n;i++){
	sum+=h[i];
    }
    cout<<sum<<"\n";
  }
}   

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384626433832795

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main(){
	int n,in,inn;
	cin >> n;
	vector < vector <bool>> g(n, vector<bool>(n,false));
	rep(i, n) {
		cin >> in;
		cin >> in;
		rep(j, in) {
			cin >> inn;
			g[i][inn - 1] = true;
		}
	}
	rep(i, n) {
		rep(j, n) {
			cout << (g[i][j] ? 1 : 0) << (j != n - 1 ? " " : "") ;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
typedef vector<int> vec;
int main(){
  int n,k,count,a,ans,s,t;
  cin>>n>>k;
  ans=0;
  
  rep(i,n){
    cin>>a;
    if(a==1)count=i;
  }

  count=1;
  
  while(count<n){
    ans++;
    count+=k-1;  
  }

  cout<<ans;
}


Measured memory_bytes: 256