akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def func(root, left, right):
    if right <= left:
        return
    print root, right
    print root, left
    func(right, left + 1, right - 1)

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    s = 0
    sum_list = [0 for i in range(N + 1)]
    for i in range(1, N + 1):
        sum_list[i] = sum_list[i - 1] + i
        s += i


    if N % 2 == 0:
        groups = []
        for i in range(1, N/2 + 1):
            groups.append((i, N-i + 1))
        groups = set(groups)
        groups_copy = copy.deepcopy(groups)
        pair = []
        for g1 in groups:
            groups_copy.remove(g1)
            for g2 in groups_copy:
                    for nd1 in g1:
                        for nd2 in g2:
                            if nd1 != 0 and nd2 != 0:
                                pair.append((nd1, nd2))
        print len(pair)
        for i in range(len(pair)):
            print pair[i][0], pair[i][1]
##        left_list = []
##        right_list = []
##
##        for k in range(1, N + 1):
##            left_sum = 0
##            for i in range(k, N + 1):
##                if sum_list[i] - sum_list[i - k] == s / 2:
##                    left_list = set([j for j in range(i - k + 1, i + 1)])
##                    right_list = set([j for j in range(1, N + 1)]) - left_list
##                    print len(left_list) * len(right_list)
##                    for l in left_list:
##                        for r in right_list:
##                            print l, r
##                    return
    else:
        groups = [(N, 0)]
        for i in range(1, N/2 + 1):
            groups.append((i, N-i))
        groups = set(groups)
        groups_copy = copy.deepcopy(groups)
        pair = []
        for g1 in groups:
            groups_copy.remove(g1)
            for g2 in groups_copy:
                    for nd1 in g1:
                        for nd2 in g2:
                            if nd1 != 0 and nd2 != 0:
                                pair.append((nd1, nd2))
        print len(pair)
        for i in range(len(pair)):
            print pair[i][0], pair[i][1]




if __name__ == '__main__':
    main()


Measured memory_bytes: 3436
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

using namespace std;

#define li long long int
#define ld double_t
#define mod (li)(1e9+7)
const int MX1=1e5+5;
const int MX2=1e6+5;
const li inf=1e18;

li power(li a,li b){li res=1;while(b){if(b%2)res=(res*a)%mod;
a=(a*a)%mod;b/=2;}return res;}

li mmi(li a){return power(a,mod-2);}

li cntbit(li n){li cnt=0;while(n){n&=(n-1);cnt++;}return cnt;}

int n,a[MX1],mark[MX1];

void solve(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mark[a[i]]++;
	}
	int tot=0,ext=0;
	for(int i=1;i<=(int)(1e5);i++){
		if(mark[i]==0) continue;
		tot++;
		ext+=mark[i]-1;
	}
	cout<<tot-(ext%2);
}

int main(){
	ios_base::sync_with_stdio(false);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <string>
#pragma warning(disable : 4996)

#define MAX_N 40

int P[MAX_N];
int I[MAX_N];

struct Node {
	int id;
	int parent;
	int left;
	int right;
	int depth;
	int hight;
	Node() : id(-1), parent(-1), depth(-1), left(-1), right(-1), hight(-1) {}
};

Node nodes[MAX_N+1];

Node *GetRoot(int n) {
	for (int i = 1; i < n+1; ++i) {
		if ((nodes[i].parent == -1) && (nodes[i].id != -1)){
			return &nodes[i];
		}
	}
	return NULL;
}
int CalcDHr(Node *n, int depth) {
	n->depth = depth;
	int md = n->depth;
	if (n->left != -1) {
		Node *l = &nodes[n->left];
		int cd = CalcDHr(l, depth+1);
		if (md < cd) md = cd;
	}
	if (n->right != -1) {
		Node *r = &nodes[n->right];
		int cd = CalcDHr(r, depth+1);
		if (md < cd) md = cd;
	}
	n->hight = md - n->depth;
	return md;
}
void CalcDH(int n) {
	Node *root = GetRoot(n);
	CalcDHr(root, 0);
}
void Preorder(Node *node) {
	printf(" %d", node->id);
	if(node->left != -1) Preorder(&nodes[node->left]);
	if(node->right != -1) Preorder(&nodes[node->right]);
}
void Inorder(Node *node) {
	if (node->left != -1) Inorder(&nodes[node->left]);
	printf(" %d", node->id);
	if (node->right != -1) Inorder(&nodes[node->right]);
}
void Postorder(Node *node) {
	if (node->left != -1) Postorder(&nodes[node->left]);
	if (node->right != -1) Postorder(&nodes[node->right]);
	static bool isFirst = true;
	if (isFirst == true) {
		isFirst = false;
	}
	else {
		printf(" ");
	}
	printf("%d", node->id);
}

void Reconstruct(int pre[], int pl, int in[], int il) {
	Node *root = &nodes[pre[0]];
	int index = -1;
	for (int i = 0; i < il; ++i) {
		if (in[i] == pre[0]) {
			index = i;
			break;
		}
	}
	if (index == 1) {
		root->left = in[index-1];
		nodes[root->left].parent = pre[0];
	}
	else if (index > 1) {
		root->left = pre[1];
		nodes[root->left].parent = pre[0];
		Reconstruct(&pre[1], index, in, index);
	}
	if (il - index - 1 == 1) {
		root->right = in[index + 1];
		nodes[root->right].parent = pre[0];
	}
	else if (il - index - 1 > 1) {
		root->right = pre[1+index];
		nodes[root->right].parent = pre[0];
		Reconstruct(&pre[1+index], pl-index-1, &in[1+index], il-index-1);
	}
}
int main(void) {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &P[i]);
	}
	for (int i = 0; i < n; ++i) {
		scanf("%d", &I[i]);
	}
	for (int i = 1; i < n+1; ++i) {
		nodes[i].id = i;
	}
	Reconstruct(P, n, I, n);
	Node *root = GetRoot(n);
	Postorder(root);
	printf("\n");
	return 0;
}


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

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

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int a,b,c;
bool flag[110] = {false};

