akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;

int main(){
    int w, h;
    cin >> w >> h;
    int mat[h][w], sum = 0;
    vector<int> one, zero;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
            if(i==0){
                if(mat[i][j]==0)    zero.push_back(j);
                else                one.push_back(j);
            }
        }
    }
    bool valid = false;
    if(zero.size() == (w+1)/2){
        bool ng = false;
        vector<int> ind;
        for(int i = 0; i < zero.size(); i++){
            ind.push_back(zero[i]);
            if(i < one.size())  ind.push_back(one[i]);
        }
        int z = 1;
        for(int i = 1; i < h; i++){
            int bef = mat[i][ind[0]];
            bool ok = true;
            for(int j = 1; j < w; j++){
                ok &= bef != mat[i][ind[j]];
                bef = mat[i][ind[j]];
            }
            if(!ok){
                ng = true;
                break;
            }
            if(ok && mat[i][ind[0]]==0) z++;
        }
        if(!ng && (z == h/2 || z == (h+1)/2))    valid = true;
    }
    if(one.size() == (w+1)/2){
        bool ng = false;
        vector<int> ind;
        for(int i = 0; i < one.size(); i++){
            ind.push_back(one[i]);
            if(i < zero.size())  ind.push_back(zero[i]);
        }
        int o = 1;
        for(int i = 1; i < h; i++){
            int bef = mat[i][ind[0]];
            bool ok = true;
            for(int j = 1; j < w; j++){
                ok &= bef != mat[i][ind[j]];
                bef = mat[i][ind[j]];
            }
            if(!ok){
                ng = true;
                break;
            }
            if(ok && mat[i][ind[0]]==1) o++;
        }
        if(!ng && (o == h/2 || o == (h+1)/2))    valid = true;
    }
    cout << (valid ? "yes" : "no") << endl;
    return 0;
}


Measured memory_bytes: 7012
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int A, B; cin >> A >> B;
  if (A <= 5) cout << 0 << endl;
  else if (A < 13) cout << B/2 << endl;
  else cout << B << endl;
}


Measured memory_bytes: 3596
n = int(input())
for i in range(n-1):
    n *= i+1
y = 1
while n % 2 == 0:
    y += 1
    n //= 2
f = 3
x = 1
while n > 1:
    if n % f == 0:
        x += 1
        n //= f
    else:
        f += 2
        y *= x
        x = 1
else: y *= x
print(y%1000000007)

Measured memory_bytes: 3064
void main()
{
    long v, e, r;
    rdVals(v, e, r);

    Graph[][] g = new Graph[][](v);
    foreach (i; 0 .. e)
    {
        long s, t, d;
        rdVals(s, t, d);
        g[s] ~= Graph(t, d);
    }

    long[] Dijkstra(long x)
    {
        long[] result = new long[v];
        result[] = inf;
        result[x] = 0;

        auto que = new BinaryHeap!(Array!Graph, "a.cost > b.cost");
        que.insert(Graph(x, 0));
        while (!que.empty)
        {
            Graph f = que.front;
            que.popFront;
            if (f.cost > result[f.to]) continue;
            foreach (y; g[f.to])
            {
                if (result[y.to] > result[f.to] + y.cost)
                {
                    result[y.to] = result[f.to] + y.cost;
                    que.insert(Graph(y.to, result[y.to]));
                }
            }
        }

        return result;
    }

    long[] dist = Dijkstra(r);
    foreach (x; dist)
    {
        if (x == inf) "INF".writeln;
        else x.writeln;
    }
}

struct Graph
{
    long to, cost;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;


Measured memory_bytes: 43208
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $n = <STDIN>);
chomp (my @a = split / /, <STDIN>);
my @f;
$f[0] = 0;
for my $i (1..$n) {
  $f[$i] = $a[$i-1] + $f[$i-1];
}
my %h;
$h{$_}++ for @f;
my $ans = 0;
for my $value (values %h) {
  $ans += $value * ($value - 1) / 2 if $value > 1;
}
say $ans;

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

string S;
int main(){

    cin >> S;
    int up = atoi(S.substr(0, 2).c_str());
    int lw = atoi(S.substr(2, 2).c_str());
    bool yymm = false;
    bool mmyy = false;
    if(up >= 0 && up <= 99 && lw >= 1 && lw <= 12){
        yymm = true;
    }
    if(lw >= 0 && lw <= 99 && up >= 1 && up <= 12){
        mmyy = true;
    }
    if(yymm && !mmyy){
        cout<< "YYMM" << endl;
    }
    else if(!yymm && mmyy){
        cout<< "MMYY" << endl;
    }
    else if(yymm && mmyy){
        cout << "AMBIGUOUS" << endl;
        
    }
    else{
        cout << "NA" << endl;
    }
    

    return 0;
}


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

