akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<list>
#include<cstring>
#include<algorithm>
#include <utility>
#include<stdio.h>
#include<climits>
#include <vector>
#include <queue>

using namespace std;

struct ps{
    int x1,y1,x2,y2,m;
    ps(int a,int b,int c,int d){
        if(a > c){
            x1 = c;
            x2 = a;
        }
        else{
            x1 = a;
            x2 = c;
        }
        if(b > d){
            y1 = d;
            y2 = b;
        }
        else{
            y1 = b;
            y2 = d;
        }
        m = (x2-x1)*(y2-y1);
    }
};

int main(void){
    int n,w,d;
    int si,pi;
    vector<ps> l;
    ps p(0,0,0,0);
    int i,j;
    int s[200];
    while(1){
        cin >> n >> w >> d;
        if(!w) break;
        l.clear();
        l.push_back(ps(0,0,w,d));
        for(i = 0;i < n;i++){
            cin >> pi >> si;
            pi--;
            p = l[pi];
            w = p.x2-p.x1;
            d = p.y2-p.y1;
            si %= 2*(w+d);
            if(si > w+d){
                si -= w+d;
                if(si > w){
                    si -= w;
                    si *= -1;
                    si += d;
                    si += w;
                }
                else{
                    si *= -1;
                    si += w;
                }
            }
            if(si > w){
                si -= w;
                si += p.y1;
                if(p.y2-si > si-p.y1){
                    l.push_back(ps(p.x1,p.y1,p.x2,si));
                    l.push_back(ps(p.x1,si,p.x2,p.y2));
                }
                else{
                    l.push_back(ps(p.x1,si,p.x2,p.y2));
                    l.push_back(ps(p.x1,p.y1,p.x2,si));
                }
            }
            else{
                si += p.x1;
                if(p.x2-si > si-p.x1){
                    l.push_back(ps(p.x1,p.y1,si,p.y2));
                    l.push_back(ps(si,p.y1,p.x2,p.y2));
                }
                else{
                    l.push_back(ps(si,p.y1,p.x2,p.y2));
                    l.push_back(ps(p.x1,p.y1,si,p.y2));
                }
            }
            l.erase(l.begin()+pi);
        }
        for(i = 0;i < l.size();i++){
            s[i] = l[i].m;
        }
        sort(s,s+l.size());
        for(i = 0;i < l.size()-1;i++){
            cout << s[i] << " ";
        }
        cout << s[i] << endl;
    }
}

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

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

    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for(int i = 0; i < n; i++)
    {
        if(a[i] % 2 == 0 && a[i] % 3 != 0 && a[i] % 5 != 0)
        {
            cout << "DENIED";
            return 0;
        }
    }
    cout << "APPROVED";
    cout << "\n";
    return 0;
    }


Measured memory_bytes: 3528
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << 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 ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int x, y, z;
	cin >> x >> y >> z;
	swap(x, y);
	swap(x, z);
	cout << x << " " << y << " " << z;

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())

p = [0] * m
s = [0] * m
ac = [0] * n
wa = [0] * n

for i in range(m):
    p[i], s[i] = input().split()

p = [int(i) for i in p]
 
for i in range(m):
    if ac[p[i] - 1] == 0:
        if s[i] == 'AC':
            ac[p[i] - 1] = 1
        else:
            wa[p[i] - 1] += 1

for i in range(n):
    if ac[i] == 0:
        wa[i] = 0

print(sum(ac), sum(wa))


Measured memory_bytes: 21296
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(void) {
  int n, m;
  map<string, int> s, t;
  cin>>n;
  for(int i=0; i<n; i++) {
    string x;
    cin>>x;
    if(s.find(x)==s.end()) {
      s[x]=1;
    } else {
      s[x]++;
    }
  }
  cin>>m;
  for(int i=0; i<m; i++) {
    string x;
    cin>>x;
    if(t.find(x)==t.end()) {
      t[x]=1;
    } else {
      t[x]++;
    }
  }
  int ans=0;
  for(auto itr=s.begin(); itr != s.end(); itr++) {
    string x=itr->first;
    int c=0;
    if(t.find(x)==t.end()) {
      c=0;
    } else {
      c=t[x];
    }
    ans=max(ans, itr->second-c);
  }
  cout<<ans<<endl;
  return 0;
}


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

signed main() {
  int N;
  string S;
  cin >> N >> S;

  int ans = 0;
  for (int i = 0; i + 2 < N; i++) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int a,b,c;
    char op;
    while(true){
        scanf("%d %c %d",&a,&op,&b);
        if(op == '?') break;
        else if(op == '+') c = a + b;
        else if(op == '-') c = a - b;
        else if(op == '*') c = a * b;
        else if(op == '/') c = a / b;

        printf("%d\n",c);
        }
    return 0;
}


Measured memory_bytes: 2696
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,y;
  cin>>x>>y;
  cout<<x+(y/2);
  return(0);
}


Measured memory_bytes: 256
# ある文字を起点としたとき、ある文字同士に挟まれた区間の最大値が操作回数
# jackal -> aに挟まれた最大区間は2
# 100文字で、アルファベット26種類なので全通り試す

