akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

char s[15][15]={};
int h,w;
bool dfs(int y,int x){
	if(y>=h || x>=w)return false;
	if(s[y][x]!='#')return false;
	s[y][x]='@';
	bool res=true;
	if(y+1==h && x+1==w){
		rep(y,h)rep(x,w){
			if(s[y][x]=='#')res=false;
		}
	}
	else{
		res = (dfs(y+1,x) || dfs(y,x+1));
	}
	s[y][x]='#';
	return res;
}

int main(void){
	scanf("%d%d",&h,&w);
	rep(y,h)scanf("%s",s[y]);
	printf("%s\n",dfs(0,0)?"Possible":"Impossible");
	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define emp emplace
 
using namespace std;
using ll = long long int;
using ii = pair<int, int>;
 
const int MOD = 1000 * 1000 * 1000 + 7;
const int N = 2*100000;
const int max_height = 524287;
 
ll tree[max_height];

void build(int index, int l, int r){
    if(l == r){
        tree[index] = 0;
    }
    else{
        int mid = (l+r)/2;

        build(2*index+1, l, mid);

        build(2*index+2, mid+1, r);

        tree[index] = 0;
    }
}

void update(int node, int l, int r, int index, ll val){
    if(l>index || r<index)
        return;

    if(l==r)
        tree[node] = val;   
    else{
        int mid = (l+r)/2;
        update(2*node+1, l, mid, index, val);
        update(2*node+2, mid+1, r, index, val);

        tree[node] = max(tree[2*node+1], tree[2*node+2]);
    }
}

ll query(int index, int start, int end, int l, int r){
    if(start>r || end<l)
        return 0;

    if(start >=l && end <= r)
        return tree[index];
    else
    {
        int mid = (start+end)/2;
        return max(query(2*index+1,start,mid,l,r), query(2*index+2,mid+1,end,l,r));
    }
}


int main()
{

    int n;cin>>n;
    int height[n];
    ll beauty[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>height[i];
    }
    for (int i = 0; i < n; ++i)
    {
        cin>>beauty[i];
    }

    for (int i = n-1; i >= 0; --i)
    {
        ll mx =query(0,0,n-1,height[i],n-1) + beauty[i];
        update(0,0,n-1,height[i]-1,mx);
    }

    cout<<query(0,0,n-1,0,n-1);
    return 0;
} 



Measured memory_bytes: 6656
N = int(input())
F = []
P = []
for i in range(N):
    F.append(list(map(int,input().split())))
for i in range(N):
    P.append(list(map(int,input().split())))

cand = []

def dfs(string, n, f, p):
    global cand
    if len(string) < 10:
        dfs(string + "f", n, f, p)
        dfs(string + "t", n, f, p)
    else:
        tf = list(string)
        booltf = []
        for i in range(10):
            if tf[i] == "t":
                booltf.append(True)
            else:
                booltf.append(False)
        #print(booltf)
        c = []
        c_sum = []
        for kth in range(N):
            c = [i*j for i,j in zip(booltf, F[kth])]
            c_sum.append(sum(c))
        
        profit = 0
        for i,c in zip(range(N), c_sum):
            profit += P[i][c]
            
        cand.append(profit)
        
        if len(cand) == 2**10:        
            ans = max(cand[1:])
            
            print(ans)

        

dfs("", N, F, P)

Measured memory_bytes: 3064
program main
	implicit none
	integer(8):: N,i,j,t,B,K
	integer,dimension(1:2*10**6)::A    	
	read *, N
    read(*,*) (A(i), i = 1, N)
    j=1;t=0
	do i=1,N
		if(A(i)==j)then
		j=1+j
		t=1
		end if
	end do
	
	if(j>1.and.t==1)print'(I0)',N-j+1
	if(j>0.and.t==0)print'(I0)',-1
	if(j==1.and.t==1)print'(I0)',0
	
end program main

Measured memory_bytes: 1536
#include<stdio.h>
#define N 36


struct Card {
 char suit; int value;
};

void BubbleSort(struct Card A[], int n );
void SelectionSort(struct Card A[], int n );
int judge(struct Card A1[],struct Card A2[],int n);

int main(){
  int i,j,n,flag,a,b=0,m,minj,k;
  struct Card A1[100],A2[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&A1[i].suit,&A1[i].value);
   }for(j=0;j<n;j++){
    A2[j]=A1[j];
   }
  BubbleSort(A1,n);
  SelectionSort(A2,n);
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%c%d",A1[i].suit,A1[i].value);
   }printf("\n");
   printf("Stable\n");
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%c%d",A2[i].suit,A2[i].value);
  }printf("\n");
  if(judge(A1,A2,n)){
    printf("Stable\n");
   }else{
     printf("Not stable\n");
   } return 0;
  }

void BubbleSort(struct Card A[], int n ){
  int i,j;
  struct Card c;
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(A[j].value<A[j-1].value){
        c=A[j];A[j]=A[j-1];A[j-1]=c;
      }
    }
  }
}