using namespace std;

const unsigned long long int MAXN = 1000001L;
int preffix_L[MAXN], preffix_R[MAXN], suffix_L[MAXN], suffix_R[MAXN], ans[MAXN];

int main() {
    string S;
    cin >> S;
    int N = S.size();

    // sum of preffixes
    for(int i = 0; i < N; ++i) {
        if('L' == S[i]) {
            preffix_L[i] = preffix_L[i-1]+1;
            preffix_R[i] = 0;
        } else {
            preffix_R[i] = preffix_R[i-1]+1;
            preffix_L[i] = 0;
        }
    }

    // sum of suffixes
    for(int i = N; i >= 0; --i) {
        if('L' == S[i]) {
            suffix_L[i] = suffix_L[i+1]+1;
            suffix_R[i] = 0;
        } else {
            suffix_R[i] = suffix_R[i+1]+1;
            suffix_L[i] = 0;
        }
    }

    for(int i = 0; i < N-1; ++i) {
        if('R' == S[i] and 'L' == S[i+1]) {
            ans[i] = (preffix_R[i]+1)/2 + suffix_L[i+1]/2;
            ans[i+1] = preffix_R[i]/2 + (suffix_L[i+1]+1)/2;
        }
    }

    for(int i = 0; i < N; ++i)
        cout << ans[i] << " ";
    cout << endl;

    return 0;
}



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

int main() {
  int N, A, det;
  cin >> N >> A;
  det = N % 500 - A;
  
  if (det <= 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);

    if(a > b){
        printf("a > b\n");
    }else if(a < b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }

    return 0;
}


Measured memory_bytes: 2112
<?php
list($n, $m) = explode(" ", trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    $a[] = explode(" ", trim(fgets(STDIN)));
}
for ($i = 0; $i < $m; $i++) {
    $b[] = trim(fgets(STDIN));
}
for ($i = 0; $i < $n; $i++) {
    $c[] = 0;
    for ($j = 0; $j < $m; $j++) {
        $c[$i] += $a[$i][$j] * $b[$j];
    }
    echo $c[$i]. PHP_EOL;
}

Measured memory_bytes: 10968
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
using namespace std;
int field[128][128];
bool memo[128][128];
int w,h;
void func(int x,int y,int c){
	if(x < 1 || y < 1 || x > w || y > h)return;
	if(memo[y][x])return ;
	if(field[y][x] != c)return ;
	memo[y][x] = 1;
	func(x-1,y,c);
	func(x+1,y,c);
	func(x,y+1,c);
	func(x,y-1,c);
	return ;
}
int main(){
	while(scanf("%d%d",&w,&h),w,h){
		int xs,ys,xg,yg,n;
		memset(field,0,sizeof(field));
		memset(memo,0,sizeof(memo));
		scanf("%d%d%d%d%d",&xs,&ys,&xg,&yg,&n);
		for(int i = 0; i < n; i++){
			int c,d,x,y;
			scanf("%d%d%d%d",&c,&d,&x,&y);
			if(d == 0){
				for(int j = x; j < x + 4; j++){
					field[y][j] = c;
					field[y+1][j] = c;
				}
			}
			else{
				for(int j = y; j < y + 4; j++){
					field[j][x] = c;
					field[j][x+1] = c;
				}
			}
		}
		func(xs,ys,field[ys][xs]);
		cout << (memo[yg][xg]?"OK":"NG") << endl;
	}
	return 0;
}

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

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


