akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/dp/tasks/dp_c
#include<bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
	int n;
	cin >> n;
	vector<vector<int>> c (n, vector<int>(3));
	for (auto& x:c) {
		for (auto& y:x) {
			cin >> y;
		}
	}
	vector<vector<int>> dp (n, vector<int>(3));
	dp[0][0] = c[0][0];
	dp[0][1] = c[0][1];
	dp[0][2] = c[0][2];
	for (int i = 1; i < n; i++) {
		dp[i][0] = max(dp[i-1][1], dp[i-1][2])+c[i][0];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2])+c[i][1];
		dp[i][2] = max(dp[i-1][1], dp[i-1][0])+c[i][2];
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl; 
	return 0;
}

Measured memory_bytes: 11136
#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];
	}
	sort(a.begin(), a.end());
	int alice, bob;
	alice = 0;
	bob = 0;
	for (i = 1; i <= n; i++) {
		if (i % 2 == 1) {
			alice += a[n - i];
		} else {
			bob += a[n - i];
		}
	}
	cout << alice - bob << endl;
	return 0;
}


Measured memory_bytes: 256
#define f(X) for(c=0;c<X;c+=v[p++]);if(c-X)goto L;
n,v[50],s,p,c,a[9];main(){for(;n=atoi(gets(a));){for(s=0;s<n;)v[++s]=strlen(gets(a));s=0;L:p=++s;f(5)f(7)f(5)f(7)f(7)printf("%d\n",s);}}

Measured memory_bytes: 524
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sum = a + b;
        if (sum % 2 == 1) {
            System.out.println("IMPOSSIBLE");
        } else {
            System.out.println(sum/2);
        }

    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,a[101010],ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]==i+1)
		{
			ans++;
			i++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
import sys
N = int(input())
if N < 0 or N > 100:
    sys.exit()

max = 0
answer = 1
for I in reversed(range(N+1)):
    if I % 2 == 0:
        result = I
        count = 0
        for J in range(I):
            if result % 2 == 0:
                result = int(result/2)
                count += 1
            if max <= count:
                max = count
                answer = I
print(answer)

Measured memory_bytes: 9168
using System;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        StringBuilder ans = new StringBuilder();
        int[] l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int c = l[1];
        int[] cans = new int[c + 1];
        
        for (int i = 0; i < l[0]; i++)
        {
            string[] o = Console.ReadLine().Split(' ');
            int a = 0;

            for (int j = 0; j < c; j++)
            {
                cans[j] += int.Parse(o[j]);
                a += int.Parse(o[j]);
                ans.Append(o[j] + " ");
            }

            cans[c] += a;
            ans.Append(a + "\r\n");
        }
        for (int i = 0; i < c; i++)
        {
            ans.Append(cans[i] + " ");
        }
        ans.Append(cans[c] + "\r\n");

        Console.Write(ans);
    }
}

Measured memory_bytes: 9956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; 

int main(){
  map<ll,ll>mp;
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
    if(mp.count(a[i])){
      mp.at(a[i])++;
    }
    else{
      mp[a[i]] = 1;
    }
  }
  ll ans =0;
  for(auto p:mp){
    ans += (p.second*(p.second-1)/2);
  }
  for(int i=0; i<n; i++){
    cout << ans-mp.at(a[i])+1 << endl;
  }
}

Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << max(min(B, D) - max(A, C), 0) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n, m, k[30], tmp, a[30] = {0};
    cin >> n >> m;
    rep(i, n){
        cin >> k[i];
        rep(j, k[i]){
            cin >> tmp;
            a[tmp-1]++;
        }
    }

    int count = 0;
    rep(i, m){
        if(a[i] == n){
            count++;
        }
    }
    cout << count;



    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  vector<pair<int,int>>a(n),c(m);
  for(int i=0;i<n;i++)cin>>a.at(i).first>>a.at(i).second;
  for(int i=0;i<m;i++)cin>>c.at(i).first>>c.at(i).second;
  for(int i=0;i<n;i++){
    long int l=200000001;int p=0;
    for(int j=0;j<m;j++){
      long int x=abs(a.at(i).first-c.at(j).first)+abs(a.at(i).second-c.at(j).second);
      if(x<l){p=j;l=x;}
    }
    cout<<p+1<<endl;
  }
}
        


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

