akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1000000007;

/*WA→解説
mapを使うかvectorをソートして使うかの違い？
kCa+kC(a+1)+,,+kC(b-1)+kCb
の部分で、解説ではC[n][k].k>nが0なので問題ないが、
nCkがnCk[n][0]~nC[n][n]までしか定義してなく、b=min(b,k)にする必要あり
*/
int main(){
    vector<vector<long long>> nCk(51);
    nCk[0].push_back(1);
    rep(i,50){
        nCk[i+1].push_back(1);//nC0
        rep(j,nCk[i].size()-1)//nC1~nC(n-1)
            nCk[i+1].push_back(nCk[i][j]+nCk[i][j+1]);
        nCk[i+1].push_back(1);//nCn
        /*for(auto num:nCk[i+1]) cout<<num<<" ";
        cout<<endl;*/
    }
    
    int n,a,b;
    cin>>n>>a>>b;
    map<long long,int> minuscount; //vに-をかけて保存、大きい順に取り出す
    rep(i,n){
        long long v;
        cin>>v;
        minuscount[-1*v]++;
    }
    //大きい順にa個の値選ぶとき、すべて同じかそうでないか
    //cout<<minuscount.begin()->first<<" "<<minuscount.begin()->second<<endl;
    int k=minuscount.begin()->second;
    if(k>=a){
        cout<<-1*minuscount.begin()->first<<endl;
        //kCa+kC(a+1)+,,+kC(b-1)+kCb
        long long erabi=0;
        for(int j=a;j<=min(k,b);++j)
            erabi+=nCk[k][j];
        cout<<erabi<<endl;
    }
    else{//個数がaを超えるまで取り、余りがあれば計算
        int kosu=0,saigo=0;
        long long sum=0;
        for(auto m:minuscount){
            long long val=-1*m.first;
            int num=m.second;
            if(num+kosu<=a){
                sum+=num*val;
                kosu+=num;
                if(kosu==a) break;
            }
            else{
                sum+=(a-kosu)*val;
                saigo=num;
                break;
            }
        }
        printf("%.10lf\n",(double)sum/a);
        //cout<<kosu<<" "<<saigo<<endl;
        if(kosu==a) cout<<"1"<<endl;
        else{
            int nokori=a-kosu;
            cout<<nCk[saigo][nokori]<<endl;
        }
    }
    return 0;
}

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

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;
typedef pair<ll,ll> pll;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

void init(){
    cin.tie(0);
    ios::sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}


int main(){
    init();

    stack<char> s;
    char c;
    while(cin >> c){
        if(c == 'B' && !s.empty())
            s.pop();
        else if(c != 'B')
            s.push(c);
    }

    string ans = "";
    while(!s.empty()){
        ans += s.top();
        s.pop();
    }

    reverse(ans.begin(), ans.end());

    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
const ll inf = 1001001001001001001;
int main(){
  ll x,y;scanf("%lld%lld",&x,&y);
  ll ans = inf;
  if(x <= y) ans = min(ans,y-x);//A
  if(-x <= y) ans = min(ans,y+x+1);//B or BA
  if(-x >= y) ans = min(ans,-y-x+1);//AB
  if(x >= y) ans = min(ans,-y+x+2);//BAB
  printf("%lld\n",ans);
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  string s;
  cin >> s;
  if(s[0]=='S') cout<< "Cloudy" <<endl;
  else if(s[0]=='C') cout<< "Rainy" <<endl;
  else cout<< "Sunny" <<endl;
}


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

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

	ll a, b;
	cin >> a >> b;
	if (a == 1 || b == 1)
		cout << 1 << endl;
	else
		cout << (a * b + 1) / 2 << endl;
}


Measured memory_bytes: 256
n, k = (int(x) for x  in input().split())
l = []
la = l.append
for _ in range(k):
    input();la(list((int(x)for x in input().split())))
p = set(sum(l, []))
ans = 0
for x in range(1, n+1):
    if x not in p:
        ans += 1
print(ans)


