akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
main(){
  int W,H,i,j,flg,cnt,x[]={0,1,0,-1},y[]={1,0,-1,0},a,b,c,d;
  char tmp[20][20];
  while(1){
    flg=1;
    scanf("%d %d",&W,&H);
    if(W==0&&H==0)break;
    for(i=0;i<H;i++) scanf("%s",tmp[i]);
    cnt=1;
    while(flg==1){
      flg=0;
      for(i=0;i<H;i++){
	for(j=0;j<W;j++){
	  if(tmp[i][j]=='@'){
	    for(a=0;a<4;a++){
	      for(b=i+x[a],c=j+y[a];b>=0&&b<H&&c>=0&&c<W;b+=x[a],c+=y[a]){
		if(tmp[b][c]=='#')break;
		else if(tmp[b][c]=='.'){
		  tmp[b][c]='@';
		  flg=1;
		  cnt++;
		}
	      }
	    }
	  }
	}
      }
    }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 604
package main

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

func main() {
	N := nextInt()
	chars := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}

	prev := make([]data, 0)
	curr := make([]data, 0)

	prev = append(prev, data{"a", 0})

	for i := 1; i < N; i++ {
		for j := 0; j < len(prev); j++ {
			d := prev[j]

			for k := 0; k <= d.max+1; k++ {
				curr = append(curr, data{d.str + chars[k], max(d.max, k)})
			}
		}
		prev = curr
		curr = make([]data, 0)
	}

	for i := 0; i < len(prev); i++ {
		fmt.Println(prev[i].str)
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

type data struct {
	str string
	max int
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


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

int main(){
    string s;
    cin >> s;
    bool ok = true;
    if(s[2]!=s[3]) ok = false;
    if(s[4]!=s[5]) ok = false;
    ok ? puts("Yes") : puts("No");
    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

ll X;
vector<ll> koho;

signed main(){
    cin >> X;
    for(ll i=0; i<=LLONG_MAX; i++){
        koho.pb(i*i*i*i*i);
        if(lower_bound(all(koho), i*i*i*i*i-X) != koho.end() && 
            *lower_bound(all(koho), i*i*i*i*i-X) == i*i*i*i*i-X){
            cout << i << " " << lower_bound(all(koho), i*i*i*i*i-X)-koho.begin() << endl;
            return 0;
        }
        if(lower_bound(all(koho), -i*i*i*i*i-X) != koho.end() &&
            *lower_bound(all(koho), -i*i*i*i*i-X) == -i*i*i*i*i-X){
            cout << -i << " " << lower_bound(all(koho), -i*i*i*i*i-X)-koho.begin() << endl;
            return 0;
        }
        if(lower_bound(all(koho), -(i*i*i*i*i-X)) != koho.end() &&
            *lower_bound(all(koho), -(i*i*i*i*i-X)) == -(i*i*i*i*i-X)){
            cout << i << " " << -(lower_bound(all(koho), -(i*i*i*i*i-X))-koho.begin()) << endl;
            return 0;
        }
        if(lower_bound(all(koho), -(-i*i*i*i*i-X)) != koho.end() &&
            *lower_bound(all(koho), -(-i*i*i*i*i-X)) == -(-i*i*i*i*i-X)){
            cout << -i << " " << lower_bound(all(koho), -(-i*i*i*i*i-X))-koho.begin() << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3632
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import deque, defaultdict, Counter
import heapq
def main():
    K = I()
    print('ACL' * K)

if __name__ == "__main__":
    main()


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

using namespace std;
//first : cost ,second : index
using P = pair<long long,int>;

using graph = vector<vector<P>>;

vector<long long> dijkstra(const graph &g , int n, int start,long long inf){
  vector<long long> dist(n,inf);
  priority_queue<P,vector<P>,greater<P>> queue;
  int size = 0;
  queue.push(make_pair(0,start));

  while(queue.size() > 0 && size < n){
    P now = queue.top() ; queue.pop();

    long long cost = now.first;
    int v = now.second;

    if(inf > dist[v])continue;

    dist[v] = cost;

    size++;

    for(auto e : g[v]){
      if(cost + e.first < dist[e.second]){
        queue.push(make_pair(cost + e.first,e.second));
      }
    }
  }

  return dist;
}

int main() {
  int n,m,s,t;
  cin >> n >> m >> s >> t;
  s--;t--;
  vector<vector<P>> yen(n,vector<P>(0));
  vector<vector<P>> snuuk(n,vector<P>(0));
  int u,v,a,b;
  for(int i=0;i<m;i++){
    cin >> u >> v >> a >> b;
    u--;v--;
    yen[u].emplace_back(make_pair(a,v));
    yen[v].emplace_back(make_pair(a,u));
    snuuk[v].emplace_back(make_pair(b,u));
    snuuk[u].emplace_back(make_pair(b,v));
  }

  long long inf = 1'000'000'000'000'000LL;
  vector<long long> yen_val = dijkstra(yen,n,s,inf);
  vector<long long> snuuk_val = dijkstra(snuuk,n,t,inf);
  vector<pair<long long , int>> total(n);
  for(int i=0;i<n;i++){
    total[i] = make_pair(yen_val[i] + snuuk_val[i],i);
  }

  sort(total.begin(),total.end());
  int idx = 0;

  for(int i=0;i<n;i++){
    while(total[idx].second <= i-1){
      idx++;
    }
    cout << inf - total[idx].first << endl;
  }
  
  return 0;
}


Measured memory_bytes: 21320
#include <cstdio>
#include <algorithm>
using namespace std;

int a,b;

int main()
{
    scanf("%d%d",&a,&b);
    if (a>=13) printf("%d",b);
    else if (a<=5) printf("0");
    else printf("%d",b/2);
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 128
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/13/20 21:03:09
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  struct Data {
    int v=0,w=0;
  };
  vector<Data> ds(n+1);
  for (int i = 0; i < n; i++) {
    int v,w; cin>>v>>w;
    ds[i+1] = {v,w};
  }
  int m = min(2<<9, n);
  vector<vector<int>> dp(m+1, vector<int>(1e5+1, -1));
  dp[0][0]= 0;
  for (int t = 1; t <= m; t++) {
    dp[t] = dp[t/2];
    for (int s = 1e5; s >= ds[t].w; s--) {
      if (dp[t/2][s-ds[t].w] == -1) continue;
      dp[t][s] = max(dp[t][s], dp[t/2][s-ds[t].w]+ds[t].v);
    }
  }
  for (int t = 1; t <= m; t++) {
    for (int s = 1; s <= 1e5; s++) {
      dp[t][s] = max(dp[t][s], dp[t][s-1]);
    }
  }

  int q; cin>>q;
  for (int i = 0; i < q; i++) {
    int v,l; cin>>v>>l;
    int f = 0;
    while (v>>f > m) {
      f++;
    }
    int ans = dp[v>>f][l];
    if (v > m) {
      for (int mask = 1; mask < 1<<f; mask++) {
        int cv = 0, cw = 0;
        for (int j = 0; j < f; j++) {
          if ((mask&(1<<j)) == 0) continue;
          cv += ds[v>>(f-j-1)].v;
          cw += ds[v>>(f-j-1)].w;
          if (cw > l) break;
        }
        if (cw > l) continue;
        ans = max(ans, dp[v>>f][l-cw]+cv);
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 407356
def main():
    n = int(input())
    As = [int(input()) for _ in range(n)]

    As_sort = sorted(As)
    second, first = As_sort[-2:]
    for i in range(n):
        if As[i] == first:
            print(second)
        else:
            print(first)


if __name__ == "__main__":
    main()


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

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

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int H1, H2, M1, M2; 
	cin >> H1 >> M1 >> H2 >> M2;
	int K; 
	cin >> K;
	int mins = 0;
	while (H2 > H1) {
		H2--;
		mins += 60;
	}
	mins += M2 - M1;
	print(mins - K);
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
const int NOI=0x3f3f3f3f;
int ans=NOI;
string s,t;
int ls,lt,sum,i,j;
int main(){
	cin>>s>>t;
	ls=s.size();
	lt=t.size();
	for(i=0;i<=ls-lt;i++){
	    sum=0;
		for(j=0;j<lt;j++)if(s[i+j]!=t[j])sum++;
		ans=min(ans,sum);
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 3624
import java.util.*;
import java.text.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static boolean[] ary;
    public static void main(String[] args) throws Exception {
        ary = new boolean[30];
        for (int i = 0; i < 28; i++) {
            ary[sc.nextInt()-1] = true;
        }
        
        for (int i = 0; i < 30; i++) {
            if (!ary[i]) {
                System.out.println(i+1);
            }
        }
    }
}

Measured memory_bytes: 26364
import itertools
S=raw_input()
#print S

n=[i for i in range(1,len(S))]

pattern=[]
for i in range(1,len(S)):
	#print list(itertools.combinations(n,i))
	pattern+=list(itertools.combinations(n,i))

#print pattern

a=[]
a.append(S)
for i in pattern:
	prev=0
	n=len(i)
	for j in range(n):
		if j==0:
			if j==n-1:
				a.append(S[0:i[j]])
				a.append(S[i[j]:])
			else:
				a.append(S[0:i[j]])
				prev=i[j]
		elif j==n-1:
			a.append(S[prev:i[j]])
			a.append(S[i[j]:])
			break	
		else:
			a.append(S[prev:i[j]])
			prev=i[j]

print sum(int(i) for i in a)





Measured memory_bytes: 2820
#include<bits/stdc++.h>
using namespace std;
char s[100001];
int a,b,c,d,e,i,j,k;
bool g;
int main()
{
	scanf("%s",s);
	for(i=0;i<=strlen(s);++i)
	{
		if(s[i]=='C')g=true;
		if(s[i]=='F'&&g==true)
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	
}
		

Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
count_color=[0]*8
wild_color=0
for i in range (N):
    if a[i]<400:
        count_color[0]=1
    elif a[i]<800:
        count_color[1]=1
    elif a[i]<1200:
        count_color[2]=1
    elif a[i]<1600:
        count_color[3]=1
    elif a[i]<2000:
        count_color[4]=1
    elif a[i]<2400:
        count_color[5]=1
    elif a[i]<2800:
        count_color[6]=1
    elif a[i]<3200:
        count_color[7]=1
    else:
        wild_color+=1
color=count_color.count(1)
if color!=0:
    print (color, color+wild_color)
else:
    print(1, color+wild_color)

Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#define FR first
#define SE second
#define MOD 1000000007

using namespace std;

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

ll pow_mod(ll x,int k) {
  ll ans=1;
  while (k) {
  	if (k&1) ans=ans*x%MOD;
  	x=x*x%MOD;
  	k>>=1;
  }
  return ans;
}

ll facd[205],facv[205],inv[205];
int k;

void pre(int n) {
  facd[0]=1;
  for(int i=1;i<=n;i++) facd[i]=facd[i-1]*i%MOD;
  facv[n]=pow_mod(facd[n],MOD-2);
  for(int i=n-1;i>=0;i--) facv[i]=facv[i+1]*(i+1)%MOD;
  inv[1]=1;
  for(int i=2;i<=n;i++) inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
}

inline ll C(int n,int m) {
  return (n<m)?0:facd[n]*facv[m]%MOD*facv[n-m]%MOD;
}

int gcd(int x,int y) {
  return (x%y==0)?y:gcd(y,x%y);
}

ll calc(int n) {
  ll ans=0;
  for(int i=1;i<=n;i++) ans=(ans+pow_mod(k,gcd(i,n)))%MOD;
  return ans*inv[n]%MOD;
}

struct Edge {
  int s,t,next;
  Edge() {}
  Edge(int a,int b,int c):s(a),t(b),next(c) {}
};

Edge e[205];
int head[205];

int dfn[205],low[205],tot;
bool vis[205],vis2[205];
int st[205],top;
ll ans=1;

void dfs(int x,int fa) {
  dfn[x]=low[x]=++tot;
  for(int i=head[x];i;i=e[i].next)
    if (((i+1)>>1)!=fa) {
    	int u=e[i].t;
    	st[++top]=i;
    	if (!dfn[u]) {
    		dfs(u,(i+1)>>1);
    		low[x]=min(low[x],low[u]);
    		if (low[u]>=dfn[x]) {
    			memset(vis,0,sizeof(vis));
    			int t,s1=0,s2=0;
    			do {
    				t=st[top--];
    				if (!vis2[(t+1)>>1]) {
    					vis2[(t+1)>>1]=1;
    					s2++;
    				if (!vis[e[t].s]) {
    					vis[e[t].s]=1;
    					s1++;
					}
					if (!vis[e[t].t]) {
						vis[e[t].t]=1;
						s1++;
					}
				    }
				} while (t!=i);
				if (s2==1) ans=ans*k%MOD;
				else if (s1==s2) ans=ans*calc(s2)%MOD;
				else ans=ans*C(s2+k-1,k-1)%MOD;
		    }
		}
		else if (dfn[u]<low[x]) low[x]=min(low[x],dfn[u]);
	}
}

int main() {
  int n,m;
  scanf("%d%d%d",&n,&m,&k);
  pre(m+k);
  for(int i=1;i<=m;i++) {
  	int x,y;
  	scanf("%d%d",&x,&y);
  	e[2*i-1]=Edge(x,y,head[x]);
  	head[x]=2*i-1;
  	e[2*i]=Edge(y,x,head[y]);
  	head[y]=2*i;
  }
  for(int i=1;i<=n;i++)
    if (!dfn[i]) dfs(i,0);
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

N, M = map(int,input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

class UnionFind:
    def __init__(self, N):
        self.Parent = [-1]*N

    def root(self, A):
        if self.Parent[A] < 0: return A
        self.Parent[A] = self.root(self.Parent[A])
        return self.Parent[A]
    
    def size(self, A):
        return -self.Parent[self.root(A)]
    
    def connect(self, A, B):
        if self.root(A) == self.root(B): return False
        if self.size(A) < self.size(B): A,B = B,A

        self.Parent[self.root(A)] += self.Parent[self.root(B)]
        self.Parent[self.root(B)] = self.root(A)
        return True

Uni = UnionFind(N+1)
ans = [0]*(M)
ans[M-1] = N*(N-1)//2

for i in reversed(range(1, M)):
    ans[i-1] = ans[i]
    if Uni.root(AB[i][0]) != Uni.root(AB[i][1]):
        ans[i-1] -= Uni.size(AB[i][0])*Uni.size(AB[i][1])
        Uni.connect(AB[i][0],AB[i][1])
for i in range(M):
    print(ans[i])
    

Measured memory_bytes: 33416
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int age = sc.nextInt();
        String res = "NO";

        switch (age) {
            case 3:
            case 5:
            case 7:
                res = "YES";
            default:
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 23636
n = int(input())
x = [int(i) for i in input().split()]
mod = 1000000007

fact = [1]*(n+1)
for i in range(1,n+1):
    fact[i] = (fact[i-1]*i)%mod
inv = [1]*(n+1)
inv[n] = pow(fact[n],mod-2,mod)
for i in range(n-1,1,-1):
    inv[i] = (inv[i+1]*(i+1))%mod

l = 0
ans = 0
for i in range(n-2):
    l = (l+x[n-2-i]-x[i])%mod
    f = (fact[n-1]*fact[i]*inv[i+2])%mod
    ans = (ans+l*f)%mod
for i in range(n-1):
    l = (x[n-1]-x[n-2-i])%mod
    ans = (ans+((fact[n-1]*fact[i]%mod)*inv[i+1]%mod)*l%mod)%mod
print(ans)

Measured memory_bytes: 15020
import sys
input = sys.stdin.readline
from collections import deque
def main():
  N=int(input())
  A=[deque()]+[deque(map(int,input().split())) for _ in range(N)]
  Days=[0]*(N+1)
  NOW=[0]*(N+1)
  
  q=deque([i+1 for i in range(N)])
  
  while q:
    i=q.popleft()

    if not A[i]:
      continue
    a=A[i].popleft()
    
    if NOW[a]==i:
      Days[a]=Days[i]=max(Days[a],Days[i])+1
      q.append(i)
      q.append(a)
      NOW[a]=NOW[i]=0
    else:
      NOW[i]=a
    
  for i in range(1,N+1):
    if A[i]:
      print(-1)
      return
  print(max(Days))
      

if __name__ == '__main__':
  main()

Measured memory_bytes: 78704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  string s;
  cin >> s;
  bool ok=true;
  if(s[0]!='A') ok=false;
  bool tmp=false;
  for(int i=2; i<s.size()-1; i++){
    if(s[i]=='C'){
      if(tmp) ok=false;
      else tmp=true;
    }
    else if(s[i]<'a' || s[i]>'z') ok=false;
  }
  if(tmp!=true) ok=false;
  if(s[s.size()-1]<'a' || s[s.size()-1]>'z') ok=false;
  if(s[1]<'a' || s[1]>'z') ok=false;
    
  if(ok) cout << "AC" << endl;
  else cout << "WA" << endl;
  
  return 0;
    

}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int w, h, n;
int space[100];
int iniField[20][20];
int field[110][20][20];
int ansField[20][20];
int used[20];

void PrintField(int field[20][20]) {
  REP(y, h) {
    REP(x, w) {
      if (x != 0) { putchar(' '); }
      printf("%d", field[y][x]);
    }
    puts("");
  }
}

int calc(int x, int y) {
  int depth = y * w + x;
  int ndepth = depth + 1;
  if (y == h) {
    memcpy(ansField, field[depth], sizeof(field[depth]));
    return 1;
  }
  if (x == w) { return calc(0, y + 1); }
  if (field[depth][y][x] != -1) {
    memcpy(field[ndepth], field[depth], sizeof(field[depth]));
    return calc(x + 1, y);
  }
  int ret = 0;
  REP(i, n) {
    if (used[i]) { continue; }
    used[i] = i;
    FOREQ(hh, 1, space[i]) {
      memcpy(field[ndepth], field[depth], sizeof(field[depth]));
      int ww = space[i] / hh;
      bool exist = false;
      if (hh * ww != space[i]) { continue; }
      REP(yy, hh) {
        REP(xx, ww) {
          if (field[ndepth][yy + y][xx + x] != -1 ||
              (iniField[yy + y][xx + x] != 0 &&
               iniField[yy + y][xx + x] != i + 1)) { goto next; }
          exist |= iniField[yy + y][xx + x] == i + 1;
          field[ndepth][yy + y][xx + x] = i + 1;
        }
      }
      if (!exist) { goto next; }
      ret += calc(x + 1, y);
      if (ret >= 2) { return ret; }
next:;
    }
    used[i] = 0;
  }
  return ret;
}

int main() {
  while (scanf("%d %d %d", &w, &h, &n), w|h|n) {
    MEMSET(used, 0);
    MEMSET(iniField, 0x0f);
    REP(i, n) {
      int f, v;
      scanf("%d %d", &f, &v);
      space[f - 1] = v;
    }
    REP(y, h) {
      REP(x, w) {
        scanf("%d", &iniField[y][x]);
      }
    }
    MEMSET(field, -1);
    if (calc(0, 0) == 1) {
      PrintField(ansField);
    } else {
      puts("NA");
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

Vec pn;

bool isPrime(ll n){
	if(n == 1) return false;
	for(ll i : pn){
		if(i * i > n) return true;
		if(n % i == 0) return false;
	}
	return true;
}

void init(ll n = 2e5){
	pn.pb(2);
	REP(num, 3, n) if(isPrime(num)) pn.pb(num);
}

VecP primeFactorization(ll n){
	VecP res;

	for(ll i : pn){
		ll cnt = 0;
		while(n % i == 0){
			n /= i;
			cnt++;
		}
		if(cnt) res.pb({i, cnt});
		if(n < i * i) break;
	}
	if(n != 1) res.pb({n, 1});

	return res;
}

Vec divisorEnumeration(ll n){
	auto v = primeFactorization(n);

	Vec res, a, b, cp;
	res.pb(1);
	for(auto p : v){
		cp.resize(res.size());
		copy(all(res), cp.begin());
		a.resize(res.size());
		repn(k, p.sc){
			ll t = pow(p.fs, k);
			rep(i, a.size()) a[i] = cp[i] * t;
			merge(all(res), all(a), back_inserter(b));
			swap(res, b);
			b.clear();
		}
	}

	return res;
}

int main(void){
	init();
	ll n;
	cin >> n;
	Vec a(n);
	rep(i, n) cin >> a[i];

	multiset<ll> st;
	rep(i, n) st.insert(a[i]);

	ll ans = 0;
	rep(i, n){
		st.erase(st.find(a[i]));
		auto v = divisorEnumeration(a[i]);
		bool flg = true;
		for (ll j : v){
			if(st.find(j) != st.end()){
				flg = false;
				break;
			}
		}
		if (flg) ans++;
		st.insert(a[i]);
	}
	co(ans);

	return 0;
}


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

int main() {

	vector<long long> x(4);
	long long a, b, c, d;

	cin >> a >> b >> c >> d;

	x[0] = a * c;
	x[1] = a * d;
	x[2] = b * c;
	x[3] = b * d;

	sort(x.begin(), x.end());

	cout << x[3] << endl;


}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007;
#define MOD2 998244353;
#define INF ((1<<30)-1);
#define LINF (1LL<<60);
#define EPS (1e-10);
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    Int n;
    cin >> n;
    Int ans = 0;
    if (n % 2 == 0) {
        for (Int i = 10; i <= n; i*=5) {
            ans += n / i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(),x.end()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<int,ull> piu;
typedef vector<vector<int>> matrix;

const ll INF=1e18+123;
const ld EPS=1e-9;
const int inf=1e9+123;
const int MOD=1e9+7;
const int N=5e5+123;
const int M=1e6+123;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

vector<pii>ans;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int>q,w;
    int z=0;
    for(int i=1,x;i<=n;i++){
        cin>>x;
        if(x>=0)q.pb(x);
        else w.pb(x);
    }
    sort(all(q));
    sort(all(w));
    reverse(all(q));
    if(!sz(w)){
        if(n==2){
            cout<<q[0]-q[1]<<endl<<q[0]<<" "<<q[1]<<endl;
            return 0;
        }
        ans.pb({q.back(),q[0]});
        w.pb(q.back()-q[0]);
        q.pop_back();
        q.erase(q.begin());
    }
    if(!sz(q)){
        ans.pb({w.back(),w[0]});
        q.pb(w.back()-w[0]);
        w.pop_back();
        w.erase(w.begin());
    }
    while(sz(q)>1){
        int x=q.back();
        ans.pb({w[0],x});
        w[0]-=x;
        q.pop_back();
    }
    for(int x : w){
        ans.pb({q[0],x});
        q[0]-=x;
    }
    cout<<q[0]<<endl;
    for(pii p: ans){
        cout<<p.x<<" "<<p.y<<endl;
    }
    return 0;
}


Measured memory_bytes: 3444
#include <cstdio>
#include <algorithm>
#include <queue>
#include <tuple>
using namespace std;
typedef unsigned long long ll;

ll arr[200005];
int dec[200005];
double S[200005];
int pmin[200005];
int main(){
	int K; scanf("%d", &K);
	int k = 0;
	for (int i = 1;i < 10000;i++) arr[k++] = i;
	for (ll i = 4, p = 10;i <= 17;i++, p *= 10) {
		for (ll j = 1;j < 10000;j++) {
			arr[k++] = j * p + (p - 1);
		}
	}
	sort(arr, arr + k);
	k = unique(arr, arr + k) - arr;
	for (int i = 0;i < k;i++) {
		ll cur = arr[i];
		while (cur) {
			dec[i] += cur % 10;
			cur /= 10;
		}
		S[i] = 1.0*arr[i] / dec[i];
	}
	S[k] = 1e30;
	pmin[k] = k;
	for (int i = k - 1;i >= 0;i--) {
		if (S[pmin[i + 1]] < S[i]) pmin[i] = pmin[i + 1];
		else pmin[i] = i;
	}
	vector<ll> ans;
	for (int i = 0;i < k;i++) {
		if (arr[i]*dec[pmin[i+1]] <= arr[pmin[i + 1]]*dec[i]) ans.push_back(arr[i]);
	}
	for (int i = 0;i<K;i++) printf("%llu\n", ans[i]);
}

Measured memory_bytes: 4096
s=input()
n=len(s)
a=(n-1)//2
f=0
for i in range(n):
  if s[i]!=s[n-1-i]:
    f=1
for i in range(a):
  if s[i]!=s[(n-1)//2-1-i]:
    f=1
if f==0:
  print("Yes")
else:
  print("No")

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

using namespace std;

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

int main(){

	int x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <stdio.h>

using namespace std;

int main()
{
	string str;

	cin>>str;

	for(int i=str.size()-1;i>=0;i--) cout<<str[i];
	cout<<endl;

	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws InterruptedException {
		FastScanner fs=new FastScanner();
		int n=fs.nextInt();
		System.out.println(n>=30?"Yes":"No");
			
	}
	
	void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}
	
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
		
		public long[] readLongArray(int n) {
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
	}

}


Measured memory_bytes: 32720
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
prime = primes(55555)

N = int(input())

# 5で割り切れる10以上の整数 -> 必ず合成数になる
# 5で割って1余る、55555以下の素数をN個列挙

ans = []
for p in prime:
    if p % 5 == 1:
        ans.append(p)
    if len(ans) == N:
        break

print(*ans)

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

int n, m;

int main(){
  cin >> n >> m;
  int res =  (1900 * m + 100 * (n - m)) * pow(2, m);
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 2000000000;

int distance(int a, int b) {
  if (a < b) swap(a, b);
  return a-b;
}

int main() {
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  vector<int> stick(n+1, 0);
  int ans = INF;
  rep(i, pow(4, n)) {
    int asum = 0;
    int bsum = 0;
    int csum = 0;
    int mp = -30;
    rep(j, n) {
      if (stick[j] == 3) continue;
      if (stick[j] == 0) asum += l[j];
      if (stick[j] == 1) bsum += l[j];
      if (stick[j] == 2) csum += l[j];
      mp += 10;
    }
    stick[0]++;
    rep(j, n) {
      if (stick[j] == 4) {
        stick[j+1]++;
        stick[j] = 0;
      }
    }
    if (asum == 0 || bsum == 0 || csum == 0) continue;
    mp += distance(a, asum);
    mp += distance(b, bsum);
    mp += distance(c, csum);
    ans = min(ans, mp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
while True:
  H, W=map(int, input().split())
  if H==0 and W==0:
    break
  for i in range(H):
    for j in range(W):
      if (i+j)%2==0:
        print("#", end="")
      else:
        print(".", end="")
    print()
  print()


Measured memory_bytes: 7008
#include <iostream>
#include <math.h>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>

#define DOLL long double
#define LOLI long long int
using namespace std;

const long C_10PW9 = 1000000000;
const int ULCODE = 32;

int divc(int s) {
	int r = 0;
	int sq = sqrt(s);
	for (int i = 1; i <= sq; i++) {
		if (s % i == 0) {
			r++;
			if (s / i != i) { r++; }
		}
	}
	return r;
}
int main()
{
	int n;
	cin >> n;
	int f = 0;
	for (int i = 1; i < n; i++) {
		int a = (n - 1) / i;
		f += a;
	}
	cout << f << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define _GLIBCXX_DEBUG
#define INF 100000010
using namespace std;
const int mod = 1000000007;




int main() {

    string N, M, ans = "";
    cin >> N >> M;
    if (N.size() < M.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for (int i = N.size() - M.size(); i >= 0; i--) {
            for (int j = 0; j < M.size(); j++) {
                if (M[j] != N[i+j] && N[i+j] != '?')break;
                if (j == M.size()-1) {
                    for (int k = 0; k < N.size(); k++) {
                        
                        if (k == i) { ans += M; k += M.size() - 1; }
                        else if (N[k] == '?')ans.push_back('a');
                        else ans.push_back(N[k]);
                        if (k == N.size() - 1)goto end;
                    }
                }
            }
        
    }
    end :
    if (ans == "")ans = "UNRESTORABLE";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<vector>
#include<algorithm>
#include<iostream>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
int main(){
    int bing[9],N,q,w,e,r,t,y,u,o;
    rep(i,9){
        cin>>bing[i];
    }
    cin>>N;
    int b[N];
    rep(j,N){
        cin>>b[j];
        if(b[j]==bing[0]){
            bing[0]=0;
        }
        if(b[j]==bing[1]){
            bing[1]=0;
        }
        if(b[j]==bing[2]){
            bing[2]=0;
        }
        if(b[j]==bing[3]){
            bing[3]=0;
        }
        if(b[j]==bing[4]){
            bing[4]=0;
        }
        if(b[j]==bing[5]){
            bing[5]=0;
        }
        if(b[j]==bing[6]){
            bing[6]=0;
        }
        if(b[j]==bing[7]){
            bing[7]=0;
        }
        if(b[j]==bing[8]){
            bing[8]=0;
        }
    }
    q=bing[0]+bing[1]+bing[2];
    w=bing[3]+bing[4]+bing[5];
    e=bing[6]+bing[7]+bing[8];
    r=bing[0]+bing[3]+bing[6];
    t=bing[1]+bing[4]+bing[7];
    y=bing[2]+bing[5]+bing[8];
    u=bing[0]+bing[4]+bing[8];
    o=bing[2]+bing[4]+bing[6];
    if(q==0||w==0||e==0||r==0||t==0||y==0||u==0||o==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<cmath>
#include<list>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long ll;
const int maxn = 200000 + 8;


int n,a[maxn];
ll num = 0;

void Merge(int a[],int left,int mid,int right,int temp[])
{
    int i = left,j = mid + 1, cur = 0;
    //int n1 = mid - left + 1;
    int n1 = mid - left + 1;
    //cout << left << " "<< mid <<" "<< right << " " << n1 <<endl;
    while(i <= mid && j <= right)
    {
        if(a[i] <= a[j]) {
            temp[cur++] = a[i++];
        } else{
            temp[cur++] = a[j++];
            //num += mid - i + 1;
            num += n1 - (i - left);
            //num += n1 - (i-left) = mid - left + 1 - i + left = mid - i + 1;
        }
    }

    while(i <= mid) temp[cur++] = a[i++];
    while(j <= right) temp[cur++] = a[j++];

    for(int z = 0; z < cur; ++z)
    {
        a[left + z] = temp[z];
    }
}
void MergeSort(int a[],int left,int right,int temp[])
{
    if(left < right)
    {
        int mid = (right + left) / 2;
        MergeSort(a, left, mid, temp);
        MergeSort(a, mid+1, right, temp);
        Merge(a,left,mid,right, temp);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i = 0; i < n; ++i)
        scanf("%d",&a[i]);

    int temp[maxn];
    MergeSort(a, 0, n-1,temp);
    printf("%lld\n", num);
    return 0;
}

/*
5
3 5 2 1 4
6
3 5 2 6 1 4
*/

Measured memory_bytes: 4784
from collections import deque
H, W = map(int, input().split())
S = [input() for i in range(H)]
D = [(-1, 0), (1, 0), (0, -1), (0, 1)]


def BFS(x, y, M):
    dist = [[-1] * W for i in range(H)]
    quex = deque([x])
    quey = deque([y])
    dist[x][y] = 0

    while quex:
        vx = quex.popleft()
        vy = quey.popleft()
        d = dist[vx][vy]
        for w in D:
            nx = w[0] + vx
            ny = w[1] + vy
            if nx < 0 or H <= nx or ny < 0 or W <= ny:
                continue
            elif dist[nx][ny] > -1 or S[nx][ny] == "#":
                continue
            dist[nx][ny] = d + 1
            M = max(M, d+1)
            quex.append(nx)
            quey.append(ny)

    return M


M = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            M = BFS(i, j, M)
print(M)

Measured memory_bytes: 43504
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef pair<int, int> pi;
#define SQ(a) (a) * (a)
#define deb(x) cout << #x << " = " << x << '\n'
#define deb2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
 
 
int main(int argc, char const *argv[])
{
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++){
    	cin>>a[i];
    }
    int dp[n+1];
    dp[0]=0;
    dp[1]=0;
    for(int i=2;i<=n;i++){
    	int mn=INT_MAX;
    	int curr = max(1,i-k);
    	while(curr<i){
    		int temp = abs(a[i]-a[curr])+dp[curr];
    		mn=min(temp,mn);
    		curr++;
    	}
    	dp[i]=mn;
    }
    
    cout<<dp[n];

    return 0;
}

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

#define fi first
#define se second

const int N = 100100;

using namespace std;

int n, q;
long long k[N];
long long a[N];
long long s[N];
long long res[N];

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

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n >> q;
        vector < long long > qu;

        qu.push_back(n);
        for(int i = 1; i <= q; i++){
                cin >> a[i];
                while(!qu.empty() && a[i] <= qu.back()){
                        qu.pop_back();
                }
                qu.push_back(a[i]);
        }
        q = qu.size();
        for(int i = 1; i <= q; i++) a[i] = qu[i - 1];

        k[q] = 1;
        for(int i = q; i > 1; i--){
                k[i - 1] += k[i] * (a[i] / a[i - 1]);

                long long rem = (a[i] % a[i - 1]);
                while(rem > 0){
                        if(rem <= a[1]){
                                s[rem] += k[i];
                                break;
                        }

                        int l = 1, r = q;
                        while(l < r){
                                int m = (l + r) / 2;
                                if(a[m] > rem){
                                        r = m;
                                } else{
                                        l = m + 1;
                                }
                        }
                        k[l - 1] += (rem / a[l - 1]) * k[i];
                        rem %= a[l - 1];
                }
        }
        for(int i = 1; i <= a[1]; i++) res[i] += k[1];
        for(int i = n; i >= 1; i--){
                s[i] += s[i + 1];
                res[i] += s[i];
        }

        for(int i = 1; i <= n; i++) cout << res[i] << "\n";
}


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

using namespace std;
typedef long long llint;
const int maxn = 1e6+10;

int n;
int main() {
    scanf("%d", &n);
    llint sol = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) sol += i;
    }
    printf("%lld", sol);
    return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

ll dp[55][3000][55];


int main(){
    int N, A;
    cin >> N >> A;
    vector<int> X(N);
    for(int i=0; i<N; i++) cin>>X[i];

    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;

    for(int i=0; i<N; i++) {
        for(int s=0; s<=A*N; s++) {
            for(int k=0; k<N; k++) {
                if(dp[i][s][k] == 0) continue;
                dp[i+1][s][k] += dp[i][s][k];
                dp[i+1][s+X[i]][k+1] += dp[i][s][k];
            }
        }
    }

    ll ans = 0;
    for(int k=1; k<=N; k++) ans += dp[N][A*k][k];
    cout << ans;
}

Measured memory_bytes: 74508
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
typedef long long ll;
ll prefix[402];
ll cost[402][402];

ll sum(int l, int r) {
	return prefix[r] - (l > 0 ? prefix[l - 1] : 0);
}

int main() {
	int n; cin >> n;
	vector<int> nums(n);
	for (auto &x : nums) { cin >> x; }
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) { cost[i][j] = 1e15; }
		prefix[i] = nums[i] + (i ? prefix[i - 1] : 0);
		cost[i][i] = 0;
	}

	for (int l = n-1; l >= 0; l--)
		for (int r = l + 1; r < n; r++)
			for (int k = l; k < r; k++)
				cost[l][r] = min(cost[l][r], cost[l][k] + cost[k + 1][r] + sum(l, r));

	cout << cost[0][n - 1] << endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for( int i=0;i<N; ++i )
    cin >> a[i];
  vector< vector<ll> > dp(N+1, vector<ll>(K+1));

  dp[0][0] = 1;
  for( int i=0;i<N; ++i )
    {
      int cumsum = 0;
      for( int j=0;j<K+1;++j )
	{
	  cumsum = (cumsum+dp[i][j])%1000000007;
	  dp[i+1][j] = cumsum;
	  if( j>a[i]-1 )
	    cumsum = (1000000007+cumsum-dp[i][j-a[i]])%1000000007;
	}
    }
  cout << dp[N][K] << endl;
  
}


Measured memory_bytes: 80256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//const ll mod=1000000007;
int GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
  int n;
  cin>>n;
  V<ll> a(n);
  map<ll,ll> mp;
  for(int i=0;i<n;i++){
      cin>>a[i];
      mp[i+1-a[i]]++;
  }
  ll ans=0;
  for(int i=0;i<n;i++){
      ll t=0;
      if(a[i]+i+1==i+1-a[i])t=1;
      ll d=mp[i+1+a[i]];
      ans+=(d-t);
      mp[i+1-a[i]]--;
  }
  cout<<ans<<"\n";
}


Measured memory_bytes: 27264
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")


# 1-indexed
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


# 処理内容
def main():
    N, M = map(int, input().split())
    T = UnionFind(N)
    for _ in range(M):
        a, b = map(int, input().split())
        T.Unite(a, b)
    
    ans = 0
    for i in range(1, N+1):
        ans = max(ans, T.Count(i))
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 80380
import math

n,m = map(int, input().split())

x=int(math.sqrt(m))

ans=1
for i in range(1,x+1):
  if m%i==0:
    if i*n<=m:
      ans=max(ans,i)
    if int(m/i)*n<=m:
      ans=max(ans,int(m/i))
print(ans)




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

int main() {
	int n;
	while(cin >> n, n) {
		vector<int> h;
		h.resize(n+1);
		for(int i = 0; i < h.size(); i++)
			cin >> h[i];
		for(int i = 0; i < h.size(); i++) {
			bool flg = true;
			vector<int> v;
			for(int j = 0; j < h.size(); j++) {
				if(i != j)
					v.push_back(h[j]);
			}
			int dff = v[1] - v[0];
			for(int j = 2; j < v.size(); j++) {
				if(dff != v[j] - v[j-1])
					flg = false;
			}
			if(flg) {
				cout << h[i] << endl;
				break;
			}
		}
	}
}

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

#define pi 3.14159265358

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a, b, h, m;
	cin >> a >> b >> h >> m;
	cout << fixed << setprecision(10) << sqrt(pow(a, 2) + pow(b, 2) - 2*a*b*cos(2*pi*(60*h+m)/720 - 2*pi*m/60)) << "\n";
	return 0;
}


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

using namespace std;

int main()
{
	double weight;
	while(cin>>weight){
		if(weight<=48) cout<<"light fly"<<endl;
		else if(48 < weight && weight <=51)cout<<"fly"<<endl;
		else if(51 < weight && weight <=54)cout<<"bantam"<<endl;
		else if(54 < weight && weight <=57)cout<<"feather"<<endl;
		else if(57 < weight && weight <=60)cout<<"light"<<endl;
		else if(60 < weight && weight <=64)cout<<"light welter"<<endl;
		else if(64 < weight && weight <=69)cout<<"welter"<<endl;
		else if(69 < weight && weight <=75)cout<<"light middle"<<endl;
		else if(75 < weight && weight <=81)cout<<"middle"<<endl;
		else if(81 < weight && weight <=91)cout<<"light heavy"<<endl;
		else cout<<"heavy"<<endl;
	}
	return 0;
}

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

int main() {
	int h,n,w=0,cnt=0;
	cin>>h>>n;
	for(int i=0;i<n;i++){
		cin>>w;
		cnt+=w;
	}
	if(cnt>=h){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;

}



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

void reverse(char *s){
    char t[100001];
    int length;
    int i;
    length = strlen(s);
    strcpy(t, s);
    for(i=0;i<length;i++){
        s[i] = t[length-1-i];
    }
}

int main()
{
    char s[100001];
    int i = 0;
    char a[4][8] = {"dream", "dreamer", "erase", "eraser"};
    
    scanf("%s", s);
    
    reverse(s);
    for(i=0;i<4;i++) reverse(a[i]);
    
    int c = 0, l = strlen(s);
    
    while(c<l){
        int k = -1;
        for(i=0;i<4;i++){
            if(!strncmp(s+c,a[i], strlen(a[i]))){
                k = strlen(a[i]);
                break;
            }
        }
        if(k<0){
            printf("NO");
            return 0;
        }
        c += k;
    }
    printf("YES");
    
    return 0;
}

Measured memory_bytes: 384
# frozen_string_literal: true

# maximum matching
class MaximumMatching
  def initialize(vertex_num)
    @vertex_num = vertex_num
    @edges = Array.new(vertex_num) { [] }
    @matches = Array.new(vertex_num) { -1 }
    @visited = []
  end

  def add_edge(u, v)
    @edges[u] += [v]
    @edges[v] += [u]
  end

  def dfs(v)
    @visited[v] = true
    @edges[v].each do |e|
      w = @matches[e]
      next if w >= 0 && (@visited[w] || !dfs(w))

      @matches[v] = e
      @matches[e] = v
      return true
    end
    false
  end

  def maximum_matching
    count = 0
    0.upto(@vertex_num - 1) do |v|
      next if @matches[v] >= 0

      @visited.clear
      count += 1 if dfs(v)
    end
    count
  end
end

n = gets.to_i
ab = n.times.map { gets.split.map(&:to_i) }
cd = n.times.map { gets.split.map(&:to_i) }

m = MaximumMatching.new(n * 2)

ab.each_index do |i|
  cd.each_index do |j|
    if ab[i][0] < cd[j][0] && ab[i][1] < cd[j][1]
      m.add_edge(i, j + n)
    end
  end
end

puts m.maximum_matching


Measured memory_bytes: 2428