Measured memory_bytes: 1024
/*input
6
AC
TLE
AC
AC
WA
TLE
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>

using namespace std; 

int GCD(int x,int y){return y?GCD(y,x%y):x;}
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define rept(v) for(auto it=v.begin();it<v.end();it++)
#define all(v) v.begin(),v.end()
const int INF = 1<<30;
typedef long long ll;
typedef pair<int,int> pii;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	string s;
	int ac=0,wa=0,tle=0,re=0;
	rep(i, n) {
		cin >> s;
		if(s=="AC") ac++;
		else if(s=="WA") wa++;
		else if(s=="TLE") tle++;
		else re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
	return 0;
}

Measured memory_bytes: 3640
N, K = map(int, input().split())
S = list(input())

if S[K-1] == "A":
    S[K-1] = "a"
    print("".join(S))
elif S[K-1] == "B":
    S[K-1] = "b"
    print("".join(S))
elif S[K-1] == "C":
    S[K-1] = "c"
    print("".join(S))

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0, cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A')
      cnt++;
    else if (s[i] == 'T')
      cnt++;
    else if (s[i] == 'C')
      cnt++;
    else if (s[i] == 'G')
      cnt++;
    else
      cnt = 0;
    ans = max(ans, cnt);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_176
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();

            long res = 0;
            long max = 0;
            for(int i = 0; i < n; i++)
            {
                max = Max(max, array[i]);
                res += max - array[i];
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 46156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
		}
		bubbleSort(a, n);
	}

	static int[] bubbleSort(int[] a, int n) {
		int flg = 1;
		int cnt = 0;
		while(flg == 1){
			flg = 0;
			for(int j = n - 1 ; j >= 1 ; j--) {
				if(a[j] < a[j - 1]) {
					int v = a[j];
					a[j] = a[j - 1];
					a[j - 1] = v;
					flg = 1;
					cnt++;
				}
			}
		}
		for(int i = 0 ; i < n ; i++) {
			if(i != n - 1) {
				System.out.print(a[i] + " ");
			} else {
				System.out.println(a[i]);
			}
		}
		System.out.println(cnt);
		return a;
	}

}

Measured memory_bytes: 26356
n,m = map(int, input().split())
ref = list(map(int, input().split()))
ref = set(ref[1:])
if n==1:
  print(len(ref))
else:
  for i in range(n-1):
    con = list(map(int, input().split()))
    con = set(con[1:])
    ref = ref&con
    if len(ref)==0:
      break
  print(len(ref))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
double ac;
double TLE() {return (double)(clock() - ac) / CLOCKS_PER_SEC;}
//only try

int main(){
 std::ios::sync_with_stdio(0);
 char c;
 cin>>c;
 if(isupper(c))cout<<"A\n";
 else cout<<"a\n";
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int x, y, z;
    cin >> x >> y >> z;
    x -= z;
    int ans = x / (y + z);
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
//文字の並び方が同じなら入れ替えて実現できる
int main(){
	string S,T;
	cin >> S;
	cin >> T;
	// cout << S << endl;
	// cout << T << endl;
	vector<int> sc(26,0);
	vector<int> tc(26,0);
	vector<int> s;
	vector<int> t;
	int k = 1;
	for (ll i = 0;i < S.size();i++){
		if (sc[S[i] - 'a'] == 0){//初めて出てきた文字
			sc[S[i] - 'a'] = k;
			s.pb(k);
			k++;
		}
		else{
			s.pb(sc[S[i] - 'a']);
		}
	}

	k = 1;
	for (ll i = 0;i < S.size();i++){
		if (tc[T[i] - 'a'] == 0){//初めて出てきた文字
			tc[T[i] - 'a'] = k;
			t.pb(k);
			k++;
		}
		else{
			t.pb(tc[T[i] - 'a']);
		}
	}
	int flag = 0;
	for (ll i = 0;i < s.size();i++){
		if (s[i] != t[i]){
			flag = 1;
			break;
		}
	}
	if (flag == 1){
		cout << "No" <<endl; 
	}
	else{
		cout << "Yes" <<endl; 
	}

	return 0;
}

Measured memory_bytes: 2940
// テ」ツつ「テ」ツつォテ」ツつヲテ」ツδウテ」ツδ暗ゥツ鳴禿ゥツ?陛」ツ?暗」ツ?淌・ツ按?」ツ?ョテ」ツδ堙」ツδ甘」ツδォテ」ツδ?」ツつ」ireta
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

long double calcArea( vector<long double> v ) {
  long double sum = 0;
  
  for(int i=0; i<v.size(); i++) {
    sum += sin(v[i]*M_PI/180);
  }
  
  return sum;
}

int main() {

  vector<long double> in;
  int n;
  while(cin >> n, n) {
    in.clear();
    
    long double sum = 0;
    for(int i=0; i<n-1; i++) {
      long double x;
      cin >> x;
      in.push_back(x);
      sum += x;
    }
    if( 360-sum < 180 ) {
      in.push_back(360-sum);
    }
    
    long double A1 = calcArea(in);

    in.clear();
    int m;
    cin >> m;

    sum = 0;
    for(int i=0; i<m-1; i++) {
      long double x;
      cin >> x;
      in.push_back(x);
      sum += x;
    }
    
    if( 360-sum < 180 ) {
      in.push_back(360-sum);
    }
    long double A2 = calcArea(in);
    
    if( (float)A1 < (float)A2 ) cout << 2 << endl;
    else if( (float)A1 == (float)A2 ) cout << 0 << endl;
    else cout << 1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1260
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int N, R;

    cin >> N >> R;

    if(N>=10) {
        cout << R << endl;
    } else {
        cout << R+(100*(10-N)) << endl;
    }

    return 0;
    
}

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

int main()
{cin.tie(0);
cin.sync_with_stdio(0);
int a,c=1;
cin>>a;
string str;
string arr[a];
for(int i=0;i<a;i++)
    cin>>arr[i];
sort(arr,arr+a);
for(int i=1;i<a;i++)
   if(arr[i]!=arr[i-1])
    c++;
  cout<<c;}


Measured memory_bytes: 9844
def dp(a):
	dp_list = [ 1 for i in range(a+1) ]
	for i in range(2,a+1):
		dp_list[i] = (dp_list[i-1] + dp_list[i-2]) % mod
	return dp_list

n, m = [ int(v) for v in input().split() ]
mod = 10**9+7
l, r = 0, 0
s = 0
stop = 0
c = -100
step_list = [ None for i in range(m+1) ]

for i in range(m):
	b = int(input())
	l, r = b-1,b+1
	d = l-s
	step_list[i] = d
	s = r
	if b == c+1:
		stop = 1
		break
	c = b
	
step_list[-1] = (n-r)


if stop == 0:
	ans = 1
	step2_list = dp(max(step_list))
	for i in step_list:
		ans = (ans*step2_list[i])%mod

	print(ans)
else:
	print(0)

Measured memory_bytes: 7064
n, a, b = list(map(int, input().split()))

mod = 10**9 + 7

# x ** a をmodで割った余りを、O(log(a))時間で求める。
def power(x, a):
	if a == 0:
		return 1
	elif a == 1:
		return x
	elif a % 2 == 0:
		return power(x, a//2) **2 % mod
	else:
		return power(x, a//2) **2 * x % mod


# xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
# https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
def modinv(x):
	return power(x, mod-2)

mod_table = [-1] * (b+1)
mod_table[1] = 1
for i in range(2, b+1):
    mod_table[i] = (mod_table[i - 1] * (i)) % mod

def binomial_coefficients2(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans %= mod
    ans *= modinv(mod_table[k])
    return ans % mod

# (2 ** n - 1) - nCa - nCb
ans = power(2, n) - 1

ans -= (binomial_coefficients2(n, a) + binomial_coefficients2(n, b))
print(ans % mod)


Measured memory_bytes: 10868
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int d;
vector<int> c(26);
vector<vector<int>> s(400, vector<int>(26));

int get_score(vector<int> t){
    int ans = 0;
    vector<int> last(26, 0);
    rep(i, d){
        ans += s[i][t[i]];
        rep(j, 26){
            if(t[i] == j)last[j] = i+1;
            ans -= c[j] * ((i+1)-last[j]);
        }
    }
    return ans;
}

int main() {
    cin >> d;
    rep(i, 26)cin >> c[i];
    rep(i, d)rep(j, 26)cin >> s[i][j];
    //-----code------//
    vector<int> t(d);
    rep(i, d){cin >> t[i]; t[i]--;}
    int m;
    cin >> m;
    rep(i, m){
        int D, q;
        cin >> D >> q;
        t[D-1] = q-1;
        cout << get_score(t) << endl;
    }
}


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

bool ispalindrome (string s, int start, int end)
{
	int i=start-1;
	int j=end+1;

	while (i<j and s[++i]==s[--j]);
	return (i>=j);
}

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

	string s;
	cin >> s;
	int n=s.length();

	bool a=ispalindrome(s,0,n-1);
	bool b=ispalindrome(s,0,(n-3)/2);
	bool c=ispalindrome(s,(n+1)/2,n-1);
	if (a&&b&&c==true)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : SHASHANK *
* NICK : lance_lot *
* INSTITUTION : BIT MESRA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <ll, ll> pll;
const ll M=1e9+7;
ll inf=1e18;

ll power(ll a, ll b, ll mod) { 
    ll c = 1; 
    a = a%mod;
    while(b>0) { 
        if(b%2) c*=a;
        c%=mod; 
        b/=2; 
        a*=a;
        a%=mod; 
    } 
    return c; 
}

int main() {
fast;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    for(ll i = 0;i < n;i++)
      cin>>arr[i];
    ll dp[k+1] = {0};
    for(ll i = 1;i <= k;i++) {
      bool ok = true;
      for(ll j = 0;j < n;j++) {
        if(i-arr[j] >= 0 && dp[i-arr[j]] == 0)
           ok = false; 
      }
      //cout<<ok<<endl;
      if(ok)
        dp[i] = 0;
      else
        dp[i] = 1;
    }
    dp[k]?(cout<<"First"):(cout<<"Second");
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    string s,t;
    cin>>s>>t;
    if(s==t.substr(0,t.size()-1)){
        if(s.size()+1==t.size()){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

struct sushi_t {
  int d;
  int t;
};

static int n, k;
static std::array<sushi_t, 100000> sushis{};
static std::array<int, 100001> worstSushis{0};
static std::array<int, 100000> replaceables{};

int64_t solve() {
  int64_t ret0 = 0;
  int64_t nn = 0;
  int replaceableIdx = 0;
  int i = 0;
  for (; i < k; ++i) {
    const auto& s = sushis[i];
    int const prev = worstSushis[s.t];
    worstSushis[s.t] = i + 1;
    ret0 += int64_t(s.d);
    if (prev <= 0) {
      nn++;
    } else {
      replaceables[replaceableIdx++] = i;
    }
  }
  int64_t ret = ret0 + nn * nn;
  std::vector<int> replacements{};
  for (; i < n; ++i) {
    const auto& s = sushis[i];
    int const prev = worstSushis[s.t];
    worstSushis[s.t] = i + 1;
    if (prev <= 0) {
      replacements.push_back(i);
    }
  }

  replaceableIdx--;
  int replacementIdx = 0;
  for (++nn;
       nn <= k && replaceableIdx >= 0 && replacementIdx < replacements.size();
       ++nn, --replaceableIdx, ++replacementIdx) {
    ret0 -= int64_t(sushis[replaceables[replaceableIdx]].d);
    ret0 += int64_t(sushis[replacements[replacementIdx]].d);
    if (ret0 + int64_t(k) * int64_t(k) <= ret) {
      break;
    }
    ret = std::max(ret0 + nn * nn, ret);
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    auto& s = sushis[i];
    std::cin >> s.t >> s.d;
    s.t--;
  }
  std::sort(sushis.begin(), sushis.begin() + n,
            [](const auto& lhs, const auto& rhs) { return lhs.d > rhs.d; });
  std::cout << solve() << std::endl;
  return 0;
}


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

void print_array(int A[], int N) {
  for(int i = 0; i < N-1; ++i) {
    std::cout << A[i] << " ";
  }
  std::cout << A[N-1] << std::endl;
  return;
}

int count;

void bubbleSort(int A[], int N) {
  bool flag = true;
  while( flag ) {
    flag = false;
    for(int j = N-1; j >= 1; --j) {
      if( A[j] < A[j-1] ) {
        std::swap(A[j], A[j-1]);
        flag = true;
        count += 1;
      }
    }
  }
  return;
}

int main(void) {

  int N;
  int A[128];

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

  bubbleSort(A, N);

  print_array(A, N);
  std::cout << count << std::endl;

  return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int main(){
    int D, G;
    cin >> D >> G;
    vector<int> p(D), c(D);
    for(int i = 0; i < D; i++) cin >> p[i] >> c[i];

    int res = 1<<21;
    for(int bit = 0; bit < 1<<D; bit++){
        int score = 0, total = 0;
        for(int i = 0; i < D; i++){
            if(bit>>i & 1){
                score += 100*(i+1)*p[i] + c[i];
                total += p[i];
            }
        }

        if(score < G){
            for(int j = D-1; 0 <= j; j--){
                if(bit>>j & 1) continue;
                for(int k = 0; k < p[j]; k++){
                    score += 100*(j+1);
                    total++;
                    if(G <= score) break;
                }
                if(G <= score) break;
            }
        }

        res = min(res, total);
        //cout << "score = " << score << endl;
        //cout << "total = " << total << endl;

    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  string f = N.substr(0,1);
  string s = N.substr(1,1);
  string t = N.substr(2,1);
  string p = N.substr(3,1);

  if (f==s && s==t || s==t && t==p){
     cout << "Yes" << endl; 
    }
  else{
    cout << "No" << endl;
  }  

}

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


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

	for(int n; cin >> n, n;) {
		int a = 0, b = 0;

		for(int i = 0; i < n; ++i) {
			int x, y;
			cin >> x >> y;

			if(x > y)
				a += x + y;
				
			else if(x < y)
				b += x + y;

			else {
				a += x;
				b += y;
			}
		}

		cout << a << " " << b << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1196
import java.lang.Math.abs
import java.lang.Math.max

fun main(array: Array<String>) = abc112c()

fun abc112c() {
    data class Coordinate(val x: Long, val y: Long, val h: Long) {
        override fun toString() = "$x $y $h"
    }

    val n = readLine()!!.toInt()
    val coordinates = Array(n) {
        val (x, y, h) = readLine()!!.split(' ').map { it.toLong() }
        Coordinate(x, y, h)
    }

    val referencePoint = coordinates.maxBy { it.h } ?: error("なんで？")

    for (x in 0..100L) {
        for (y in 0..100L) {
            val h = referencePoint.let { it.h + abs(x - it.x) + abs(y - it.y) }
            val all = coordinates.all { it.h == max(h - abs(x - it.x) - abs(y - it.y), 0) }
            if (all) return println(Coordinate(x, y, h))
        }
    }

    error("なんで？")
}


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

string ans = "Yes";
const ll MAX = 1 << 50;
vector<ll> dist;
vector<vector<P>> edge;

void dfs(int v, int pv, int d){
    dist[v] = d;
    for(auto i : edge[v]){
        if(i.first == pv) continue;
        if(dist[i.first] == MAX){
            dfs(i.first, v, d+i.second);
        }else{
            if(dist[i.first] != dist[v] + i.second) ans = "No";
        }
    }
}

int main(){
    int N, M;cin >> N >> M;
    edge.resize(N, vector<P>());
    dist.resize(N, MAX);
    rep(i, M){
        int l,r,d; cin >> l >> r >> d;
        l--,r--;
        edge[l].push_back({r, d});
        edge[r].push_back({l, -d});
    }
    rep(i, N){
        if(dist[i] == MAX) dfs(i, 0, 0);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16340
using System;

namespace ITP1_3_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int cnt = 0;
            int[] array = new int[10001];
            while (true) {
                int x = int.Parse(Console.ReadLine());
                if (x == 0) break;
                cnt++;
                array[cnt] = x;
            }
            for (int i=1;i<=cnt;i++)
            {
                Console.WriteLine("Case " + i + ": " + array[i]);
            }
        }
    }
}

Measured memory_bytes: 9296
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2000 + 10; 

int n,id[maxn];
ll a[maxn],dp[maxn][maxn];

int main()
{
	fastIO;
	cin >> n;
	rep(i,1,n + 1) {
		cin >> a[i];
		id[i] = i;
	}
	sort(id + 1, id + 1 + n, [&] (int x,int y) {
		return a[x] > a[y];
	});
	ll ans = 0;
	rep(i,1,n + 1){
		int x = id[i]; 
		ll t = a[x];
		for(int l = 0; l <= i; ++l) {
			int r = i - l;
			if(l != i) dp[i][l] = max(dp[i][l],dp[i - 1][l] + t * abs(n - r + 1 - x));
			if(l)  dp[i][l] = max(dp[i][l],dp[i - 1][l - 1] + t * abs(l - x));
			if(i == n) ans = max(ans,dp[i][l]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 26316
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll x; cin >> x;
    (x >= 30) ? Yes() : No();
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll              long long 
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll N=4500+1;
const ll inf=1e17;
ll dp[N];
ll n,m;
ll lmt;
vector<ll>p;
vector<ll>b;

ll Set(ll N,ll pos){return N=N | (1<<pos);}
ll reset(ll N,ll pos){return N= N & ~(1<<pos);}
bool check(ll N,ll pos){return (bool)(N & (1<<pos));}
 
int main()
{
    IOS
    cin>>n>>m;
    lmt=(1<<n);     
    for(ll i=0;i<N;i++)
    {
        dp[i]=inf;     
    }
    for(ll i=0;i<m;i++)
    {
        ll t,cst;
        cin>>cst>>t;
        ll val=0;
        while(t--)
        {
            ll x;
            cin>>x;
            val=Set(val,x-1);
        }
        p.pb(val);          
        b.pb(cst);
        dp[val]=min(dp[val],cst);
    }
    for(ll i=0;i<m;i++)
    {
        for(ll j=0;j<lmt;j++)
        {        
            dp[j|p[i]]=min(dp[j|p[i]],b[i]+dp[j]);
        }
    }           
    if(dp[lmt-1]!=inf)
    cout<<dp[lmt-1]<<endl;
    else
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};


int main(){
    IOS;
    make(ll,n);
    makevec(ll,a,n); ll c=0;
    for(ll i=0;i<n-2;i++){
        for(ll j=i+1;j<n-1;j++){
            for(ll k=j+1;k<n;k++){
                if(a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k] && max(a[i],max(a[j],a[k]))<a[i]+a[j]+a[k]-max(a[i],max(a[j],a[k]))) c++;
            }
        }
    }
    cout<<c<<endl;


    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
//#include <string>

/*struct pair {
	int x;
	int y;
};*/