int main(){
  scanf("%d %d %d",&a,&b,&c);
  int mod = a % b;
  flag[mod] = true;
  REP(i,b){
    flag[(mod*i)%b] = true;
  }
  if(flag[c]){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>

using namespace std;

typedef complex<double> P;

#define EPS (1e-6)

P p[300];
P tmp;

int main() {
  int n;
  while (cin >> n, n) {
    for (int i=0; i<n; i++) {
      cin >> p[i].real() >> p[i].imag();
    }

    int ans = 1;
    for (int i=0; i<n; i++) {
      for (int j=i+1; j<n; j++) {
        P v = p[i] - p[j];
        double absv = abs(v);
        if (absv > 2.0 + EPS) { continue; }

        P m = p[j] + (v / 2.0);
        P unv = (v * P(0, 1)) / absv; // unit normal vector
        P nv = sqrt(1.0 - absv*absv/4.0) * unv;
        for (int s=0; s<2; s++) {
          nv *= -1;
          P c = m + nv; // center point of the circle

          int cnt = 0;
          for (int k=0; k<n; k++) {
            // if (abs(p[k] - c) < 1.0 + EPS) { cnt++; } // too slow
            tmp = p[k] - c;
            if ( tmp.real()*tmp.real() + tmp.imag()*tmp.imag() < 1.0 + EPS ) { cnt++; }
          }
          if (cnt > ans) { ans = cnt; }
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}

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

int main() {
    int W, a, b;
    cin >> W >> a >> b;
    cout << max(max(a,b) - (min(a,b) + W), 0) << endl;
}


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

#define mx 100005
#define ll long long 

void IO()
{
     #ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
}

int ar[mx];
char ch[mx];

int m,n,k,ii;


void solve()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>ar[i];
	sort(ar+1,ar+n+1);
    ll re=0;
    for(int i=1;i<=n-2;i++)
    {
    	for(int j=i+1;j<=n-1;j++)
    	{
    		if(ar[i]==ar[j])continue;
    		for(int l=j+1;l<=n;l++)
    		{
    			if(ar[j]==ar[l])continue;
    			if(ar[i]+ar[j]>ar[l])re++;
    		}
    	}
    }
    cout<<re<<endl;
}

int main()
{
	IO();

	int t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int K, A, B; cin >> K >> A >> B;
  string ans = "NG";
  for(int i = A; i <= B; ++i) {
    if(i % K == 0) ans = "OK";
  }
  cout << ans << endl;
}


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

using namespace std;

#define fo(i, n) for(int i = 1; i <= n; ++i)
#define pb push_back

typedef long long ll;

const int N = 500500;
const int mod = 1e9 + 7;
const ll inf = 2e18;

int n, k, a[N];
int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    cin >> n >> k;
    fo(i, n)
        cin >> a[i];
    if(n <= k) return cout << 1, 0;
    cout << 1 + (n - k + (k - 2) ) / (k - 1);
    return 0;
}

Measured memory_bytes: 1020
using System;
class Program
 {
   static void Main(string[] args)
   {
     string S;
     S = Console.ReadLine();
     long K;
     K = long.Parse(Console.ReadLine());

     for(int i = 0;i<S.Length;i++)
     {
      if(S[i] == '1')
      {
        K -= 1;
        if(K == 0)
        {
          Console.WriteLine("1");
          break;
        }        
      }else{
        Console.WriteLine(S[i]);
        break;
      } 
     }
     
         
   }
 }

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){

    int x,k,d,t;
    cin>>x>>k>>d;
    x=abs(x);
    t=x/d;
    if(t>=k){

      x=x-k*d;
      cout<<abs(x)<<endl;
    }
    else{
        x=x-t*d;
        k=k-t;
        if(k%2==0){
            cout<<abs(x)<<endl;
        }
        else{
            cout<<abs(x-d)<<endl;
        }

    }



}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int N, Q; cin >> N >> Q;
    string str; cin >> str;

    vector<int> s(N+1, 0);
    for (int i = 0; i < N; ++i) {
        if (i+1 < N && str[i] == 'A' && str[i+1] == 'C') s[i+1] = s[i] + 1;
        else s[i+1] = s[i];
    }
    for (int q = 0; q < Q; q ++) {
        int l, r; cin >> l >> r;
        -- l, -- r;
        cout << s[r] - s[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 500055
//#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,sum,a[N];
char str[N];
signed main(){
	scanf("%s",str+1);n=strlen(str+1);
	F(i,1,n) a[n-i+1]=str[i]-'0';
	F(i,1,n) a[i]=a[i]*9;
	F(i,1,n){
		a[i+1]+=a[i]/10;a[i]%=10;
	}
	if (a[n+1]) n++;
	F(i,1,n) sum+=a[i];
	F(i,1,n){
		sum+=9;
		a[1]+=9;
		int t=1;
		while (a[t]>=10){
			sum-=9;
			a[t+1]++;
			a[t]%=10;
			t++; 
		}
		if (t>n) n++;
		if (sum<=i*9) return wrn(i),0;
	}
	return 0;
}

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

using namespace std;

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

  if(s[0] == 'S') cout << "Cloudy" << endl;
  if(s[0] == 'C') cout << "Rainy" << endl;
  if(s[0] == 'R') cout << "Sunny" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define int long long
const int CN = 2e5 + 5;
const int INF = 0x3f3f3f3f3f3f3f3f;
int n, x[CN], y[CN], mx = -INF, mn = INF, ans = -INF;
signed main()
{
    ios :: sync_with_stdio(false);
    // freopen("_in.in", "r", stdin);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> x[i] >> y[i];
    for(int i = 1; i <= n; i++) mx = max(mx, x[i] + y[i]), mn = min(mn, x[i] + y[i]);
    ans = max(ans, mx - mn);
    mx = -INF, mn = INF;
    for(int i = 1; i <= n; i++) mx = max(mx, x[i] - y[i]), mn = min(mn, x[i] - y[i]);
    ans = max(ans, mx - mn);
    cout << ans;
}

Measured memory_bytes: 6784
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0, i##_len=(n); i<i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

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

          cout << max({(a+b),(a-b),(a*b)}) << endl;

          return 0;
}


Measured memory_bytes: 256
[N,D] = list(map(int,input().split()))
X = []
for i in range(N):
    X.append(list(map(int,input().split())))

import math

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

#dis = []
count=0
dammy2=[]
for i in range(N-1):
    for j in range(i+1,N):
        for k in range(D):
            dammy1 = (X[i][k] - X[j][k]) ** 2
            dammy2.append(dammy1)
        if is_integer_num(math.sqrt(sum(dammy2))) == True:
            count+=1
        #dis.append(math.sqrt(sum(dammy2)))
        dammy2 = []

print(count)

Measured memory_bytes: 38484
#include <stdio.h>
int main() {
	char A [5];
	scanf("%s", A);
	
	if(A [1] == 'B') {
		A [1] = 'R';
		printf("%s", A);
	}
	else if(A [1] == 'R') {
		A [1] = 'B';
		printf("%s", A);
	}
	return 0;
}

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

using namespace std;

int main()
{
    int a,b,t,n,total;
    cin>>a>>b>>t;
    n=t/a;
    total=n*b;
    cout<<total<<endl;
	return 0;
}
    //cout<<vector1.at(0)<<" "<<vector1.at(1)<<" "<<vector1.size()<<endl


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

struct node{
  struct node *parent;
  struct node *right;
  struct node *left;
  int key;
};

typedef struct node *Tree;

#define NILL NULL

Tree tree;


void TreeInsert(int k){
  Tree m = NILL;
  Tree l = tree;
  Tree n;

  n = malloc(sizeof(struct node));
  n->key = k;
  n->left = NILL;
  n->right = NILL;

  while(l != NILL){
    m = l;
    if(n->key < l->key){
      l = l->left;
    }
    else{
      l = l->right;
    }
  }
  n->parent = m;
  
  if(m == NILL){
    tree = n;
  }
  else if(n->key < m->key){
    m->left = n;
  }
  else{
    m->right = n;
  }
}

void TreePreorder(Tree n){
  if(n != NILL){
    printf(" %d",n->key); 
    TreePreorder(n->left);
    TreePreorder(n->right);
  }
}

void TreeInorder(Tree n){
  if(n != NILL){
    TreeInorder(n->left);
    printf(" %d",n->key);
    TreeInorder(n->right);
  }
}
Tree TreeMin(Tree n){
  while(n->left != NILL){
    n = n->left;
  }
  return n;
}

Tree TreeSearch(Tree n,int k){
  if(n == NILL || k == n->key){
    return n;
  }
  if(k < n->key){
    return TreeSearch(n->left,k);
  }
  else{
    return TreeSearch(n->right,k);
  }
}

Tree TreeCreate(Tree n){
  Tree m;

  if(n->right != NILL){
    return TreeMin(n->right);
  }
  m = n->parent;
  while(m != NILL && n == m->right){
    n = m;
    m = m->parent;
  }
  return m;
}

void TreeDelete(Tree n){
  Tree m;
  Tree l;

  if(n->left == NILL || n->right == NILL){
    m = n;
  }
  else{
    m = TreeCreate(n);
  }

  if(m->left != NILL){
    l = m->left;
  }
  else{
    l = m->right;
  }

  if(l != NILL){
    l->parent = m->parent;
  }

  if(m->parent == NILL){
    tree = l;
  }
  else if(m == m->parent->left){
    m->parent->left = l;
  }
  else{
    m->parent->right = l;
  }

  if(m != n){
    n->key = m->key;
  }
}

int main(){
  int n,i,j;
  char command[10];
  scanf("%d",&n);

  for(i - 0;i < n;i++){
    scanf("%s",command);
    if(command[0] == 'i'){
      scanf("%d",&j);
      TreeInsert(j);
    }
    else if(command[0] == 'p'){
      TreeInorder(tree);
      printf("\n");
      TreePreorder(tree);
      printf("\n");
    }
    else if(command[0] == 'f'){
      scanf("%d", &j);
      Tree temp = TreeSearch(tree,j);
      if(temp != NILL)printf("yes\n");
      else printf("no\n");
    }
    else if(command[0] == 'd'){
      scanf("%d",&j);
      TreeDelete(TreeSearch(tree,j));
    }
  }
  return 0;
}

Measured memory_bytes: 19364
using System;
class Program
{
    static void Main(string[] args)
    {
        string s = ReadStr();
        int n = s.Length;
        int a = 0;
        for(int i = 0; i < n; i++)
        {
            if (s[i] == ((i % 2 == 0) ? '0' : '1')) { a++; }
        }
        Write(min(a,n-a));
    }

    static void Write(string s) { Console.WriteLine(s); return; }
    static void Write(int n) { Console.WriteLine(n.ToString()); return; }
    static string ReadStr() { return Console.ReadLine(); }
    static string[] ReadStrs() { return Console.ReadLine().Split(' '); }
    static int Read() { return int.Parse(Console.ReadLine()); }
    static int[] Read(int n)
    {
        int[] p = new int[n];
        string[] t = Console.ReadLine().Split(' ');
        for(int i = 0; i < n; i++) { p[i] = int.Parse(t[i]); }
        return p;
    }
    static int abs(int n) { return (n > 0) ? n : -n; }
    static int gcd(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = gcd(p, n[i]); } return p; }
    static int gcd(int a, int b) { return (a==0)?b:gcd(b % a, a); }
    static int lcm(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = lcm(p, n[i]); } return p; }
    static int lcm(int a, int b) { return a * b / gcd(a, b); }
    static int max(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p>n[i])?p:n[i]; } return p; }
    static int min(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p<n[i])?p:n[i]; } return p; }
}


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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define make0(a) memset(a,0,sizeof(a))
#define make1(a) memset(a,-1,sizeof(a))
#define ALL(v) v.begin(),v.end()
#define pi pair <int,int>
#define pll pair <ll,ll>
#define fast_cin() ios_base::sync_with_stdio(0)

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