import sys
readline = sys.stdin.readline

S = readline().rstrip()

a = ord("a")
z = ord("z")

ans = 10 ** 10
for i in range(a,z + 1):
  arr = S.split(chr(i))
  maxlen = 0
  for a in arr:
    if len(a) > maxlen:
      maxlen = len(a)
  if maxlen < ans:
    ans = maxlen
  
print(ans)

Measured memory_bytes: 3064
from numpy import*
n,m,*a=int_(open(0).read().split())
b=[0]*2**18
for i in a:b[i]+=1
i=2**18
c=0
for a in int_(fft.irfft(fft.rfft(b)**2)+.5)[::-1]:
  i-=1
  if a:
    t=min(m,a)
    c+=i*t
    m-=t
    if not m:break
print(c)

Measured memory_bytes: 33256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

vector<int> G[100010];
P dp[100010];
//white, black

P calc(int now, int pre){
    P res = {1, 1};
    rep(i, 0, G[now].size()){
        if(G[now][i] == pre) continue;
        P tmp = calc(G[now][i], now);
        (res.first *= tmp.first + tmp.second) %= mod;
        (res.second *= tmp.first) %= mod;
    }
    return res;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i, 0, n - 1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    P ans = calc(0, -1);
    cout << (ans.first + ans.second) % mod << endl;
}

Measured memory_bytes: 12672
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def main():
    N = int(input())
    p = list(map(int, input().split()))

    s_p = sorted(p)

    c = 0
    for i in range(N):
        if p[i] != s_p[i]:
            c += 1
            if c > 2:
                print('NO')
                exit()

    print('YES')

if __name__ == "__main__":
    main()


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

int main()
{
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  int c = 0;
  for(int i = 0; i < n; ++i){
    scanf("%d", &a[i]);
    c += a[i] != (i+1);
  }
  if (c <= 2) printf("YES");
  else printf("NO");
  return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
D=list(map(int,input().split()))
dp=[0]*10
for i in range(K):
  dp[D[i]]=1
for i in range(N,10**6+1):
  a=str(i)
  flag=True
  for j in range(len(a)):
    if dp[int(a[j])]==1:
      flag=False
      break
  if flag:
    print(i)
    exit()

Measured memory_bytes: 9188
#include <stdio.h>
#include <string.h>
#include <math.h>

#define max 20

int* sortMaxmin(int*, int);
int* sortMinmax(int*, int);

int main()
{
    int n, i, count=0;
    char p[max];
    
    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%d", &p[i]);
    }
    
    for(i=1; i<n-1; i++){
        if(p[i-1]<p[i]&&p[i]<p[i+1]){
            count++;
        }else if(p[i-1]>p[i]&&p[i]>p[i+1]){
            count++;
        }
    }
    
    printf("%d", count);
    
    return 0;
}