Measured memory_bytes: 67960
#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int a;
  int i, j, k;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin>>a){
    count=0;
    if(past>=a){
      for(i=2; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=(int)sqrt((double)a);
      for(i=2; i<=a_sqrt; i++){
        for(j=i; j<=a/i; j++){
          chk[j*i]=false;
        }
      }
      past=a;
      for(i=2; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}

Measured memory_bytes: 1844
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();

		if (a + b == c || a + c == b || a == b + c)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (ll i=(a); i >= b; i--)

#define MN 200005
int n, k;
ll sm(int a, int b){
    return 1LL*(a+b)*(b-a+1)/2;
}

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

    cin >> n >> k;
    ll tot = 0;
    FOR(i, k, n+1){
        ll mn = sm(0, i-1);
        ll mx = sm(n-i+1, n);
        tot = (tot+mx-mn+1)%MOD;
    }
    cout << tot << "\n";

    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int a=0,b=0,c=0;
  for(int i=0;i<3;++i){
    if(s.at(i)=='a') ++a;
    else if(s.at(i)=='b') ++b;
    else ++c;
  }
  if(a&b&c) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    for (auto& x: a) {
        cin >> x;
    }
    for (auto& x: b) {
        cin >> x;
    }
    for (auto& x: c) {
        cin >> x;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vector<long long> sum(n+1);
    sum[0] = 0;
    for (int i = 0; i < n; i++) {
        int k = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        sum[i+1] = sum[i] + k;
    }
    long long res = 0;
    for (int i = 0; i < n; i++) {
        int k = lower_bound(b.begin(), b.end(), c[i]) - b.begin();
        res += sum[k];
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 2176
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner fs = new FastScanner();
		int l = fs.nextInt();
		int r = fs.nextInt();
		int d = fs.nextInt();

		int ans = 0;

		for(int i = l;i <= r;i++) {

			if(i%d==0) {
				ans++;
			}

		}

		//Output
		PrintWriter out = new PrintWriter(System.out);
		out.println(ans);

		out.flush();

	}

}

//Input
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

using namespace std;

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

typedef long long ll;

const int N = 302066;
const ll inf = 1e9;

struct node {
    bool is_t;
    map<int, int> nxt;
} t[5005 * 20];
int sz = 0;
string res;
int k;
inline void dfs(int v) {
    if(t[v].is_t) {
        --k;
    }
    if(k == 0) {
        cout << res;
        exit(0);
    }
    for(auto to : t[v].nxt) {
        res += char(to.first + 'a');
        dfs(to.second);
        res.pop_back();
    }
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    string s;
    cin >> s >> k;
    int n = s.length();
    for(int i = 0; i < s.length(); ++i) {
        int v = 0;
        int en = min(int(s.length()), i + 15);
        for(int j = i; j < en; ++j) {
            if(!t[v].nxt.count(s[j] - 'a')) {
                t[v].nxt[s[j] - 'a'] = ++sz;
            }
            v = t[v].nxt[s[j] - 'a'];
            t[v].is_t = 1;
        }
    }
    dfs(0);
    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string t; cin >> t;
  int n = SZ(t);

  REP(i, n) {
    if(t[i] == '?') t[i] = 'D';
  }

  cout << t << endl;

}
























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

ll rec(ll N, ll X)
{
  if (X == 0) {
    return 0;
  }
  if (N == 0) {
    return 1;
  }
  ll H = pow(2, N + 2) - 3;
  ll P = pow(2, N + 1) - 1;
  if (X <= H / 2) {
    return rec(N - 1, X - 1);
  }
  else if (X == H / 2 + 1) {
    return P / 2 + 1;
  }
  else {
    return P / 2 + 1 + rec(N - 1, X - H / 2 - 1);
  }
}

int main()
{
  ll N, X;
  cin >> N >> X;
  cout << rec(N, X) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// Macros for easier access
#define ll long long
#define endl '\n'
#define F first
#define S second
#define umap unordered_map
#define uset unordered_set
#define test ll cases; cin>>cases; for(ll testCase = 1; testCase <= cases; testCase++)
#define fill(name, val) memset(name, val, sizeof(name));
#define mop(a, op, b)    (a%mod op b%mod)%mod
#define precise fixed<<setprecision(50)
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define get(a, n)    for(ll it = 0; it < n; it++)    cin>>a[it];
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cerr << #x << " : " << (x) << endl
// Constants
#define MX 100001
#define mod 1000000007LL
#define inf 1000000000000000000LL
void init(){
	boost;
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

ll n, dp[1001][10001];	vvll a(1001, vll(3));
bool cmp(vll& a, vll& b){
	return a[0] + a[1] < b[0] + b[1];
}
ll calc(ll i, ll w){
	if(w > 10000)	return 0;
	if(i == n)	return 0;
	if(dp[i][w] != -1)	return dp[i][w];
	dp[i][w] = calc(i+1, w);
	if(a[i][1] >= w)	dp[i][w] = max(dp[i][w], a[i][2] + calc(i+1, w + a[i][0]));
	return dp[i][w];
}
int main(){
	init();
	cin>>n;	fill(dp, -1);
	for(ll i = 0; i < n; i++)	cin>>a[i][0]>>a[i][1]>>a[i][2];
	sort(a.begin(), a.begin() + n, cmp);
	cout<<calc(0, 0);
}

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

int main(){
    double x1,y1,x2,y2;
    cin >>x1 >>y1 >>x2 >>y2;
    double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%lf\n",d);
    return 0;
}


Measured memory_bytes: 3192
import copy
roads = []
roads2 = []
roads_stay = []
for s in range(3):
    a = [int(i) for i in input().split()]
    roads += [a]
lines=[]
for i in roads:
    lines.append(i[0])
    lines.append(i[1])
#print(lines)
copys=copy.deepcopy(lines)
for i in range(len(lines)):
    lines=copy.deepcopy(copys)
    form=True if i%2==0 else False
    #print(lines)
    #print('form {} i={}'.format(form,i))
    if form:
        tag=lines[i+1]
        end=[lines[i],lines[i+1]]
        lines[i]=0
        lines[i+1]=0
    else:
        tag=lines[i-1]
        end=[lines[i-1],lines[i]]
        lines[i]=0
        lines[i-1]=0
    flag=True

    while sum(lines)!=0:
        #print('us')
        if tag in lines:
            index=lines.index(tag)
            form = True if index % 2==0 else False
            if form:
                tag = lines[index + 1]
                end += [lines[index + 1]]
                lines[index] = 0
                lines[index + 1] = 0
            else:
                tag = lines[index - 1]
                end += [lines[index - 1]]
                lines[index] = 0
                lines[index - 1] = 0
        else:
            break
    if len(set(end))==4 and sum(lines)==0:
        print('YES')
        exit(0)
    #print('next')

print('NO')

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

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

    long long int ans = 0, alc = 0;
    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == 'A') {
            ans += alc;
        } else if (s[i] == 'C' && i > 0 && s[i - 1] == 'B') {
            i--;
            alc++;
        } else {
            alc = 0;
        }
    }

    cout << ans << '\n';
}


Measured memory_bytes: 768
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll n;
    vector <ll> avec;
    cin >> n;
    REP(i,n){
        ll tmp;
        cin >> tmp;
        avec.push_back(tmp);
    }
    ll ans =0;
    REP(i,n){
        if( ((i+1)%2) ==0 ){
            continue;
        }
        if( (avec[i]%2) ==0  ){
            continue;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <map>
#include <math.h>
using namespace std;
typedef long long int ll;

constexpr ll mod=1e9+7;

ll mod_pow(ll a,ll b){
	a%=mod;
	if(b==0)return 1;
	if(b==1)return a;
	ll res=mod_pow(a,b/2)%mod;
	res*=res; res%=mod;
	if(b%2)res*=a;
	return res%mod;
}

ll dp[3030][3030][2];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	if(n>=m){
		printf("%lld\n",mod_pow(2,2*m));
	}
	else{
		for(int i=0;i<=n;i++){
			dp[0][i][i==0]=1;
		}
		for(int i=1;i<=m;i++){
			for(int j=0;j<=n;j++){
				for(int k=0;k<2;k++){
					if(j){
						(dp[i][j][k||j==1]+=dp[i-1][j][k])%=mod;
						(dp[i][j-1][k||j==1]+=dp[i-1][j][k])%=mod;
					}
					if(n-j){
						(dp[i][j][k]+=dp[i-1][j][k])%=mod;
						(dp[i][j+1][k]+=dp[i-1][j][k])%=mod;
					}
				}
			}
		}
		ll res=0;
		for(int i=0;i<=n;i++){
			(res+=dp[m][i][1])%=mod;
		}
		printf("%lld\n",res);
	}
}


Measured memory_bytes: 143104
// C - Chocolate Bar
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll min_Diff(ll minDiff, ll s1, ll s2, ll s3){
	return min(minDiff, max({s1, s2, s3}) - min({s1, s2, s3}));
}

ll check(int Y, int X){
	ll minDiff = LLONG_MAX;
	ll e = (Y+2-1)/2;//roundup
	for(ll y1=1; y1<=e; ++y1){//-: vertical division
		ll y2,y3,x2,x3;
		// T: horizontal division
		y2 = Y - y1;
		x2 = X / 2;
		x3 = X - x2;
		minDiff = min_Diff(minDiff, y1*X, y2*x2, y2*x3);
		//-: vertical division
		y2 = y2 / 2;
		y3 = Y - y1 - y2;
		minDiff = min_Diff(minDiff, y1*X, y2*X, y3*X);
	}
	return minDiff;
}

int main(){
	int H,W; cin>>H>>W;
	ll ans = min(check(H, W), check(W, H));
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)


int main()
{
	int r, g, b;
	cin >> r >> g >> b;
	int sum = r * 100 + g * 10 + b;
	if (sum % 4 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            Console.WriteLine((A * B) % 2 == 1 ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 200005;
int a[MAX_N],cnt[1000005];

int main()
{
	int n;
	cin >> n;
	rep(i,n)
	{
		cin >> a[i];
		cnt[a[i]]++;
	}
	if (cnt[1] == 1)
	{
		cout << "1" << endl;
		return 0;
	}
	if (cnt[1] > 1)
	{
		cout << "0" << endl;
		return 0;
	}
	bool flag = true;
	int ans = 0;
	rep(i,n)
	{
		flag = true;
		if (cnt[a[i]] > 1) flag = false;
		for (int j = 2; j*j <= a[i]; ++j)
		{
			if (a[i] % j == 0)
			{
				if (cnt[j] > 0)
				{
					flag = false;
					break;
				}
				if (cnt[a[i]/j] > 0)
				{
					flag = false;
					break;
				}
			}
		}
		if (flag) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8208
#include<iostream>
int main()
{
	int D;
    scanf("%d",&D);
    int C[26];
    for(int a = 0; a < 26; a++)
    {
        scanf("%d",&(C[a]));
    }
    int SCORE[365][26];
    for(int a = 0; a < 365; a++)
    {
        for(int b ; b <26; b++)
        {
        	scanf("%d",SCORE[a][b]);
        }
    }
    int HUMANABC[26] = {0};
    int KEKKA[365] = {0};
    for(int a = 0; a < 365; a++)
    {
    	for(int b = 0; b <26; b++)
        {
        	HUMANABC[b] += C[b];
        }
        int GOUKEI[26] = {0};
        for(int c = 0; c <26; c++)
        {
            GOUKEI[c] = SCORE[a][c] + HUMANABC[c];
        }
        for(int c = 0; c < 26; c++)
        {
            int n = 0;
            if(n < GOUKEI[c])
            {
                n = GOUKEI[c];
                KEKKA[a] = c;
            }
        }
        HUMANABC[KEKKA[a]] = 0;
    }
	for(int a =0; a < 365; a++)
    {
    	printf("%d\n",KEKKA[a]);
    }
}


Measured memory_bytes: 3212
from collections import defaultdict

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

d = defaultdict(int)

#約数を求める
def makeDivisor(n):
    for i in range(1, int(n ** 0.5)+1):
        if n % i == 0:
            d[i] += 1
            if i != n // i:
                d[n//i] += 1
    return

b = [0] * N
cnt = 0
for i in range(N, 0, -1):
    if d[i] % 2 == 1 and a[i-1] == 0:
        b[i-1] = 1
        cnt += 1
        makeDivisor(i)
    elif d[i] % 2 == 0 and a[i-1] == 1:
        b[i-1] = 1
        cnt += 1
        makeDivisor(i)

print(cnt)
for i in range(N):
    if b[i] == 1:
        print(i+1,end=' ')


Measured memory_bytes: 95208
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N, M;
const int MAX_M = int(1e5);
ll P[MAX_M + 1], Y[MAX_M + 1];
vector<ll> nums[MAX_M + 1];

void solve() {
    REP(i, M) {
        auto at = lower_bound(nums[P[i]].begin(), nums[P[i]].end(), Y[i]);
        string sp = to_string(P[i]), sdiff = to_string(at - nums[P[i]].begin() + 1);
        if (sp.length() < 6) sp = string(6 - sp.length(), '0') + sp;
        if (sdiff.length() < 6) sdiff = string(6 - sdiff.length(), '0') + sdiff;
        string ans = sp + sdiff;
        printf("%s\n", ans.c_str());
    }
}

int main() {
    cin >> N >> M;
    REP(i, M) {
        scanf("%lli %lli", &P[i], &Y[i]);
        nums[P[i]].emplace_back(Y[i]);
    }
    REPONE(i, N) {
        sort(nums[i].begin(), nums[i].end());
    }
    solve();
    return 0;
}

Measured memory_bytes: 8576
import sys

input = sys.stdin.readline


def main():
    N, W = map(int, input().split())
    vw = [None] * N
    for i in range(N):
        vw[i] = tuple(map(int, input().split()))

    dp = [0] * (W + 1)
    for v, w in vw:
        for i in range(w, W + 1):
            dp[i] = max(dp[i], dp[i - w] + v)

    ans = max(dp)
    print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5724
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main()
{
    vector < vector <int> > a;
    vector <int> b;
    int n, m, tmp, sum;
    std::cin >> n >> m;
    a.resize(n);
    for (int i=0; i<n; i++){
        a[i].resize(m);
        for (int j=0; j<m; j++){
            std::cin >> tmp;
            a[i][j] = tmp;
        }
    }
    b.resize(m);
    for (int i=0; i<m; i++){
        std::cin >> tmp;
        b[i] = tmp;
    }
    for (int i=0; i<n; i++){
        sum = 0;
        for (int j=0; j<m; j++){
            sum += a[i][j] * b[j];
        }
        std::cout << sum << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include<cstdio>
using namespace std;
int a,b;
int PD(int x)
{
	int c[15];
	int n=0;
	int ans=0;
	while(x>0)
	{
		c[++n]=(x%10);
		x/=10;
	}
	//for(int i=1;i<=n-1;i++)
	//printf("%d ",c[i]);
	//printf("%d\n",c[n]);
	for(int i=1;i<=n;i++)
	{
		if(c[i]==c[n-i+1])ans++;
	}
	if(ans==n) return 1;
	return 0;
}
int main()
{
	int cnt=0;
	scanf("%d %d",&a,&b);
	for(int i=a;i<=b;i++)
	{
		if(PD(i)) cnt++;
	}
	printf("%d",cnt);
}

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

typedef long long ll;
typedef pair<int,string> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int i = a;i < b;++i) cout << ary[i] << (b-1 == i ? "]\n" : ", "); } while(0)
#define p_map(map,it) do {cout << "{";for (auto it = map.begin();;++it) {if (it == map.end()) {cout << "}\n";break;}else cout << "" << it->first << "=>" << it->second << ", ";}}while(0)

int main () {
    int n,m;
    string s,t;
    cin >> s >> t;
    n = s.size();m = t.size();
    vector<vector<P>> dp(2,vector<P>(m+1,P(0,"")));
    for (int k = 0;k < n;++k) {
        int i = k%2;
        for (int j = 0;j < m;++j) {
            if (s[k] == t[j]) {
                if (dp[i][j].first+1 > dp[i^1][j].first && dp[i][j].first+1 > dp[i][j+1].first) dp[i^1][j+1] = P(dp[i][j].first+1,dp[i][j].second+s[k]);
                else dp[i^1][j+1] = (dp[i^1][j] > dp[i][j+1] ? dp[i^1][j] : dp[i][j+1]);
            } else dp[i^1][j+1] = (dp[i^1][j] > dp[i][j+1] ? dp[i^1][j] : dp[i][j+1]);
        }

    }
    cout << dp[n&1][m].second << endl;
    return 0;
}

Measured memory_bytes: 7908
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N, M = map(int, input().split())
KS = []
for i in range(M):
    ks = list(map(int, input().split()))
    KS.append(ks)

P = list(map(int,input().split()))

count = 0
for i in range(2 ** N):
    switchs = []
    for j in range(N):
        if ((i >> j) & 1):
            # ON
            switchs.append(1)
        else:
            # OFF
            switchs.append(0)

    # 1-index に
    switchs = [0] + switchs
    is_on = True
    for x in range(len(KS)):
        k, *s = KS[x]
        # onの数
        on = 0
        for z in s:
            if switchs[z] == 1:
                on += 1

        if on % 2 == P[x]:
            pass
        else:
            is_on = False

    if is_on:
        count += 1

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#define INF 1e+9
using namespace std;

int main(){
	int n;
	while(cin >> n,n){
		int a[300],dp2[301] = {};
		bool dp1[301][301] = {};
		for(int i = 0;i < n;i++){
			cin >> a[i];
			dp1[i][i] = true;
		}
		for(int i = 2;i <= n;i += 2){
			for(int j = 0;j + i <= n;j++){
				for(int k = 0;k <= i;k++){
					if(dp1[j][j + k] && dp1[j + k][j + i]) dp1[j][j + i] = true;
				}
				if(dp1[j + 1][j + i - 1] && abs(a[j] - a[j + i - 1]) <= 1) dp1[j][j + i] = true;
			}
		}
		for(int i = 1;i <= n;i++){
			dp2[i] = dp2[i - 1] + 1;
			for(int j = 0;j <= i;j++){
				if(dp1[j][i]) dp2[i] = min(dp2[i],dp2[j]);
			}
		}
		cout << n - dp2[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>

int main(){
	long int a[26] = {}, t = 1, n;
	char input;
	std::cin >> n;
	for(int i = 0; i < n; i++){
		std::cin >> input;
		a[input - 'a']++;
	}
	for(int i = 0; i < 26; i++){
		t *= a[i] + 1;
		t %= 1000000007;
	}
	std::cout << t - 1 << std::endl;
	return 0;
}



Measured memory_bytes: 256
n=int(input())
s=input()
e=[]
w=[]
cnt_e=0
cnt_w=0
e.append(0)
w.append(0)
for x in s:
    if x=="E":
        cnt_e+=1
    else:
        cnt_w+=1
    e.append(cnt_e)
    w.append(cnt_w)

ans=100000000
for i in range(n):
    t=(w[i])+(e[n]-e[i+1])
    ans=min(ans,t)

print(ans)

Measured memory_bytes: 17752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		sc.close();
		n = n.replaceAll("1","a");
		n = n.replaceAll("9","1");
		n = n.replaceAll("a","9");
		System.out.println(n);
	}

}

Measured memory_bytes: 35496
#include <iostream>

using namespace std;

typedef long long ll;

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    ll m = a*c;

    if(a*d > m){
        m = a*d;
    }

    if(b*c > m){
        m = b*c;
    }

    if(b*d > m){
        m = b*d;
    }

    cout << m << endl;
    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> adj(n, vector<int>(n));
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    adj[u][v] = w;
    adj[v][u] = w;
  }
  vector<vector<int>> gr(n, vector<int>(1 << n));
  for (int i = 0; i < n; ++i) {
    for (int s = 0; s < (1 << n); ++s) {
      for (int j = 0; j < n; ++j) {
        if (s >> j & 1) gr[i][s] += adj[i][j];
      }
    }
  }
  vector<vector<int>> dp(1 << n, vector<int>(n, 1'000'000'000));
  dp[1][0] = 0;
  for (int s = 0; s < (1 << n); ++s) {
    for (int i = 0; i < n; ++i) {
      if (dp[s][i] == 1'000'000'000) continue;
      for (int j = 0; j < n; ++j) {
        if (s >> j & 1) continue;
        if (adj[i][j] == 0) continue;
        dp[s ^ (1 << j)][j] = min(dp[s ^ (1 << j)][j], dp[s][i] + gr[j][s ^ (1 << i)]);
      }
      for (int sub = ((1 << n) - 1) ^ s; sub > 0; sub = (sub - 1) & (((1 << n) - 1) ^ s)) {
        int sum = 0;
        for (int j = 0; j < n; ++j) {
          if (j == i) continue;
          if (s >> j & 1) sum += gr[j][sub];
        }
        if (gr[i][sub] == 0) continue;
        assert((s & sub) == 0);
        dp[s ^ sub][i] = min(dp[s ^ sub][i], dp[s][i] + sum);
      }
    }
  }
  cout << dp[(1 << n) - 1][n - 1] << "\n";
  return 0;
}


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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))

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

    cin >> n;
    vector<pll>v;

    for(i=0;i<n;i++)
    {
        cin >> k >> l;
        v.pb({l,k});
    }

    sort(all(v));
    ll rv = 0,cnt=0;
    for(i=0;i<n;i++)
    {
        if(rv+v[i].S <= v[i].F)
        {
            cnt ++ ;
            rv += v[i].S;
        }
    }
    if(cnt == n)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 6512
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    int n,ans;
    string s;
    ans = 0;
    cin >> n >> s;
    rep(i,n-2){
       if(s.compare(i,3,"ABC")==0)ans++;
    }
    cout << ans;
    return 0;
}

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

int H,W;char c[209][209];

int main(){
	cin>>H>>W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>c[i][j];
		}
	}
	for(int i=0;i<2*H;i++){
		for(int j=0;j<W;j++) cout<<c[i/2][j];
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    cout << r/d - (l-1)/d << "\n";
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    COMinit();
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    cins(all(a));
    SORT(a);
    ll ma = 0;
    rep(i,k-1,n){
        (ma += ((a[i]-a[n-i-1])*COM(i,k-1)%MOD))%=MOD;
    }
    PRINT(ma);
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
using namespace std;
 
int main() {
  ll N, K, ma = 0, current;
  cin >> N >> K;
  vector<ll> p(N);
  for(ll i = 0; i < N; i++) {
    cin >> p.at(i);
    if(i == K - 1) {
      for(ll j = 0; j < K; j++) {
        ma += p.at(j);
        current = ma;
      }
    }
    else if(i > K - 1) {
      current += - p.at(i - K) + p.at(i);
      if(current > ma) {
        ma = current;
      }
    }
  }
  cout << fixed << setprecision(15) << double(ma + K) / 2 << endl;
}

Measured memory_bytes: 4836
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;
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;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    int H,W; cin >> H >> W;
    rep(i,W+2) cout << "#";
    cout << endl;
    rep(i,H){
        string s; cin >> s;
        cout << "#" << s << "#" << endl;
    }
    rep(i,W+2) cout << "#";
    cout << endl;
    
    
}



Measured memory_bytes: 256
# AOJ 0066 Tic Tac Toe
# Python3 2018.6.15 bal4u

def check(a):
	for koma in ['o', 'x']:
		for i in range(3):
			if a[i:9:3].count(koma) == 3 or a[3*i:3*i+3].count(koma) == 3: return koma
		if a[0:9:4].count(koma) == 3 or a[2:7:2].count(koma) == 3: return koma
	return 'd'

while True:
	try: print(check(list(input())))
	except EOFError: break


Measured memory_bytes: 5564
#include <iostream>
#include <vector>

using namespace std;

bool solve(int i,int m , vector<int> &v){
    if (m == 0 )return true;
    if (i >= v.size()) return false;
    return solve(i+1,m,v) || solve(i+1,m - v[i],v);
}

int main(){
    int n,q;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i){
        int x;
        cin >> x;
        v.push_back(x);
    }

    cin >> q;
    for (int i = 0; i < q; ++i) {
        int s;
        cin >> s;
        string result = solve(0,s,v) ? "yes":"no";
        cout << result << endl;
    }
    return 0;
}

Measured memory_bytes: 3156
def create_fact_mod(num_max)
    $fmod = Array.new(num_max + 1)
    $fmod[0] = 1
    $fmod[1] = 1
    (2..num_max).each do |i|
        $fmod[i] = ($fmod[i - 1] * i) % MOD
    end
end

def create_seq_inv_mod(num_max)
    $simod = Array.new(num_max + 1)
    $simod[0] = 1
    $simod[1] = 1
    (2..num_max).each do |i|
        $simod[i] = (MOD - MOD / i) * $simod[MOD % i] % MOD
    end
end

def create_fact_inv_mod(num_max)
    $fimod = Array.new(num_max + 1)
    $fimod[0] = 1
    $fimod[1] = 1
    (2..num_max).each do |i|
        $fimod[i] = ($fimod[i - 1] * $simod[i]) % MOD
    end
end

def create_mod_tables(n)
    create_fact_mod(n)
    create_seq_inv_mod(n)
    create_fact_inv_mod(n)
end

def comb_mod(n, k)
    return $fmod[n] * $fimod[n - k] * $fimod[k] % MOD
end

def perm_mod(n, k)
    return $fmod[n] * $fimod[n - k] % MOD
end

MOD = 10**9+7
K = gets.to_i
N = gets.chomp.size

create_mod_tables(N+K)

p26 = Array.new(K+1, 1)
p25 = Array.new(K+1, 1)
K.times do |i|
    p26[i+1] = p26[i] * 26 % MOD
    p25[i+1] = p25[i] * 25 % MOD
end

ans = 0
(K+1).times do |t|
    ans = (ans + comb_mod(N-1+K-t, K-t) * p26[t] * p25[K-t]) % MOD
end

puts ans

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

using namespace std;


int main() {
    int count=1<<5;
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i) {
        long x;
        int c=0;
        cin>>x;
        while(x%2==0){
            c++;
            x/=2;
        }
        count=min(c,count);
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    int A,B,C,D;
  	cin >> A>>B>>C>>D;
  	while(1)
  	{
      	if( C-B<1)
        {
            cout << "Yes";
            break;
        }
      	else
            C = C-B;
        if( A-D<1 )
        {
            cout << "No";
            break;
        }
        else
            A = A-D;
  	}
    return 0;
     
}

Measured memory_bytes: 3636
#include <stdio.h>
int main(void){
    int t[4][3][10]={0};
  int b,f,r,v,i,j,k,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d%d%d%d",&b,&f,&r,&v);
t[b-1][f-1][r-1]=t[b-1][f-1][r-1]+v;
 
       
     
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
    printf(" %d",t[i][j][k]);
      }
      printf("\n");
    }
    if(i!=3)printf("####################\n");
  }
  return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N,X,Y;
  cin>>N>>X>>Y;
  int d[2001][2001];
  rep(i,2001) rep(j,2001) d[i][j] = 1000000;
  vector<int> G[2001];
  for(int i(1);i<N;i++){
    G[i].push_back(i+1);
    G[i+1].push_back(i);
  }
  G[X].push_back(Y);
  G[Y].push_back(X);

  for (int i(1);i<=N;i++){
    queue<int> q;
    q.push(i);
    d[i][i] = 0;
    while(!q.empty()){
      int now = q.front();q.pop();
      for(int j(0);j<int(G[now].size());j++){
        int next = G[now][j];
        if (d[i][next] == 1000000){
          d[i][next] = min(d[i][next],d[i][now]+ 1);
          //d[next][i] = min(d[next][i],d[i][now]+ 1);
          q.push(next);
        }
      }
    }
    // iを出発とする幅優先
  }
  //２重配列dには、変が存在する際には変のコストを、存在しない場合には、INFを入れておく
  int cnt[2001] = {0};
  for (int i(1);i<=N;i++){
    for (int j(i+1);j<=N;j++){
      cnt[d[i][j]]++;
    }
  }
  for(int i(1);i<N;i++){
    cout << cnt[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int D=365;
  cin>>D;
  vector<int> c(26);
  vector<vector<int>> s(D,vector<int>(26,0));
  vector<int> t(D,0);
  rep(i,26)
    cin>>c.at(i);
  rep(i,D){
    rep(j,26)
      cin>>s.at(i).at(j);
  }
  
  /*rep(i,D){
    cin>>t.at(i);
    t.at(i)--;
  }*/
  
  vector<in> v(D,0);
  vector<int> last(26,0);
  vector<int> last_alt=last;
  in sum=0;
  
  for(int i=0;i<D;i++){
    rep(T,26){
      in sum_alt;
      if(i==0) sum=0;
      else
        sum_alt=v.at(i-1);
      
      last_alt=last;
      
      last_alt.at(T)=i+1;
      sum_alt+=s.at(i).at(T);
      rep(j,26)
        sum_alt-=c.at(j)*(i+1-last.at(j));
      if(sum<sum_alt){
        t.at(i)=T;
        sum=sum_alt;
      }
    }
    v.at(i)=sum;
  }
  
  /*rep(i,D)
    cout<<v.at(i)<<endl;*/
  rep(i,D)
    cout<<t.at(i)+1<<endl;
  
}

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

using namespace std;

#define int int64_t
const int MAX = 3e3+5;
const int MOD = 1e9+7;

int n;
int total[MAX][MAX];
string s;

int solve(int p, int lim, int temp) {
	if(lim > n-p) return 0;
	if(lim == 0) return 0;
	if(p == n-1) return 1;
	
	if(total[p][lim] != -1) return total[p][lim];
	
	char state = s[p];
	int nlim = (state == '>') ? (lim-1) : lim, ntemp = (state == '>') ? -1 : 1;
	int curr = (solve(p, lim+temp, temp) + solve(p+1, nlim, ntemp)) % MOD;
	
	total[p][lim] = curr;
	return curr;  
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(total, -1, sizeof(total));
	
	cin >> n;
	cin >> s;
	cout << solve(0, 1, 1);
}

Measured memory_bytes: 281856
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int N,M,i,j,temp,ans=0;
	int flag=0;
	cin >>N>>M;
	int A[N][M],K[N];
	for(i=0;i<N;i++){
		cin >>K[i];
		for(j=0;j<K[i];j++){
			cin >>A[i][j];
		}
	}
	for(temp=1;temp<=M;temp++){
		flag=0;
		for(i=0;i<N;i++){
			for(j=0;j<K[i];j++){
				if(temp==A[i][j]){
					flag+=1;
				}
			}
		}
		if(flag==N){
			ans+=1;
		}
	}
	cout<<ans;
	return 0;
}
	

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

using namespace std;

const int INF = 1e9;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<array<int, 3>> dp(n + 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 3; ++j) {
      dp[i][j] = -INF;
      int x;
      cin >> x;
      for (int k = 0; k < 3; ++k) {
        if (k == j)
          continue;
        dp[i][j] = max(dp[i][j], dp[i - 1][k] + x);
      }
    }
  }
  cout << max({dp[n][0], dp[n][1], dp[n][2]}) << '\n';
  return 0;
}

Measured memory_bytes: 1408
def solve(N, probs):
  # dp[i][j]: probability of having j heads in i coin tosses
  # shorter version: dp[j]: probability of j heads
  dp = [0 for _ in range(N + 1)]
  dp[0] = 1

  for toss_id in range(1, N + 1):
    head_prob = probs[toss_id - 1]
    tail_prob = 1.0 - probs[toss_id - 1]
    # only until i needed
    for j in range(toss_id, -1, -1):
      # zero heads
      if j == 0:
        dp[j] = dp[j] * tail_prob
      else:
        dp[j] = (dp[j] * tail_prob) + (dp[j - 1] * head_prob)

  # sum all probabilies where heads > tails
  ans = sum(dp[N // 2 + 1:])
  print(ans)


def iin(): return int(input())
def fln(): return list(map(float, input().split()))


N = iin()
probs = fln()
solve(N, probs)


Measured memory_bytes: 3316