const int mod = 1e9+7;



int main()
{
	fast_cin();
	int n, m;
	cin >> n;
	int d[n + 1];
	map <int, int> mp;
	for(int i = 1; i <= n; i++)
	{
		cin >> d[i];
		if(mp.find(d[i]) != mp.end())
			mp[d[i]] ++;
		else
			mp[d[i]] = 1;
	}
	cin >> m;
	int t[m + 1];
	bool ans = true;
	for(int i = 1; i <= m; i++)
	{
		cin >> t[i];
		if(mp.find(t[i]) == mp.end() or mp[t[i]] == 0)
			ans = false;
		// trace(mp[t[i]]);
		mp[t[i]] --;
	}
	cout << (ans == true ? "YES":"NO");
	cout << endl;


	return 0;
}

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

int main()
{
  double N;
  cin >> N;
  const double PI = acos(-1);
  cout << 2 * PI * N << endl;
}

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

int main() {
  char A[200100];

  cin >> A;
  int N = strlen(A);

  int apos = 0;
  while (A[apos] != 'A') {
    ++apos;
  }

  int zpos = N - 1;
  while (A[zpos] != 'Z') {
    --zpos;
  }

  int ans = zpos - apos + 1;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
l, r = map(int, input().split())
m = 2019
l, r = l%m, l%m+(r-l)
if r-l >= m-1:
    print(0)

else:
    mi = 2018
    for i in range(l, r):
        for j in range(i+1, r+1):
            m = (i*j)%2019
            mi = min(m, mi)
    print(mi)


Measured memory_bytes: 3060
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    s = list(input()[:-1])
    abc = list('ABC'.encode())
    ans = 0
    for i in range(n - 2):
        if s[i: i + 3] == abc:
            ans += 1
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38384
s=list(input())

for i in range(len(s)):
  if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
    s[i]=1
  else:
    s[i]=0

if s.count(1) == 0:
  print(0)
  exit()

n=0
for i in range(len(s)):
  if s[i] == 1:
    s[i]=n
    n += 1
  else:
    n = 0
    s[i]=n

print(max(s)+1)

Measured memory_bytes: 3064
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
#define N (ll)(1e6+3)
#define INF (ll)(1e18+3)
#define MOD (ll)(1e9+7)
 
#define ll long long
#define rep(i,a,n) for(ll i = a; i < n; i++)
#define per(i,a,n) for(ll i = n-1; i >= a; i--)
 
//using namespace __gnu_pbds;
using namespace std;
 
// typedef
// tree<
//     pair<ll,ll>,
//     null_type,
//     less<pair<ll,ll>>,
//     rb_tree_tag,
//     tree_order_statistics_node_update>
// ordered_set;

ll a[N];

void solve() {
    ll n; cin >> n;
    ll sum = 0;
    rep(i,0,n) {
        cin >> a[i];
        sum += a[i];
    }
    ll cur = 0;
    ll ans = INF;
    rep(i,0,n) {
        cur += a[i];
        if (i < n-1) {
            ans = min(abs(cur-(sum-cur)),ans);
        }
    }
    cout << ans << endl;
}
 
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

long double dfs(int v, int par, int d, long double p,
                vector<int> &cnt, const vector< vector< pair<int,int> > > &t){
  cnt[d]++;
  long double res = 0;
  for(int i=0;i<t[v].size();i++){
    pair<int,int> e = t[v][i];
    int u = e.first, c = e.second;
    if(u==par) continue;
    res += (dfs(u,v,d+1,p,cnt,t) + c) * p;
  }
  return res;
}

int main(){
  long double p; cin >> p;
  int n; cin >> n;
  vector< vector< pair<int,int> > > t(n);
  rep(i,n-1){
    int a,b,c;
    cin >> a >> b >> c; a--; b--;
    t[a].push_back(MP(b,c));
    t[b].push_back(MP(a,c));
  }
  vector<int> cnt(n,0);
  cnt[0]++;
  long double exp = dfs(0,-1,0,p,cnt,t);

  long double ans = 0, k = 1;
  rep(i,n){
    ans += exp*cnt[i]*k;
    k *= p;
  }
  cout << fixed << setprecision(9) << ans << endl;
}

Measured memory_bytes: 19788
H, W = map(int, input().split())
X = [input() for _ in range(H)]

grid0 = [[0] * (W + 1) for _ in range(H + 1)]
for i in range(H):
    for j in range(W):
        grid0[i + 1][j + 1] = int(X[i][j] == ".")

# Left to right
for i in range(H + 1):
    for j in range(W):
        if grid0[i][j + 1] > 0:
            grid0[i][j + 1] += grid0[i][j]

# Right to left
for i in range(H + 1):
    for j in reversed(range(W)):
        if grid0[i][j] > 0:
            grid0[i][j] = max(grid0[i][j], grid0[i][j + 1])

grid1 = [[0] * (W + 1) for _ in range(H + 1)]
for i in range(H):
    for j in range(W):
        grid1[i + 1][j + 1] = int(X[i][j] == ".")

# Top to down
for i in range(H):
    for j in range(W + 1):
        if grid1[i + 1][j] > 0:
            grid1[i + 1][j] += grid1[i][j]

# Down to top
for i in reversed(range(H)):
    for j in range(W + 1):
        if grid1[i][j] > 0:
            grid1[i][j] = max(grid1[i][j], grid1[i + 1][j])

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, grid0[i + 1][j + 1] + grid1[i + 1][j + 1] - 1)

