akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

void dfs(int v, int color_v, vector<int> &colors,
         const vector<vector<int>> &adj) {
  if (colors[v] != -1) {
    assert(colors[v] == color_v);
    return;
  }
  colors[v] = color_v;
  for (int u : adj[v])
    dfs(u, 1 - color_v, colors, adj);
}

vector<vector<int>> get_colors(int n, int d) {
  vector<vector<int>> adj(n * n);
  for (int y = 0; y < n; ++y)
    for (int x = 0; x < n; ++x) {
      int y_low = y, y_high = y;
      for (int x2 = n - 1; x2 >= x; --x2) {
        while (y_low >= 0 &&
               (x2 - x) * (x2 - x) + (y_low - y) * (y_low - y) < d)
          --y_low;
        while (y_high < n &&
               (x2 - x) * (x2 - x) + (y_high - y) * (y_high - y) < d)
          ++y_high;

        if (x2 > x && y_low >= 0 &&
            (x2 - x) * (x2 - x) + (y_low - y) * (y_low - y) == d) {
          adj[y * n + x].push_back(y_low * n + x2);
          adj[y_low * n + x2].push_back(y * n + x);
        }
        if (y_high != y && y_high < n &&
            (x2 - x) * (x2 - x) + (y_high - y) * (y_high - y) == d) {
          adj[y * n + x].push_back(y_high * n + x2);
          adj[y_high * n + x2].push_back(y * n + x);
        }
      }
    }

  vector<int> colors(n * n, -1);
  for (int v = 0; v < n * n; ++v)
    if (colors[v] == -1)
      dfs(v, 0, colors, adj);

  vector<vector<int>> result(n, vector<int>(n));
  for (int y = 0; y < n; ++y)
    for (int x = 0; x < n; ++x)
      result[y][x] = colors[y * n + x];
  return result;
}

int main() {
  int n, d1, d2;
  scanf("%d %d %d", &n, &d1, &d2);
  n *= 2;
  vector<vector<int>> colors_d1 = get_colors(n, d1);
  vector<vector<int>> colors_d2 = get_colors(n, d2);

  map<pair<int, int>, vector<pair<int, int>>> points_with_colors;
  for (int y = 0; y < n; ++y)
    for (int x = 0; x < n; ++x)
      points_with_colors[{colors_d1[y][x], colors_d2[y][x]}].emplace_back(y, x);

  vector<pair<int, int>> result =
    max_element(points_with_colors.begin(), points_with_colors.end(),
                [](const auto &kv1, const auto &kv2) {
                  return kv1.second.size() < kv2.second.size();
                })->second;

  assert((int)result.size() >= n * n / 4);
  result.resize(n * n / 4);

  for (const pair<int, int> &point : result)
    printf("%d %d\n", point.first, point.second);

  return 0;
}


Measured memory_bytes: 76160
#include<cstdio>
#include<cstring>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 200010
#define INF 0x3FFFFFFF
using namespace std;
int h,w;
int a[MAXN],b[MAXN];
int ans;
struct node{
	int minv,tag;	
}tr[MAXN*4];
void pushdown(int id){
	if(tr[id].tag){
		tr[id<<1].tag=tr[id].tag;
		tr[id<<1].minv=tr[id].tag;
		tr[id<<1|1].tag=tr[id].tag;
		tr[id<<1|1].minv=tr[id].tag;
		tr[id].tag=0;
	}
}
void pushup(int id){
	tr[id].minv=min(tr[id<<1].minv,tr[id<<1|1].minv);
}
void change(int pl,int pr,int val=INF,int l=1,int r=w,int id=1){
	if(l!=r)
		pushdown(id);
	if(l>=pl&&r<=pr){
		tr[id].tag=val;
		tr[id].minv=val;
		return ;
	}
	int mid=(l+r)>>1;
	if(mid>=pl)
		change(pl,pr,val,l,mid,id<<1);
	if(mid<pr)
		change(pl,pr,val,mid+1,r,id<<1|1);
	pushup(id);
}
int query1(int pl,int pr,int l=1,int r=w,int id=1){
	if(l!=r)
		pushdown(id);
	if(pl<=l&&r<=pr)
		return tr[id].minv;	
	int mid=(l+r)>>1;
	int ans=INF;
	if(mid>=pl)
		ans=min(ans,query1(pl,pr,l,mid,id<<1));
	if(mid<pr)
		ans=min(ans,query1(pl,pr,mid+1,r,id<<1|1));
	return ans;
}
int query(int pl,int pr,int l=1,int r=w,int id=1){
	if(l!=r)
		pushdown(id);
	if(tr[id].minv==INF)
		return INF;
	if(l==r){
//		PF("[%d %d]\n",l,tr[id].minv+pr-l+1);
		return tr[id].minv+pr-l+1;
	}
	int mid=(l+r)>>1;
	int ans=INF;
	if(mid<pr)
		ans=query(pl,pr,mid+1,r,id<<1|1);
	if(ans!=INF)
		return ans;
	if(mid>=pl)
		ans=query(pl,pr,l,mid,id<<1);
	return ans;
}
int main(){
	SF("%d%d",&h,&w);
	for(int i=0;i<h;i++)
		SF("%d%d",&a[i],&b[i]);
	for(int i=0;i<h;i++){
//		if(i==2)PF("*%d(%d) %d*\n",query1(b[i]+1,b[i]+1),b[i]+1,query1(a[i],b[i]));
		if(b[i]!=w&&query1(b[i]+1,b[i]+1)==INF&&query1(a[i],b[i])<INF){
			int ans1=query(a[i],b[i]);	
			change(b[i]+1,b[i]+1,ans1);
		}
		change(a[i],b[i]);
		if(tr[1].minv==INF)
			PF("-1\n");
		else
			PF("%d\n",tr[1].minv+i+1);
	}
}