g = [[] for i in range(n + 1)]
v = [0] * (n + 1)
e = []
for i in range(m):
    a, b = map(int, input().split())
    e.append((a, b))
    g[a].append(b)
    g[b].append(a)

def dfs(start, end):
    q = []
    q.append(start)

    while q:
        # 現在位置curをスタックに追加
        cur = q.pop()
        # 訪れた場所として記録
        v[cur] = 1

        if cur == end:
            return True

        # 繋がっている頂点next_vをまだ訪れていなければ、qに追加
        # (cur, next_v) != (start, end)は、辺になっていなければ、つまり一旦他の頂点を経由して目的地にたどり着いてしまった場合...
        for next_v in g[cur]:
            if v[next_v] != 1 and (cur, next_v) != (start, end):
                q.append(next_v)
    return False

ans = 0
for a,b in e:
    v = [0] * (n + 1)
    if not dfs(a,b):
        ans += 1

print(ans)


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


int par[100005];
int sz[100005];
vector <int> vec[100005];

int root(int v){
    if(par[v] == v) return v;
    return par[v] = root(par[v]);
}

void unite(int a, int b){
    int a1 = root(a);
    int b1 = root(b);
    if(a1 == b1) return;
    if(sz[a1] < sz[b1]) swap(a1, b1);
    sz[a1] += sz[b1];
    par[b1] = a1;
}

int main(){

    int n, m;
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        par[i] = i;
        sz[i] = 1;
    }
    for(int i=1; i<=n; i++){
        int k;
        cin >> k;
        while(k--){
            int x;
            cin >> x;
            vec[i].push_back(x);
        }
        k = vec[i].size();
        for(int j=1; j<k; j++){
            unite(vec[i][j], vec[i][j-1]);
        }
    }
    int prvi = root(vec[1][0]);
    for(int i=1; i<=n; i++){
        int tren = root(vec[i][0]);
        if(tren != prvi){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}

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

int main() {
  int n;
  long long s = 0;
  vector<long long> a(100005);
  cin >> n;
  for (int i = 0; i < 100005; i++) a[i] = 0;
  for (int i = 0; i < n; i++) {
    long long t;
    cin >> t;
    a[t]++;
    s += t;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    a[c] += a[b];
    s -= (a[b] * b);
    s += (c * a[b]);
    a[b] = 0;
    cout << s << endl;
  }
}

Measured memory_bytes: 3872
A = gets.to_f
B = gets.to_f
C = gets.to_f
D = gets.to_f
E = gets.to_f

AC = (A/10).ceil() * 10
BC = (B/10).ceil() * 10
CC = (C/10).ceil() * 10
DC = (D/10).ceil() * 10
EC = (E/10).ceil() * 10

diff = [AC-A, BC-B, CC-C, DC-D, EC-E].max
puts (AC + BC + CC + DC + EC - diff).to_i


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b==c||a+c==b||b+c==a) {
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
}

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

bool bsearch(const int array[], int left, int right, int value){
  while (left + 1 < right){
    int med = (left+right)/2;
    if (array[med] > value) right = med;
    else left = med;
  }
  return left < right && array[left] == value;
}

bool ok(int P,int n,int k,int w[]){
  int max=0,count=1,weight=P;
  
  for (int i=0;i<n;i++){
    if (w[i]>max) max=w[i];
    
    if (w[i]>weight){
      count ++;
      weight = P - w[i];
    }else{
      weight = weight - w[i];
    }
  }
    return k >= count && P >= max;
}

int main(){
  int n,k,w[100100];
  cin >> n >> k;
  
  for (int i=0;i<n;i++){
    cin >> w[i];
  }

  int l=0, h=1000000050;
  while (l+1<h){
    int m=(l+h)/2;
    if(ok(m,n,k,w)) h=m ; else l=m;
  }
  cout << h << endl;  
  return 0;
}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	int n,w;
	sd(n);sd(w);
	vector<ll> a[2], dp[n];
	for(int i=0;i<n;i++){
		int a1, a2;
		sd(a1);sd(a2);
		a[0].pb(a1);
		a[1].pb(a2);
		//cout<<a[0][i]<<" "<<a[1][i]<<endl;
	}
	//return 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=w;j++){
			if(i==0){
				if(j-a[0][i]<0){
					dp[i].pb(0);
				}else{
					dp[i].pb(a[1][i]);
				}
			}else{
				if(j-a[0][i]<0){
					dp[i].pb(dp[i-1][j]);
				}else{
					dp[i].pb(max(dp[i-1][j], a[1][i]+dp[i-1][j-a[0][i]]));
				}
			}
			//cout<<dp[i][j]<<" ";
		}
		//cout<<endl;
	}
	plld(dp[n-1][w]);
}