void SelectionSort(struct Card A[], int n ){
 int i,j,minj;
 struct Card c;
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(A[j].value<A[minj].value){
        minj=j;
      }
    }c=A[i];A[i]=A[minj];A[minj]=c;
  }
}

int judge(struct Card A1[],struct Card A2[],int n){
  int i;
  for(i=0;i<n;i++){
    if(A1[i].suit!=A2[i].suit){
      return 0;
    }
  }return 1;
}



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

long long int gcd(long long int a, long long int b) {
	if(a < b) return gcd(b, a);
	if(b == 0) return a;
	return gcd(b, a % b);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	long long int k;
	cin >> k;
	if(k % 7 == 0) k /= 7;
	if(gcd(10, k) != 1) {
		cout << -1;
		return 0;
	}
	long long int v = 1 % k;
	long long int len = 1;
	while(v != 0) {
		v = (10 * v + 1) % k;
		len += 1;
	}
	cout << len;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;

long long int ans = 0;
void sum(string str){
    for(int i = 0; i < str.size();i++){
        string plus = "";
        while(1){
            if(str[i] == '+')break;
            plus += str[i];
            i++;
            if(i >= str.size())break;
        }
//        cout << plus << endl;
        ans += atol(plus.c_str());
    }
}

int main(){
    string s;
    cin >> s;
    set <string> formulas;
    rep(i, s.size()){
        vector <int> zero_one;
        rep(j, i)zero_one.push_back(1);
        rep(j, s.size() - i)zero_one.push_back(0);
        sort(zero_one.begin(), zero_one.end());
        do{
            if(zero_one[0] == 1)continue;
            string str = s;
            for(int j = zero_one.size() - 1; j >= 0; j--)
                if(zero_one[j])str.insert(j, "+");
//            cout << str << endl;
            sum(str);
        }while(next_permutation(zero_one.begin(), zero_one.end()));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)-1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,a,b,c;  

  cin >> a >> b >> c;
  cin >> k;
  while(k>=1 && a>=b){
    b*=2;
    k--;
  }
  while(k>=1 && b>=c){
    c*=2;
    k--;
  }
  cout << ((a<b && b<c) ? "Yes" : "No") << endl;
  
  return 0;
}

Measured memory_bytes: 3604
from sys import stdin
lis =[]
#k = int(stdin.readline().rstrip())
lis= stdin.readline().rstrip().split()
k = int(lis[0])
s = int(lis[1])
count = 0
x = 0
y = 0
z = 0
for x in range(k+1):
    y = 0
    for y in range(k+1):
        z = 0
        z = s - x - y
        if z <= k and z >= 0:
                count +=1



print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main(){
	int n;
	cin>>n;
	cout<<n*n*n<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
   long int a[1000],n,k,max=0,count=0,i,j,min=9999;
   scanf("%ld%ld",&n,&k);
   i=(n==1 || n==3 || n==5 || n==7 || n==8 || n==10 || n==12)?1:(n==4 || n==6 || n==9 || n==11)?2:0;
   j=(k==1 || k==3 || k==5 || k==7 || k==8 || k==10 || k==12)?1:(k==4 || k==6 || k==9 || k==11)?2:0;
   if(i==j)
   {
       printf("Yes");
   }else{
       printf("No");
   }
    return 0;
}


Measured memory_bytes: 128
# bを必要なだけ(strideの分)右にずらせばよい
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    ai, bi = 0, 0
    stride = 0
    while ai < n and bi < n:
        ax, bx = a[ai], b[bi]
        if ax == bx:
            cnt = 2

            ai += 1
            while ai < n and a[ai] == ax:
                cnt += 1
                ai += 1

            bi_copy = bi
            bi += 1
            while bi < n and b[bi] == bx:
                cnt += 1
                bi += 1

            if cnt > n:
                print('No')
                exit()

            if stride < ai - bi_copy:
                stride = ai - bi_copy

        elif ax < bx:
            ai += 1
        else:
            bi += 1

    print('Yes')
    print(' '.join(map(str, b[n-stride:] + b[:n-stride])))

main()

Measured memory_bytes: 43044
#include <iostream>
#include <vector>
#include <string.h>
typedef long long ll;

using namespace std;

static const ll MOD =1e9+7;

int n;
char s[100001];
ll dp[100001][13];

int main() {
    scanf("%s", s);
    int n = strlen(s);

    dp[0][0]=1;

    for(int i=0; i<n; i++) {
        int c;
        if(s[i]=='?') c = -1;
        else c = s[i] - '0';

        for(int j=0; j<10; j++) {
            if(c != -1 && c != j) continue;
            for(int ki=0; ki<13; ki++) {
                dp[i+1][(ki*10+j)%13] += dp[i][ki];
            }
        }
        for(int j=0; j<13; j++) dp[i+1][j] %= MOD;
    }

    cout << dp[n][5] << endl;

    return 0;
}


Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
int r,id[8],d[222][222],n;
int main(){
	int m;
	scanf("%d%d%d",&n,&m,&r);
	for(int i=0; i<r; i++)
		scanf("%d",&id[i]);
	sort(id,id+r);
	for(int i=1; i<=n; i++)for(int j=1; j<=n; j++)
		d[i][j] = i==j?0:1000000000;
	while(m--){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		d[x][y] = d[y][x] = z;
	}
	for(int k=1; k<=n; k++)
	for(int i=1; i<=n; i++)
	for(int j=1; j<=n; j++)
		d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
	int res = 1000000000;
	do{
		int now = 0;
		for(int i=1; i<r; i++)
			now += d[id[i]][id[i-1]];
		res = min(res, now);
	}while(next_permutation(id,id+r));
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;

int main(){
    int n; cin>>n;
    int ans=0;
    FOR(i,1,n+1){
        int k=0;
        if(i%2==0) continue;
        FOR(j,1,i+1){
            if(i%j==0) k++;
        }
        if(k==8) ans++;
    }
    co(ans);
}


Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Arrays;
import java.util.Collections;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int hairetu[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

        int k = sc.nextInt();

        System.out.println(hairetu[k-1]);

	}
}

Measured memory_bytes: 21844
#include<stdio.h>

int main(void){
	int N, A, B;
	do {
		scanf("%d", &N);
	}while (N != 1 && N != 2);
	if (N == 1){
		printf("Hello World");
	}
	if (N == 2) {
		scanf("%d", &A);	scanf("%d", &B);
		printf("%d\n", A + B);
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
const ll mod = 998244353;
ll dp[3001][3001];
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n,s; cin >> n >> s;
    dp[0][0] = 1;
    vector<int> a(n);
    rep(i,n)
        cin >> a[i];
    rep(i,n){
        rep(j,s+1){
            if (j+a[i] <= s){
                dp[i+1][j+a[i]] += dp[i][j];
                dp[i+1][j+a[i]] %= mod;
            }
            dp[i+1][j] += 2 * dp[i][j];
            dp[i+1][j] %= mod;
        }
    }
    cout << dp[n][s] << endl;
}


Measured memory_bytes: 74000
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	aa := make([]int, n+2)
	sum := 0
	for i := 0; i < n; i++ {
		aa[i+1] = getNextInt(scanner)
		sum += absint(aa[i+1] - aa[i])
	}
	sum += absint(aa[n+1] - aa[n])

	for i := 1; i < n+1; i++ {
		ans := sum - absint(aa[i+1]-aa[i]) - absint(aa[i]-aa[i-1]) + absint(aa[i+1]-aa[i-1])
		fmt.Fprintln(writer, ans)
	}

	writer.Flush()
}

func absint(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 4224
#include <cstdio>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int MAXN=15;
int c[MAXN][MAXN];
int a[205][205];
int dist[MAXN][MAXN];
int h, w, cnt;
bool vis[MAXN];
void dijstra(int s, int t)
{
    memset(vis,false, sizeof(vis));
    for(int i=0;i<=9;++i)
        dist[s][i]=c[s][i];
    vis[s]=true;
    for(int j=0;j<=9;++j)
    {
        int Min=inf, v=-1;
        for(int i=0;i<=9;++i)
        {
            if(!vis[i]&&dist[s][i]<Min)
                Min=dist[s][v=i];
        }
        vis[v]=true;
        for(int i=0;i<=9;++i)
        {
            if(!vis[i]&&dist[s][i]>dist[s][v]+c[v][i])
            {
                dist[s][i]=dist[s][v]+c[v][i];
            }
        }
    }
}
int main()
{
    scanf("%d %d", &h, &w);
    for(int i=0;i<=9;++i)
    {
        for(int j=0;j<=9;++j)
        {
            scanf("%d", &c[i][j]);
        }
    }
    for(int i=0;i<h;++i)
    {
        for(int j=0;j<w;++j)
        {
            scanf("%d", &a[i][j]);
        }
    }
    cnt=0;
    for(int i=0;i<=9;++i)
        dijstra(i,1);
    int sum=0;
    for(int i=0;i<h;++i)
    {
        for(int j=0;j<w;++j)
        {
            if(a[i][j]!=-1)
            {
                sum+=dist[a[i][j]][1];
            }
        }
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
char str[4];
scanf("%s",str);
if(str[1]==82)
{
str[1]=66;
}
else if(str[1]==66)
{
str[1]=82;
}
for(int i=0;i<3;i++)
{
printf("%c",str[i]);
}
return 0;
}

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

int main()
{
	int h1 , m1 , h2 , m2 , k;
	scanf("%d %d %d %d %d" , &h1 , &m1 , &h2 , &m2 , &k);
	int len = 0;
	len += (60 - m1);
	len += (h2 - h1 - 1) * 60;
	len += m2;
	if(h1 > h2 || (h1 == h2 && m1 > m2)) len = 24 * 60 - len;
	printf("%d" , max(len - k , 0));
	return 0;
}


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


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long int i=0;i<(n);++i)
typedef long long int ll;

class DNumberOfAmidakuji {
public:
	void solve(std::istream& in, std::ostream& out) {
        int h,w,k;
        ll mo=1e+9+7;
        in >> h >> w >> k;
        k--;
        vector<int> c;
        for(int l=0;l<pow(2,w-1);l++){
            bool f=true;
            for(int i=0;i<w;i++){
                if(l>>i&1&&l>>(i+1)&1){
                    f=false;
                    break;
                }
            }
            if(f){
                c.push_back(l);
            }
        }
        vector<vector<ll>> dp(h+1,vector<ll>(w,0));
        dp[0][0]=1;
        if(c.size()==1){
            out << 1 << endl;
            return ;
        }
        for(int i=1;i<=h;i++){
            for(int j=0;j<w;j++){
                for(int l=0;l<c.size();l++){
                    int b=c[l];
                    if(j!=0&&j!=w-1) {
                        if(b>>(j-1)&1){
                            dp[i][j]+=(b>>(j-1)&1?dp[i-1][j-1]:dp[i-1][j]);
                        }else if(b>>j&1){
                            dp[i][j]+=(b>>j&1?dp[i-1][j+1]:dp[i-1][j]);
                        }else{
                            dp[i][j]+=dp[i-1][j];
                        }
                    }else if(j==0){
                        dp[i][j]+=(b>>j&1?dp[i-1][j+1]:dp[i-1][j]);
                    }else{
                        dp[i][j]+=(b>>(j-1)&1?dp[i-1][j-1]:dp[i-1][j]);
                    }
                    dp[i][j]%=mo;
                }
            }
        }
//        rep(i,h+1){
//            rep(j,w){
//                out << dp[i][j] << (j==w-1?"\n":" ");
//            }
//        }
        out << dp[h][k] << endl;
	}
};


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


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

long long gcd(long long x, long long y){
  if(y > x) swap(x,y);
  if(!y) return x;
  return gcd(y,x%y);
}

int main(){
  long long N, M;
  cin >> N >> M;
  string S, T;
  cin >> S >> T;
  long long g = gcd(N,M);
  map<long long, char> A;
  for(int i = 0; i < N; ++i){
    A[M/g*i] = S[i];
  }
  for(int i = 0; i < M; ++i){
    if(A[N/g*i] < 'a') continue;
    if(A[N/g*i] != T[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << N/g*M << endl;
  return 0;
}


Measured memory_bytes: 10880
def main():
    A = []
    for _ in range(3):
        a = map(int,input().split())
        A += a
    N = int(input())
    B = [int(input()) for _ in range(N)]
    for i in range(N):
        for j in range(9):
            if A[j] == B[i]:
                A[j] = -1
    ans = False
    #縦方向
    for i in range(3):
        if A[i] == -1 and A[i + 3] == -1 and A[i + 6] == -1 :
            ans = True
    #横
    for i in range(3):
        if A[3 * i] == - 1 and A[3 * i + 1] == -1 and A[3 * i + 2] == -1 :
            ans = True
    #斜め
    for i in [2, 4]:
        if A[4] == -1 and A[4 - i] == -1 and A[4 + i] == -1 :
            ans = True
    if ans :
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
n = int(input())
a = input().split()
dic1 = {}
firitem1 = "0"
firnum1 = 0
secitem1 = "0"
secnum1 = 0
dic2 = {}
firitem2 = "0"
firnum2 = 0
secitem2 = "0"
secnum2 = 0

for i in range(len(a)):
  if i%2 == 0:
    if a[i] in dic1:
      dic1[a[i]] += 1
    else:
      dic1[a[i]] = 1
    
    if dic1[a[i]] > firnum1:
      if firitem1 == a[i]:
        firnum1 = dic1[a[i]]
      else:
        secitem1 = firitem1
        secnum1 = firnum1
        firitem1 = a[i]
        firnum1 = dic1[a[i]]
        
    elif dic1[a[i]] > secnum1:
      secitem1 = a[i]
      secnum1 = dic1[a[i]]
  else:
    if a[i] in dic2:
      dic2[a[i]] += 1
    else:
      dic2[a[i]] = 1
    
    if dic2[a[i]] > firnum2:
      if firitem2 == a[i]:
        firnum2 = dic2[a[i]]
      else:
        secitem2 = firitem2
        secnum2 = firnum2
        firitem2 = a[i]
        firnum2 = dic2[a[i]]
    elif dic2[a[i]] > secnum2:
      secitem2 = a[i]
      secnum2 = dic2[a[i]]

if firitem1 != firitem2:
  print(int(n/2-firnum1 + n/2-firnum2))
else:

  print(int(min(n/2-firnum1 + n/2-secnum2, n/2-secnum1 + n/2-firnum2)))

Measured memory_bytes: 18408
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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<_>>()
    };

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"20"# => r#"15800"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: i64,
        b: i64,
        c: i64,
    }

    if b - a == c - b { "YES" } else { "NO" }.to_string()
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
int main()
{
	char a[100],b[100],c[100];
	int d,e;
	scanf("%s",a);
	scanf("%s",b);
	scanf("%d %d",&d,&e);
	scanf("%s",c);
	if(strcmp(a,c)==0)
		printf("%d %d",d-1,e);
	if(strcmp(b,c)==0)
		printf("%d %d",d,e-1);
}

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

int main(){
  string s;
  cin >> s;

  long long ret = 0;
  int cnt = 0;

  for(int i = s.length()-1;i >= 0;i--){
    if(s[i] == 'B'){
      ret += s.length()-1-i-cnt;
      cnt++;
    }
  }

  cout << ret << endl;
}


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

const int maxn=2e5+7;
int a[maxn];
bool vis[maxn];

vector<int>v[maxn];
set<int>s;

void dfs(int pos){
    vis[pos]=1;
    s.insert(pos);
    for(int k:v[pos]) if(!vis[k]) dfs(k);
}

int main (){
    ios_base::sync_with_stdio(false);
    int n,m;cin>>n>>m;
    memset(vis,0,(n+3)*sizeof(bool));
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=m;i++){
        int x,y;cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(!vis[i]) dfs(i);
        for(int k:s) if(s.find(a[k])!=s.end()) ans++;
        s.clear();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 16256
#include<stdio.h>

int main(void){
    int x, y, min, max, rem;

    scanf("%d %d", &x, &y);

    if(x == y){
        printf("%d\n", x);
        return 0;
    }

    if(x < y){
        min = x;
        max = y;
    }else{
        min = y;
        max = x;
    }

    while(min > 0){
        rem = max%min;
        max = min;
        min = rem;
    }

    printf("%d\n", max);

    return 0;
}



Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int m1,d1;
  int m2,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if(d2==1 && m1==(m2-1))cout<< 1 <<endl;
  else cout<< 0 <<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            int[] arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int min = int.MaxValue;
            int max = int.MinValue;
            long sum = 0;
            
            foreach(int v in arr)
            {
                min = Math.Min(min, v);
                max = Math.Max(max, v);
                sum += v;
            }

            Console.WriteLine("{0} {1} {2}", min, max, sum);

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 10472
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad
import Control.Monad.ST
import Data.Bits
import qualified Data.Map.Strict as M
import Data.Sequence hiding (length, splitAt, zip, scanl, replicate)
import Data.Char
import Debug.Trace

traceQ :: (Show a) => String -> a -> a
-- traceQ label a = trace (label ++ ": " ++ show a) a
traceQ _ a = a

lsbAdd :: Int -> Int
lsbAdd k = k + (k .&. (-k))

lsbOff :: Int -> Int
lsbOff k = k .&. complement (k .&. (-k))

bitSum :: VM.MVector s Int -> Int -> ST s Int
bitSum vec n = 
  foldM g 0 $ takeWhile (> 0) $ iterate lsbOff n
  where g sum i = (+ sum) <$> (VM.read vec (i - 1))

bitUpd :: Int -> VM.MVector s Int -> Int -> Int -> ST s ()
bitUpd nMax vec n diff = forM_ indices act
  where indices = takeWhile (<= nMax) (iterate lsbAdd (n + 1))
        act k = VM.modify vec (+ diff) (k - 1)

type MyMap = M.Map Char (Seq Int)

myAct :: [Char] -> ST s Int
myAct s = do
  let num = length s
      size = bit $ ceiling $ logBase 2 $ fromIntegral num
      imapInit = foldr f M.empty (zip [0..] s)
        where f (i, c) m = M.alter f' c m
                where f' Nothing   = Just $ i <| empty
                      f' (Just is) = Just $ i <| is
  vec <- VM.new num
  forM_ (zip [0..] s) $ \(i, c) -> VM.write vec i c
  bit <- VM.replicate size 0
  (result, _, _, _, _, _) <-
    foldM actBody (0, vec, bit, (traceQ "size" size), imapInit, False)
                  [num-1, num-2 .. 0]
  return result

type MyAB s = (Int, VM.MVector s Char, VM.MVector s Int, Int, MyMap, Bool)
actBody :: MyAB s -> Int -> ST s (MyAB s)
actBody ab@(-1, _, _, _, _, _) _ = return ab
actBody (acc, vec, bit, size, imap, exOdd) i = do
  c <- VM.read vec i
  if (traceQ "c" c) == 'X' then return (acc, vec, bit, size, imap, exOdd)
    else do
    VM.write vec i 'X'
    let is :> _ = viewr (imap M.! c)   -- the last element must be i
    case viewl is of    
      j :< body -> do
        VM.write vec j 'X'
        count <- bitSum bit (traceQ "j" j)
        bitUpd size bit j 1
        let newAcc = acc + (j - (traceQ "count" count)) + (if exOdd then 1 else 0)
            newImap = M.update (const (Just body)) c imap
        return ((traceQ "newAcc" newAcc), vec, bit, size, newImap, exOdd)
      _ -> if exOdd then return (-1, vec, bit, size, imap, exOdd)
           else return (acc, vec, bit, size, imap, True)

solve :: [Char] -> Int
solve s = runST (myAct s)
      
main :: IO ()
main = do
  cont <- getContents
  putStrLn $ show $ solve (takeWhile isLower cont)


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
const ll mod = 1e9 + 7;

ll fac[maxn], ifac[maxn];

ll modpow(ll, ll);
ll inv(ll);
ll nck(ll, ll);
void build();
void testlib();





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

  ll n, k; cin>>n>>k;
  for (ll i=1; i<=k; i++) {
    // n-k red dividers, and blue balls will go in any of the n-k+1 slots
    ll groups = nck(n-k+1,i);
    // figure out how much to put in each group, assuming that each group>=1
    // this is equivalent to putting i-1 dividers into K blue balls
    ll splits = nck(k-1,i-1);
    ll ans = groups*splits;
    ans %= mod;
    cout<<ans<<"\n";
  }

  

  return 0;
}

///////////////////////////////////////////////////////////////////////////////////////////////////


ll modpow(ll x, ll y) {
  x %= mod;
  ll res = 1;
  while (y > 0) {
    if (y%2 == 1) {
      res *= x;
      res %= mod;
    }
    x = x * x;
    x %= mod;
    y = y / 2;
  }
  return res;
}

ll inv(ll x) {
  assert(x != 0);
  return modpow(x, mod-2);
}

void build() {
  fac[0] = ifac[0] = 1;
  for (int i=1; i<maxn; i++) {
    fac[i] = fac[i-1] * i;
    fac[i] %= mod;
    ifac[i] = inv(fac[i]);
    ifac[i] %= mod;
  }
}

ll nck(ll n, ll k) {
  assert(n>=0 && k>=0);
  if (k > n) return 0;
  return (((fac[n] * ifac[k]) % mod) * ifac[n-k]) % mod;
}

void testlib() {
  assert(modpow(1,1) == 1);
  assert(modpow(4,2) == 16);
  assert(modpow(2,5) == 32);
  assert(fac[3] == 6);
  assert(nck(4,2) == 6);
  assert(nck(10,2) == 45);
}


Measured memory_bytes: 15872
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;	
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) {
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}

template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
int modulo = 1e9 + 7;

int fpow(int a, int n) {
	int ans = 1;
	while (n) {
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n; cin >> n;
	int arr[n];
	For(i,0,n) cin >> arr[i];
	int ans = 0, curr = 0;
	Forr(i,n-2,-1) {
		if (arr[i] >= arr[i+1]) ++curr;
		else curr = 0;
		ans = max(ans, curr);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N=1e5+5;
int n,m,a[N],ji;
pii p[N];
long long ans;
inline bool cmp(pii x,pii y){return x.S>y.S;}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<m;i++)cin>>p[i].F>>p[i].S;
	sort(p,p+m,cmp); 
	for(int i=0;i<n;i++)
	{
		if(a[i]<p[ji].S)
		{
			p[ji].F--;
			a[i]=p[ji].S;
			if(p[ji].F==0)ji++;
		}
	}
	for(int i=0;i<n;i++)ans+=a[i];
	cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

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

	int k, t;
	cin >> k >> t;

	vector<int> a(t);
	rep(i, t) cin >> a[i];

	if(t == 1){
		cout << k - 1 << endl;
		return 0;
	}

	sort(a.begin(), a.end(), greater<int>());
	int x = 0, y = 0;
	rep(i, t){
		if(x <= y) x += a[i];
		else y += a[i];
	}

	cout << max(max(x, y) - min(y, x) - 1, 0) << endl;

}


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

int main()
{
  i64 h;
  cin >> h;
  i64 ans = 0, mob = 1;
  while (1 < h)
  {
    ans += mob;
    h /= 2;
    mob *= 2;
  }
  ans += mob;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
d=list(map(int,input().split()))
r={'N':(0,1,5,4),'W':(0,2,5,3),'E':(0,3,5,2),'S':(0,4,5,1)}
for o in list(input()):
 s=r[o]
 for i in range(3):
  d[s[i+1]],d[s[i]]=d[s[i]],d[s[i+1]]
print(d[0])

Measured memory_bytes: 5596
#include <iostream>

int main() {
    int num, x, min, max;
    long total;
    std::cin >> num;
    std::cin >> x;
    min = x; max = x; total = x;
    for (int i = 1; i < num; i++) {
        std::cin >> x;
        if (min > x) {
            min = x;
        }
        if (max < x) {
            max = x;
        }
        total += x;
    }
    std::cout << min << ' ' << max << ' ' << total << std::endl;
}



Measured memory_bytes: 3100
n = int(input())
s = input()
ans = 0
for i in range(1,n):
    cnt = 0
    s_b = s[:i]
    s_a = s[i:]
    for j in set(s_b):
        if j in s_a:
            cnt+=1
    if cnt > ans:
        ans = cnt
print(ans)

Measured memory_bytes: 3064
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll factorial[201000];
ll invfactorial[201000];
 
ll extGCD(ll a, ll b, ll &x, ll &y){
	if (b == 0){
		x = 1;
		y = 0;
		return a;
	}
 
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
 
ll nCrM(ll n, ll r){
	ll ret = factorial[n];
	ret *= invfactorial[n - r];
	ret %= MOD;
	ret *= invfactorial[r];
	ret %= MOD;
	return ret;
}
int main(void){
    ll n, k;
    cin >> n >> k;

    factorial[0] = 1;
    for(int i = 1; i <= n; i++){
        factorial[i] = (factorial[i - 1] * i) % MOD;
    }
    for (int i = 0; i <= n; i++){
		ll x, y;
		ll g = extGCD(factorial[i], MOD, x, y);
		while (x < 0) x += MOD;
		x %= MOD;
		invfactorial[i] = x;
	}

    for(ll i = 1; i <= k; i++){
        if(n - k + 1 < i){
            cout << 0 << endl;
            continue;
        }
        ll ans = 1;
        ans *= nCrM(n - k + 1, i);
        ans %= MOD;
        ans *= nCrM(k - 1, i - 1);
        ans %= MOD;
        cout << ans << endl;
    }


}

Measured memory_bytes: 256
x = input()

if x[0]=='R' and x[1]=='R' and x[2]=='R':
    ans=3
if x[0]=='R' and x[1]=='R' and x[2]=='S':
    ans=2
if x[0]=='R' and x[1]=='S' and x[2]=='R':
    ans=1
if x[0]=='R' and x[1]=='S' and x[2]=='S':
    ans=1
if x[0]=='S' and x[1]=='R' and x[2]=='R':
    ans=2
if x[0]=='S' and x[1]=='R' and x[2]=='S':
    ans=1
if x[0]=='S' and x[1]=='S' and x[2]=='R':
    ans=1
if x[0]=='S' and x[1]=='S' and x[2]=='S':
    ans=0

print(ans)

Measured memory_bytes: 9112
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef pair<ll, pair<int, int>> P;
typedef pair<ll,pair<ll,ll>> T;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;


int main(){
    int A,B;
    cin >> A >> B;
    if(A <= 8 && B <= 8){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;

const int N = 3e2 + 5;

int n, a[N], dp[N][N][N], pref[N];
const int M = 998244353;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string S;
    int k;
    cin >> S >> k;
    int sz = S.size();
    k = min(k, sz);
    int cur = 0;
    for (int i = 0; i < S.size(); i++)
        if (S[i] == '1')
            cur++;
        else
            n++, a[n] = cur, cur = 0;
    n++;
    a[n] = cur;
    for (int i = 1; i <= n; i++)
        pref[i] = pref[i - 1] + a[i];
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++)
        for (int s = pref[i]; s <= pref[n]; s++)
            for (int j = 0; j <= k; j++) {
                for (int q = max(1ll, a[i] - s); q <= a[i]; q++)
                    //if (s >= a[i] - q)
                        dp[i][s][j] += dp[i - 1][s - (a[i] - q)][j], dp[i][s][j] %= M;
                for (int q = 0; q <= min(j, s - a[i]); q++)
                   // if (s >= a[i] + q)
                        dp[i][s][j] += dp[i - 1][s - (a[i] + q)][j - q], dp[i][s][j] %= M;
                //cout << i << ' ' << s << ' ' << j << ' ' << dp[i][s][j] << endl;
            }
    int ans = 0;
    for (int j = 0; j <= k; j++)
        ans += dp[n][pref[n]][j], ans %= M;
    cout << ans;
    return 0;
}


Measured memory_bytes: 56740
import math

N = int(input())
x = [0] * N
y = [0] * N
for i in range(0, N):
    x[i], y[i] = [int(a) for a in input().split()]

d = 0
for i in range(0, N):
    for j in range(i+1, N):
        d += math.sqrt(  (x[i] - x[j])**2 + (y[i] - y[j])**2  )

print(2 * d / N)


Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> a(n+2);
    for (int i=1; i<=n; i++) {
        cin >> a.at(i);
    }
    a.at(0) = a.at(n);
    a.at(n+1) = a.at(1);
    vector<ll> b(n+2);
    for (int i=1; i<=n; i++) {
        cin >> b.at(i);
    }
    b.at(0) = b.at(n);
    b.at(n+1) = b.at(1);
    priority_queue<pair<ll, int>> que;
    for (int i=1; i<=n; i++) {
        if (a.at(i) != b.at(i)) {
            que.push(make_pair(b.at(i), i));
        }
    }
    ll cnt = 0;
    while (!que.empty()) {
        int i = que.top().second;
        que.pop();
        ll buf = b.at(i-1) + b.at(i+1);
        if (buf > b.at(i)) {
            cout << -1 << endl;
            return 0;
        }
        if (b.at(i)%buf > a.at(i)) {
            cnt += b.at(i)/buf;
            b.at(i) = b.at(i)%buf;
            if (i == 1) {
                b.at(n+1) = b.at(1);
            }
            else if (i == n) {
                b.at(0) = b.at(n);
            }
            que.push(make_pair(b.at(i), i));
        }
        else {
            if ((b.at(i)-a.at(i))%buf == 0) {
                cnt += (b.at(i)-a.at(i))/buf;
                b.at(i) = a.at(i);
                if (i == 1) {
                    b.at(n+1) = b.at(1);
                }
                else if (i == n) {
                    b.at(0) = b.at(n);
                }
            }
            else {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 9200
#include <stdio.h>
#include <stdlib.h>
#define INF 10000000

//void matrixChainOrder(int,int *,int **);
int min(int,int);

int main()
{
  int n,i,j,k,l,q,r[105],c[105],p[105]; //r=行,c=列
  int m[105][105];

  scanf("%d",&n);
  if(n<1 || n>100) exit(1);

  //*m = (int *)malloc(sizeof(int)*n);
  //m = (int **)malloc(sizeof(int *)*n);
  
  for(i=1;i<=n;i++){
    scanf("%d %d",&r[i],&c[i]);
    if(r[i]<1 || c[i]<1 || r[i]>100 || c[i]>100) exit(2);
    p[i] = c[i];
  }
  p[0]=r[1]; //行を使うのは一つ目の行だけ
  
  for(i=1;i<=n;i++) m[i][i] = 0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1; 
      m[i][j] = INF; //大小計算をできるようにする
      for(k=i;k<=j-1;k++){ // kの範囲 i<=k<j (i<=k<=j-1)
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]; //コストの計算
	m[i][j] = min(m[i][j],q); //コストが少ない方を入れる
      }
    }
  }

  //matrixChainOrder(n,p,m);
  
  printf("%d\n",m[1][n]);

  return 0;
}
/*
void matrixChainOrder(int n,int *p,int **m)
{
  int i,l,j,k,q;
  
  for(i=1;i<=n;i++) m[i][i] = 0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i;k<=j-1;k++){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	m[i][j] = min(m[i][j],q);
      }
    }
  }
}
*/
int min(int a,int b)
{
  return a>b ? b : a;
}



Measured memory_bytes: 2112
#include<stdio.h>
int main(void){
  char s[4];
  scanf("%s",s);
  if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]){
    printf("Yes");
  }
  else if(s[0]==s[3]&&s[2]==s[1]&&s[0]!=s[2]){
    printf("Yes");
  }
  else if(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]){
    printf("Yes");
  }
  else{
    printf("No");
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    rep(i,0,3){
        if(S[i] == S[i+1]){
            print("Bad");
            return 0;
        }
    }
    print("Good");
    
}

Measured memory_bytes: 256
import collections
import sys


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


def bfs(K):
    q = collections.deque(list("123456789"))
    ans = list("123456789")
    while len(ans) < K:
        n = q.popleft()
        for i in range(int(n[-1]) - 1, int(n[-1]) + 2):
            if 0 <= i < 10:
                q.append(n + str(i))
                ans.append(n + str(i))

    return ans[K - 1]


def main():
    K = int(input())
    print(bfs(K))


if __name__ == "__main__":
    main()


Measured memory_bytes: 15340
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Info{
	int cost,vocal,dance,looks;
};

int main(){

	int N,M,dp[301][301],maximum;
	char buf[32];
	Info info[301];

	while(true){
		if(scanf("%d %d",&N,&M) == EOF){
			break;
		}

		getchar();
		for(int i = 1; i <= N; i++){
			fgets(buf,31,stdin);
			scanf("%d %d %d %d",&info[i].cost,&info[i].vocal,&info[i].dance,&info[i].looks);
			getchar();
		}

		maximum = 0;

		for(int i = 0; i <= 2; i++){ //0.vocal 1.dance 2.looks

			for(int k = 0; k <= N; k++){
				for(int p = 0; p <= M; p++)dp[k][p] = 0;
			}

			for(int bydol = 1; bydol <= N; bydol++){

				for(int cost = M; cost >= 0; cost--){
					dp[bydol][cost] = dp[bydol-1][cost];
				}

				for(int cost = M; cost >= 0; cost--){
					for(int num = 1; info[bydol].cost*num <= cost; num++){
						switch(i){
						case 0:
							dp[bydol][cost] = max(dp[bydol][cost],dp[bydol][cost-info[bydol].cost*num]+info[bydol].vocal*num);
							break;
						case 1:
							dp[bydol][cost] = max(dp[bydol][cost],dp[bydol][cost-info[bydol].cost*num]+info[bydol].dance*num);
							break;
						case 2:
							dp[bydol][cost] = max(dp[bydol][cost],dp[bydol][cost-info[bydol].cost*num]+info[bydol].looks*num);
							break;
						}
					}
				}
			}

			for(int cost = M; cost >= 0; cost--){
				maximum = max(maximum,dp[N][cost]);
			}
		}

		printf("%d\n",maximum);
	}

	return 0;
}

Measured memory_bytes: 2924
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main(){
    int n; cin>>n;
    int nn=n%10;
    if(nn==3){
        cout<<"bon"<<endl;
    }else if(nn==0 or nn==1 or nn==6 or nn==8){
        cout<<"pon"<<endl;
    }else cout<<"hon"<<endl;
}

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

using namespace std;
typedef long long ll;
#define DBG(v) cerr << #v << " = " << (v) << endl;

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

    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    cout << w * h / 2.0 << ' ' << (x * 2 == w && y * 2 == h);
    return 0;
}

Measured memory_bytes: 256