int main() {
	int n, m, a[1000];
	std::cin >> n >> m;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
		sum += a[i];
	}
	if (sum % m == 0) {
		sum /= m*4;
	}
	else{
		sum = (sum / (m*4)) + 1;
	}
	//std::cout << sum << std::endl;
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] >= sum) {
			count++;
		}
		//std::cout << a[i] << " " << count << std::endl;
	}
	if (count >= m) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
}


Measured memory_bytes: 256
// AOJ 0172: Doctor's Research Rooms
// 2018.1.24 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { char rm; int light; } Q;
Q q[491520]; int top, end;
Q *used[15][32768];

int rm[15][15], s_rm[15];
int sw[15][15], s_sw[15];

char *msg[7] = {0,
"You can go home in %d steps.\n",
"You can not switch off all lights.",
"Help me!",
"Move to room %d.\n",
"Switch on room %d.\n",
"Switch off room %d.\n" };

typedef struct { char msg, rm; } T;
T res[1000]; int sz;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	while (c < '0') c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int cmp(int *a, int *b) { return *a - *b; }

int main()
{
	int n, m, i, j, s, t, ans;
	int room, light;

	while (n = in()) {
		m = in();
		memset(s_rm, 0, sizeof(s_rm));
		memset(s_sw, 0, sizeof(s_sw));

		for (i = 0; i < m; i++){
			s = in()-1, t = in()-1;
			rm[s][s_rm[s]++] = t;
			rm[t][s_rm[t]++] = s;
		}

		light = 0; for (i = 0; i < n; i++) if (in()) light |= 1 << i;

		for (i = 0; i < n; i++) {
			j = in(); while (j--) sw[i][s_sw[i]++] = in()-1;
			qsort(sw[i], s_sw[i], sizeof(int), cmp);
        }

		memset(used, 0, sizeof(used));
		q[0].rm = 0, q[0].light = light; top = 0, end = 1;
		used[0][light] = q;

		ans = 3;
		while (top < end) {
			s = q[top].rm, t = q[top].light;

			if (s == n-1) {
				if (t == 1<<(n-1)) { ans = 1; break; }
				ans = 2;
			}

			for (i = 0; i < s_sw[s]; i++) if (sw[s][i] != s) {
				light = t ^ (1<<sw[s][i]);
				if (used[s][light] == 0) {
					used[s][light] = q + top;
					q[end].rm = s, q[end++].light = light;
				}
			}

			for (i = 0; i < s_rm[s]; i++) {
				room = rm[s][i];
				if (t & (1<<room)) {
					if (used[room][t] == 0) {
						used[room][t] = q + top;
						q[end].rm = room, q[end++].light = t;
					}
				}
			}

			top++;
		}
 
		if (ans > 1) puts(msg[ans]);
		else {
			Q p = q[top];
			sz = 0;
			while (1) {
				Q nxt = *used[p.rm][p.light];
				if (nxt.rm == p.rm && nxt.light == p.light) break;
				if (p.rm != nxt.rm) res[sz].msg = 4, res[sz++].rm = p.rm;
				else for (i = 0; i < n; i++) if ((p.light & (1<<i)) ^ (nxt.light & (1<<i))) {
					if (p.light & (1<<i)) res[sz].msg = 5; else res[sz].msg = 6;
					res[sz++].rm = i;
					break;
				}
				p = nxt;
			}
			printf(msg[ans], sz);
			while (sz--) printf(msg[res[sz].msg], 1 + res[sz].rm);
		}
    }
    return 0;
}