Measured memory_bytes: 79352
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(int n, int[] a, int[] b) {
    long ans = 0;
    for (int i = 0; i < n; i++) {
        int d = min(a[i], b[i]);
        ans += d;
        if (a[i] < b[i]) {
            int d2 = min(a[i+1], b[i] - a[i]);
            a[i+1] -= d2;
            ans += d2;
        }
    }
    return ans;
}

void main() {
    int n; scan(n);
    auto a = readints;
    auto b = readints;
    writeln(calc(n, a, b));
}


Measured memory_bytes: 8904
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

const int MOD = 1e9 + 7;

int add(int x, int y) {
    x += y;
    if (x >= MOD)
        return x - MOD;
    return x;
}

int sub(int x, int y) {
    x -= y;
    if (x < 0)
        return x + MOD;
    return x;
}

int mul(int x, int y) {
    return (1LL * x * y) % MOD;
}

int bin_pow(int a, int p) {
    if (!p)
        return 1;
    if (p % 2)
        return (1LL * bin_pow(a, p - 1) * a) % MOD;
    int t = bin_pow(a, p / 2);
    return (1LL * t * t) % MOD;
}

int inv(int x) {
    return bin_pow(x, MOD - 2);
}


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    string s;
    cin >> s;
    int n = sz(s);
    forn (i, 0, n)
        s[i] -= '0';
    int d;
    cin >> d;
    int sum = 0;
    vector <int> dp(d);
    forn (i, 0, n) {
        vector <int> new_dp(d);
        forn (j, 0, s[i])
            new_dp[(sum + j) % d]++;
        sum = (sum + s[i]) % d;
        forn (j, 0, d)
            forn (k, 0, 10)
                new_dp[(j + k) % d] = add(new_dp[(j + k) % d], dp[j]);
        swap(dp, new_dp);
    }
    cout << (dp[0] - 1 + (sum % d == 0) + MOD) % MOD;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	int N; cin >> N;
	map<int, int>mp;
	for (int i = 0; i < N; ++i) {
		int p; string m; cin >>p>> m;
		long long int num = 0;
		for (auto c : m) {
			num *= p;
			if (isdigit(c)) {
				num += c - '0';
			}
			else if (c >= 'A'&&'Z' <= c) {
				num += c - 'A' + 10;
			}
			else {
				num += c - 'a' + 36;
			}
		}
		bitset<100>bs(num);
		int n = 0;
		for (int i = 0; i < 99; ++i) {
			if (bs[i]) {
				n++;
			}
			else {
				if (n) {
					mp[n]++;
					n = 0;
				}
			}
		}
	}
	int k = 0;
	for (auto m: mp) {
		if (m.second%2) {
			k ^= m.first;
		}
	}
	if (k)cout << "win" << endl;
	else cout << "lose" << endl;
	return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

vector<ii> tmp;
int main(){
    IOS();
    ll n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    ll idx = 0;
    REP (i,n) {
        idx = i;
        while (idx < n && s[idx] == s[i]) idx++;
        tmp.eb(ii(idx-i,!(s[i]-'0')));
        i = idx-1;
    }
    debug(tmp);
    ll cnt = 0, cur = 0;
    ll ans = 0;
    deque<ii> dq;
    REP (i,SZ(tmp)) {
        while (SZ(dq) && cnt > k) {
            cur -= dq.front().X;
            cnt -= dq.front().Y;
            dq.pop_front();
        }
        ans = max(ans,cur);
        dq.eb(tmp[i]);
        cur += tmp[i].X;
        cnt += tmp[i].Y;
        debug(cur);
    }
    while (SZ(dq) && cnt > k) {
        cur -= dq.front().X;
        cnt -= dq.front().Y;
        dq.pop_front();
    }
    ans = max(ans,cur);
    cout << ans << endl;
}