int* sortMaxmin(int *a, int b)
{
    int i, j, tmp;
    for(i=0; i<b; i++){
        for (j=i+1; j<b; j++) {
            if(a[i]>a[j]){
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    return a;
}

int* sortMinmax(int *a, int b)
{
    int i, j, tmp;
    for(i=0; i<b; i++){
        for (j=i+1; j<b; j++) {
            if(a[i]<a[j]){
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    return a;
}



Measured memory_bytes: 128
#include <stdio.h>
main(void){
int a,b,c,x,y,z;
scanf("%d%d%d",&a,&b,&c);
if(a > b){
x = a;
a = b;
b = x;
}
if(b > c){
y = b;
b = c;
c = y;
}
if(a > b){
z = a;
a = b;
b = z;
}
printf("%d %d %d\n",a,b,c);
return 0;
}

Measured memory_bytes: 596
N, M = map(int, input().split())

links = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    links[L].append((R, D))
    links[R].append((L, -D))

t = [None] * (N + 1)
for i in range(1, N + 1):
    if t[i] is not None:
        continue
    t[i] = 0
    s = [i]
    while s:
        j = s.pop()
        for k, l in links[j]:
            if t[k] is None:
                t[k] = t[j] + l
                s.append(k)
            else:
                if t[k] != t[j] + l:
                    print('No')
                    exit()
print('Yes')


Measured memory_bytes: 65968
#include<iostream>
using namespace std;
int main()
{char arj[3],ark[3];int c=0;
    for(int i=0;i<3;i++)
    {
        cin>>arj[i];
    }
    for(int i=0;i<3;i++)
    {
        cin>>ark[i];
    }
    for(int i=0;i<3;i++)
    {
        if(ark[i]==arj[i])
            c+=1;
    }
    cout<<c;

}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      int N = sc.nextInt();
      int K = sc.nextInt();
      System.out.println((K == 1) ? 0 : N - K);
	}
}


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

using namespace std;

const long long base = 998244353;


long long pow_mod(long long a, long long b, long long c) {
	long long ret = 1;
	while (b) {
		if (b & 1) {
			ret *= a;
			ret %= c;
		}
		a *= a;
		a %= c;
		b >>= 1;
	}
	return ret;
}

int main() {
	ios_base :: sync_with_stdio(false);
	int n, m, k;
	cin >> n >> m >> k;
	vector < long long > f(n + 1, 0), rf(n + 1, 0), mp(n + 1, 0);
	f[0] = 1;
	rf[0] = 1;
	mp[0] = 1;
	for (int i = 1; i <= n; i++) {
		mp[i] = mp[i - 1] * (m - 1);
		mp[i] %= base;
		f[i] = f[i - 1] * i;
		f[i] %= base;
		rf[i] = pow_mod(f[i], base - 2, base);
	}
	long long ans = 0;
	for (int i = 0; i <= k; i++) {
		long long cs = m * mp[n - i - 1];
		cs %= base;
		cs *= f[n - 1];
		cs %= base;
		cs *= rf[i];
		cs %= base;
		cs *= rf[n - 1 - i];
		cs %= base;
		ans += cs;
		if (ans >= base) {
			ans -= base;
		}
	}
	cout << ans;
	return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int a;string s;cin>>a>>s;
	if(a>=3200)cout<<s<<endl;
	else cout<<"red"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
		string S = Console.ReadLine();
		string T = Console.ReadLine();

		int sum = 0;
		int i = 0;
		foreach (var item in S) 
			if (item == T[i++]) sum++;

		Console.WriteLine(sum);
	}
}


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

const int maxn = 2e3 + 5;
LL a[maxn];
LL b[maxn][maxn];

int main(){
    int n;
    LL x,sum = 1LL << 60LL;
    cin >> n >> x;
    for(int i = 1;i <= n;i++) cin >> a[i];
    for(int i = 1;i <= n;i++){
        b[i][0] = a[i];
        for(int k = 1;k <= n - 1;k++){
            int pos = i - k;
            if(pos <= 0) pos = n - abs(pos);
            b[i][k] = min(b[i][k - 1],a[pos]);
        }
    }
    for(int k = 0;k <= n - 1;k++){
        LL ans = 0;
        for(int i = 1;i <= n;i++){
            ans += b[i][k];
        }
        sum = min(sum,ans + x * k);
    }
    cout << sum << endl;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<pair<int, P>> v(n);
  rep(i, 0, n) {
    int a, b;
    cin >> a >> b;
    v[i] = make_pair(a + b, make_pair(a, b));
  }

  sort(v.rbegin(), v.rend());

  ll ans = 0;
  rep(i, 0, n) {
    if (i % 2 == 0)
      ans += v[i].second.first;
    else
      ans -= v[i].second.second;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4488
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int k = sc.nextInt();
    int n = s.length();
    HashSet<String> set = new HashSet<>();
    for(int i=0;i<n;i++){
      for(int j=1;j<=Math.min(k,n-i);j++){
        set.add(s.substring(i,i+j));
      }
    }
    ArrayList<String> list = new ArrayList<>(set);
    Collections.sort(list);
    System.out.println(list.get(k-1));
  }
}

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

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        long sum = 0;

        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
            sum += a[i];
        }
        Arrays.sort(a);
        System.out.println(a[0]+" "+a[n-1]+" "+sum);
        sc.close();
    } 
}


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