Measured memory_bytes: 5900
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    while(n--){
        int outcount=3,runner=0,point=0;
        while(outcount){
            string kind;
            cin>>kind;
            if(kind=="HIT")runner++;
            else if(kind=="HOMERUN"){
                point+=runner+1;
                runner=0;
            }
            else outcount--;

            if(runner>3){
                point++;
                runner--;
            }
        }
        cout<<point<<endl;

    }
    return 0;
}

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

using namespace std;

int main()
{
    string n;
    set < int > s;
    cin >> n;
    for(int i = 0 ; i < n.size(); i++)
    {
        s.insert(n[i]);
    }
    if( n.size() == s.size())
        cout << "yes";
    else
        cout << "no";
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a, b, c;
    int i = 0;
    scanf("%d %d %d", &a, &b, &c);

    while (a <= b) {
        if (c % a == 0) {
            i++;
        }
        a++;
    }
    printf("%d\n", i);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define srep(i,s,t) for(ll i = s; i < t; ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 3005

const ll MOD = 998244353;

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long FINV(int n){
    if (n < 0) return 0;
    return finv[n];
}


ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll dp[MAX_N][MAX_N];

int main() {
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    ll ans = 0;
    COMinit();

    dp[A][B] = 1;

    srep(i,A,C+1){
        srep(j,B,D+1){
            if(i == A && j == B) continue;
            dp[i][j] = dp[i-1][j] * j % MOD + dp[i][j-1] * i % MOD + MOD - dp[i-1][j-1] * (i-1) % MOD * (j-1) % MOD;
            dp[i][j] %= MOD;
        }
    }
    ans = dp[C][D];
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 85772
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int h=sc.nextInt();
        int w=sc.nextInt();
        while(h!=0 || w!=0){
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(i%2==0){
                        if(j%2==0){
                            System.out.
                            printf("#");
                        }else{
                            System.out.printf(".");
                        }
                    }else{
                        if(j%2==1){
                            System.out.
                            printf("#");
                        }else{
                            System.out.printf(".");
                        }
                    }
                }
                System.out.printf("\n");
            }
            h=sc.nextInt();
            w=sc.nextInt();
            System.out.printf("\n");
        }
        sc.close();

    }
}