Measured memory_bytes: 2880
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
int main() {
    	int n,ans=0;
	cin>>n;
	if(n>=500){
		ans+=(n/500)*1000+(n%500)/5*5;
	}
	else{
		ans+=(n/5)*5;
	}
	cout<<ans<<endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
//const int mod = 1e18 + 7;
int main()
{
	SPEED
	int n;
	cin >> n;
	int y = n/2;
	if (n&1)
	{
		y++;
	}
	float p = (float)y/n;
	cout << p ;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()

	ans = 0
	total = N * (N+1) // 2
	for i in range(1,N+1):
		tmp = i * ((N//i) * ((N//i)+1) // 2)
		ans += tmp

	print(ans)



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 76532
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n;
  ll c[101][21]={};
  int a;
  int i,j;

  cin>>n;
  cin>>a;
  c[1][a]++;

  for(i=2;i<n;i++){
    cin>>a;
    for(j=0;j<21;j++)
      if(c[i-1][j]){
	if(j+a<21)
	  c[i][j+a]+=c[i-1][j];
	if(j-a>=0)
	  c[i][j-a]+=c[i-1][j];
      }
  }
  cin>>a;
  /*
  for(i=1;i<11;i++){
    for(j=0;j<21;j++)
      printf(" %2d",c[i][j]);
    cout<<endl;
  }
  */

  cout<<c[n-1][a]<<endl;

}

Measured memory_bytes: 1180
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
a,b=map(int,input().split())
if a==b:
  print("Draw")
elif a==1:
  print("Alice")
elif b==1:
  print("Bob")
elif a<b:
  print("Bob")
elif a>b:
  print("Alice")


Measured memory_bytes: 65196
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const W = parseInt(arg[0].split(" ")[0]);
    const a = parseInt(arg[0].split(" ")[1]);
    const b = parseInt(arg[0].split(" ")[2]);
    
    if(a <= b && b <= (a + W)) {
        console.log(0);
        return;
    }
    
    if(a <= (b + W) && (b + W) <= (a + W)) {
        console.log(0);
        return;
    }
    
    console.log(a < b ? b - (a + W) : a - (b + W));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define mp make_pair
#define f1 first
#define f2 second
#define int long long
#define int1 int
#define pb push_back
using namespace std;
int dp[309][309][309];
main()
{
  string s;
  cin>>s;
  int k;
  cin>>k;
  int n=s.size();
  for(int i=0 ; i<n ; i++)
  {
      for(int j=0 ; j<=k ; j++)
      {
          dp[i][i][j]=1;
      }
  }
  for(int j=1 ; j<n ; j++)
  {
      for(int i=j-1 ; i>=0 ; i--)
      {
          for(int w=0 ; w<=k ; w++)
          {
              if(s[i]==s[j])
              {
                  dp[i][j][w]=dp[i+1][j-1][w]+2;
              }
              else if(w==0)
              {
                  dp[i][j][w]=max(dp[i+1][j][w],dp[i][j-1][w]);
              }
              else
              {
                dp[i][j][w]=max(max(dp[i+1][j][w],dp[i][j-1][w]),dp[i+1][j-1][w-1]+2);
              }
          }
      }
  }

cout<<dp[0][n-1][k];
}


Measured memory_bytes: 225536
#include<stdio.h>

void init(int matrix[][11]){
  int i, j;
  for(i=0; i<11; i++){
    for(j=0; j<11; j++){
      matrix[i][j]=0;
    }
  }
}

int matrixCompute(int matrix[][11], int size){
  int i, j;
  for(i=0; i<size; i++){
    for(j=0; j<size; j++){
      matrix[i][size]+=matrix[i][j];
    }
  }
  for(i=0; i<size; i++){
    for(j=0; j<size; j++){
      matrix[size][i]+=matrix[j][i];
    }
  }
  for(i=0; i<size; i++){
    matrix[size][size] += matrix[size][i];
  }
  for(i=0; i<=size; i++){
    for(j=0; j<=size; j++){
      printf("%5d", matrix[i][j]);
    }
    printf("\n");
  }
}

int main(){
  int n, i, j;
  int matrix[11][11];
  while(scanf("%d", &n), n){
    init(matrix);
    for(i=0; i<n; i++){
      for(j=0; j<n; j++){
        scanf("%d", &matrix[i][j]);
      }
    }
    matrixCompute(matrix, n);
  }
  return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

const ll MOD = 1000000007;

int main() {
    int n; ll k;
    cin >> n >> k;

    vector<ll> a(n);
    map<int, int> a_b;
    rep(i, n) {
        int c, b; cin >> c >> b;
        a[i] = c;
        a_b[c] += b; 
    }

    sort(a.begin(), a.end());
    set<int> a_set;
    rep(i, n) a_set.insert(a[i]);
    ll sum = 0; ll ans = 0; auto itr = a_set.begin();
    do {
        sum += a_b[*itr];
        ans = *itr; itr++;
    }
    while (k > sum);

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

Measured memory_bytes: 9764
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;

bool know[101][101];

int main () {
    int n;
    while (cin >> n, n) {
        memset(know, 0, sizeof(know));
        for (int i = 1; i <= n; i++) {
            int m;
            cin >> m;
            for (int j = 1; j <= m; j++) {
                int p;
                cin >> p;
                know[i][p] = true;
            }
        }
        int k;
        cin >> k;
        vector<int> l(k);
        for (int i = 0; i < k; i++) {
            cin >> l[i];
        }

        queue<int> result;
        for (int i = 1; i <= n; i++) {
            bool out = true;
            for (int j = 0, size = l.size(); j < size; j++) {
                if (know[i][l[j]] == false) {
                    out = false;
                    break;
                }
            }
            if (out) {
                result.push(i);
            }
        }

        int out = -1;
        if (result.size() == 1) {
            out = result.front();
        }
        cout << out << endl;
    }
}

Measured memory_bytes: 920
#include<stdio.h>

int main(){
	int n, a, max = -1000000, min = 1000000;
	long long sum = 0;

	scanf("%d", &n);
	for (int i = 0; i<n; i++){
		scanf("%d", &a);
		if (max<a){
			max = a;
		}
		if (min>a){
			min = a;
		}
		sum = sum + a;
	}
	printf("%d %d %lld\n", min, max, sum);
	return 0;
}



Measured memory_bytes: 2108
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int h,w,a,b; 
  cin >> h >> w >> a >> b;

  mat ans(h,vec(w));
  REP(i,h){
    REP(j,w){
      if(j<a) ans[i][j] = 0;
      else ans[i][j] = 1;
    }
  }

  REP(i,h){
    REP(j,w){
      if(i<b) cout << (ans[i][j]^1);
      else cout << ans[i][j];
      
    }cout << endl;
  }

  return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <map>

using namespace std;

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

    map<string, int> m;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        m[s]++;
    }

    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}


Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var raw = ReadLine().Split().Select(int.Parse).ToArray();
            var N = raw[0];
            var M = raw[1];
            var X = ReadLine().Split().Select(int.Parse).ToArray();

            X = X.OrderBy(x => x).ToArray();
            var len = new int[M - 1];
            for (int i = 0; i < len.Length; i++)
            {
                len[i] = X[i + 1] - X[i];
            }
            var ans = len.OrderBy(s => s).Take(M - N).Sum();
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 24672
s = input()
if s == 'RRR':
    print(3)
elif s == 'SRR' or s == 'RRS':
    print(2)
elif s == 'RSS' or s == 'SSR' or s == 'RSR' or s == 'SRS':
    print(1)
else:
    print(0)

Measured memory_bytes: 9028
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

lo n,m,b[li],a[li],k,flag,t;
lo cev;
string s;
vector<lo> v;

int main(void){
	scanf("%lld",&n);
	for(lo i=1;i<=n+1;i++){
		scanf("%lld",&a[i]);
	}
	FOR{
		scanf("%lld",&b[i]);
	}
	lo at=1;
	for(lo i=1;i<=n+1;i++){
		//~ cout<<cev<<endl;
		if(at>n)break;
		if(at+1<i){at++;i--;continue;}
		if(at>i){continue;}
		if(a[i]>b[at]){cev+=b[at];a[i]=a[i]-b[at];i--;at++;continue;}
		b[at]-=a[i];
		cev+=a[i];
		a[i]=0;
	}
	printf("%lld\n",cev);
	return 0;
}


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

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

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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;
}

//最大公倍数。（最小公倍数は a + b / gcd）
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

signed main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
    A[i]/=2;
  }

  ll buf = 0;
  buf = A[0];
  int div2 = 0;
  rep(i, INF_INT) {
    if(buf >> i & 1){
      div2 = i;
      break;
    }
  }
  int divideNo = 1 << div2;
  rep(i, N) {
    if(A[i] >> div2 & 1 && A[i]%divideNo == 0) continue;
    cout << 0 << endl;
    return 0;
  }
  rep(i, N-1) {
    buf = buf*A[i+1]/gcd(buf,A[i+1]);
    if(buf > 2*M){
      cout << 0 << endl;
      return 0;
    }
  }

  cout << ((M+buf)/(2*buf)) << endl;


}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
#define pi 3.141592653589
using namespace std;
ll n, l; ll a[114514]; pair<ll, ll>cnt[114514];
signed main() {
	cin >> n >> l;
	rep(i, n)cin >> a[i];
	for (int i = 0; i < n - 1; i++)cnt[i].first = a[i] + a[i + 1];
	for (int i = 0; i < n - 1; i++)cnt[i].second = i + 1;
	sort(cnt, cnt + n - 1);
	if (cnt[n - 2].first < l) {
		puts("Impossible");
		return 0;
	}
	puts("Possible");
	ll memo = cnt[n - 2].second;
	for (int i = 1; i < memo; i++)cout << i << endl;
	for (int i = n - 1; i > memo; i--)cout << i << endl;
	cout << memo << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x[5];
    rep(i, 5) cin >> x[i];
    rep(i, 5) {
        if(x[i] == 0) {
            cout << i + 1 << endl;
        }
    }

    return 0;
}


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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC   
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

