akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const int N = 1e6+5;
string s;
vector<int> v[N];
ll n,m,b,c,result;
ll a[17];
bool k[17];
vector<pair<ll,bool> > p[17];

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  rep(i,n) {
    cin >> a[i];
    rep(j,a[i]) {
      cin >> b >> c;
      p[i].push_back(P(b-1,c==1?true:false));
    }
  }
  ll g = pow(2,n);
  rep(i,g) {
    bool flag = true;
    ll num = 0;
    rep(j,n) {
      // cout << i << " : " << j << " : " << (i >> j) << endl;
      if(i >> j & 1)  {
        k[j] = true;
        num++;
      }
      else k[j] = false;
    }
    // cout << i << " : " << num << endl;
    rep(j,n) {
      if(k[j]) {
        rep(l,p[j].size()) {
          if(k[p[j][l].first] != p[j][l].second) {
            // cout << j << endl;
            flag = false;
            num = 0;
            break;
          }
        }
        if(!flag) break;
      }
    }
    if(flag) result = max(result, num);
    // cout << i << " : " << result << endl;
  }
  cout << result << endl;
}


Measured memory_bytes: 23936
#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(){
    int h, w, n;
    cin >> h >> w >> n;
    vector<vector<int>> map(h+2, vector<int>(w+2));
    rep(i, h+2) rep(j, w+2) map.at(i).at(j) = -1;
    rep(i, h+2){
        map.at(i).at(0) = -2;
        map.at(i).at(w+1) = -2;
    }
    rep(i, w+2){
        map.at(0).at(i) = -2;
        map.at(h+1).at(i) = -2;
    }
    vector<int> co(n);
    rep(i, n) cin >> co.at(i);
    vector<int> col(0);
    rep(i, n) rep(j, co.at(i)) col.push_back(i+1);
    int x = 1;
    int y = 0;
    int l = 0;
    vector<vector<int>> hou(4, vector<int>(2));
    hou.at(0) = {0, 1};
    hou.at(1) = {1, 0};
    hou.at(2) = {0, -1};
    hou.at(3) = {-1, 0};
    for(int i=0; i<h*w; i++){
        x += hou.at(l).at(0);
        y += hou.at(l).at(1);
        map.at(y).at(x) = col.at(i);
        if(map.at(y+hou.at(l).at(1)).at(x+hou.at(l).at(0)) != -1){
            l++;
            l %= 4;
        }
    }
    rep(i, h){
        rep(j, w){
            cout << map.at(i+1).at(j+1) << ' ';
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,n=0;
    cin >> a >> b >> c;
    for(int i = a; i <= b; i++){
        if (c % i == 0) {
            n++;
        }
        
    }
    cout << n << endl;
}



Measured memory_bytes: 3088
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
long waru = (long)1e9 + 7;
vector<long> factroial, finverse,mother,answer;
int c = 0;
long getpower(long a, long p, long base) {
	long result = 1;  //d = (long)log2(p);
	vector<long> L;
	for (long i = 1; i < p * 2; i *= 2)
	{
		long ap = ((p / i) % 2 == 1) ? a : 1;
		result = result * ap % base;
		a = (a * a) % base;
	}
	return result;

}
long counttree(map<long, vector<long>> &path, long pos, long parent, vector<long>& d) {
	long result;
	result = 1;
	for (int i = 0;i < path[pos].size();i++){//(long x : path[pos]) {
		if (parent != path[pos][i]) {
			result += counttree(path, path[pos][i], pos, d);
		}
	}
	mother[pos] = parent;
	d[pos] = result;
	return result;
}
long rootans(map<long, vector<long>> &path, long pos, long parent
	, vector<long>& d, vector<long>& ts) {
	long result;
	result = factroial[ts[pos] - 1];
	for (long x : path[pos]) {
		if (parent != x) {
			result = result * rootans(path, x, pos, d, ts) % waru;
			result = result * finverse[ts[x]] % waru;
		}
	}
	d[pos] = result;
	return result;
}
void calans(map<long, vector<long>> &path, long pos, long parent
	, vector<long>& ts,long N) {
	long result;
	long ans = factroial[N - 1];
	//rootQA[i]*(rootQA[mother](n-1-size)!size!/n!/rootQA[i])<除いた親
					//*(N-1)!/(size-1)!/(N-)!
	ans = ans * answer[parent] % waru;
	ans = ans * finverse[N - 1] % waru;
	ans = ans * factroial[N - 1 - ts[pos]] % waru;
	ans = ans * factroial[ts[pos]] % waru;
	ans = ans * finverse[ts[pos]-1] % waru;
	ans = ans * finverse[N-1-(ts[pos]-1)] % waru;
	answer[pos] = ans;
	for (long x : path[pos]) {
		if (parent != x) {
			calans(path, x, pos, ts,N);
		}
	}
}
int main()
{
	long N;
	cin >> N;
	factroial = vector<long>(N + 1);
	finverse = vector<long>(N + 1);
	mother = vector<long>(N + 1);


	factroial[0] = 1;
	finverse[0] = 1;
	for (int i = 1; i < N + 1; i++)
	{
		factroial[i] = (factroial[i - 1] * i) % waru;
		finverse[i] = getpower(factroial[i], waru - 2, waru);
	}
	map<long, vector<long>> path;
	vector<long> treesize(N + 1), rootQA(N + 1);
	for (int i = 0; i < N - 1; i++)
	{
		long a, b;
		cin >> a >> b;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	counttree(path, 1, -1, treesize);
	rootans(path, 1, -1, rootQA, treesize);
	answer=vector<long>(N + 1);
	answer[1] = rootQA[1];

	for (long x : path[1]) {
		if (1 != x) {
			calans(path, x, 1, treesize, N);
		}
	}
	for (int i = 1; i < N+1; i++)
	{
		cout << answer[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 35056
#include<stdio.h>
int main(void)
{
	int a,b,x,n;
	scanf("%d %d %d",&x,&a,&b);
	n=a+x+1;
	if(n<=b) {
		printf("dangerous\n");
	}
	if(a<b&&b<=x+a) {
		printf("safe\n");
	}
	if(b<=a) {
		printf("delicious\n");
	}
	return 0;
}

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

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, a[200001];
    cin >> n;
    map<llong,llong> M;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ++M[a[i]];
    }

    vector<llong> P2;
    llong k = 2;
    while (1) {
        P2.push_back(k);
        k *= 2;
        if (k > 2 * 1000000000) break;
    }

    sort(a, a + n, greater<int>());
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (M.find(a[i]) == M.end()) continue;
        if (M[a[i]] == 1) M.erase(a[i]);
        else --M[a[i]];
        for (vector<llong>::iterator itr = P2.end() - 1; itr != P2.begin() - 1; --itr) {
            llong target_key = *itr - a[i];
            // cout << *itr << " " << a[i] << endl;
            if (target_key <= 0) break;
            if (M.find(target_key) != M.end()) {
                // cout << "find" << " " << a[i] << " " << target_key << " " << M[target_key] << endl;
                ++ans;
                if (M[target_key] == 1) M.erase(target_key);
                else --M[target_key];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13568
def main():
    N, *A = map(int, open(0).read().split())
    count = 0
    cur = 1
    while count < N:
        count += 1
        cur = A[cur - 1]
        if cur == 2:
            print(count)
            return
    print(-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14068
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

const int mod = 100000;
void add(int &x, int y) {
  x = (x+y) % mod;
}

int dp[2][1<<20][2];
char ba[20][20];
int cnt[20][20];              // (i,j)以降に何個?があるか
int pow3[400];

int main() {
  int h,w;
  cin >> h >> w;
  
  REP(y,h) REP(x,w) {
    cin >> ba[y][x];
  }
  
  int sum = 0;                  // ?の累積和
  for (int y=h-1; y>=0; --y) {
    for (int x=w-1; x>=0; --x) {
      cnt[y][x] = sum;
      if (ba[y][x] == '?') {
        sum += 1;
      }
    }
  }
  // pow3の計算
  pow3[0] = 1;
  REP(i,400-1) pow3[i+1] = pow3[i] * 3 % mod;
  
  memset(dp,0,sizeof(dp));
  dp[0][0][0] = 1;
  
  int c = 0;
  ll ans = 0;
  REP(y,h) {
    REP(x,w) {
      int d = !c;
      REP(S,1<<w) REP(i,2) dp[d][S][i] = 0;
      REP(S,1<<w) {
        int T = S & ~(1<<x);
        // J
        if (ba[y][x] == 'J' || ba[y][x] == '?') {
          add(dp[d][T][1], dp[c][S][0]+dp[c][S][1]);
        }
        // O
        if (ba[y][x] == 'O' || ba[y][x] == '?') {
          ll tmp = dp[c][S][0];
          if (x) {
            // 左がJならフラグを立てる
            add(dp[d][T|1<<(x-1)][0], dp[c][S][1]);
          } else {
            tmp += dp[c][S][1];
          }
          // 左がJで無かったり、左端の場合
          add(dp[d][T][0], tmp);
        }
        // I
        if (ba[y][x] == 'I' || ba[y][x] == '?') {
          int tmp = dp[c][S][0] + dp[c][S][1];
          if (S>>x&1) {           // 上にJOができてる
            ans = (ans + (ll)tmp * pow3[cnt[y][x]]) % mod;
          } else {
            add(dp[d][T][0], tmp);
          }
        }
      }
      c ^= 1;
    }
  }
  cout << ans << endl;
}

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


int n,m;
int count[100010],p[100010],cnt,pl;

int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		int id;
		char s[4];
		scanf("%d%s",&id,s);
		if(count[id]) continue;
		if(s[0]=='A') count[id]=1,cnt++,pl+=p[id];
		else p[id]++;
	}
	printf("%d %d\n",cnt,pl);
	return 0;
}


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

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

ll table[40][MAX_N];

int main(){
    int n, C;
    cin >> n >> C;
    for (int i = 0; i < n; i++){
        int s, t, c;
        cin >> s >> t >> c;
        table[c][s - 1]++;
        table[c][t]--;
    }

    for (int i = 1; i <= C; i++){
        for (int j = 1; j < MAX_N; j++){
            table[i][j] += table[i][j - 1];
        }
    }

    for (int i = 1; i <= C; i++){
        for (int j = 1; j < MAX_N; j++){
            if (table[i][j] >= 2) table[i][j] = 1;
        }
    }

    for (int i = 1; i <= C; i++){
        for (int j = 1; j < MAX_N; j++){
            table[i][j] += table[i - 1][j];
        }
    }

    ll ans = 0;
    for (int i = 1; i < MAX_N; i++){
        ans = max(ans, table[C][i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 24064
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

int parent[MAX];

/* Union Find / DSU */
//have a parent array global
int find(int u) {
	if(u == parent[u])return u;
	return parent[u] = find(parent[u]);
}

void _union(int u, int v) {
	parent[find(u)] = find(v);
}

void solve() {
	int n, m;
	in2(n, m);
	
	for(int i=1;i<=n;i++) parent[i] = i;
	
	for(int i=0;i<m;i++) {
		int u, v;
		in2(u, v);
		_union(u, v);
	}
	
	set<int> s;
	for(int i=1;i<=n;i++) {
		int pp = find(i);
		s.insert(pp);
	}
	
	cout<<s.size()-1<<en;
}

int main() {
	int t = 1;
	
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 7960
x, n = input().split()
x = int(x)
n = int(n)

if n==0:
	print(x)
else:
	p = list(map(int, input().split()))

	ans = -1
	mn = 10000

	for i in range(0, 102):
		if(p.count(i) == 0):
			d = x - i
			if d<0:
				d = -d
			if d<mn:
				ans = i
				mn = d
	print(ans)

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    lli a , b , c;
    cin >> a >> b >> c ;
    (c >= a && c <= b ? Yes : No ) ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



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

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

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            string s = Read();
            WriteLine(s.Replace('?', 'D'));
        }

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


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

const int Max=100010;
int n,m,ans,pre;
int num[Max];

signed main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&num[i]);
	for(int i=1;i<=n;i++)
	{
	  if(num[i]+pre>m) ans+=num[i]+pre-m,pre=num[i]-(num[i]+pre-m);
	  else pre=num[i];
	}
	cout<<ans;
	return 0;
}

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

ll n,m,l,p,c,ch[101000][2],cnt=1,ans;
char s[101000];

ll dfs(ll x,ll d){
	if (!x) return 0;
	if (dfs(ch[x][0],d-1)^dfs(ch[x][1],d-1)) ans^=d&-d;
	return 1;
}

int main(){
	for (scanf("%lld%lld",&n,&m);n--;){
		scanf("%s",s+1); l=strlen(s+1);
		for (int i=p=1;i<=l;++i){
			c=s[i]-'0';
			if (!ch[p][c]) ch[p][c]=++cnt;
			p=ch[p][c];
		}
	}
	dfs(1,m);
	puts(ans?"Alice":"Bob");
}

Measured memory_bytes: 6656
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int[][] mat = new int[n][n];

        int u, k, v;
        for (int i = 0; i < n; i++) {
            u = scanner.nextInt();
            k = scanner.nextInt();
            for (int j = 0; j < k; j++) {
                v = scanner.nextInt();
                mat[u-1][v-1] = 1;
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(mat[i][j]);
                if (j != n - 1)
                    System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
}

Measured memory_bytes: 34956
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

pair<ll, ll> rec(int depth, const vi& a, const int n, ll r) {
  if (r < a[depth]) {
    return pair<ll, ll> (-1, -1);
  }
  if (depth == n) {
    return pair<ll, ll>(a[depth], a[depth]);
  }

  pair<ll, ll> ans = rec(depth + 1, a, n, min(2 * (r - a[depth]), (ll)1e18));
  if (ans.second < 0) return ans;
  ll can =  min(ans.first + a[depth], r);
  return pair<ll, ll>(can, ans.second + can);
}

ll solve(int n, const vi& a) {
  return rec(0, a, n, 1).second;
}

int main(){
  int n;
  cin >> n;
  vi a(n+1);
  rep(i, n+1) {
    cin >> a[i];
  }

  ll ans = solve(n, a);
  cout << ans << endl;
}


Measured memory_bytes: 6748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int a[22][22];
ll dp[1 << 22] = {0};
int n;

int main(){
    cin >> n;
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> a[i][j];
    dp[0] = 1;
    for(int bit = 1; bit < (1 << n); bit++) {
        int i = __builtin_popcount(bit);
        for(int j = 0; j < n; j++) {
            if((1&bit>>j) && a[i-1][j] == 1) {
                dp[bit] += dp[bit^(1<<j)];
                dp[bit] %= MOD;
            }
        }
    }
    int ans = dp[(1<<n)-1];
    cout << ans << endl;
    

}

Measured memory_bytes: 18688
#include<iostream>
#include<vector>
#define NIL -1
using namespace std;

struct M{
    int r;
    int c;
};

int calc(int s, int e, const vector<M>& M_set,
         vector<vector<int> >& MEMO) {
    if (s == e) return MEMO[s][e] = 0;
    if (MEMO[s][e] != NIL) return MEMO[s][e];
    int min = 1e9;
    for (int split = s; split < e; split++) {
        int val = calc(s, split, M_set, MEMO)
                  + calc(split + 1, e,M_set, MEMO)
                  + M_set[s].r * M_set[split].c * M_set[e].c;
        if (min > val) min = val;
    }
    return MEMO[s][e] = min;
}

int main(){
    int n;
    cin >> n;
    vector<vector<int> > MEMO(n, vector<int>(n, NIL));
    vector<M> M_set(n);
    for (int i = 0; i < n; i++) {
        cin >> M_set[i].r >> M_set[i].c;
    }
    cout << calc(0, n - 1, M_set, MEMO) << endl;
    return 0;
}

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

int main()
{
    int h;
    int w;
    bool bLoop = true;
    
    while (bLoop)
    {
        cin >> h >> w;
        
        if ((h == 0) && (w == 0))
        {
            bLoop = false;
        }
        else
        {
            for (int i = 0; i < h; ++i)
            {
                for (int j = 0; j < w; ++j)
                {
                    if (i % 2 == 0)
                    {
                        if (j % 2 == 0)
                        {
                            cout << "#";
                        }
                        else
                        {
                            cout << ".";
                        }
                    }
                    else
                    {
                        if (j % 2 == 0)
                        {
                            cout << ".";
                        }
                        else
                        {
                            cout << "#";
                        }  
                    }
                }
                cout << endl;
            }
            cout << endl;
        }
    }
    return 0;
    
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)((v).size())
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 


#define M 100010

// (Ax/B) - A(x/B) =y;
// x/B =t  x=Bt,B(t+1)  x=Bt+c   c>=0 c<B  Ac/B 
// Ax/B - At  At,A(t+1)-At
int main(){
    IOS;
    tihs;
    
    ll a,b,n;cin>>a>>b>>n;
    if(n>=b){
    	cout<<(a*(b-1))/b;
  		return 0;
    }
    cout<<(a*(n%b))/b;
    return 0;
}

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

int main() {
  uint64_t X;
  cin >> X;
  uint64_t m = 100;
  uint64_t count = 0;
  while (X > m) {
    m *= 1.01;
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const ld eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1; i>=(a); i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl;})

int main(){
	cin.sync_with_stdio(0);

	ll n, w;
	cin >> n >> w;
	vl wi(n);
	vl vi(n);

	vl values(w + 1);

	FOR(i,0,n){
		cin >> wi[i] >> vi[i];
	}
	
	FOR(i,0,n){
		FORD(j,0,w+1-wi[i]){
			values[j + wi[i]] = max(values[j + wi[i]], (values[j] + vi[i]));
		}
	}

	ll out = 0;
	FOR(i,0,w+1){
		out = max(out, values[i]);
	}
	cout << out << endl;
}


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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int ret = 0;
    for (int i = 0; i < 3; i++)
        if (s[i] == t[i])ret++;
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	int min = 99999999;
	int max = -99999999;
	long long int sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		sum = sum + a;
		if (min > a) min = a;
		if (max < a) max = a;
	}
	cout << min << " " << max << " " << sum << endl;


	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int v[100];
int main(){
	int n,K;cin>>n>>K;
	rep(i,n){
		scanf("%d",&v[i]);
	}
	int Max=0;
	rep(i,n+1){//[0,i)
		for(int j=i;j<=n;j++){//[j,n)
			if(i+(n-j)>K)continue;
			vector<int>a;
			rep(k,i)a.push_back(v[k]);
			for(int k=j;k<n;k++)a.push_back(v[k]);
			sort(a.begin(),a.end(),greater<>());
			int sum=0;
			int rem=K-(i+(n-j));
			while(rem&&!a.empty()&&a.back()<0){
				rem--;
				a.pop_back();
			}
			for(int i:a)sum+=i;
			Max=max(Max,sum);
		}
	}
	cout<<Max<<endl;
}

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 2e5 + 55;

int n;
ll a[maxN];

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

	cin >> n;

	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}

	if(a[1] > 0){
		cout << "-1\n";
		return 0;
	}
	
	ll ans = 0;
	for(int i = 1; i + 1 <= n; i++){
		if(a[i] + 1 < a[i + 1]){
			cout << "-1\n";		
			return 0;
		}

		if(a[i] + 1 == a[i + 1]){
			ans++;
		} else {
			ans += a[i + 1];
		}
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 1792
N,M = map(int,input().split())
s = [0] * M
c = [0] * M
for i in range(M):
    s[i],c[i] = map(int, input().split())
flag = [0] * N

ans = [0] * N
for i in range(M):
    if((N>=2) & (s[i]==1) & (c[i]==0)):
        ans = -1
        print(-1)
        exit()
        break
    if(flag[s[i]-1] == 0):
        ans[s[i]-1] = c[i]
        flag[s[i]-1] = 1
    
    elif(c[i] != ans[s[i]-1]):
        ans = -1
        print(-1)
        exit()
        break
if((N>=2) & (flag[0]==0)):
    ans[0] = 1

a = 0
for i in range(N):
    a += ans[N-i-1]*10**i
print(a)

Measured memory_bytes: 3064
// Problem : C - : (Colon)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define sort(v) sort(all(v))
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
static const long double pi = 3.141592653589793;
using namespace std;
int main()
{
    IOS
    int t=1;
    //cin>>t;
    while(t--)
    {
    	int A, B, H, M;
    	cin>>A>>B>>H>>M;
    	long double H_rad = ((long double)H/12.0 + (long double)M/60.0/12.0) * 2 * pi;
	    long double M_rad = ((long double)M/60.0) * 2 * pi;
	    long double rad = abs(H_rad - M_rad);
	    long double ans = (long double)(A*A)+(long double)(B*B)-(long double)(2*A*B)*cosl(rad);
	   	printf("%20.20Lf\n", sqrtl(ans)); 
    }
    return 0;
}


Measured memory_bytes: 4112
#include <iostream>
#include <ctype.h>
using namespace std;
int main(void){
  string a;
  cin >> a ;
  if(a[0] >= 'a' && a[0] <= 'z'){
    cout << "a" << endl;
  }else if(a[0] >= 'A' && a[0] <= 'Z'){
    cout << "A" << endl;
  }
}


Measured memory_bytes: 3028
#include<stdio.h>

int main(void)
{
  int n,num,i,min=100,counter;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      counter = 0;
      scanf("%d",&num);
      while(num % 2 == 0)
	{
	  num = num / 2;
	  counter++;
	}
      if(min > counter)
	{
	  min = counter;
	}
    }
  printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 128
//54
#include<iostream>
#include<queue>
#include<cstdlib>
#include<cctype>

using namespace std;

struct S{
  int x,y,t,f;
  bool operator<(S a)const{
    return t>a.t;
  }
};

int main(){
  for(int w,h;cin>>w>>h,w|h;){
    char g[60][30];
    priority_queue<S> que;
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
	cin>>g[y][x];
	if(g[y][x]=='S'){
	  S is={x,y,0,0};
	  que.push(is);
	  is.f=1;
	  que.push(is);
	}
      }
    }
    bool m[60][30][2]={{{}}};
    while(!que.empty()){
      S c=que.top();
      if(g[c.y][c.x]=='T')break;
      que.pop();
      if(m[c.y][c.x][c.f]++)continue;
      for(int y=0;y<h;y++){
	for(int x=0;x<w;x++){
	  if(g[y][x]!='X'&&((c.f&&x<c.x)||(!c.f&&c.x<x))&&abs(x-c.x)+abs(y-c.y)<=3){
	    S n={x,y,c.t+(isdigit(g[y][x])?g[y][x]-'0':0),!c.f};
	    que.push(n);
	  }
	}
      }
    }
    cout<<(que.empty()?-1:que.top().t)<<endl;
  }
  return 0;
}

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

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> x(n);
  rep(i,n) cin >> x[i];
  
  ll ans = 0;
  rep(i,n){
    int aMove = x[i]*2;
    int bMove = (k-x[i])*2;
    ans += min(aMove,bMove);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3636
import numpy as np

M = np.array(list(map(int,open(0).read().split()))).reshape(3,3)

hSum = M.sum(axis=0)
vSum = M.sum(axis=1)

f=True
for i in range(3):
  if (hSum[i]-hSum[(i+1)%3])%3!=0:
    f = False

for i in range(3):
  if (vSum[i]-vSum[(i+1)%3])%3!=0:
    f = False
    
print("Yes" if f else "No")

Measured memory_bytes: 27212
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			
			while (true) {
				//StringTokenizer st = new StringTokenizer(br.readLine());
				String[] readLine = br.readLine().split(" ");
				
				int a = Integer.parseInt(readLine[0]);
				String op = readLine[1];			
				int b = Integer.parseInt(readLine[2]);
				
				if (op.equals("?")) {
					break;
				}
				
				int ans = 0;
				switch (op) {
				case "+":
					ans = a + b;
					break;
				case "-":
					ans = a - b;
					break;
				case "*":
					ans = a * b;
					break;
				case "/":
					ans = a / b;
					break;
				}
					System.out.println(ans);						
			}
	}
}


Measured memory_bytes: 24448
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
int val[maxn*20],hd[maxn],n,m;
int to[maxn*20],ne[maxn*20],num,S;
int XS[maxn],now,ci[20],d[maxn],C[233];
inline void add(int x,int y,int z){ to[++num]=y,ne[num]=hd[x],hd[x]=num,val[num]=z;}
inline void build(){
	for(int i=1;i<ci[15];i++)
	    for(int j=1;j<=15;j++) if(ci[j-1]&i){
	    	now=i^ci[j-1],add(now,i,1);
	    	for(int k=1;k<=15;k++) if(ci[k-1]&now) add(now^ci[k-1]^ci[(j^k)-1],i,1+((now&ci[(j^k)-1])?1:0));
		}
}
inline void spfa(){
	queue<int> q; bool v[maxn];
	memset(d,0x3f,sizeof(d));
	memset(v,0,sizeof(v));
	d[0]=0,q.push(0),v[0]=1;
	int x;
	while(!q.empty()){
		x=q.front(),q.pop();
		for(int i=hd[x];i;i=ne[i]) if(d[x]+val[i]<d[to[i]]){
			d[to[i]]=d[x]+val[i];
			if(!v[to[i]]) v[to[i]]=1,q.push(to[i]);
		}
		v[x]=0;
	}
}
inline void init(){
	ci[0]=1;
	for(int i=1;i<=15;i++) ci[i]=ci[i-1]<<1;
	build();
	spfa();
}
inline void solve(){
	int uu,vv,ww,ans=1<<30;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d%d",&uu,&vv,&ww);
		uu++,vv++,XS[uu]^=ww,XS[vv]^=ww;
	}
	for(int i=1;i<=n;i++) C[XS[i]]++;
	for(int i=1;i<=n;i++){
		C[XS[i]]--;
		S=0,now=0;
		for(int j=1;j<=15;j++){
			now+=C[j]>>1;
			S|=(C[j]&1)*ci[j-1];
		}
		now+=d[S];
		ans=min(ans,now);		
		C[XS[i]]++;
	}	
	printf("%d\n",ans);
}
int main(){
	init();
	solve();
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int mark[256];

int main(){
	string s; cin >> s;
	int n = s.size();

	for (int i = 0; i < n; i++) mark[ s[i] ] = 1;
	if ( !(mark['S'] ^ mark['N']) && !(mark['W'] ^ mark['E']) ) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char c[3];
int main(){
	int x;
	cin>>x;
	for(int i=x;i<1000;i++)
		if((i/100)==(i/10)%10&&i/100==i%10)
		{
			cout<<i;
			return 0;
		}	
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------
int l, r;
int dp[60][2][2][2];
int solve(int i, int a, int b, int c) {
	//今i桁目を見ていて、Lにxが触れていて、Rにyが触れていて、今までにMSBを使ったことがある
	if (i == -1) return 1;
	if (dp[i][a][b][c] > -1) return dp[i][a][b][c];
	int sum = 0;
	rep(s, 2)rep(t, 2) {
		if (s == 0 && a && (l >> i & 1) == 1) continue;
		if (t == 1 && b && (r >> i & 1) == 0) continue;
		if (s > t) continue;
		if (c == 0 && s != t) continue;
		int lt = a && ((l >> i & 1) == s);
		int rt = b && ((r >> i & 1) == t);
		int st = c || (s == 1 && t == 1);
		sum += solve(i - 1, lt, rt, st);
	}
	return dp[i][a][b][c] = sum % mod;
}
signed main() {
	cin >> l >> r;
	for (int i = 0; i < 60; i++) {
		for (int j = 0; j < 2; j++) {
			for (int x = 0; x < 2; x++) {
				for (int y = 0; y < 2; y++) {
					dp[i][j][x][y] = -1;
				}
			}
		}
	}
	cout << solve(59, 1, 1, 0) << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

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

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	S := readBytes()

	ok := true

	for i := range S {
		if i%2 == 0 {
			if S[i] == 'L' {
				ok = false
			}
		} else {
			if S[i] == 'R' {
				ok = false
			}
		}
	}
	if ok {
		println("Yes")
	} else {
		println("No")
	}
}

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


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

using namespace std;

int main()
{
    long long a,b;
    while(cin >> a >> b)
    {
        if(a>b)
        swap(a,b);
        if(b==1)
            printf("1\n");
        else if(a==1)
            printf("%lld\n",b-2);
        else if(a==2)
            printf("0\n");
        else
            printf("%lld\n",(a-2)*(b-2));
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
/*
1からmまでの数をn*n個重複しないように選び、合計がsになるパターンの数を求める。
ナップサック
*/
int n,m,s;
int dp[50][3001];



int main(){
	
	while(cin>>n>>m>>s,n){
		
		//初期化?
		for(int i=0;i<50;i++)for(int j=0;j<=3000;j++)dp[i][j]=0;
		dp[0][0]=1;
		
		
		for(int i=1;i<=m;i++){
			for(int j=n*n;j>=1;j--){
				for(int k=i;k<=s;k++){
					dp[j][k]=(dp[j][k]+dp[j-1][k-i])%100000;
				}
			}
		}
		
		//出力
		cout<<dp[n*n][s]<<endl;
		
		
		
	}
	
	return 0;
}


Measured memory_bytes: 1744
s = input()

if s[0] == "1":
    ans = 0
    for i in range(len(s)) :
        if i % 2 == 0 and s[i] != "1" :
            ans += 1
        elif i % 2 == 1 and s[i] != "0" :
            ans += 1
else :
    ans = 0
    for i in range(len(s)):
        if i % 2 == 0 and s[i] != "0":
            ans += 1
        elif i % 2 == 1 and s[i] != "1":
            ans += 1
print(ans)


Measured memory_bytes: 9240
def listFromInput():
    N=int(input())
    numbers=[]
    for i in range(N):
        numbers.append(int(input()))
    return numbers
R=listFromInput()
min=10000000000
max=-10000000000
for i in range(len(R)):
    if R[i]-min > max:
        max=R[i]-min
    if min > R[i]:
        min=R[i]
print(max)

Measured memory_bytes: 15692
n=int(input())
t=list(map(int,input().split()))
v=list(map(int,input().split()))+[0]
V=max(v)
dp=[[0]]+[[] for i in range(V)]
for i in range(0,n):
    a=t[i]
    b=v[i]
    c=v[i+1]
    h=[[] for j in range(V+1)]
    for j in range(V+1):
        l=V-j
        if dp[l]:
            if max(0,l-a)<=min(b,l+a):
                for k in range(max(0,l-a),min(b,c,l+a)+1):
                    if not h[k]:
                        h[k]=dp[l]+[k]
    dp=h
ans=0
for i in range(n):
    a=t[i]
    b=v[i]
    v1=dp[0][i]
    v2=dp[0][i+1]
    if v1==v2==b:
        ans+=a*b
    elif v1==b:
        ans+=a*b-(b-v2)**2/2
    elif v2==b:
        ans+=a*b-(b-v1)**2/2
    else:
        if 2*b-v1-v2<=a:
            ans+=a*b-(b-v2)**2/2-(b-v1)**2/2
        else:
            ans+=a*a/2+a*v1-(a+v1-v2)**2/4
print(ans)

Measured memory_bytes: 42732
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int F[100][10];

int P[100][11];

void solve(){
	ll ans = -10000000000;
	rep(i, 1024){
		int c[100] = {};
		int b = 1;
		rep(j, 10){
			if(i & b)
			rep(k, N){
				c[k] += F[k][j];
			}
			b <<= 1;
		}
		ll a = 0;
		bool t =false;
		rep(j, N){
			if(c[j] != 0) t= true;
			a += P[j][c[j]];
		}
		if(t)
		chmax(ans ,a);
	}
	cout << ans <<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) {
		rep(j, 10) {
			cin >> F[i][j];
		}
	}
	rep(i, N){
		rep(j, 11) {
			cin >> P[i][j];
		}
	}
		solve();
	return 0;
}


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

#define gc() std::getchar()
#define pc(i) std::putchar(i)

template <typename T>
inline T read(){ 
	T x = 0;
	char ch = gc();
	bool f = 0;
	while(!std::isdigit(ch)){ 
		f = (ch == '-');
		ch = gc();
	} 
	while(std::isdigit(ch)){ 
		x = x * 10 + (ch - '0');
		ch = gc();
	} 
	return f ? -x : x; 
}

template <typename T>
void put(T x){ 
	if (x < 0){ 
		x = -x;
		pc('-');
	} 
	if (x < 10){ 
		pc(x + 48);
		return;
	} 
	put(x / 10);
	pc(x % 10 + 48);
	return ;
} 

#define For(i, j, k) for(int i = j; i <= k; ++i)
#define Rep(i, j, k) for(int i = j; i >= k; --i)
#define rdi() read <int> ()
#define rdl() read <long long> ()
#define pti(i) put <int> (i), putchar(' ')
#define ptl(i) put <long long> (i), putchar(' ')
#define pub(i) push_back(i)
#define pob() pop_back()

typedef long long ll;
typedef float fl;
typedef double db;

const int N = 2.2e5;
const int P = 1e9 + 7;
int a[N], s[N];

void fake_main(){ 
	int n = rdi();
	For(i, 1, n) a[i] = rdi();
	
	s[n] = a[n];
	Rep(i, n - 1, 2) s[i] = (a[i] + s[i + 1]) % P;
	
	int ans = 0;
	For(i, 2, n) ans = (1ll * a[i - 1] * s[i] + ans) % P;
	
	printf("%d\n", ans);
} 

int main(){ 
	fake_main();
	
	return 0;
} 

Measured memory_bytes: 5248
// by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

// DELETE the debugging information!
#define debug(x) std::cerr << #x << " = " << (x) << std::endl

const int N_MAX = 500003;
char s[N_MAX];
int pre[N_MAX], suf[N_MAX];

int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1) + 1;
  for (int i = 2; i <= n; ++i)
    pre[i] = s[i - 1] == '<' ? pre[i - 1] + 1 : 0;
  for (int i = n - 1; i > 0; --i)
    suf[i] = s[i] == '>' ? suf[i + 1] + 1 : 0;
  long long ans = 0;
  for (int i = 1; i <= n; ++i)
    ans += std::max(pre[i], suf[i]);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 4608
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
bitset<30000> dp[80][80];
int main(){
	int H,W;
	int A[81][81],B[81][81],sa[81][81];
	scan(H>>W);
	rep(i,H){
		rep(j,W){
			scan(A[i][j]);
		}
	}
	rep(i,H){
		rep(j,W){
			scan(B[i][j]);
		}
	}
	rep(i,H) rep(j,W) sa[i][j]=abs(A[i][j]-B[i][j]);
	int MID=15000;
	dp[0][0].set(MID+sa[0][0]);
	dp[0][0].set(MID-sa[0][0]);
	rep(k,H+W-2){
		for(int y=max(0,k+1-W);y<=min(H-1,k);y++){
			int x=k-y;
			if(x<0||x>=W) continue;
			//printf("k:%d y:%d x:%d\n",k,y,x);
			if(y<H-1){
				dp[y+1][x]|=(dp[y][x]<<sa[y+1][x]);
				dp[y+1][x]|=(dp[y][x]>>sa[y+1][x]);
			}
			if(x<W-1){
				dp[y][x+1]|=(dp[y][x]<<sa[y][x+1]);
				dp[y][x+1]|=(dp[y][x]>>sa[y][x+1]);
			}
		}
	}
	int ans=INF;
	/*rep(i,H){
		rep(j,W){
			printf("i:%d j:%d ",i,j);
			rep(k,30000){
				if(dp[i][j][k]) printf("%d ",k-MID);
			}
			kaigyo;
		}
	}*/
	rep(k,30000){
		if(dp[H-1][W-1][k]){
			ans=min(ans,abs(k-MID));
		}
	}
	prin(ans);
	return 0;
}


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/

int main(){
	int N,L;
	cin >> N >> L;
	int all = 0;
	REP(i,N){
	    all += L + (i+1) - 1;
	}

	int diff = 1000000000;
	int ans = 0;
	REP(i,N){
		int nans = 0;
	    REP(j,N){
	    	if (i == j) continue;
	    	nans += L + (j+1) - 1;
	    }
	    if (chmin(diff,abs(all-nans))){
	    	ans = nans;
	    }
	}


	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256