print(ans)


Measured memory_bytes: 143132
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n;
    cin>>n;
    vector<ll> a(2*n);
    for(int i=0;i<n*2;i++){cin>>a[i];}
    sort(a.begin(),a.end());
    ll ans=0;
    for(int i=0;i<n;i++){ans+=a[i*2];}
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
import           Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  let n' = 2 ^ n
  as <- replicateM n' readLn :: IO [Int]
  print $ solve as

solve as
  | length as == 1 = head as
  | otherwise = solve (go as)
  where
    go [] = []
    go (x:y:zs)
      | x == y = x:go zs
      | otherwise = abs (x - y) : go zs


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

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

	if (s == "Sunny") {
		ans = "Cloudy";
	}
	else if (s == "Cloudy") {
		ans = "Rainy";
	}
	else {  // Rainy
		ans = "Sunny";
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  string S; cin >> S;
  int zero=0;
  int one=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='0'){
      zero++;
    }
    else one++;
  }
  cout << min(zero, one)*2 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n, ans;
    cin >> n;
    for (int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        ans += (r - l + 1);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

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


int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    
    ll ans = 0;
    rep(i,N){
        cin >> A[i];
        if(i != 0){
            if(A[i] <= A[i-1]){
                ll diff = A[i-1] - A[i];
                ans += diff;
                A[i] += diff;
            }
        }
    }

    cout << ans << endl;


}