const ll MOD = (ll)1e9+7; //change it for other mods

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

ll primes[10000001];
ll vis[10000001];
ll ans[10000001];

int main()
{
    FAST_IO;
    #ifdef STIO 
      freopen("input.txt" , "r", stdin);
      freopen("output.txt" , "w", stdout);
    #endif
    ll n;
    cin >> n;
    for(ll i=2;i<=n;i++) {
    	if(vis[i] == 1) {
    		continue;
    	}
    	for(ll j=i;j<=n;j+=i) {
    		primes[j] = i;
    		vis[j] = 1;	
    	}
    }
    ll sum = 1;
    ans[1] = 1;
    for(ll i=2;i<=n;i++) {
    	ll temp = 1;
    	ll cnt = 1;
    	ll hoo = i;
    	while(hoo % primes[i] == 0) {
    		hoo /= primes[i];
    		cnt++;
    	}
    	ans[i] = temp*cnt*ans[hoo];
    	sum += i*ans[i];
    }
    cout << sum << "\n";
}

Measured memory_bytes: 237944
while True:

    x, y = [int(item) for item in input().split(" ")]

    if x == 0:
        break

    if x < y:
        x, y = y, x

    count = 0

    while y != 0:
        x = x % y
        x, y = y, x
        count += 1

    print(x, count)



