akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define lint long long
//#define P pair<int, int>

lint MOD = 1e9 + 7;


int main()
{
    int H, W;
    cin >> H >> W;
    
    vector<string> S(H);
    for(int i = 0; i < H; ++i){
        cin >> S[i];
    }
    
    int largest = 0;
    
    int L[H][W], R[H][W], U[H][W], D[H][W];
    
    for(int i = 0; i < H; ++i){
        L[i][0] = (S[i][0] != '#' ? 1 : 0);
        for(int j = 1; j < W; ++j){
            if(S[i][j] == '#') L[i][j] = 0;
            else L[i][j] = L[i][j - 1] + 1;
        }
        R[i][W - 1] = (S[i][W - 1] != '#' ? 1 : 0);
        for(int j = W - 2; j >= 0; --j){
            if(S[i][j] == '#') R[i][j] = 0;
            else R[i][j] = R[i][j + 1] + 1;
        }
    }
    
    for(int j = 0; j < W; ++j){
        U[0][j] = (S[0][j] != '#' ? 1 : 0);
        for(int i = 1; i < H; ++i){
            if(S[i][j] == '#') U[i][j] = 0;
            else U[i][j] = U[i - 1][j] + 1;
        }
        D[H - 1][j] = (S[H - 1][j] != '#' ? 1 : 0);
        for(int i = H - 2; i >= 0; --i){
            if(S[i][j] == '#') D[i][j] = 0;
            else D[i][j] = D[i + 1][j] + 1;
        }
    }
    
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            //cout <<  L[i][j] << R[i][j] << U[i][j] << D[i][j] << endl;
            largest = max(largest, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
        }
        //cout << endl;
    }
    
    cout << largest << endl;
}

Measured memory_bytes: 66816
let find_max m n = if m - n >= 0 then m else n in
    let rec pow m n =  if n - 1 >= 0 then m * pow m (n - 1) else 1 in 
    let a = ref 0 and b = ref 0 and c = ref 0 and k = ref 0 in
    Scanf.sscanf (read_line ()) "%d %d %d" (fun x y z -> a := x; b := y; c := z);
    Scanf.sscanf (read_line ()) "%d" (fun x -> k := x);
    print_int (!a + !b + !c + find_max (find_max !a !b) !c * pow 2 !k - find_max (find_max !a !b) !c); print_string "\n"

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

int a[100000] = {};

const long long mod = 1000000007;

long long mod_pow(long long x, long long n) {
    if(n == 0) return 1;
    long long res = mod_pow(x * x % mod, n / 2);
    if(n % 2) res = res * x % mod;
    return res;
}