Measured memory_bytes: 4800
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> num(1e6+10, 0);
    for(ll i=0;i<n;++i){
        cin>>a[i];
        num[a[i]]++;
    }

    bool x = true, y = true;
    vector<bool> era(1e6+10, true);
    for(ll i=2;i<=1e6;++i){
        if(era[i]){
            ll co = 0;
            for(ll j=i;j<=1e6;j+=i){
                co += num[j];
                era[j] = false;
            }
            if(co > 1){
                x = false;
            }
            if(co == n){
                y = false;
            }
        }
    }

    if(x){
        cout<<"pairwise coprime"<<endl;
    }else if(y){
        cout<<"setwise coprime"<<endl;
    }else{
        cout<<"not coprime"<<endl;
    }

    return 0;
}

Measured memory_bytes: 20608
using System;
using System.Collections;
using System.Collections.Generic;

namespace A
{
    class Program
    {
        public class TupleList<T1, T2, T3> : List<Tuple<int, int, string>>
        {
            public void Add(int item1, int item2, string s)
            {
                Add(new Tuple<int, int, string>(item1, item2, s));
            }
        }
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            string[] second_input = Console.ReadLine().Split(' ');
            char[] dislike_number = new char[k];
            for(int i = 0; i< k; i++)
            {
                dislike_number[i] = char.Parse(second_input[i]);
            }