Measured memory_bytes: 64068
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cstdlib>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<bitset>
#define lmid l,mid,rt<<1
#define rmid mid+1,r,rt<<1|1
#define ll long long
using namespace std;
int main()
{
     int n;
     scanf("%d",&n);
     int res=0,x=0,y=0;
     bool flag=false;
     for(int i=0;i<n;i++)
     {
          int a,b,c;
          scanf("%d%d%d",&a,&b,&c);
          int d=a-res;
          res=a;
          int sum=abs(b-x)+abs(c-y);
          x=b,y=c;
          if(sum>d||(sum+d)%2==1)
               flag=true;
     }
     if(!flag) printf("Yes\n");
     else printf("No\n");
     return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, M;
    cin >> N >> M;
    vv<int> A = vvec(N, M, 0);
    rep(i, N) rep(j, M) {
        cin >> A[i][j];
        A[i][j]--;
    }

    int ans = N;
    vector<int> idxs(N, 0);
    vector<int> np(M);
    set<int> no;
    rep(m, M) {
        np.assign(M, 0);
        rep(i, N) {
            np[A[i][idxs[i]]]++;
        }

        int mmost = max_element(all(np)) - np.begin();
        ans = min(ans, np[mmost]);

        no.insert(mmost);
        rep(i, N) {
            while (no.find(A[i][idxs[i]]) != no.end()) {
                idxs[i]++;
            }
        }
    }

    write(ans);
}