Measured memory_bytes: 5612
from sys import stdin
INF = 10**9 + 7
n = int(stdin.readline().rstrip())
ten = 1
nine = 1
eight = 1
for x in range(n):
    ten = (ten * 10) % INF
    nine = (nine * 9) % INF
    eight = (eight * 8) % INF
ans = (((ten + eight) % INF) - ((2 * nine) % INF)) % INF
if ans < 0:
    ans += INF
print(ans)

Measured memory_bytes: 63340
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
const int mod = 1e9+7;
typedef pair<int,int> P;
#define fi first
#define se second

int dp[302][302][302];
int calc(int k, int n){
	int res = 0;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			if(k == 0)res += dp[n][i][j];
			if(k == 1)res += dp[i][n][j];
			if(k == 2)res += dp[i][j][n];
			res %= mod;
		}
	}
	return res;
}

int MAX(int a, int b, int c){
	int res = max(a, b);
	return max(res, c);
}

int MIN(int a, int b, int c){
	int res = min(a, b);
	return min(res, c);
}

signed main(){
	int n, m;
	scanf("%lld%lld", &n, &m);
	vector<vector<P> > v(n+1);
	for(int i = 0;i < m;i++){
		int l, r, x;
		scanf("%lld%lld%lld", &l, &r, &x);
		v[r].push_back(P(l, x));
	}
	
	dp[0][0][0] = 1;
	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= n;j++){
			for(int k = 0;k <= n;k++){
				int r = MAX(i, j, k), l = MIN(i, j, k);
				int mid = (i+j+k)-r-l;
				if(l != 0 && (mid == l || mid == r || l == r))continue;
				for(int p = 0;p < v[r].size();p++){
					P pp = v[r][p];
					if(pp.se == 1){
						if(pp.fi <= mid)dp[i][j][k] = 0;
					}else if(pp.se == 2){
						if(pp.fi <= l)dp[i][j][k] = 0;
						if(pp.fi > mid)dp[i][j][k] = 0;
					}else{
						if(pp.fi > l)dp[i][j][k] = 0;
					}
				}
				dp[r+1][j][k] += dp[i][j][k] %= mod;
				dp[i][r+1][k] += dp[i][j][k] %= mod;
				dp[i][j][r+1] += dp[i][j][k] %= mod;
			}
		}
	}
	
	int ans = 0;
	for(int i = 0;i < 3;i++)ans += calc(i, n);
	printf("%lld\n", ans%mod);
	return 0;
}