int main()
{
  int N;
  cin >> N;
  vector<int> P;
  for(int i=0;i<N;i++){
    P.push_back(i+1);
  }

  int num=0;
  for(int i=0;i<N;i++){
    int p;
    cin >> p;
    if(p !=i+1){
      num ++;
    }
    
  }
  if((num==0)||(num==2)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

}

Measured memory_bytes: 3616
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}
int main() {
    int h, w; cin >> h >> w;
    vector<string> v;
    REP(i, h) {
        string tmp; cin >> tmp;
        v.push_back(tmp);
    }
    int dp[110][110];
    memset(dp, 0, sizeof(dp));

    REP(i, h) {
        REP(j, w) {
            if (i == 0 && j == 0) {
                continue;
            }
            if (i == 0) {
                if (v[i][j] == v[i][j-1]) {
                    dp[i][j] = dp[i][j-1];
                } else {
                    dp[i][j] = dp[i][j-1] + 1;
                }
            } else if (j == 0) {
                if (v[i][j] == v[i-1][j]) {
                    dp[i][j] = dp[i-1][j];
                } else {
                    dp[i][j] = dp[i-1][j] + 1;
                }
            } else {
                if ((v[i][j] == v[i][j-1]) && (v[i][j] == v[i-1][j])) {
                    dp[i][j] = min(dp[i][j-1], dp[i-1][j]);
                } else if ((v[i][j] == v[i][j-1]) && (v[i][j] != v[i-1][j])) {
                    dp[i][j] = min(dp[i][j-1], dp[i-1][j]+1);
                } else if ((v[i][j] != v[i][j-1]) && (v[i][j] == v[i-1][j])) {
                    dp[i][j] = min(dp[i][j-1]+1, dp[i-1][j]);
                } else {
                    dp[i][j] = min(dp[i][j-1]+1, dp[i-1][j]+1);
                }
            }
        }
    }
    if (v[0][0] == '.' && v[h-1][w-1] == '.') {
        cout << dp[h-1][w-1] / 2 << endl;
    } else {
        cout << dp[h-1][w-1] / 2 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <set>
#include <iostream>
#include <cassert>
#include <queue>
using namespace std;


bool isPrime(int x){
    for(int i= 2; i * i <= x; ++i){
        if(x%i==0)
            return false;
    }
    return true;
}

int main()
{
    int x;
    cin>>x;
    while(1){
        if(!isPrime(x)) x++;
        else {
            cout<<x;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
s = gets.to_s.chomp

ATGC = %w( A T G C )

ans = 0
cnt = 0
s.each_char do |c|
  
  if ATGC.include?(c)
    cnt += 1
    ans = [ans, cnt].max
  else
    cnt = 0
  end
end

puts ans

Measured memory_bytes: 1916
A,B,m= list(map(int, input().split()))
a= list(map(int, input().split()))
b= list(map(int, input().split()))
ans=1000000000000007
for i in range(m):
    x,y,c= list(map(int, input().split()))
    ans=min(a[x-1]+b[y-1]-c,ans)
ans=min(ans,min(a)+min(b))
print(ans)

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

int main(){
	int n;
	while(cin >> n,n){
		int num;
		double mi = 1e+9;
		for(int i = 0;i < n;i++){
			int p;
			double h,w;
			cin >> p >> h >> w; h /= 100.0;
			double d = abs(22.0 - w / h / h);
			if(abs(mi - d) < 1e-8) num = min(num,p);
			else if(mi > d) {
				num = p;
				mi = d;
			}
		}
		cout << num << endl;
	}
	return 0;
}

Measured memory_bytes: 3156
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define N 20000
#define pi M_PI

typedef struct Data{
    int area,pos;
}D;
D t[N];
int u[N],n,i,T,U,ans,A;
char str[N+1];
D X,Y;

void Dpush(D data){
    t[T++]=data;
}

D Dpop(){
    return t[--T];
}
 void push(int x){
     u[U++]=x;
 }
 int pop(){
     return u[--U];
 }
 void init(){
     ans=U=T=0;
 }
 D makeD(int x,int y){
     D res;
     res.area=x;
     res.pos=y;
     return res;
 }
int main(){
  init();
  scanf("%s",str);
  n=strlen(str);
  
  for(i=0;i<n;i++){
  
    if(str[i]=='/'){
      if(U==0)
    continue;
    A=pop();
    X=makeD(i-A,A);
    ans+=i-A;
    while(T>0){
      Y=Dpop();
      if(Y.pos<A){
        Dpush(Y);
        break;
      }
      X.area+=Y.area;
      if(Y.pos<X.pos)
        X.pos=Y.pos;
    }
    Dpush(X);
    }
    else if(str[i]=='\\'){
      push(i);
    }
  }
  printf("%d\n%d",ans,T);
  for(i=0;i<T;i++){
    printf(" ");
    printf("%d",t[i].area);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2104
import java.io.BufferedReader
import java.io.PrintWriter
import java.util.*

var out: PrintWriter = PrintWriter(System.out)  // これを使って出力すると早い

fun main(args: Array<String>) {
    try {
        val nk = MyScanner.readAsLongArray()
        val map = mutableMapOf<Int, Int>()

        for (i in 1..nk[0]){
            val ab = MyScanner.readAsIntArray()
            map[ab[0]] = ab[1] + (map[ab[0]] ?: 0)
        }

        val sortedMap = map.toSortedMap()

        var kp = 0L

        for (entry in sortedMap){
            kp += entry.value
            if (kp >= nk[1]){
                out.println(entry.key)
                return
            }
        }

        out.println(sortedMap.lastKey())

    } finally {
        out.flush()   // 消さない
    }
}

/**
 * 読み取り
 */
class MyScanner {
    companion object {
        private var reader : BufferedReader = System.`in`.bufferedReader()

        fun reset(){
            reader = System.`in`.bufferedReader()
        }

        fun readAsInt(): Int {
            return Integer.parseInt(reader.readLine())
        }

        // Int
        fun readAsIntArray(delimiters: String = " "): IntArray {
            return reader
                .readLine()
                .split(delimiters)
                .map { s -> Integer.parseInt(s) }
                .toIntArray()
        }

        fun readNTimesAsInt(n: Int): IntArray {
            return (1..n).map { readAsInt() }.toIntArray()
        }

        fun readNTimesAsIntArray(n: Int): Array<IntArray> {
            return (1..n).map { readAsIntArray() }.toTypedArray()
        }

        // long
        // TODO 別の方法を考える
        fun readAsLong(): Long {
            return reader.readLine().toLong()
        }

        fun readAsLongArray(delimiters: String = " "): LongArray {
            return reader.readLine()
                .split(delimiters)
                .map { s -> s.toLong() }
                .toLongArray()
        }

        fun readNTimesAsLong(n: Int): LongArray {
            return (1..n).map { readAsLong() }.toLongArray()
        }

        fun readAsString(): String {
            return reader.readLine()
        }

        fun readAsStringArray(delimiters: String = " "): Array<String> {
            return readAsString().split(delimiters).toTypedArray()
        }

    }
}

/**
 * 要素とその個数を出力
 */
fun <T> Array<T>.ofCountMap(): Map<T, Int> {
    return this.groupBy { it }.mapValues { it.value.count() }
}

/**
 * 文字とその個数を出力
 */
fun String.ofCountMap(): Map<Char, Int> {
    return this.toCharArray().ofCountMap()
}

/**
 * 文字とその個数を出力
 */
fun CharArray.ofCountMap(): Map<Char, Int> {
    return this.groupBy { it }.mapValues { it.value.count() }
}

Measured memory_bytes: 58392
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int n,cnt,t[N],ch[N][26],dp[N][26];
string a[N];
map<string,int>mp;
long long ans;
bool cmp(string a,string b)
{
	return a.size()!=b.size()?a.size()<b.size():a<b;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		for(int k=0;k<26;k++)
			t[k]=0;
		for(int j=0;j<a[i].size();j++)
			t[a[i][j]-'a']++;
		int u=0;
		for(int k=0;k<26;k++)
		{
			if(t[k]==0)
				continue;
			ans+=dp[u][k];
		}
		if(a[i].size()==1)
			dp[u][a[i][0]-'a']++;
		for(int j=a[i].size()-1;j>=0;j--)
		{
			int x=a[i][j]-'a';
			if(ch[u][x]==0)
				ch[u][x]=++cnt;
			u=ch[u][x];
			t[x]--;
			for(int k=0;k<26;k++)
			{
				if(t[k]==0)
					continue;
				ans+=dp[u][k];
			}
			if(j==1)
				dp[u][a[i][0]-'a']++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
	
	for(int n;cin>>n,n;){
		int ans,tmp,k;
		cin>>ans;
		tmp=ans;
		for(n--;n--;){
			cin>>k;
			if(tmp<=0){
				ans=max(ans,k);
				tmp=k;
			}
			else{
				ans=max(ans,tmp+k);
				tmp+=k;
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int A,B,H,M;
 double a,C;
 static const double pi = 3.141592653589793;
 cin >> A >> B >> H >> M;
 a=M*6-(H*30+M*0.5);
 if(a<0)
   a=a*-1;
 if(a>180)
   a=360-a;
 a=(a/180)*pi;
 C=A*A+B*B-2*A*B*cos(a);
 C=sqrt(C);
 cout << fixed << setprecision(20) << C << endl;
}

Measured memory_bytes: 4084
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  for(int i=0; i<N; i++)
    cin >> A[i];
  sort(A.begin(), A.end());
  cout << A[N-1] - A[0] << endl;
  return 0;
}


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

int dp[2][2001][2001] = {};

int main(){
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(s[i] == 'I') dp[1][i+1][j] = 1;
            if(t[j] == 'I') dp[1][i][j+1] = 1;
        }
    }
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            for(int k = 0; k < 2; k++){
                if(dp[k][i][j] == 0)    continue;
                if(i < n && s[i] == "IO"[k]) dp[1-k][i+1][j] = max(dp[1-k][i+1][j], dp[k][i][j]+1);
                if(j < m && t[j] == "IO"[k]) dp[1-k][i][j+1] = max(dp[1-k][i][j+1], dp[k][i][j]+1);
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            ans = max(ans, dp[1][i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 34468
#include <iostream>
using namespace std;
 
int main(){
  int n,h,m,s;
  cin >> n;
 
  h = n / 3600;
  m = n % 3600 / 60;
  s = n % 3600 % 60;
 
  cout << h << ':' << m << ':' << s << endl;
}

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

int main()
{
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h)cin >> s[i];
    int ans = 1001001001;
    int cnt[10][1005];
    rep(div,1<<(h-1)){
        int g = 0;
        vector<int> group(h);
        rep(i,h){
            group[i] = g;
            if((div>>i)%2)g++;
        }
        
        rep(i,g+1)rep(j,w)cnt[i][j] = 0;
        rep(i,h)rep(j,w)cnt[group[i]][j] += (s[i][j] - '0');
        bool ok = true;
        rep(i,g+1)rep(j,w)if(cnt[i][j] > k)ok = false;
        if(!ok)continue;

        int res = g++;
        vector<int> a(g);
        auto add = [&](int j){
            rep(i,g)a[i] += cnt[i][j];
            rep(i,g) if(a[i] > k)return false;
            return true;
        };
        rep(j,w){
            if(!add(j)){
                res++;
                a = vector<int>(g);
                add(j);
            }
        }
        ans = min(ans,res);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 7004
function main(s) {
	s = s.split("\n")[0].split(" ").map(x => Number(x));
	var v = [4, 6, 9, 11];
	console.log(
		(s[0] === 2) || (s[1] === 2) ? "No" : 
			(v.some(x => x === s[0]) ? 
				(v.some(x => x === s[1]) ? "Yes" : "No") : (v.some(x => x === s[1]) ? "No" : "Yes")));
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7372
#include <iostream>
#include <stdio.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
#include <string.h>

#define maxN 1024

using namespace std;

typedef pair<int, int> P;

int a[maxN * 3][maxN * 3];
int x1[maxN], x2[maxN], y1[maxN], y2[maxN];
int w, h, n, dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};

int compress(int *X1, int *X2, int W)
{
	int i, j, tx1, tx2;
	vector<int> xs;
	for (i = 0; i < n; i++)
	{
		tx1 = X1[i];
		tx2 = X2[i];
		if (1 <= tx1 && tx1 <= W)
			xs.push_back(tx1);
		if (1 <= tx2 && tx2 <= W)
			xs.push_back(tx2);
	}
	xs.push_back(0);
	xs.push_back(w);
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	for (i = 0; i < n; i++)
	{
		X1[i] = find(xs.begin(), xs.end(), X1[i]) - xs.begin();
		X2[i] = find(xs.begin(), xs.end(), X2[i]) - xs.begin();
	}
	return xs.size() - 1;
}

int main()
{
	int i, j, y, x;
	while (scanf("%d %d", &w, &h) && (w || h))
	{
		scanf("%d", &n);
		for (i = 0; i < n; i++)
		{
			scanf("%d %d %d %d", &x1[i], &y1[i], &x2[i], &y2[i]);
		}
		w = compress(x1, x2, w);
		h = compress(y1, y2, h);
		memset(a, 0, sizeof(a));
		for (i = 0; i < n; i++)
		{
			a[y1[i]][x1[i]]++;
			a[y1[i]][x2[i]]--;
			a[y2[i]][x1[i]]--;
			a[y2[i]][x2[i]]++;
		}
		for (i = 0; i < h; i++)
		{
			for (j = 1; j < w; j++)
			{
				a[i][j] += a[i][j - 1];
			}
		}
		for (i = 1; i < h; i++)
		{
			for (j = 0; j < w; j++)
			{
				a[i][j] += a[i - 1][j];
			}
		}
		int ans = 0;
		for (y = 0; y < h; y++)
		{
			for (x = 0; x < w; x++)
			{
				if (a[y][x])
					continue;
				ans++;
				queue<P>que;
				que.push(P(x, y));
				while (!que.empty())
				{
					int sx = que.front().first, sy = que.front().second;
					que.pop();
					for (i = 0; i < 4; i++)
					{
						int tx = sx + dir[i][0], ty = sy + dir[i][1];
						if (tx >= 0 && tx < w && ty >= 0 && ty < h && a[ty][tx] == 0)
						{
							que.push(P(tx, ty));
							a[ty][tx] = 1;
						}
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 38104
//Robs Code
/***********HEADER***************/
#include<bits/stdc++.h>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 10000007
#define mxval 1e9
#define grt [](auto x,auto y){return x>y;}
#define pii pair<int,int>
/*********VARIABLE****************/
using namespace std;
int i,j,n,m,k,l,q,t,a,b,sum[3],tot[3],cnt[3];
/***********MAIN******************/
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>m>>a;
    if((a>n&&a<m)||(a<n&&a>m)){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
	return 0;
}
//.........


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

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

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

const ll L = 1e5+5;

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

    ll N;
    cin >> N;

    if(N & 1)
    {
        cout << 0 << endl;
        return 0;
    }

    N >>= 1;
    ll mul = 5;

    ll ans = 0;

    while(N >= mul)
    {
        ans += (N/mul);
        mul *= 5;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

bool slow(string s) {
    if(s.size() == 2) { return false; }
    for(int i = 1; i+1 < s.size(); i++) {
        if(s[i-1] != s[i+1]) {
            if(!slow(s.substr(0, i) + s.substr(i+1))) {
                return true;
            }
        }
    }
    return false;
}

bool wrong2(string s) {
    if(s[0] == s[s.size()-1]) {
        return (s.size()) % 2 == 0;
    }
    int n = s.size();
    int t = 0;
    char A = s[0];
    char B = s[s.size()-1];
    int cnt = 0;
    for(int i = 1; i+1 < s.size(); i++) {
        if(t == 0 && s[i] == B) {
            t = 1;
        } else if(t == 1 && s[i] == A) {
            t = 0;
        } else {
            cnt++;
        }
    }
    if(t == 1) cnt++;
    return cnt % 2 != 0;
}

void dfs(string s, int n, int m) {
    if(s.size() == n) {
        bool w = wrong2(s);
        bool v = slow(s);
        if(w != v) {
            cout << "s: " << s << endl;
            cout << "wrong: " << w << endl;
            cout << "slow: " << v << endl;
            assert(false);
        }
        return;
    }
    REP(i, n) {
        if(s[s.size()-1] != ('a' + i)) {
            dfs(s + (char)('a' + i), n, m);
        }
    }
}

int main(){
    iostream_init();
    string s;
    cin >> s;
    cout << (wrong2(s) ? "First" : "Second") << endl;
    return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N, K;
	cin >> N >> K;
	vector<int>a(N);
	rep(i, N)cin >> a[i];
	vector<bool>dp(K + 1); //dp[i] : 先手が勝てたらtrue
	dp[0] = false;
	for (int i = 1; i <= K; i++) {
		bool Win = false;
		rep(j, N) {
			if (a[j] > i)break;
			if (dp[i - a[j]] == false)Win = true;
		}
		dp[i] = Win;
	}
	if (dp[K])cout << "First" << endl;
	else cout << "Second" << endl;
}

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

using namespace std;

#ifdef KACTL
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
#endif
#define all(x) begin(x), end(x)

using ll = int64_t;
using ld = long double;
using pii = pair<int32_t, int32_t>;
using vi = vector<int32_t>;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int move = 0;
    while (min(a, c) > 0) {
        if (move) {
            a -= d;
        } else {
            c -= b;
        }
        move ^= 1;
    }

    cout << (move ? "Yes" : "No") << endl;

    return 0;
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

int N,A;
vector<ll> V;
ll dp [51] [2501] [51];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> A;
	V.resize(N);
	FOR(i,0,N){
		cin >> V [i];
	}

	dp [0] [0] [0] = 1;
	for(int i = 0;i < N;i++){
		for(int j = 0;j <= N * 50;j++){
			for(int k = 0;k < N;k++){
				dp [i + 1] [j] [k] += dp [i] [j] [k];
				if(j + V [i] <= N * 50){
					dp [i + 1] [j + V [i]] [k + 1] += dp [i] [j] [k];
				}
			}
		}
	}

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

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 50048
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll A, B;
  cin >> A >> B;
  vector<vector<char>> board(100, vector<char>(100));
  for (ll i = 0; i < 100; ++i)
  {
    for (ll j = 0; j < 100; ++j)
    {
      if (i < 50)
      {
        board.at(i).at(j) = '.';
      }
      else
      {
        board.at(i).at(j) = '#';
      }
    }
  }
  ll b_row = (B - 1) / 50;
  ll b_remain = (B - 1) % 50;
  for (ll i = 0; i < 2 * b_row; ++i)
  {
    if (i % 2 == 1)
    {
      continue;
    }
    for (ll j = 0; j < 100; ++j)
    {
      if (j % 2 == 0)
      {
        board.at(i).at(j) = '#';
      }
    }
  }
  for (ll i = 0; i < 2 * b_remain; ++i)
  {
    if (i % 2 == 0)
    {

      board.at(b_row * 2).at(i) = '#';
    }
  }

  ll a_row = (A - 1) / 50;
  ll a_remain = (A - 1) % 50;
  for (ll i = 0; i < 2 * a_row; ++i)
  {
    if (i % 2 == 1)
    {
      continue;
    }
    for (ll j = 0; j < 100; ++j)
    {
      if (j % 2 == 0)
      {
        board.at(100 - i - 1).at(j) = '.';
      }
    }
  }
  for (ll i = 0; i < 2 * a_remain; ++i)
  {
    if (i % 2 == 0)
    {
      board.at(100 - a_row * 2 - 1).at(i) = '.';
    }
  }

  cout << 100 << ' ' << 100 << endl;
  for (ll i = 0; i < 100; ++i)
  {
    for (ll j = 0; j < 100; ++j)
    {
      cout << board.at(i).at(j);
    }
    cout << endl;
  }
}


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

using namespace std;

int n,m;
vector<vector<bool>> v;
int ans=0;

void recurse(int i)
{
    int cnt=0,idx=0;
    for(int j=0;j<n;j++) {
        if(v[i][j]){cnt++;idx=j;}
    }
    if(cnt==1){
        ans++;
        v[i][idx]=false;
        v[idx][i]=false;
        recurse(idx);
    }
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++) {
        vector<bool> tmp;
        for(int j=0;j<n;j++) {
            tmp.push_back(false);
        }
        v.push_back(tmp);
    }
    for(int i=0;i<m;i++) {
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a][b]=true;
        v[b][a]=true;
    }
    for(int i=0;i<n;i++) {
        recurse(i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,i,j,k,a[110][110],f[110][110];
int main(){
	scanf("%d",&n);
	for(i=1;i<=2;i++)
	  for (j=1;j<=n;j++)
	    scanf("%d",&a[i][j]);
	for (i=1;i<=2;i++)
	  for (j=1;j<=n;j++)
	    f[i][j]=max(f[i-1][j],f[i][j-1])+a[i][j];
	printf("%d",f[2][n]);
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
data=[]
for i in range(M):
    line=list(map(int,input().split()))
    data.append(line[1:])
P=list(map(int,input().split()))
def check(S):
    for x in range(M):
        cnt=0
        for s in data[x]:
            if S[s-1]=="1":
                cnt+=1
        if cnt%2!=P[x]:
            return False
    return True
ans=0
for i in range(pow(2,N)):
    S=bin(i)[2:]
    S="0"*(N-len(S))+S
    if check(S):
        ans+=1
print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
n = input()
s = input()
num = 0
l = 0
for c in s:
    if c=="(":
        num += 1
    else:
        if num>0:
            num -= 1
        else:
            l += 1
r = num

print("("*l+s+")"*r)


Measured memory_bytes: 2940
#include <math.h>
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main(void) {
    int n;
    cin >> n;
    int a[200000];
    for(int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        a[i] = temp;
    }
    int high = 0;
    long long total = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] >= high) {
            high = a[i];
        } else {
            total += high - a[i];
        }
    }
    cout << total << endl;
}


Measured memory_bytes: 4352
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	rep(i,n) {
		std::cin >> a[i];
		a[i]--;
	}
	std::vector<int> went(n,-1);
	int loop=0;
	int curr=0;
	rep(i,k) {
		debug(curr);
		if(went[curr]==-1) went[curr]=i;
		else {
			loop = i-went[curr];
			k-=i;
			k%=loop;
			debug(loop,k);
			rep(j,k) {
				curr=a[curr];
			}
			print(curr+1);
			return 0;
		}
		curr=a[curr];
	}
	print(curr+1);
	return 0;
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
int main () {
    string s[2];
    cin >> s[0] >> s[1];
    string t[2];
    t[0] = s[1], t[1] = s[0];
    reverse(t[0].begin(), t[0].end());
    reverse(t[1].begin(), t[1].end());
    if (s[0] == t[0] && s[1] == t[1]) {
        puts("YES");
    }
    else {
        puts("NO");
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101

int m[MAX][MAX];
int p[MAX];

int main(){
  int min(int,int);
  int n;
  int i;
  int j;
  int k;
  int l;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }

  for(i=2;i<=n;i++){
    for(j=0;j<=n-i+1;j++){
      k = j + i - 1;
      m[j][k] = (1<<21);
      for(l = j;l <= k-1;l++){
        m[j][k] = min(m[j][k],m[j][l] + m[l+1][k] + p[j-1]*p[l]*p[k]);
      }
    }
  }

  printf("%d\n",m[1][n]);
  return 0;
}

int min(int a,int b){
  if(a<b) return a;
  return b;
}



Measured memory_bytes: 2108
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

const ll MOD=1e9+7;

int N;
ll a[100100], b[100100];

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

  cin>>N;
  for(int i=0;i<N;i++) cin>>a[i];
  for(int i=0;i<N;i++) cin>>b[i];

  int res=0;
  ll s=0;
  vector<ll> v;
  for(int i=0;i<N;i++) {
    if (a[i] < b[i]) s += b[i]-a[i], res++;
    else v.pb(a[i]-b[i]);
  }
  sort(v.rbegin(),v.rend());

  for (ll k:v) {
    if (s==0) break;
    ll z = min(k,s);
    s-=z, res++;
  }

  cout << (s==0 ? res : -1) << endl;


  return 0;
}


Measured memory_bytes: 2936
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int n,k;
int a[200005];
int judge(int x)
{
	int i,cnt=0;
	for(i=1;i<=n;i++)
		cnt+=ceil(1.0*a[i]/x)-1;
	return cnt;
}
int main()
{
	int i,j;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int l=1,r=1e9;
	while(l<r)
	{
		int mid=l+r>>1;
		if(judge(mid)>k)
			l=mid+1;
		else r=mid;
	}
	printf("%d",l);
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

long long dp[110][100010];

int main(){

  int n, W; cin >> n >> W;
	long long w[n + 10], v[n + 10];

	for (int i = 0; i < n; i++)cin >> w[i] >> v[i];

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= W; j++) {

			if (j - w[i] >= 0) {
				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			}else dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);

		}
	}

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

  return 0;
}


Measured memory_bytes: 79360
import sys
input()
pt, px, py = 0, 0, 0
for ct, cx, cy in [map(int, e.split()) for e in sys.stdin]:
    d = (ct - pt) - abs(cx - px) - abs(cy - py)
    if d < 0 or d % 2 == 1:
        print('No')
        break
    pt, px, py = ct, cx, cy
else:
    print('Yes')

Measured memory_bytes: 48884
#include<iostream>
#include<vector>
#include<string>
#define int long long
using namespace std;

signed main() {
	vector<int>l(21);
	vector<int>r(21);
	int a;
	cin >> a;
	vector<int>b(a-1);
	int s;
	for (int c = 0; c < a - 1; c++) {
		cin >>b[c];
	}
	cin >> s;
	l[b[0]]++;
	for (int  d = 1; d < a - 1; d++) {
		for (int e = 0; e < 21; e++) {
			if (e + b[d] < 21)r[e + b[d]] += l[e];
			if (e - b[d] > -1)r[e - b[d]] += l[e];
		}
		for (int p = 0; p < 21; p++) {
			l[p] = r[p];
			r[p] = 0;
		}
	}
	cout << l[s] << endl;
}

Measured memory_bytes: 3096
n = int(input())
# a = [0 for i in range(n)]
a = [int(i) for i in input().split()]

count = 0
for i in range(n):
    while 1:
        if a[i] % 2 == 0:
            a[i] /= 2
            count += 1
        else:
            break
print(count)


Measured memory_bytes: 4148
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int A, B, M;
int a[123456], b[123456];

int main() {
	cin >> A >> B >> M;
	int as = INT_MAX, bs = INT_MAX;
	for (int i = 0; i < A; ++i) {
		cin >> a[i];
		as = min(as, a[i]);
	}
	for (int i = 0; i < B; ++i) {
		cin >> b[i];
		bs = min(bs, b[i]);
	}
	int ans = as + bs;
	for (int i = 0; i < M; ++i) {
		int x, y, c;
		cin >> x >> y >> c;
		--x;
		y--;
		ans = min(ans, a[x] + b[y] - c);
		a[x] + b[y] - c;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024