            while (true)
            {
                string n_string = n.ToString();
                for(int i = 0; i< k; i++)
                {
                    for (int j = 0; j < n_string.Length; j++)
                    {
                        if (n_string[j] == dislike_number[i]) goto fail;
                    }
                }

                Console.WriteLine(n);
                break;
            fail: n++;
            }
        }
    }
}


Measured memory_bytes: 5208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int cnt = 0;

            for (int i = 0; i < n; i++)
            {
                int input = int.Parse(Console.ReadLine());

                bool isPrime = true;

                if (input < 2) isPrime = false;
                else if (input == 2) isPrime = true;
                else if (input % 2 == 0) isPrime = false;
                else
                {
                    for (int j = 3; j <= Math.Sqrt(input); j++)
                    {
                        if (input % j == 0) isPrime = false;
                    }
                }

                if (isPrime) cnt++;
            }

            Console.WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 9024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
	int N,i,ans=0,ans2=0;
	int* score;
	vector<int> v;
	cin>>N;
	score = new int [N];
	for(i=0;i<N;i++){
		cin>>score[i];
		ans += score[i];
		v.push_back(score[i]);
	}
	if(ans % 10 != 0){
		cout<<ans<<endl;
		return 0;
	}
	ans2=ans;

	sort(v.begin(),v.end());
	for(i=0;i<N;i++){
		ans -= v[i];
		if(ans % 10 != 0){
			break;
		}
	}

	for(i=0;i<N;i++){
		if(v[i]%10 == 0){
			continue;
		}
		ans2 -= v[i];
		if(ans2 % 10 != 10){
			break;
		}
	}
	if(ans2 > ans && ans2%10 != 0){
		ans = ans2;
	}
	cout<<ans<<endl;


	return 0;

}

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