int main() {
    int n, wrong = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int A;
        cin >> A;
        a[A]++;
    }
    if(n % 2) {
        for(int i = 0; i < n; i += 2) {
            if((i == 0 && a[i] != 1) || (i && a[i] != 2)) {
                wrong = 1;
                break;
            }
        }
    }
    else {
        for(int i = 1; i < n; i += 2) {
            if(a[i] != 2) {
                wrong = 1;
                break;
            }
        }
    }
    if(wrong) {
        cout << 0 << endl;
    }
    else {
        cout << mod_pow(2, n / 2) % mod << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
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() {
 int n,k;
  cin>>n>>k;
  vin p(n);
  rep(i,0,n) cin>>p[i];
  //
 sort(all(p));
  int ans=0;
  rep(i,0,k){
   ans+=p[i]; 
  }
  cout<<ans<<endl;
}

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

#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;

using namespace std;
 
int main() {
	int n,k;
    cin>>n>>k;
    int h[n];
    REP(i,n){
        cin>>h[i];
    }
    int cost[n];
    REP(i,n){
        int end;
        if(i>=k){
            end=k;
        }else{
            end=i;
        }
        if(i==0){
            cost[0]=0;
        }else{
        REP(j,end){
            if(j==0){
                cost[i]=cost[i-1-j]+abs(h[i]-h[i-1-j]);
            }else{
                if(cost[i]>cost[i-1-j]+abs(h[i]-h[i-1-j])){
                    cost[i]=cost[i-1-j]+abs(h[i]-h[i-1-j]);
                }
            }
        }
        }
    }
    cout<<cost[n-1];
	return 0;
}

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

int n, k, ans;

int dis1(int x) {
    return x;
}

int dis2(int x) {
    return k - x;
}

int main(void) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ans += min(dis1(x), dis2(x))*2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main()
{
	ll n;
	ll ans=0;
	cin>>n;
	if((n&1)||n==0)
	{
		cout<<0<<endl;
		return 0;
	}
	ll tmp=10;
	while(tmp<=n)
	{
		ans+=(n/tmp);
		tmp*=5;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;
  set<char> chs;
  bool ans = true;
  for (int i = 0; i < s.size(); ++i) {
    if (chs.count(s[i]) > 0) {
      ans = false;
      break;
    }

    chs.insert(s[i]);
  }

  if (ans) {
    cout << "yes" << '\n';
  } else {
    cout << "no" << '\n';
  }

  return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef vector<vector<P>> mat;


mat G(100010);
vec color(100010);
int M=0;
void DFS(int s,int p,int c){
    int k=1;
    for(auto t:G[s]){
        if(t.first==p){continue;}
        if(k==c){k++;}
        color[t.second]=k;
        M=max(M,k);
        DFS(t.first,s,k);
        k++;
    }
}

int main(){
    int N;cin>>N;
    
    int a,b;
    for(int i=0;i<N-1;i++){
        cin>>a>>b;
        G[a].push_back((P){b,i});
        G[b].push_back((P){a,i});
    }
    DFS(1,0,0);
    cout<<M<<endl;
    for(int i=0;i<N-1;i++){
        cout<<color[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 9472
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;

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

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

int main() {
  char C;
  cin >> C;
  
  if (C == 'a' || C == 'i' || C == 'u' || C == 'e' || C == 'o') {
    cout << "vowel";
  }
  else {
    cout << "consonant";
  }
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e6+5;

int s;
map<int, int> idx;

int32_t main()
{
	IOS;
	cin>>s;
	idx[s]=1;
	for(int i=2;;i++)
	{
		if(s%2==0)
			s/=2;
		else
			s=3*s+1;
		if(idx.find(s)!=idx.end())
		{
			cout<<i;
			return 0;
		}
		idx[s];
	}
	return 0;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = new int[3, 3];
            var B = new int[3, 3];

            for (int i = 0; i < 3; i++)
            {
                var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < 3; j++) A[i, j] = input[j];
            }

            var N = int.Parse(Console.ReadLine());
            for (int _ = 0; _ < N; _++)
            {
                var b = int.Parse(Console.ReadLine());
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        if (A[i, j] == b) B[i, j] = 1;
                    }
                }
            }

            Console.WriteLine(Judge(B) ? "Yes" : "No");
        }

        static bool Judge(int[,] B)
        {
            for (int i = 0; i < 3; i++) if (B[i, 0] + B[i, 1] + B[i, 2] == 3) return true;
            for (int i = 0; i < 3; i++) if (B[0, i] + B[1, i] + B[2, i] == 3) return true;
            if (B[0, 0] + B[1, 1] + B[2, 2] == 3 || B[2, 0] + B[1, 1] + B[0, 2] == 3) return true;
            return false;
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    if(a < b && b < c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<int> a(3);
 for(int i = 0;i<3;i++){
   cin >> a[i];
 }
  sort(a.begin(),a.end());
  cout << a[1]-a[0] + a[2]-a[1] << endl;
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

ll K;

int main() {
  cin >> K;

  if (K <= 1e16) {
    if (K == 0) {
      cout << 2 << endl;
      cout << 0 << " " << 0;
      return 0;
    }

    if (K == 1) {
      cout << 2 << endl;
      cout << 0 << " " << 2;
      return 0;
    }

    if (K % 2 == 0) {
      cout << 2 << endl;
      ll num = 1 + K / 2;
      cout << num << " " << num;
      return 0;
    }

    ll num = 1 + K / 2;
    cout << 2 << endl;
    cout << num + 2 << " " << num - 1;
    return 0;
  } else {
    ll base = 49 + K / 50;
    ll rest = K % 50;

    ll high = base + 50 - (rest - 1);
    ll low = base - rest;

    cout << 50 << endl;
    rep(i, 0, rest) { cout << high << " "; }
    rep(i, 0, 50 - rest) { cout << low << " "; }
  }
}


Measured memory_bytes: 3536
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
s = []
for i in range(N):
    s.append(list(input()))

count = 0
enda = 0
startb = 0
both = 0
for i in range(N):
    for j in range(len(s[i])-1):
        if s[i][j] == 'A' and s[i][j+1] == 'B':
            count += 1
    if s[i][-1] == 'A':
        enda += 1
    if s[i][0] == 'B':
        startb += 1
    if s[i][-1] == 'A' and s[i][0] == 'B':
        both += 1

temp = count+min(enda,startb)
if enda == startb == both and enda >= 1:
    temp -= 1
print(temp)

Measured memory_bytes: 44144
#include <iostream>
using namespace std;
int main(){

  int n,m,sh,s[200],a[200],b[200],i,j;

  cin>>n>>m;

  for(i = 0; i < 2*n; i++) s[i]=i+1;

  for(i = 0; i < m; i++){

    cin>>sh;

    if(sh != 0){

      for(j = 0; j < sh; j++) b[j]=s[j];
      for(j = 0; j < 2*n-sh; j++) a[j]=s[sh+j];
      
      for(j = 0; j < 2*n-sh; j++) s[j]=a[j];
      for(j = 0; j < sh; j++) s[2*n-sh+j]=b[j];

    } else {

      for(j = 0; j < n; j++) a[j]=s[j];
      for(j = 0; j < n; j++) b[j]=s[n+j];

      for(j = 0; j < n; j += 1){

        s[2*j]=a[j];
        s[2*j+1]=b[j];

      }

    }

  }

  for(i = 0; i < 2*n; i++) cout<<s[i]<<endl;
    
  return 0;

}

      

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

const int N = 100001;

int color[N];
bool vis[N][11];

vector<int> edges[N];

struct Query
{
	int v, d, c;
} queries[N];

void f(int v, int d, int c)
{
	if (!color[v]) {
		color[v] = c;
	}
	if (d > 0) {
		if (!vis[v][d - 1]) {
			vis[v][d - 1] = true;
			f(v, d - 1, c);
		}
		for (int i = 0; i < edges[v].size(); ++i) {
			if (!vis[edges[v][i]][d - 1]) {
				vis[edges[v][i]][d - 1] = true;
				f(edges[v][i], d - 1, c);
			}
		}
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		scanf("%d%d%d", &queries[i].v, &queries[i].d, &queries[i].c);
	}
	for (int i = q - 1; i >= 0; --i) {
		if (!vis[queries[i].v][queries[i].d]) {
			vis[queries[i].v][queries[i].d] = true;
			f(queries[i].v, queries[i].d, queries[i].c);
		}
	}
	for (int i = 1; i <= n; ++i) {
		printf("%d\n", color[i]);
	}
	return 0;
}



Measured memory_bytes: 9080
import bisect

N, Q = map(int, input().split())
S = input()
lr_list = [list(map(int, input().split())) for _ in range(Q)]

AC_l_list = []
AC_r_list = []

for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        AC_l_list.append(i)
        AC_r_list.append(i + 1)
        
        
for l, r in lr_list:
    i = bisect.bisect_left(AC_l_list, l - 1)
    j = bisect.bisect_right(AC_r_list, r - 1)
    print(j - i)

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

int n,m;

ll gcd(ll a,ll b){
	return b? gcd(b,a%b) : a;
}



int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	ll c=gcd(a,b);
	ll cnt=0;
	for(int i=2;i<=sqrt(c);i++){
		if(c%i==0){
			cnt++;
			while(c%i==0){
	//		printf("::%d\n",i);
	//		cnt++;
			c/=i;
			if(c==1)break;
		}
		}
		
	}
	if(c>1) cnt++;
	printf("%lld",cnt+1);
}

Measured memory_bytes: 3812
<?php
	fscanf(STDIN, "%d", $n);
	for ($i=0; $i<$n; $i++) {
      fscanf(STDIN, "%s %d", $s, $p);
	  $sp[] = array($s, -$p, $i);
    }
	sort($sp);
	for ($i=0; $i<$n; $i++) {
      echo $sp[$i][2] + 1 . "\n";
    }
?>
	

Measured memory_bytes: 4856
N = int(input())						# 5
a = list(input())
#b = [int(i) for i in input().split()]	# 1 2 3 4 5 ...

MOD = 1000000007

if N==1:
	print(3)
	exit(0)




b=[]
bSkip = False

for i in range(N):
	if bSkip:
		bSkip = False
		continue
	if i==N-1:
		b.append(1)
	else:
		if a[i] == a[i+1]:
			b.append(2)
			bSkip = True
		else:
			b.append(1)

#print(b)


if b[0]==1:
	ans = 3
else:
	ans = 6


for i in range(1, len(b)):
	if b[i-1]==1:
		ans = (ans * 2) % MOD
	else:
		if b[i]==2:
			ans = (ans * 3) % MOD


print(ans % MOD)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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








int main() {
    ll h, w;
    scanf("%lld %lld", &h, &w);
    char s[400][401];
    REP(i, h){
        scanf("%s", s[i]);
    }
    
    const ll dy[4] = {-1, 0, 1, 0};
    const ll dx[4] = {0, 1, 0, -1};
    bool used[400][401] = {};
    ll ans = 0;
    REP(i, h){
        REP(j, w){
            if(used[i][j]) continue;
            
            used[i][j] = true;
            queue<pair<pair<ll, ll>, char>> que;
            que.push({{i, j}, s[i][j]});
            ll p_cnt = 0, s_cnt = 0;
            while(!que.empty()){
                auto tmp = que.front(); que.pop();
                ll y = tmp.first.first, x = tmp.first.second, e = tmp.second;
                ((s[y][x] == '.')? p_cnt : s_cnt)++;
                REP(k, 4){
                    ll yy = y + dy[k], xx = x + dx[k];
                    if(yy >= 0 && yy < h && xx >= 0 && xx < w && s[yy][xx] != s[y][x] && !used[yy][xx]){
                        used[yy][xx] = true;
                        que.push({{yy, xx}, s[yy][xx]});
                    }
                }
            }
            
            ans += s_cnt * p_cnt;
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 512
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int s,w;
    cin >> s>>w;
    if(w>=s){
        cout<< "unsafe"<<endl;
    }
    else{
        cout << "safe"<<endl;
    }
}

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

using namespace std;

using pii = pair<int, int>;
using lli = long long int;

#define debug(args...) //fprintf(stderr, args)
#define pb push_back
#define all(xs) xs.begin(), xs.end()

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

int main() {
	int n;
	scanf("%d", &n);

	lli x = 1;

	for (int i = 0; i < n; ++i) {
		x *= 10; x %= MOD;
	}

	debug("%lld\n", x);

	lli y = 1;

	for (int i = 0; i < n; ++i) {
		y *= 9; y %= MOD;
	}
	debug("%lld\n", y);

	lli z = 1;

	for (int i = 0; i < n; ++i) {
		z *= 8; z %= MOD;
	}

	debug("%lld\n", z);

	x += -2*(y - z) - z;
	while (x < 0) x += MOD;
	//x = abs(x);
	x %= MOD;

	printf("%lld\n", x);
}

Measured memory_bytes: 3824
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int H[4],W[4],maximum,minimum;
int table[4][2000][2000];

bool check(int table_index,int diff){

	int left_front = -1,next_left_front,sum = 0;

	for(int col = 0; col < W[table_index]; col++){
		if(table[table_index][0][col] > minimum+diff)left_front = col;
	}

	for(int col = 0; col <= left_front; col++){
		if(table[table_index][0][col] < maximum-diff)return false;
	}

	sum += (left_front+1);

	for(int row = 1; row < H[table_index];row++){

		next_left_front = -1;
		for(int col = 0; col < W[table_index]; col++){
			if(table[table_index][row][col] > minimum+diff)next_left_front = col;
		}

		next_left_front = max(next_left_front,left_front);

		for(int col = 0; col <= next_left_front; col++){
			if(table[table_index][row][col] < maximum-diff)return false;
		}
		sum += (next_left_front+1);
		left_front = next_left_front;
	}

	if((sum == 0) || (sum == H[table_index]*W[table_index]))return false;

	return true;
}


int main(){

	scanf("%d %d",&H[0],&W[0]);

	maximum = -1;
	minimum = BIG_NUM;

	for(int row = 0; row < H[0]; row++){
		for(int col = 0; col < W[0]; col++){
			scanf("%d",&table[0][row][col]);
			maximum = max(maximum,table[0][row][col]);
			minimum = min(minimum,table[0][row][col]);
		}
	}

	//回転させたテーブルをあらかじめ作っておく
	for(int i = 1; i <= 3; i++){
		H[i] = W[i-1];
		W[i] = H[i-1];
		for(int row = 0; row < H[i-1]; row++){
			for(int col = 0; col < W[i-1]; col++){
				table[i][col][(W[i]-1)-row] = table[i-1][row][col];
			}
		}
	}

	int left = 0,right = maximum-minimum,m = (left+right)/2;
	int ans = maximum-minimum;

	bool FLG;

	while(left <= right){

		FLG = false;
		for(int i = 0; i < 4; i++){
			if(check(i,m)){
				FLG = true;
				break;
			}
		}
		if(FLG){
			ans = m;
			right = m-1;
		}else{
			left = m+1;
		}
		m = (left+right)/2;
	}

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

	return 0;
}



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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_T = 70;
const int MAX_P = 20;
int M, T, P, R;
int tID, pID, ti, mes;
int wa[MAX_T][MAX_P];

struct data{int a, p, id; };

inline bool operator < (const data& x, const data& y)
{
  return x.a!=y.a ? x.a<y.a : x.p!=y.p ? x.p>y.p : x.id < y.id;
  //  return x.a!=y.a ? x.a<y.a : x.p>y.p;
}

inline bool operator > (const data& x, const data& y)
{
  return !(x < y);
}

inline bool operator == (const data& x, const data& y)
{
  return x.a==y.a && x.p==y.p;
}

ostream& operator <<(ostream& r, const vector<data> t){vrep(v,t)r<<v->id<<(v+1==t.end()?"":*v==*(v+1)?"=":",");return r;}

int main()
{
  while(cin >> M >> T >> P >> R, T){
    vector<data> g(T, (data){0, 0, 0});
    rep(i, MAX_T) rep(j, MAX_P) wa[i][j] = 0;
    rep(i, T) g[i].id = i + 1;

    rep(i, R){
      cin >> ti >> tID >> pID >> mes;
      tID -= 1;  pID -= 1;
      if(mes == 0){
        g[tID].a += 1;
        g[tID].p += wa[tID][pID] * 20 + ti;
      }
      else wa[tID][pID] += 1;
    }
    sort(ALL(g), greater<data>());
    cout << g << endl;
  }

  return 0;
}

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

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> grid(h);
	for (int i = 0; i < h; i++) cin >> grid[i];
	int a[h][w], b[h][w];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			a[i][j] = grid[i][j]=='.' ? 1 : -1;
			b[i][j] = a[i][j];
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w-1; j++) {
			if (a[i][j] != -1 && a[i][j+1] != -1) a[i][j+1] += a[i][j];
		}
		for (int j = w-1; j > 0; j--) {
			if (a[i][j] != -1 && a[i][j-1] != -1) a[i][j-1] = a[i][j];
		}
	}
	for (int j = 0; j < w; j++) {
		for (int i = 0; i < h-1; i++) {
			if (b[i][j] != -1 && b[i+1][j] != -1) b[i+1][j] += b[i][j];
		}
		for (int i = h-1; i > 0; i--) {
			if (b[i][j] != -1 && b[i-1][j] != -1) b[i-1][j] = b[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			ans = max(ans, a[i][j]+b[i][j]-1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 42424
#include <bits/stdc++.h>
using namespace std;
int main() {
   int n;cin>>n;
   int t = n;
   int s = 0;
   while (t) {
        s += t%10;
        t /= 10;
   }
   if(n % s == 0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>

#include<vector>
using namespace std;




int main(){
   
    int D, G, p[11], c[11];
    cin >> D >> G;
    for(int i = 0; i < D; ++i){
        cin >> p[i] >> c[i];
    }
    int ans=1e9;
    
    for(int mask=0;mask<(1<<D);mask++){
        
        int s=0,num=0,rest_max=-1;
        
        for(int i=0;i<D;i++){
            if(mask&(1<<i)){
                s+=(i+1)*100*p[i]+c[i];
                num+=p[i];
            }else{
                rest_max=i;
            }
        }
    
    
    if(s<G){
        int s1=100*(rest_max+1);
        int need=(G-s+s1-1)/s1;
        if(need>=p[rest_max]){
            continue;
        }
        num+=need;
    }
    ans=min(ans,num);
        
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    return 0;
}


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

int main() {
	string s;
	cin >> s;
	int win = 0, lose = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s.at(i) == 'o')
		win++;
		else
		lose++;
	}
	
	if (15 - s.size() + win >= 8) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
n, w = map(int, input().split())
a = [[int(i) for i in input().split(" ")] for j in range(n)]
dp = [[0]+[float("inf")]*(10**5) for i in range(n+1)]
for i in range(1, n+1):
    w_, v_ = a[i-1]
    for j in range(1, 10**5+1):
        if j < v_:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = min(dp[i-1][j-v_]+w_, dp[i-1][j])
for i in range(10**5, -1, -1):
    if dp[n][i]<=w:
        print(i)
        break

Measured memory_bytes: 384920
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint dp[1010][1010],ink[1010][1010];
vector<lint> zyo;
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
int main()
{
	lint mo=1000000007;
	zyo.pb(1);
	rep(i,1919) zyo.pb((zyo[i]*(i+1))%mo);
	rep(i,1005) ink[i][1]=invMod(zyo[i],mo);
	rep(i,1005) REP(j,1,1005) ink[i][j+1]=(ink[i][j]*ink[i][1])%mo;
	
	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	memset(dp,0,sizeof(dp));
	dp[a][n]=1;
	REP(i,a,b+1) rep(j,n+1){
		if(dp[i][j]<0LL) cout<<i<<' '<<j<<endl;
		if(dp[i][j]<1LL) continue;
		//cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
		for(int k=c;k<=d && i*k<=j;k++){
			dp[i+1][j-i*k]+=(((dp[i][j]*ink[i][k])%mo*ink[k][1])%mo*zyo[j])%mo*ink[j-i*k][1];
			dp[i+1][j-i*k]%=mo;
		}
		dp[i+1][j]+=dp[i][j];dp[i+1][j]%=mo;
	}
	cout<<(dp[b+1][0]%mo)<<endl;
}


Measured memory_bytes: 16128
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (register ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (register ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 2e6 + 10 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 998244353 ;
const double eps = 1e-7 ;
template <class T> void read(T &a)
{
	int f = 1 ; a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	a *= f;
}

void Plus(ll &a, ll b)
{
	a += b;
	if(a >= mod) a -= mod;
	if(a < 0) a += mod;
	return ;
}

ll n, a[maxn], w;

ll ans;

ll mu[maxn];

ll g[maxn], s[maxn];

ll power(ll a, ll b)
{
	ll ret = 1;
	for(; b; b >>= 1, (a *= a) %= mod) if(b & 1) (ret *= a) %= mod;
	return ret;
}

ll vis[maxn], prime[maxn], tot;

void init()
{
	mu[1] = 1;
	ll N = 1000000;
	rep(i, 2, N)
	{
		if(!vis[i]) vis[i] = 1, prime[++tot] = i, mu[i] = -1;
		for(ll j = 1; j <= tot && i * prime[j] <= N; ++j)
		{
			vis[i * prime[j]] = 1;
			if(i % prime[j] == 0)
			{
				mu[i * prime[j]] = 0;
				break;
			}
			mu[i * prime[j]] = -mu[i];
		}
	}
}

signed main()
{
	init();
	scanf("%lld", &n);
	rep(i, 1, n) scanf("%lld", &a[i]), s[a[i]] ++, w = max(w, a[i]);
	rep(i, 1, w)
	{
		ll sum = 0;
		rep(j, 1, w)
		{
			if(i * j > w) break;
			Plus(g[i], sum * s[i * j] % mod * i % mod * j % mod);
			Plus(g[i], s[i * j] * (s[i * j] - 1) / 2 * i % mod * j % mod * i % mod * j % mod);
			Plus(sum, s[i * j] * i % mod * j % mod);
		}
	}
	// rep(i, 1, w) printf("g : %lld\n", g[i]);
	rep(i, 1, w)
	{
		ll sum = 0;
		rep(j, 1, w)
		{
			if(i * j > w) break;
			Plus(sum, mu[j] * g[i * j]);
		}
		Plus(ans, sum * power(i, mod - 2) % mod);
	}
	printf("%lld\n", ans);
	return 0;
}

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

typedef long long ll;

int N;
ll A[310][310];
ll ans = 0;
bool mem[310][310] = {0};

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)for(int j = 0; j < N; j++)scanf("%lld",&A[i][j]);

    for(int k = 0; k < N; k++)
    {
        for(int i = 0; i < N; i++)
        {
            for(int j = 0; j < N; j++)
            {
                if(k == i || k == j || i == j)continue;
                if(A[i][j] > A[i][k] + A[k][j])
                {
                    printf("-1\n");
                    return 0;
                }
                if(A[i][j] == A[i][k] + A[k][j])mem[i][j] = true;
            }
        }
    }
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < i; j++)
        {
            if(!mem[i][j])ans += A[i][j];
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

typedef long long ll;

int main() {        
	int n;
	cin >> n;
	vector<int> t(n);
	vector<pair<int,int>> point(n);
	for (int i = 0; i < n; ++i) {
		cin >> t[i] >> point[i].first >> point[i].second;
	}
	//int last = 0;
	int left = 0;
	int right = 0;
	int tt = 0;
	for (int i = 0; i < n; ++i) {
		int a = abs(left - point[i].first);
		int b =  abs(right - point[i].second);
		if (a + b  > t[i] - tt || ((a + b) % 2 != (t[i] - tt) % 2)) {
			cout << "No";
			return 0;
		}
		left = point[i].first;
		right = point[i].second;
		tt = t[i];
	}
	cout << "Yes";
}





Measured memory_bytes: 4588
#include <iostream>

using namespace std;

int main()
{
	int qq;
	
	for(int i = 1; i < 10; i++){
		for(int iq = 1; iq < 10; iq++){
			qq = i * iq;
			
			cout << i << "x" << iq << "=" << qq << endl;
		}
	}
    
    return 0;
}

Measured memory_bytes: 1116
function main (input) {
  input = input.trim().split("\n");
  const n = Number(input[0]);
  const as = input[1].split(' ').map(n => Number(n));
  let total = 0;
  for (const a of as) {
  	total += 1/a
  }
  const result = 1/total;
  console.log(result);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cctype>
#include <stdio.h>
using namespace std;

int main(){
    int A,B;
    string op;
    cin >> A >> op >> B;
    if(op=="+"){
        cout << A + B << endl;
    } else {
        cout << A - B << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
   
   int main(void){
           while(1){
                   int n,m;
                   scanf("%d%d",&n,&m);
                   if(n==0&&m==0)
                           break;
                   int Taro[100]={0},hanako[100]={0};
                  int sum[3]={200,200,200},sumtaro=0,sumhanako=0,i,o,p=0;
                  for(i=0;i<n;i++){
                          scanf("%d",&Taro[i]);sumtaro+=Taro[i];}
                  for(i=0;i<m;i++){
                          scanf("%d",&hanako[i]);sumhanako+=hanako[i];}
                  for(i=0;i<n;i++){
                          for(o=0;o<m;o++){
                                  if(sumtaro-Taro[i]+hanako[o]==sumhanako+Taro[i]-hanako[o])                                  {
                                          if(sum[2]>Taro[i]+hanako[o]){
                                          sum[0]=Taro[i];
                                         sum[1]=hanako[o];
                                          sum[2]=Taro[i]+hanako[o];p++;}
                                  }       
                          }       
                  }       
                 
                  
         if(p==0)                printf("-1\n");
          else
                         printf("%d %d\n",sum[0],sum[1]);
         }               
          return 0;       
  }       

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

#define pb push_back
#define ll long long int
#define MD 1000000007

vector<int> E[100005];
ll dp[100005][2];  // w, b

void dfs(int n, int p)
{
    ll h0 = 1, h1 = 1;
    for (int i = 0; i < E[n].size(); i++)
    {
        int c = E[n][i];
        if (c == p) continue;
        dfs(c, n);
        h0 = h0 * (dp[c][0] + dp[c][1]) % MD;
        h1 = h1 * dp[c][0] % MD;
    }
    dp[n][0] = h0;
    dp[n][1] = h1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    if (N == 1)
    {
        cout << "2\n";
        return(0);
    }
    for (int i = 1; i < N; i++)
    {
        int x, y;
        cin >> x >> y;
        E[x].pb(y);
        E[y].pb(x);
    }
    dfs(1, -1);
    cout << (dp[1][0] + dp[1][1]) % MD << '\n';
    return(0);
}

Measured memory_bytes: 14208
//Author: AnandRaj anand873
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 2e9+7,MAX = 1e5+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
}
//////////////////Sieve////////////////////

int main()
{
	int a,b;
	cin>>a>>b;
	cout<<a*b<<endl;
}		

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

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

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 INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int n,m,x;

int main(){
   cin>>n>>m>>x;
   ll c[n],a[n][m];
   REP(i,n){
      cin>>c[i];
      REP(j,m) cin>>a[i][j];
   }
   ll kingaku=INF;
   
   REP(i,1<<n){
      ll kin=0;
      ll skill[m]={};
      REP(j,n){
         if((i>>j)%2){
            kin+=c[j];
            REP(k,m) skill[k]+=a[j][k];
         }
      }
      bool res=true;
      REP(k,m){
         res&=(skill[k]>=x);
         if(!res) break;
      }
      if(res)kingaku=min(kingaku,kin);
   }
   if(kingaku==INF)cout<<"-1";
   else cout<<kingaku;cout<<endl;
   return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int>vec(N);
  for ( int i = 0; i < N; i++ ) {
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int A = 0;
  int B = 0;
  
  for ( int i = 0;i < N; i += 2 ) {
    A += vec.at(i);
  }
  
  for ( int i = 1;i < N; i += 2 ) {
    B += vec.at(i);
  }
  
  cout << A - B << endl;
}
  
  

Measured memory_bytes: 256
from collections import deque

k = int(input())

q = deque(range(1, 10))

for i in range(k):
    t = q.popleft()

    if t % 10 != 0:
        q.append(10 * t + t % 10 - 1)

    q.append(10 * t + t % 10)

    if t % 10 != 9:
        q.append(10 * t + t % 10 + 1)
 
print(t)


Measured memory_bytes: 11908
using System;
namespace inonoa{
    class Aio{
        static void Main(){
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            string[] a_ = Console.ReadLine().Split(' ');
            for (int i=0;i<n;i++){
                a[i] = int.Parse(a_[i]);
            }
            int min_index = 0;
            int min = 1000000000+1;
            for(int i=0;i<n;i++){
                if(a[i]>=0){
                    if(min>a[i]){
                        min = a[i];
                        min_index = i;
                    }
                }else{
                    if(min>-a[i]){
                        min = -a[i];
                        min_index = i;
                    }
                }
            }
 
            
                for(int i=0;i<min_index;i++){
                    if(a[i]<0){
                        a[i] = -a[i];
                        a[i+1] = -a[i+1];
                    }
                }
                for(int i=n-1;i>min_index;i--){
                    if(a[i]<0){
                        a[i] = -a[i];
                        a[i-1] = -a[i-1];
                    }
                }
                long ans = 0;
                for(int i=0;i<n;i++){
                    ans += a[i];
                }
                Console.WriteLine(ans);
 
            /* 
            long ans = 0;
            for(int i=0;i<n;i++){
                if(i==min_index){
                    if(min>0){
                        ans += -min;
                    }else{
                        ans += min;
                    }
                }
                else{
                    if(a[i]>0){
                        ans += a[i];
                    }else{
                        ans -= a[i];
                    }
                }
            }
            */
        }
    }
}


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

typedef long long ll;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main()
{
    int N, M;
    cin >> N >> M;
    v<int> k(M, 0), p(M);
    vv<int> s(M);

    for (int i = 0; i < M; i++)
    {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++)
        {
            int r;
            cin >> r;
            s[i].push_back(r);
        }
    }

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

    int cnt = 0;
    for (int bit = 0; bit < (1 << N); bit++)
    {
        v<bool> v(N, false);
        for (int i = 0; i < N; i++)
        {
            if (bit & (1 << i))
                v[i] = true;
        }

        int right = 0;

        for (int i = 0; i < M; i++)
        {
            int n_s = 0;
            for (int j = 0; j < k[i]; j++)
            {
                if (v[s[i][j]-1])
                    n_s++;
            }
            if (n_s % 2 == p[i])
                right++;
        }

        if (right == M)
            cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<cstdio>
#include<iostream>
using namespace std;
int sx,sy,tx,ty;
int main()
{
    while(scanf("%d%d%d%d",&sx,&sy,&tx,&ty)!=EOF)
    {
        for(int i=sy;i<=ty-1;i++)
        {
            cout<<"U";
        }
        for(int i=sx;i<=tx-1;i++)
        {
            cout<<"R";
        }
        for(int i=ty-1;i>=sy;i--)
        {
            cout<<"D";
        }
        for(int i=tx-1;i>=sx;i--)
        {
            cout<<"L";
        }
        cout<<"L";
        for(int i=sy;i<=ty;i++)
        {
            cout<<"U";
        }
        for(int i=sx;i<=tx;i++)
        {
            cout<<"R";
        }
        cout<<"D";
        cout<<"R";
        for(int i=ty;i>=sy;i--)
        {
            cout<<"D";
        }
        for(int i=tx;i>=sx;i--)
        {
            cout<<"L";
        }
        cout<<"U";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

namespace search {
    bool binary_search(int x, vector<int> k) { int i, l = 0, r = k.size(); while (r - l >= 1) { i = (l + r) / 2; if (i == x) return true; else if (i < x) l = i + 1; else r = i; } return false; }
}

using namespace search;

int K, S;

void solve() {
    int res = 0;
    for (int x = 0; K >= x; x++) {
        for (int y = 0; K >= y; y++) {
            if (S - x - y <= K && S - x - y >= 0) res++;
        }
    }
    cout << res << endl;
    return;
}

int main(){
    cin >> K >> S;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define mod 998244353
#define maxn 200010
#define LL long long
using namespace std;
LL fact[maxn],inv[maxn],ans,t[maxn],p;
int n,m,k,nm;
LL quick_pow(LL a,LL b){//a^b
	LL ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans%mod;
}
void init(){
	int i;
	scanf("%d%d%d",&n,&m,&k);
	nm=n,nm=max(nm,m),fact[0]=1;
	for(i=1;i<=nm;i++)fact[i]=fact[i-1]*i%mod;//fact[i]代表i!
	inv[nm]=quick_pow(fact[nm],mod-2);
	for(i=nm-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;//inv[i]代表i!的乘法逆元
}
LL C(LL a,LL b){//组合数计算
	return fact[a]*inv[a-b]%mod*inv[b]%mod;
}
int main(){
	int i;
	init();
	ans=0,p=quick_pow(m-1,n-k-1);
	for(i=n-k;i<=n;i++){
		ans=(ans+m*p%mod*C(n-1,i-1)%mod)%mod;//C(n-1,i-1)隔板法
		p=p*(m-1)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n; cin >> n;
    map<string, int> ma;
    rep(i,n){
        string s; cin >> s;
        ma[s]++;
    }
    cout << "AC x " << ma["AC"] << endl;
    cout << "WA x " << ma["WA"] << endl;
    cout << "TLE x " << ma["TLE"] << endl;
    cout << "RE x " << ma["RE"] << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
unsigned long long a[101];
inline long long read(){
	long long x=0;
	bool f=0;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=!f;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0',c=getchar();
	}
	return f?-x:x;
}
unsigned long long gcd(unsigned long long x,unsigned long long y){
	if(y==0) return x;
	else return gcd(y,x%y);
}
int main(){
	int n;
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	unsigned long long zs;
	for(int i=2;i<=n;++i){
		a[i]=a[i]/gcd(a[i],a[i-1])*a[i-1];
	}
	cout<<a[n];
	puts("");
	return 0;
}

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

vector<int> ser;
int N, K;

int main(){
  cin >> N >> K;
  
  int v;
  for(int i = 0; i < N; i++){ cin >> v; ser.push_back(v); }  //任意のi,jでi != j ⇔ ai != ajなのでいらない？

  int j = 1;
  while(K * j - (j-1) < N) j++;

  cout << j << endl;
  return 0;
}

  

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

using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	vector<vector<int>> hoge(n,vector<int>(k,0));

	for(int i=0;i<k;i++){
		int d;
		cin>>d;
		for(int j=0;j<d;j++){
			int have;
			cin>>have;
			hoge.at(have-1).at(i)++;
		}
	}

	int ans=0;

	for(auto a:hoge){
		bool flag=true;
		for(auto b:a){
			if(b==1){
				flag=false;
				break;
			}
		}
		if(flag) ans++;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
char s[101010];
int main()
{
	int l;
	scanf("%s",s);
	l=strlen(s);
	int ans=l/2;
	for(int i=0;i<l;i++)
		if(s[i]=='p')
			ans--;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author lucasr
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMultipleOf9 solver = new BMultipleOf9();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMultipleOf9 {
        public void solve(int testNumber, MyScanner sc, PrintWriter out) {
            char[] vals = sc.next().toCharArray();
            int sum = 0;
            for (int i = 0; i < vals.length; i++) {
                sum += vals[i] - '0';
            }
            out.println(sum % 9 == 0 ? "Yes" : "No");
        }

    }

    static class MyScanner {
        private BufferedReader br;
        private StringTokenizer tokenizer;

        public MyScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 36472