Measured memory_bytes: 7360
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int l,i,k=0;
  cin>>s;
  l=s.length();
  for(i=0;i<l/2;i++) if(s.at(i)!=s.at(l-1-i)) k++;
  cout<<k<<endl;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
S=input()
ans=str()

for i in range(N):
    if i!=K-1:
        ans=ans+S[i]
    else:
        if S[K-1]=="A":
            ans=ans+"a"
        if S[K-1]=="B":
            ans=ans+"b"
        if S[K-1]=="C":
            ans=ans+"c"

print(ans)

Measured memory_bytes: 3060
// Last Change:   11/29/2018 18:25:08.
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <list>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, i;
  cin >> N >> i;
  cout << N - i + 1 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String p = sc.next();
    char[] s = new char[n];
    int d = 1;
    for(int i = 0;i<n;i++){
      s[i] = p.charAt(i);
    }
    for(int i = 0;i<n-1;i++){
      if(s[i]!=s[i+1]){
        d++;
      }
    }
    System.out.println(d);
  }
}


Measured memory_bytes: 26524
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=105;
//i_am_noob
int a[3];

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	rep(3) cin >> a[i];
	sort(a,a+3);
	if(a[0]==a[1]&&a[1]==a[2]) print1("No");
	else if(a[0]==a[1]) print1("Yes");
	else if(a[1]==a[2]) print1("Yes");
	else print1("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;

int main(){
	int H,W,N;
	cin>>H>>W>>N;
	pair<int,int> pos[N];
	for(int i=0;i<N;i++){
		cin>>pos[i].first>>pos[i].second;
	}
	sort(pos,pos+N);
	int k=0;
	for(int i=0;i<N;i++){
		if(pos[i].second<=pos[i].first-1-k){
			cout<<pos[i].first-1<<endl;
			return 0;
		}
		if(pos[i].second==pos[i].first-k){
			k++;
		}
	}
	cout<<H<<endl;
	
	
	return 0;
}


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

int main() {
    int h, w;
    cin >> h >> w;

    for (int i = 0; i < w + 2; i++) cout << "#";
    cout << endl;

    for (int i = 0; i < h; i++) {
        cout << "#";

        string a;
        cin >> a;
        cout << a;
        
        cout << "#" << endl;
    }

    for (int i = 0; i < w + 2; i++) cout << "#";
    cout << endl;
}

Measured memory_bytes: 256
from itertools import permutations
n = int(input())
x,y=[],[]
for i in range(n):
    X,Y=map(int,input().split())
    x.append(X)
    y.append(Y)
kaijo=1
for i in range(1,n+1):
    kaijo *= i
t = [i for i in range(1,n+1)]
ans=0
#print(t)
for i in list(permutations(t)):
    for j in range(n-1):
        #print(i[j+1])
        i = list(i)
        ans+=((x[i[j]-1]-x[i[j+1]-1])**2+(y[i[j]-1]-y[i[j+1]-1])**2)**0.5
print(ans/kaijo)

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_cs(i, l, n) for (int i = (l); i <= n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(v.begin(), v.end());
// int sum = accumulate(v, v + v.size(), 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;
Graph G;
vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

int main()
{
    ll n, d;
    cin >> n >> d;
    if (n % (2 * d + 1) == 0)
    {
        cout << n / (2 * d + 1) << endl;
    }
    else
    {
        cout << n / (2 * d + 1) + 1 << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
a = [int(k) for k in input().split()]
cnt = 0
for i in range(n-2):
  if a[i] < a[i+1] and a[i+1] < a[i+2]:cnt += 1
  elif a[i] > a[i+1] and a[i+1] > a[i+2]:cnt += 1
print(cnt)


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

using namespace std;

typedef long long ll;

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

	int a, b, c, x;
	cin >> a >> b >> c >> x;

	int ans = 0;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			int rem = x - i * 500 - j * 100;
			if(rem % 50 != 0 || rem < 0) continue;
			if(rem / 50 <= c) ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
A, B, C, D = list(map(int,input().split(' ')))
#print(A,B,C,D)


a = set(range(A,B+1))
b = set(range(C,D+1))
x = list(a & b)
if x:
  print(x[-1]-x[0])
else:
  print(0)

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

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            String S = sc.next();

            int ans = Arrays.asList("SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN").indexOf(S) + 1;

            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 21588
H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if j==0 and S[i][j]==".":
            L[i][j] = 1
        elif j>0 and S[i][j]==".":
            L[i][j] = L[i][j-1]+1
        if i==0 and S[i][j]==".":
            U[i][j] = 1
        elif i>0 and S[i][j]==".":
            U[i][j] = U[i-1][j]+1
for i in range(H-1,-1,-1):
    for j in range(W-1,-1,-1):
        if j==W-1 and S[i][j]==".":
            R[i][j] = 1
        elif j<W-1 and S[i][j]==".":
            R[i][j] = R[i][j+1]+1
        if i==H-1 and S[i][j]==".":
            D[i][j] = 1
        elif i>0 and S[i][j]==".":
            D[i][j] = D[i+1][j]+1
cmax = 0
for i in range(H):
    for j in range(W):
        cmax = max(cmax,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(cmax)            

Measured memory_bytes: 183940
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????? I

?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????
   +--+
 ???|???|
+--+--+--+--+
|???|???|???|???|
+--+--+--+--+
 ???|???|
   +--+

"""
class Dice:
    """ ????????????????????? """
    def __init__(self):                  # ?????????????????????
        self.side = [1, 2, 3, 4, 5, 6]

    def setDice(self, arr):  # ??¢??????????????????
        self.side = arr[0:6]

    def Turn(self, dir):
        s = self.side

        if dir == "N":     # ????????¢??????
            t = [s[1],s[5],s[2],s[3],s[0],s[4]]
        elif dir == "S": # ????????¢??????
            t = [s[4],s[0],s[2],s[3],s[5],s[1]]
        elif dir == "E": # ??±?????¢??????
            t = [s[3],s[1],s[0],s[5],s[4],s[2]]
        elif dir == "W": # ?\??????¢??????
            t = [s[2],s[1],s[5],s[0],s[4],s[3]]

        self.side = t




num = list(map(int,input().strip().split()))
cmd = input().strip()
d = Dice()
d.setDice(num)
for c in cmd:
    d.Turn(c)
#    print("{0} {1}".format(c,d.side[0]))
print(d.side[0])

Measured memory_bytes: 7808
N = int(input())
ans = []
n = 2 * (N // 2)
for x in range(1, n + 1):
    for y in range(x + 1, n + 1):
        if x + y != n + 1:
            ans += [[x, y]]
if N % 2:
    for x in range(1, N):
        ans += [[x, N]]
print(len(ans))
for edge in ans:
    print(*edge)


Measured memory_bytes: 4124
N, M = map(int, input().split())
A = [input() for _ in range(N)]
# print(A)

B = [input() for _ in range(M)]
# print(B)

ans = "No"
for i in range(N-M+1):
    for j in range(N-M+1):
        check = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    check = False
        if check == True:
            ans = 'Yes'
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)

const int NR = 1e5 + 100;

vector<int> e[NR];
int n, m, col[NR], C[2];
bool bi;

void dfs(int x, bool c) {
	col[x] = c; ++C[c];
	for (int v : e[x]) {
		if (col[v] == -1) {
			dfs(v, !c);
		} else if (col[x] == col[v]) {
			bi = false;
		}
	}
}

int main() {
	//freopen("11C.in", "r", stdin);
	scanf("%d%d", &n, &m);
	iter(i, m) {
		int x, y;
		scanf("%d%d", &x, &y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	iter(i, n) col[i] = -1;
	int d0 = 0, d1 = 0, d2 = 0;
	iter(i, n) if (col[i] == -1) {
		C[0] = C[1] = 0; bi = true;
		dfs(i, 0);
		if (bi) {
			if (C[1]) ++d2;
			else ++d0;
		} else ++d1;
	}
//	printf("%d %d %d\n", d0, d1, d2);
	printf("%lld\n", 2ll * d0 * n - 1ll * d0 * d0 + 2ll * d2 * d1 + 1ll * d1 * d1 + 2ll * d2 * d2); 
	return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
#define rSORT(a, i) sort(all(a),(i))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;

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

	ll n; cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];

	//map<int, int> map;
	//rep(i, n)map[a[i]]++;

	vector<ll> cnt;
	/*
	for (auto i : map) {
		int len, num;
		tie(len, num) = i;
		while (num >= 2) {
			cnt.push_back(len);
			num -= 2;
		}
	}
	*/

	SORT(a);
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			cnt.push_back(a[i]);
			i++;
		}
	}

	rSORT(cnt, greater<ll>());
	if (cnt.size() >= 2)cout << cnt[0] * cnt[1] << "\n";
	else cout << "0\n";
}	




Measured memory_bytes: 1660
import sys
k,t=[int(i) for i in input().split()]
array=[int(i) for i in input().split()]
array.sort()
array=array[::-1]
max=array[0]
for i in range(1,len(array)):
    max-=array[i]
    if max<=0:
        print(0)
        sys.exit()
print(max-1)

Measured memory_bytes: 3064
n,x=map(int,input().split())
if x==1 or x==2*n-1:
    print("No")
else:
    print("Yes")
    sublists=[(i+n+x)%(2*n-1) for i in range(2*n-1)]
    for some in sublists:
        if some!=0:
            print(some)
        else:
            print(2*n-1)

Measured memory_bytes: 12484
#include <stdio.h>
main()
{
	char x[1000];
	int s=0;
	int c1,c2;
	
	while(1){
		s=0;
		
		for(c1=0;;c1++){
			scanf("%c",&x[c1]);
			if(x[c1]=='\n')break;
		}
		
		for(c2=0;c2<c1;c2++){
			s+=x[c2]-'0';
		}
		if(s==0)break;
		printf("%d\n",s);
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<double> X(N);
  vector<string> U(N);
  
  for(int i = 0; i < N; i++){
    cin >> X.at(i);
    cin >> U.at(i);
  }
  
  double ans = 0.0;
  
  for(int i = 0; i < N; i++){
    if(U.at(i) == "BTC"){
      ans += X.at(i) * 380000.0;
    }
    else
      ans += X.at(i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const ll sp = 132694967;
const ll sp2 = 61438739;

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

    int n = s.size();
    int m = t.size();

    string ss;
    while(ss.size()<m){
        ss += s;
    }
    ss.erase(m);
    int flag[n+10] = {};
    int now = m % n;
    int start = 0;

    ll hash_t = 0; 
    ll hash_ss = 0;
    ll rem = 1;
    rep(i,m){
        rem = (rem*sp2) % sp;
        hash_t += (int)t[m-1-i] * rem;
        hash_t %= sp;
    }
    rem = 1;
    rep(i,m){
        rem = (rem*sp2) % sp;
        hash_ss += (int)ss[m-1-i] * rem;
        hash_ss %= sp;
    }

    rep(i,n){
        if(hash_ss==hash_t)flag[i] = 1;
        hash_ss += sp*sp2 - (int)s[start] * rem + (int)s[now];
        hash_ss %= sp;
        hash_ss *= sp2;
        hash_ss %= sp;
        
        now++;
        now %= n;
        start++;
        start %= n;
    }

    /*
    cout << '1' << endl;
    return 0;
    */

    int ans[n+10] = {};
    rep(i,n){
        if(flag[i]==1){
            int tmp = 1;
            flag[i] = i+10;
            ll ii = i;
            while(true){
                ii += m;
                ii %= n;
                if(flag[ii]==(i+10)){
                    cout << "-1" << endl;
                    return 0;
                }else if(flag[ii]>1){
                    tmp += ans[ii];
                    flag[ii] = i+10;
                    break;
                }else if(flag[ii]==1){
                    tmp++;
                    flag[ii] = i+10;
                    //break;
                }else{
                    break;
                }
            }
            ans[i] = tmp;
        }
    }
    /*
    rep(i,n)cout << flag[i];
    cout << endl;
    */


    int ma = 0;
    rep(i,n){
        ma = max(ans[i],ma);
    }

    cout << ma<< endl;

    return 0;
}
 
 


Measured memory_bytes: 6300
import java.io.*;

public class Main {


    private static String solver(String input) {
        String[] intputArray = input.split("/");
        int year = Integer.parseInt(intputArray[0]);
        int month = Integer.parseInt(intputArray[1]);
        int day = Integer.parseInt(intputArray[2]);

        int dateNum = year * 10000 + month * 100 + day;
        if(dateNum <= 20190430){
            return "Heisei";
        }else{
            return "TBD";
        }
    }


    public static void main(String[] args) {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);
        String input = "";
        try {
            input = br.readLine();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(solver(input));

    }
}

Measured memory_bytes: 22740
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final double[] ps = new double[n + 1];
        for (int i = 1; i <= n; i++) {
            ps[i] = in.nextDouble();
        }
        // [win count][current]
        double[][] dp = new double[n + 1][n + 1];
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            dp[0][i] = dp[0][i - 1] * (1 - ps[i]);
        }

        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j++) {
                double f1 = dp[i - 1][j - 1] * ps[j];
                double f2 = dp[i][j - 1] * (1 - ps[j]);
                dp[i][j] = f1 + f2;
            }
        }
        double result = 0;
        for (int i = n / 2 + 1; i <= n; i++) {
            result += dp[i][n];
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 122912
A,B,C = map(int,input().split())
if A%2 == 1 or B%2 == 1 or C%2 == 1:
    print(0)
elif A == B == C:
    print(-1)
else:
    def Base_10_to_n(X, n):
        if X//n:
            return Base_10_to_n(X//n, n)+str(X%n)
        return str(X%n)
    A = Base_10_to_n(A, 2)[::-1]
    B = Base_10_to_n(B, 2)[::-1]
    C = Base_10_to_n(C, 2)[::-1]
    ans = 0
    for i in range(min(len(A),len(B),len(C))):
        if A[i] == B[i] == C[i]:
            ans += 1
        else:
            break
    print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> indexed_set_pair;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

void solve() {
    int x,n;
    cin>>x>>n;
    unordered_map<int,bool> mp;
    int p;
    REP(i,1,n) {
        cin>>p;
        mp[p] = true;
    }
    int ans = -1;
    REP(i,0,110) {
        if(!mp[i]) {
            if(abs(ans-x)>abs(i-x)) {
                ans = i;
            }
        }
    }
    cout<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 3660
def search(arr, n, idx)
  (idx..17-n).each do |t|
    return t if arr[t, n].all?{|v| v <= 0}
  end
  nil
end

tt = [0]*17
q = []
res = [-1]*100
(0..1000).each do |i|
  break if q.empty? && res.all?{ |v| v != -1 }
  tt.map!{|j| j - 1 }
  until q.empty?
    idx = 0
    if t = search(tt, x = q[0][1], idx)
      id, n, c, s = q.shift
      tt.fill(c, t, x)
      res[id] = i - s
      idx = t + x
    else break
    end
  end
  if i % 5 == 0 && i < 500
    m = ((i/5)%5 == 1 ? 5 : 2)
    eat = 17 * ((i/5)%2) + 3 * ((i/5)%3) + 19
    if q.empty?
      if t = search(tt, m, 0)
        tt.fill(eat, t, m)
        res[i/5] = 0
      else
        q << [i/5, m, eat, i]
      end
    else q << [i/5, m, eat, i]
    end
  end
end
while gets
  p res[$_.to_i]
end

Measured memory_bytes: 8748
def a_digits_sum(N):
    def digit_sum(n):  # 非負整数nの各桁の和
        str_n = str(n)
        ret = 0
        for c in str_n:
            ret += int(c)
        return ret

    ans = float('inf')
    for A in range(1, N):
        B = N - A
        ans = min(ans, digit_sum(A) + digit_sum(B))
    return ans

N = int(input())
print(a_digits_sum(N))

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<limits>
#include<algorithm>
#include<numeric>
#include<utility>

using ULLI = unsigned long long int;
using LLI = long long int;

using namespace std;

template<class T>
class ModCal{
private:
    const int MAX = 510000;
    ULLI mod;

    std::vector<T> fac;
    std::vector<T> finv;
    std::vector<T> inv;

    void COMinit() {
        fac.resize(MAX);
        finv.resize(MAX);
        inv.resize(MAX);

        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod%i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
public:
    ModCal(ULLI _mod){
        this->mod = _mod;
        ModCal<T>::COMinit();
    }
    ModCal(){
        this->mod = 0;
    }

    T add(T a, T b){
        T tmp;
        tmp = a + b;
        if(mod != 0) tmp %= mod;
        return tmp;
    }

    T sub(T a, T b){
        T tmp;
        tmp = a - b;
        if(mod != 0){
            if(tmp < 0) tmp += mod;
            tmp %= mod;
        }
        return tmp;
    }

    T mul(T a, T b){
        T tmp;
        tmp = a * b;
        if(mod != 0) tmp %= mod;
        return tmp;
    }

    T modinv(T a, T m){
        T b = m, u = 1, v = 0;
        while (b) {
            T t = a / b;
            a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }

    T div(T a, T b){
        if(mod == 0){
            return a / b;
        }
        a %= mod;
        T tmp = a * ModCal<T>::modinv(b, mod) % mod;
        return tmp;
    }

    T pow(T a, T b){
        T tmp = 1;
        while(b > 0){
            if(mod != 0){
                if(b & 1) tmp = tmp * a % mod;
                a = a * a % mod;
            }else{
                if(b & 1) tmp *= a;
                a *= a;
            }
            b >>= 1;
        }
        return tmp;
    }

    // 以下の関数はMODを設定しない限り使えない
    // 無理やり使う場合は "ModCal<T> cal(Tの最大値)" でオブジェクトを作る
    T com(int n, int k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }

    T fact(int n){
        return fac[n];
    }
};

const ULLI MOD = 7;

struct D{
    int d;
    int idx;

    D(int d,int idx){
        this->d = d;
        this->idx = idx;
    }

    bool operator<(const D &l) const {
        return d < l.d;
    };
};

int main(){
    int r;

    cin >> r;

    cout << r*r << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[300010];
int b[300010];
int sum[300010];
int ans[300010];
int main(){
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        int tmp;cin>>tmp;a[tmp]++;
    }
    int m=0;
    for(int i=1;i<=n;i++){
        if(a[i])b[++m]=a[i];
    }
    sort(b+1,b+m+1);
    for(int i=1;i<=m;i++){
        sum[i]=sum[i-1]+b[i];
    }
    b[m+1]=1e9;
    for(int i=1;i<=m;i++){
        int l=i+1,r=m+1;
        while(l<=r){
            int m1=l+r>>1;
            int tmp=sum[m1-1]/(m1-i);
            //cout<<i<<l<<r<<tmp<<endl;
            if(tmp<=b[m1]){
                ans[m+1-i]=tmp;
                r=m1-1;
            }
            else l=m1+1;
        }
    }
    for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>


int main()
{
    long K,S;
    std::cin >> K >> S;
    long count=0;
    for(long i=0; i<=S; i++){
        if(i<=K && 2*K>=S-i){ //X決定
            if((S-i)<=K){
                count+=(S-i)+1;
                //std::cout << count << std::endl;
            }else{
                count+=(K-(S-i-K)+1);
                //std::cout << count << std::endl;
            }
        }
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
cnt = 0
n = len(s)
al = [0]*(n+1)
ag = [0]*(n+1)
for i in range(n):
    if s[i] == '<':
        al[i+1] = al[i] + 1
for i in range(n-1, -1, -1):
    if s[i] == '>':
        ag[i] = ag[i+1] + 1
a = [x if x > y else y for x, y in zip(al, ag)]
print(sum(a))


Measured memory_bytes: 31908
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	llint K,A,B;cin>>K>>A>>B;
	if(1+K<=A||A+2>=B){cout<<1+K<<endl;return 0;}
	K-=A-1;
	llint ans=A;
	ans+=(B-A)*(K/2);
	if(K%2){ans++;}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  vector<long> a(n),dp(n+1,0);
  map<int,long> mp;
  mp[0]=1;
  for(int i=0;i<n;i++){
    cin>>a[i];
    dp[i+1]=dp[i]+a[i];
    dp[i+1]%=m;
    mp[dp[i+1]]++;
  }
  long ans=0;
  for(auto p:mp){
    ans+=p.second*(p.second-1)/2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
using namespace std;
int main() {
	int N,M;
	string s[110],t[110];
	int x;
	int y = 0;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> s[i];
	}
	cin >> M;
	for(int i = 0; i<M; i++){
		cin >> t[i];
	}
	for(int i =0; i < N; i++){
			x = 0;
		for(int j =i; j < N; j++){
			if(s[i]==s[j]){
				x++;
			}
		}
		for(int j = 0; j < M; j++){
			if(s[i]==t[j]){
				x--;
			}
		}
		if(x>=y){
			y = x;
		}
	}
	cout << y << endl;
}



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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if ((A == B && A == C) || (A != B && B!=C && C!=A)){
        cout << "No" << endl;
    } else{ 
    cout << "Yes" << endl;        
    }
    return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
#include<vector>
#include<algorithm>
struct S{int w,h;}t,x,y,z={0,0};
int A(const S&s){return s.w*s.h;}
int C(const S&l,const S&r){return A(l)<A(r);}
int main()
{
	std::vector<S>v;
	v.reserve(101);
	int n,p,s;
	while(scanf("%d%d%d",&n,&t.w,&t.h),t.h)
	{
		v.clear();
		v.push_back(z);
		v.push_back(t);
		while(n--)
		{
			scanf("%d%d",&p,&s);
			x=y=t=v[p];
			v.erase(v.begin()+p);
			s%=(t.w+t.h);
			if(s>t.w)
				x.h=s-t.w,y.h=t.h-x.h;
			else
				x.w=s,y.w=t.w-s;
			if(C(y,x))std::swap(y,x);
			v.push_back(x);
			v.push_back(y);
		}
		std::sort(v.begin(),v.end(),C);
		for(n=1,s=v.size();n<s;++n)
			printf("%d%c",A(v[n]),s-n-1?' ':'\n');
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
using P = pair<int, int>;
int main() {
    int N, M;
    cin >> N >> M;
    vector2d<int> edge(N);
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> ans(N, -1);
    ans[0] = 0;
    queue<P> q;
    q.push({0, -1});
    while(q.size()) {
        int cur, prev;
        tie(cur, prev) = q.front(); q.pop();
        for(int nxt : edge[cur]) {
            if(nxt == prev || ans[nxt] >= 0) continue;
            ans[nxt] = cur;
            q.push({nxt, cur});
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i < N; i++) {
        cout << ans[i] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 10568
// E - Sequence Decomposing

// 実質的に、最長広義単調減少部分列を求める問題

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int A[100000];
int dp[100001]; // 長さがiであるような広義単調減少列における最終要素の最大値

int main() {
	int N;
	cin >> N;

	for (int i=0; i<N; i++) {
		cin >> A[i];
	}

	fill(dp, dp+N+1, -1);
	dp[0] = INF;

	int ans = 0;
	for (int i=0; i<N; i++) {
		int j = upper_bound(dp, dp+N+1, A[i], std::greater<int>()) - dp;
		dp[j] = A[i];
		ans = max(ans, j);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
N , T = map(int,input().split())
A = list(map(int,input().split()))

m = 10 ** 9
L = [m] * (N)


for i in range(0,N):
  if A[i] <= m:
    m = A[i]
  L[i] = A[i] - m

M = max(L)

print(L.count(M))
  



Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k,p[300000];
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>p[i];
    double a[300000];
    for(int i=0;i<n;i++){
        a[i]=(double(p[i]+1)/double(2));
    }
    double sum=0;
    for(int i=0;i<k;i++){
        sum+=a[i];
    }
    double ans=sum;
    for(int i=k;i<n;i++){
        sum=sum+a[i]-a[i-k];
        ans=max(ans,sum);
    }
    printf("%.10f",ans);
}


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

int main() {
    int N, M;
    cin >> N >> M;
  
  int a[100010],b[100010];
  
    vector<int> nums(N, 1), can(N, 0);
    can[0] = 1;
  
    for (int i = 0; i < M; ++i) {     
      cin >> a[i] >> b[i];
      --a[i], --b[i];
    
        if (can[a[i]]) can[b[i]] = 1;
        if (nums[a[i]] == 1) can[a[i]] = 0;
        nums[a[i]]--;
        nums[b[i]]++;
    }
  
    int res = 0;
    for (int i = 0; i < N; ++i) if (can[i] && nums[i]) ++res;
    cout << res << endl;
}


Measured memory_bytes: 1792
//--- pA ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	public Solution () {
		reader = new Reader();
		while (reader.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// int N = reader.ni();
		String str = reader.ns();
		int cnt_a = 0, cnt_b = 0;
		for (char c : str.toCharArray()) {
			if (c == 'A') {
				cnt_a ++;
			} else {
				cnt_b ++;
			}
		}
		boolean res = cnt_a == 0 || cnt_b == 0;
		if (res) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
		return;
	}
}

class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public String ns() {return this.next();}
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
#define l long long
l hcf(l a,l b)
{
  if(b==0)
    return a;
  else
    return hcf(b,abs(a-b));
}
int main()
{
  l a,b;
  cin>>a>>b;
  l gcd=hcf(a,b);
  l ans=(a*b)/gcd;
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  char pre = '_';
  for (auto c : s) {
    if (pre == c) {
      cout << "Bad" << endl;
      return 0;
    }  
    pre = c;
  }
  cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)
AB = readlines.map {|s| s.split.map(&:to_i) }

ans = Array.new(N, true)
AB.each do |a,b|
  ans[a-1] = false if H[a-1] <= H[b-1]
  ans[b-1] = false if H[b-1] <= H[a-1]
end
puts ans.count(true)


Measured memory_bytes: 29700
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

int h, w, k;

int kurokazu(vector<vector<int>> c, int rn, int cn) {
	vector<int> rs(h);
	vector<int> cs(w);

	for (int i = 0; i < h; i++) {
		rs[i] = rn % 2;
		rn /= 2;
	}
	for (int j = 0; j < w; j++) {
		cs[j] = cn % 2;
		cn /= 2;
	}
	
	int cnt = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if ((rs[i] == 1) || (cs[j] == 1)) {

			}
			else {
				if (c[i][j] == 1) {
					cnt++;
				}
			}
		}
	}
	return cnt;
}

int main()
{
	cin >> h >> w >> k;
	vector<vector<int>> c(h, vector<int>(w));
	for (int i = 0; i < h; i++) {
		string t;
		cin >> t;
		for (int j = 0; j < w; j++) {
			if (t[j] == '.') {
				c[i][j] = 0;
			}
			else if (t[j] == '#') {
				c[i][j] = 1;
			}
			else {
				c[i][j] = -100;
			}
		}
	}

	int cnt = 0;
	for (int i = 0; i < pow(2, h); i++) {
		for (int j = 0; j < pow(2, w); j++) {
			if (kurokazu(c, i, j) == k) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

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

signed main() {
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	int ans = a+b+c+max({a,b,c})*((1<<x)-1);
	cout << ans << endl;
}


Measured memory_bytes: 3552
def solve(n, a_list):
    tmp = sorted(a_list, reverse=True)
    
    alice_score = sum([x for i, x in enumerate(tmp) if i % 2 == 0])
    bob_score = sum([x for i, x in enumerate(tmp) if i % 2 == 1])
    return alice_score - bob_score

if __name__ == "__main__":
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(solve(n, a_list))



Measured memory_bytes: 3060
#!/usr/bin/ruby
n=gets.to_i
c=gets.split.map &:to_i
a=[0]*n
gets.to_i.times{|i|
	t,x,d=gets.split.map &:to_i
	t=-1 if t==2
	x-=1
	a[x]+=t*d
	if a[x]<0||c[x]<a[x]
		p x+1
		exit
	end
}
p 0



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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

bool can_choose(ll n, ll m, ll v, ll p, vector<ll> &problems, ll border) {
    // borderを当選させたい。可能か？
    if (border < p) return true;
    ll target = problems[p - 1];
    if (problems[border] + m < target) return false;

    ll budget = v * m;
    // border問目に全員が投票
    // P-1問目までは全員が投票
    // p問目からborder問目まではborder問目と一致するように投票
    // border+1問目移行は全部上げる
    // 票が余ったらfalse

    auto allocate = [&](ll ma) {
        ll k = min({budget, m, ma});
        budget -= k;
        assert(budget >= 0);
        return k;
    };

    ll border_point = problems[border] + allocate(INF);
    rep(i, p - 1) allocate(INF);

    for (ll i = border + 1; i < n; i++) allocate(INF);

    auto allocate_for_border_point = [&](ll i) {
        ll from = problems[i];
        assert(border_point >= from);
        ll diff = border_point - from;
        allocate(diff);
    };

    for (ll i = p - 1; i < border; i++) allocate_for_border_point(i);

    return budget == 0;
}


int main() {
    ll n, m, v, p;
    cin >> n >> m >> v >> p;


    vector<ll> problems(n);
    rep(i, n) cin >> problems[i];
    sort(problems.rbegin(), problems.rend());
    ll floor = 0, ceil = n - 1;
    if (can_choose(n, m, v, p, problems, ceil)) {
        cout << n << endl;
        ret();
    }
    while (floor + 1 < ceil) {
        ll mid = (floor + ceil) / 2;
        bool b = can_choose(n, m, v, p, problems, mid);
        if (b) {
            floor = mid;
        } else {
            ceil = mid;
        }
    }
    assert(can_choose(n, m, v, p, problems, floor));
    assert(!can_choose(n, m, v, p, problems, ceil));
    cout << floor + 1 << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;
typedef uint64_t u64;

void set_at (u64 *b, i32 k) {
  b[k >> 6] |= (u64) 1 << (k & 63);
}

i32 get_at (u64 *b, i32 k) {
  return (b[k >> 6] >> (k & 63)) & 1;
}

int func (u64 *a, u64 *b, u64 *c, i32 l, i32 r) {
  i32 i = l;
  for (; i <= r && i < (l / 64 + 1) * 64; ++i) {
    if (get_at (a, i) && get_at (b, i) && get_at (c, i)) {
      return 1;
    }
  }
  for (; i + 63 <= r; i += 64) {
    if ((a[i / 64] & b[i / 64] & c[i / 64]) != 0) {
      return 1;
    }
  }
  for (; i <= r; ++i) {
    if (get_at (a, i) && get_at (b, i) && get_at (c, i)) {
      return 1;
    }
  }
  return 0;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  u64 **win = (u64 **) calloc (n, sizeof (u64 *));
  for (i32 i = 0; i < n; ++i) {
    win[i] = (u64 *) calloc (n / 64 + 1, sizeof (u64));
  }
  char *s = (char *) calloc (n + 1, sizeof (char));
  for (i32 i = 1; i < n; ++i) {
    scanf ("%s", s);
    for (i32 j = 0; j < i; ++j) {
      if (s[j] == '0') {
        set_at (win[j], i);
      } else {
        set_at (win[i], j);
      }
    }
  }
  u64 **dpL = (u64 **) calloc (n, sizeof (u64 *));
  u64 **dpR = (u64 **) calloc (n, sizeof (u64 *));
  for (i32 i = 0; i < n; ++i) {
    dpL[i] = (u64 *) calloc (n / 64 + 1, sizeof (u64));
    set_at (dpL[i], i);
    dpR[i] = (u64 *) calloc (n / 64 + 1, sizeof (u64));
    set_at (dpR[i], i);
  }
  for (i32 len = 2; len <= n; ++len) {
    for (i32 l = 0; l + len - 1 < n; ++l) {
      i32 r = l + len - 1;
      if (func (win[l], dpR[l + 1], dpL[r], l + 1, r)) {
	set_at (dpL[r], l);
      }
      if (func (win[r], dpR[l], dpL[r - 1], l, r - 1)) {
	set_at (dpR[l], r);
      }
    }
  }
  i32 ans = 0;
  for (i32 i = 0; i < n; ++i) {
    ans += get_at (dpR[0], i) & get_at (dpL[n - 1], i);
  }
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 1792
from collections import Counter

N = int( input() )
tree = list( map( int, input().split() ) )

c = Counter(tree)
if tree[0] != 0 or c[0] != 1:
    print(0)
else:
    ans = 1
    a = c[0]
    for i in range( 1,len(c)):
        t = c[i]
        if t == 0:
            print(0)
            exit()
        else:
            ans *= ( a**t )
            a = t
    print(ans%998244353)


Measured memory_bytes: 19936
#include <bits/stdc++.h>
using namespace std;
using pdd = pair<double, double>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
#define EPS 0.00000001

double ans = 100000.0;

double dist(pdd P,pdd Q){
    double x = P.first-Q.first;
    double y = P.second-Q.second;
    return sqrt(x*x+y*y);
}

void within(vector<pdd> &data,double cx,double cy,double rad){
    int n = data.size();
    rep(i,n){
        double r = dist(data.at(i),pdd(cx,cy));
        if(r > rad + EPS) return; 
    }
    ans = min(ans,rad);
    return;
}

void check2(vector<pdd> &data,int i,int j){
    double ix = data.at(i).first;
    double iy = data.at(i).second;
    double jx = data.at(j).first;
    double jy = data.at(j).second;
    double cx = (ix + jx)/2.0;
    double cy = (iy + jy)/2.0;
    double r = dist(pdd(cx,cy),pdd(ix,iy));
    if(r > ans) return;
    within(data,cx,cy,r);
}

void check3(vector<pdd> &data,int i,int j,int k){
    double ix = data.at(i).first;
    double iy = data.at(i).second;
    double jx = data.at(j).first;
    double jy = data.at(j).second;
    double kx = data.at(k).first;
    double ky = data.at(k).second;
    double mx = (ix + jx)/2.0;
    double my = (iy + jy)/2.0;
    double nx = (ix + kx)/2.0;
    double ny = (iy + ky)/2.0;
    double A = my - iy;
    double B = ix - mx;
    double C = ny - iy;
    double D = ix - nx;
    double E = nx - mx;
    double F = ny - my;
    if(A*D - B*C == 0) return;
    double s = (D*E - C*F)/(A*D - B*C);
    double t = (B*E - A*F)/(A*D - B*C);
    double cx = mx + s*(my - iy);
    double cy = my + s*(ix - mx);
    double r = dist(pdd(cx,cy),pdd(ix,iy));
    if(r > ans) return;
    within(data,cx,cy,r);
}

int main(){
    fix20;
    int n;
    cin >> n;
    vector<pdd> data(n);
    rep(i,n) cin >> data.at(i).first >> data.at(i).second;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            check2(data,i,j);
            for(int k=j+1;k<n;k++){
                check3(data,i,j,k);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256