int main() {
  int t, n;

  while(cin >> t, t) {
    int ans = 0; 
    cin >> n;
    for(int i = 0; i < n; i++) {
      int s, f;
      cin >> s >> f;
      ans += f-s;
    }
    if(ans >= t) cout << "OK" << endl;
    else cout << t-ans << endl;
  }
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N, K;
    cin >> N >> K;
    vector<lli> h;
    lli x;
    for (int i = 0; i < N; i++)
    {
        cin >> x;
        h.push_back(x);
    }
    vector<lli> hcopy;
    hcopy = h;
    sort(h.begin(), h.end());
    sort(hcopy.begin(), hcopy.end());
    hcopy.erase(unique(hcopy.begin(), hcopy.end()), hcopy.end());
    if (hcopy.size() == N - K)
    {
        cout << "0" << endl;
        return 0;
    }
    else
    {
        lli minx = h[K - 1] - h[0];
        vector<lli> hd;
        for (int i = 0; i < N - K + 1; i++)
        {
            /*for (int j = i; j <= i + K - 1; j++)
            {
                hd.push_back(h[j]);
            }*/
            lli max = h[i + K - 1];
            lli tmp = h[i];
            minx = min(max - tmp, minx);
            //hd.erase(hd.begin(), hd.end());
        }
        cout << minx << endl;
    }
    return 0;
}

Measured memory_bytes: 1908
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 200005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1e9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll knapSack(ll W, ll wt[], ll val[], ll n) 
{ 
    ll i, w; 
    ll K[n + 1][W + 1]; 
  
    // Build table K[][] in bottom up manner 
    for (i = 0; i <= n; i++) { 
        for (w = 0; w <= W; w++) { 
            if (i == 0 || w == 0) 
                K[i][w] = 0; 
            else if (wt[i - 1] <= w) 
                K[i][w] = max( 
                    val[i - 1] + K[i - 1][w - wt[i - 1]], 
                    K[i - 1][w]); 
            else
                K[i][w] = K[i - 1][w]; 
        } 
    } 
  
    return K[n][W]; 
} 
signed main() {
	fast
	ll n, w;
	//scanf("%d%d", &n, &w);
	cin >> n >> w;
	ll wi[n], vi[n];
	loop(i, n)	cin >> wi[i] >> vi[i];
	//vector<vector<ll>> dp(n, vector<ll>(w + 1, -1));
	cout << knapSack(w,wi,vi,n) << END ;



//#ifndef ONLINE_JUDGE
//	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
//#endif
	return 0;
}


Measured memory_bytes: 79232
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include "fstream"
using namespace std;
#define PI acos(-1)
#define MOD (ll)1000000007
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-8
void display(vector<ll> v1){loop(i,v1.size()){cout<<v1[i]<<" ";}cout<<endl;}
ll dx[8] = {0,1,0,-1,1,1,-1,-1};
ll dy[8] = {1,0,-1,0,1,-1,1,-1};