Measured memory_bytes: 640
from itertools import product

H, W = list(map(int, input().split()))
S = [[0]*(W+2)] + [[0] + list(input()) + [0] for _ in range(H)] + [[0]*(W+2)]
D = list(product([-1,0,1], repeat=2))

for h, w in product(range(1,H+1), range(1,W+1)):
    if S[h][w]!='.' : continue
    n = 0
    for dx, dy in D:
        if S[h+dy][w+dx]=='#': n+=1
    S[h][w] = str(n)

for s in S[1:-1]:
    print(''.join(s[1:-1]))

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

int main() {
	int n; cin >> n; bool flag = false;
	for (int i = 0; i < n; i++) {
		char tmp; cin >> tmp;
		if (tmp == 'Y') flag = true;
	}

	cout << ( flag ? "Four" : "Three" ) << endl;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;


void solve() {
	int n; cin >> n;
	string s; cin >> s;
	if (n % 2) { cout << "No" << endl; return; }
	rep(i, n / 2) {
		if (s[i] != s[i + n / 2]) { cout << "No" << endl; return; }
	}
	cout << "Yes" << endl;
}

int main() {

	solve();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int A, B, K;
	cin >> A >> B >> K;

	for (int i = A; i <= B; i++) {
		if (i < A + K) {
			cout << i << endl;
		}
		else if (i > B - K) {
			cout << i << endl;
		}
	}
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

#define FOR(i,S,E) for(int i=S; i<E; i++)
#define ri(x) scanf("%d", &x)
#define rii(x,y) scanf("%d", &x, &y)
#define pb push_back
#define fst first
#define snd second

ll litro(pair<double, ll> &a) {
	double vol = a.fst; 
	ll cost = a.snd;
	return ll(cost/vol);
}

bool comp(pair<double, ll> &x, pair<double, ll> &y) {
	return litro(x) < litro(y);
}

int main () {
	ll n;
	vector < pair<double, ll> > a;
	for(double i=0.25; i<=2; i *= 2) {
		ll inp; cin >> inp;
		a.pb({i, inp});
	}
	cin >> n;
	sort(a.begin(), a.end(), comp);
	ll ans = 0;

	FOR(i,0,4) {
		if (a[i].fst <= n) {
			ans += ll(n/a[i].fst)*a[i].snd;
			if (a[i].fst <= 1)
				break;
			n = n%2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256