Measured memory_bytes: 215424
#include <stdio.h>

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

    char an[n+1][50+1];
    char bm[m+1][50+1];
    for (int i = 1; i <= n; i++) {
        scanf("%s", &(an[i][1]));
    }
    for (int i = 1; i <= m; i++) {
        scanf("%s", &(bm[i][1]));
    }

    for (int i = 1; i <= n-(m-1); i++) {
        for (int j = 1; j <= n-(m-1); j++) {
            int found = 1;
            for (int x = 1; x <= m; x++) {
                for (int y = 1; y <= m; y++) {
                    if (bm[x][y] != an[x+i-1][y+j-1]) {
                        found = -1;
                        break;
                    }
                }
            }
            if (found == 1) {
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");

    return 0;
}

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

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

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back

const int mn = 2000;

bitset<mn> g[mn], dpl[mn], dpr[mn];

int n;
char s[mn + 5];

int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif

    scanf("%d", &n);
    if (n == 1) {
        puts("1");
        exit(0);
    }
    for (int i = 1; i < n; i++) {
        scanf("%s", s);
        for (int j = 0; j < i; j++) {
            if (s[j] == '1') {
                g[i][j] = 1;
                g[j][i] = 0;
            } else {
                g[i][j] = 0;
                g[j][i] = 1;
            }
        }
    }
    for (int i = 0; i < n; i++) dpl[i][i] = dpr[i][i] = true;
    for (int len = 1; len < n; len++) {
        for (int i = 0; i + len < n; i++) {
            int j = i + len;
            // dpl[i][j] iff g[i][k] && exist k let dpl[k][j] && dpr[k][i+1]
            dpl[j][i] = (g[i] & dpl[j] & dpr[i + 1]).any();

            // dpr[j][i] iff g[j][k] && dpl[k][j-1] && dpr[k][i]
            dpr[i][j] = (g[j] & dpl[j - 1] & dpr[i]).any();
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (dpl[n - 1][i] && dpr[0][i]) ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, k;
    cin >> n >> k;
    n %= k;
    cout << min(abs(n - k), abs(k - abs(n - k))) << '\n';
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a > 0 && a < 10 && b > 0 && b < 10) {
    cout << a*b << endl;
  } else {
    cout << -1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
N=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(N):
    S=input()
    if(S=="AC"):
        ac +=1
    elif(S=="WA"):
        wa +=1
    elif(S=="TLE"):
        tle +=1
    elif(S=="RE"):
        re +=1
ac=str(ac)
wa=str(wa)
tle=str(tle)
re=str(re)
print("AC x "+ ac +"")
print("WA x "+ wa +"")
print("TLE x "+ tle +"")
print("RE x "+ re +"")

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


int main(){
    string s;
    cin>>s;
    int n=s.length();
    int d=0;
    for(int i=0;i<n;i++){
            if(isupper(s[i])){
                d++;
            }
        }
    if(s[0]!='A' || d>2){
        cout<<"WA"<<endl;
    }
    else{
        int c=0,d=0;
        for(int i=2;i<n-1;i++){
            if(s[i]=='C'){
                c++;
            }
        }
        if(c==1){
            cout<<"AC"<<endl;
        }
        else{
            cout<<"WA"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r, g;
    cin >> r >> g;
    cout << 2 * g - r << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

    vector <ll> a(n+1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i-1];
    }

    ll ans = 1LL << 60;
    for (int i = 2; i < n-1; i++) {
        ll p = a[i] / 2;
        int p_idx = lower_bound(a.begin(), a.end(), p) - a.begin();
        ll p_max = max(a[p_idx], a[i] - a[p_idx]);
        ll p_min = min(a[p_idx], a[i] - a[p_idx]);
        ll tmp_max = max(a[p_idx - 1], a[i] - a[p_idx - 1]);
        ll tmp_min = min(a[p_idx - 1], a[i] - a[p_idx - 1]);
        if (p_max - p_min > tmp_max - tmp_min) {
            p_max = tmp_max;
            p_min = tmp_min;
        }

        ll r = (a[n] - a[i]) / 2 + a[i];
        int r_idx = lower_bound(a.begin(), a.end(), r) - a.begin();
        ll r_max = max(a[r_idx] - a[i], a[n] - a[r_idx]);
        ll r_min = min(a[r_idx] - a[i], a[n] - a[r_idx]);
        tmp_max = max(a[r_idx - 1] - a[i], a[n] - a[r_idx - 1]);
        tmp_min = min(a[r_idx - 1] - a[i], a[n] - a[r_idx - 1]);
        if (r_max - r_min > tmp_max - tmp_min) {
            r_max = tmp_max;
            r_min = tmp_min;
        }

        ans = min(ans, max(p_max, r_max) - min(p_min, r_min));
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
n = gets.to_i
as = gets.split.map &:to_i
MOD = 10 ** 9 + 7
MOD_X = MOD - 2
MOD_ARR = []

y = MOD_X

while y > 1
	MOD_ARR << y % 2
	y = y / 2
end

def pow(x)
	result = x
	MOD_ARR.each.with_index(1){ |ar, i|
		result = (result * result) % MOD
		if MOD_ARR[-i] > 0 then
			result = (result * x) % MOD
		end
	}
	
	result
end

lcm_sum = as[0]

as[1..-1].each{ |a|
	lcm_sum = lcm_sum.lcm(a)
}

lcm_sum = lcm_sum % MOD

output = 0

as.each{ |a|
	output = (output + lcm_sum * pow(a)) % MOD
}

puts output % MOD

Measured memory_bytes: 50044
mod = int(1e9) + 7
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
LM = [-1 for _ in range(N)]
RM = [-1 for _ in range(N)]
LM[0] = T[0]
S = 1
for i in range(1, N):
    if T[i-1] != T[i]:
        LM[i] = T[i]
RM[-1] = A[-1]
for i in range(N, 1, -1):
    if A[i-1] != A[i-2]:
        RM[i-2] = A[i-2]
for i in range(N):
    if LM[i] != -1 and RM[i] != -1:
        if LM[i] != RM[i]:
            S *= 0
            break
    else:
        if LM[i] == -1 and RM[i] == -1:
            S *= min(T[i], A[i])
            S %= mod
        elif LM[i] != -1 and RM[i] == -1:
            if LM[i] > A[i]:
                S *= 0
                break
        elif LM[i] == -1 and RM[i] != -1:
            if RM[i] > T[i]:
                S *= 0
                break
print(S)

Measured memory_bytes: 24900
/*input
3
Hoshino
Hashino
Masayuki Hoshino was the grandson of Ieyasu Tokugawa.
*/
fn read_line() -> String {
    let mut return_ = format!("");
    std::io::stdin().read_line(&mut return_).ok();
    return_
}

fn main() {
    let n: u32 = read_line().trim().parse().expect("");
    for _ in 0..n {
        print!("{}", read_line().replace("Hoshino", "Hoshina"));
    }
}



Measured memory_bytes: 5028