//Jai Shree Krishna
//:) :) :( :( :( :( :( :( :) :( :)
//Purple Dreams ??? 
//Shit ;More Shit and Hell lot of Shit and Still Shit 



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

    ll n;
    cin>>n;
    ll odd = 0 ;
    loop2(i, n)
    {
        ll x;
        cin>>x;
        if(x&1)
        {
            odd+=1;
        }
    }
    
    if(odd%2==0)
    {
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
S=input()
flg = True
for i in range(len(S)):
    if len(S)%2 == 1:
        flg = False
        break
    if i%2==0:
        if S[i]+S[i+1] != "hi":
            flg = False

if flg == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int H, W, t[20][20];
int dy[] = {0, 1}, dx[] = {1,0}; // 横　縦

int judge(int y, int x){
  map<int, int>m;
  for(int i = -1; i < 1; i++){
    for(int j = -1; j < 1; j++){
      int ny = y+i, nx = x+j;
      if(ny < 0 || nx < 0 || t[ny][nx] == -1 || m.count(t[ny][nx])) continue;
      m[t[ny][nx]] = 1;
    }
  }
  if(m.size() < 4) return 1;
  return 0;
}

int dfs(int n){
  int i, j, res = 0;
  for(i = 0; i < H; i++) for(j = 0; j < W; j++) if(t[i][j] == -1) goto b;
 b:

  if(i == H && j == W) return 1;

  int tmp[20][20];
  rep(i, H) rep(j, W) tmp[i][j] = t[i][j];

  t[i][j] = n;
  rep(d, 2){
    int x = j+dx[d], y = i+dy[d];
    if(x < 0 || x >= W || y < 0 || y >= H || t[y][x] != -1) continue;
    t[y][x] = n;
    if(judge(i, j)) res += dfs(n+1);
    t[y][x] = -1;
  }
  rep(i, H) rep(j, W) t[i][j] = tmp[i][j];

  return res;
}

int main(){
  while(scanf("%d%d", &H, &W) && H+W){
    memset(t, -1, sizeof(t));
    printf("%d\n", dfs(0));
  }
  return 0;
}

Measured memory_bytes: 1516
using System;

namespace ITP1_9_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string W = Console.ReadLine();
            W = ToLower(W);
            int count = 0;

            while(true)
            {
                string[] str = Console.ReadLine().Split(' ');
                if (str[0] == "END_OF_TEXT")
                    break;

                for(int i = 0; i < str.GetLength(0); ++i)
                {
                    if (ToLower(str[i]) == W)
                        count += 1;
                }
            }

            Console.WriteLine("{0}", count);
        }

        static string ToLower(string str)
        {
            string Ans = "";
            for(int i = 0; i < str.Length; i++)
            {
                if (char.IsUpper(str[i]))
                    Ans += char.ToLower(str[i]);
                else
                    Ans += str[i];
            }
            return Ans;
        }
    }
}

Measured memory_bytes: 5648
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}

	var cnt int
	for _, a := range as {
		for {
			if a%2 == 0 {
				a = a / 2
				cnt++
			} else {
				break
			}
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 2580
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
vector <vector<int>> dp(3010,vector <int>(3010));
vector <int> a(3010);
int solve(int l, int r, bool p){
    if(l == r){
        if(p == 1) return - (dp[l][l] = a[l]);
        else return dp[l][l] = a[l];
    }
    if(dp[l][r]){
        return dp[l][r];
    }
    if(p == 1){
        return dp[l][r] = min( solve(l+1,r,0) - a[l], solve(l, r-1,0) - a[r]);
    }else{
        return dp[l][r] = max(solve(l+1, r, 1) + a[l], solve(l, r-1, 1) + a[r]);
    }
}
signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    int l = 0, r = n-1;
    rep(i,n) cin>>a[i];
    solve(l, r, 0);
    cout<<solve(l, r, 0)<<endl;
    //cout<<dp[l][r]<<endl;
}


Measured memory_bytes: 71296
// AOJ 2727: M and A
// 2017.10.8 bal4u@uu

#include <stdio.h>

char s[10001], t[1001];
char a[2][502];

int main()
{
	int i;
	char *p, *q, *q1;

	scanf("%s%s", s, t);
	p = s, q = a[0], q1 = a[1];
	while (*p) {
		*q++ = *p++;
		if (*p) *q1++ = *p++;
	}
	*q = *q1 = 0;
	for (i = 0; ; i++) {
		if (i == 2) { puts("No"); break; }
		p = t; q = a[i];
		while (*p && *q) {
			if (*p == *q) q++;
			p++;
		}
		if (!*q) { puts("Yes"); break; }
	}
	return 0;
}

Measured memory_bytes: 1716
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w,m;
string s[1000],s1,s2;
//vvl v;
//vl vis,d;


int main() {
    IOS;
    cin>>x>>y;
    if((x+y)%2==1)cout<<"IMPOSSIBLE";
    else cout<<(x+y)/2;
    return 0;
}


Measured memory_bytes: 256
N=int(input())
testimony=[[-1]*N for i in range(N)]
count=0
for i in range(N):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        testimony[i][x-1]=y
for i in range(1<<N):
    honest=[0]*N
    for j in range(N):
        if (i>>j)&1:
            honest[j]=1
    flag=True
    for j in range(N):
        if honest[j]:
            for k in range(N):
                if testimony[j][k]==-1:
                    continue
                if testimony[j][k]!=honest[k]:
                    flag=False
    if flag:
        count=max(count,honest.count(1))
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define R register
#define ll long long
#define mp make_pair
#define pii pair<int, int>
using namespace std;
const int mod = 1e9 + 7;

int n;
ll ans = 1;

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    int r = 0, g = 0, b = 0, x;
    read(n);
    for (R int i = 1; i <= n; ++i) {
        read(x);
        (ans *= (x == r) + (x == g) + (x == b)) %= mod;
        if (x == r) ++r;
        else if (x == g) ++g;
        else ++b;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256