akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main() {
    string s[3];
    int n[3];
    int index[3] = {0};

    for (int i = 0; i < 3; ++i) {
        cin >> s[i];
        n[i] = s[i].size();
    }

    int turn = 0;
    char card;

    while (true) {
        if (n[turn] == index[turn]) {
            break;
        }
        
        card = s[turn][index[turn]];

        ++index[turn];
        if (card == 'a') {
            turn = 0;
        }
        else if (card == 'b') {
            turn = 1;
        }
        else {
            turn = 2;
        }
    }

    if (turn == 0) {
        cout << "A" << endl;
    }
    else if (turn == 1) {
        cout << "B" << endl;
    }
    else {
        cout << "C" << endl;
    }

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;


int n;
int dp[112345];
int step[40];
vector<int> vec;
int main(){
  cin>>n;
  memset(dp,sizeof(dp),0x3f);

  dp[0]=0;
  dp[1]=1,dp[6]=1,dp[9]=1;

  for(int i=1;i<112300;i++){
    dp[i]=i;
  }

  for(int j=1;pow(6,j)<=112300;j++){
    int x=pow(6,j);
    vec.push_back(x);
  }

  for(int j=1;pow(9,j)<=112300;j++){
    int x=pow(9,j);
    vec.push_back(x);
  }

  //sort(vec.begin(),vec.end());



  for(int j=0;j<(int)vec.size();j++){
    for(int i=0;i<=112300;i++){
        if(vec[j]+i<=112300)dp[i+vec[j]]=min(dp[i]+1,dp[i+vec[j]]);
    }
  }



  cout<<dp[n]<<endl;


}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

    string t;
    cin >> t;
    int res = 0;
    for (int i=0; i<t.size(); i++) {
        if (t[i] == '?') {
            t[i] = 'D';
        }
    }
    cout << t <<"\n";

}

Measured memory_bytes: 3772
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<ll,ll>pll;

vector<int>e[101010];
vector<pair<int, int>>pa(101010);
ll ans = 0;

pair<ll,ll> dfs(int n,int p) {
	if (pa[n].first != -1)return pa[n];
	ll temp0 = 1;
	ll temp1 = 1;
	
	int ok = 0;
	fore(x, e[n]) {
		if (x != p) {
			temp0 *= (dfs(x, n).first + dfs(x, n).second) % MOD;
			temp1 *= dfs(x,n).first % MOD;
			temp0 %= MOD;
			temp1 %= MOD;
			ok = 1;
		}
	}
	return pa[n] = { temp0%MOD,temp1%MOD };
}

int main(){
	int n;
	cin >> n;
	rep(i, 0, 101010) {
		pa[i] = { -1,-1 };
	}
	rep(i, 0, n-1) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		e[x].pb(y);
		e[y].pb(x);
	}
	
	cout << (dfs(0,-1).first + dfs(0,-1).second)%MOD << endl;

	return 0;
}

Measured memory_bytes: 14848
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int n, k;


int main() {
  cin >> n >> k;
  combination c(n);
  k = min(k, n);
  mint ans = 0;
  rep(i, k+1) {
    ans += c(n,i) * c(n-1, i);
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
const int MAXV = MAXN * MAXN;
const int INF = (1 << 30);
int ID[MAXN][MAXN];
vector<int> to[MAXV];
vector<int> from[MAXV];

int id(int a, int b)
{
  if (a > b)
    swap(a, b);
  return ID[a][b];
}

void initID(int N)
{
  int id = 0;
  for (int a = 0; a < N - 1; a++)
  {
    for (int b = a + 1; b < N; b++)
    {
      ID[a][b] = id;
      id++;
    }
  }
}

bool visited[MAXV];
int dp[MAXV];
int dfs(int v)
{
  if (visited[v])
  {
    if (dp[v] > 0)
      return dp[v];
    else
      return INF;
  }
  visited[v] = true;
  int ret = 0;
  for (auto u : to[v])
  {
    ret = max(ret, dfs(u));
  }
  return dp[v] = ret + 1;
}

int main()
{
  int N, a;
  cin >> N;
  int V = N * (N - 1) / 2;
  vector<vector<int>> A(N);
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N - 1; j++)
    {
      cin >> a;
      a--;
      A[i].push_back(a);
    }
  }
  initID(N);
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N - 1; j++)
    {
      if (j != 0)
      {
        from[id(i, A[i][j])].push_back(id(i, A[i][j - 1]));
      }
      if (j != N - 2)
      {
        to[id(i, A[i][j])].push_back(id(i, A[i][j + 1]));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < V; i++)
  {
    int ret = dfs(i);
    if (ret >= INF)
    {
      cout << -1 << endl;
      return 0;
    }
    ans = max(ans, ret);
  }
  cout << ans << endl;
}

Measured memory_bytes: 93188
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 2e3 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , k , c[MAXN][MAXN];

int main() {
    fast_io;

    for(ll i = 0 ; i < MAXN ; i++)  c[i][0] = c[i][i] = 1;
    for(ll i = 1 ; i < MAXN ; i++){
        for(ll j = 1 ; j < i; j++){
            c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
        }
    }

    cin >> n >> k;
    for(ll i = 1 ; i <= k ; i++){
        cout << (c[k - 1][i - 1] * c[n - k + 1][i]) % MOD << endl;
    }

    return 0;
}
/*

*/


Measured memory_bytes: 30336
from itertools import combinations_with_replacement


def main():
    n, m, q = map(int, input().split())
    a = []
    b = []
    c = []
    d = []
    answer = 0
    for i in range(q):
        aa, bb, cc, dd = map(int, input().split())
        a.append(aa - 1)
        b.append(bb - 1)
        c.append(cc)
        d.append(dd)
    numbers = [i for i in range(1, m + 1)]
    for seq in combinations_with_replacement(numbers, n):
        now = 0
        for i in range(q):
            if seq[b[i]] - seq[a[i]] == c[i]:
                now += d[i]
        answer = max(answer, now)
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 9080
# -*- coding: utf-8 -*-

import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
K, N = map(int, input_line.split(" "))

input_line = input()
A = list(map(int, input_line.split(" ")))

ans = A[-1] - A[0]

for i in range(1, N):
    a = K - (A[i] - A[i-1])
    ans = min(a, ans)

print(ans)
    



Measured memory_bytes: 26840
#include<bits/stdc++.h>
#include <ext/rope>

#define min3(a,b,c)   min(a,min(b,c))
#define max3(a,b,c)   max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))

#define count_one(a) __builtin_popcount(a)  // Returns the number of set bits(1) in a number(a). In long long use __builtin_popcountll(a)
#define parity(i)    __builtin_parity(i)  //even parity 0 and odd parity 1
#define blz(a)       __builtin_clz(a) //Returns the number of leading zeroes in a number(a)
#define btz(a)       __builtin_ctz(a) //Returns the number of trailing zeroes in a number(a)
#define gcd(a,b)     __gcd(a,b)
#define lcm(a,b)     (a*(b/gcd(a,b)))

#define pb   push_back
#define PI   M_PI
#define endl "\n"
#define sc   scanf
#define pf   printf

#define ll  long long
#define ull unsigned long long

#define W(t)            while(t--)
#define rep1(i,n)       for(int i = 0; i < n; i++)
#define rep2(a,b)       for(int i = a; i <= b; i++)
#define rep3(a,b,c)     for(int i = a; i <= b; i+=c)
#define irep(a,b,c)     for(int i = b; i >=a; i-=c)
#define repit(it,type)  for(it = type.begin(); it != type.end(); it++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
using namespace __gnu_cxx;

int main()
{
    IOS
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll n,i,a,b,ans=0,sum=0,q;

    cin>>n;

    ll c[n+1];
    map<ll,ll> mp;
    for(i = 1; i <= n; i++)
    {
        cin>>c[i];
        sum+=c[i];
        mp[c[i]]++;
    }
    cin>>q;

    W(q)
    {
        cin>>a>>b;
        if(mp[a]!=0)
        {
            sum -= mp[a]*a;
            sum+=mp[a]*b;
            mp[b] += mp[a];
            mp[a] = 0;

            //mp[b]++;
        }
        cout<<sum<<endl;
    }

    return 0;
}



Measured memory_bytes: 10040
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int X, Y;
    cin >> X >> Y;
    if(2 * X <= Y && 4 * X >= Y && Y % 2 == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vi> mat(n, vi(n));
	REP(i, m)
	{
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		mat[a][b] = mat[b][a] = c;
	}
	set<set<int>> st;
	queue<set<int>> que;
	REP(i, n)
	{
		set<int> t = { i };
		st.insert(t);
		que.push(t);
	}
	while (que.size())
	{
		set<int> tmp = que.front();
		que.pop();
		REP(i, n)
		{
			if (tmp.count(i)) continue;
			set<int> nx = tmp;
			nx.insert(i);
			if (st.count(nx)) continue;
			bool f = true;
			for (auto j : tmp)
			{
				if (mat[i][j] == 0)
				{
					f = false; break;
				}
			}
			if (f)
			{
				que.push(nx);
				st.insert(nx);
			}
		}
	}
	int ans = 0;
	for (auto i : st)
	{
		if (i.size() == 1) continue;
		int tmp = 0;
		for (auto j : i)
		{
			int res = INF;
			for (auto k : i)
			{
				if (j == k) continue;
				else chmin(res, mat[j][k]);
			}
			tmp += res;
		}
		chmax(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10444
#include<bits/stdc++.h>
#define ri register int
using namespace std;
int n,f[2][100005],k,x,y,fen;
vector<int>g[100005];
void dfs(int u,int fa){
    f[k][u]=f[k][fa]+1;
    for(ri i=0;i<g[u].size();++i)
    if(g[u][i]!=fa)dfs(g[u][i],u);
}int main(){
    scanf("%d",&n);
    for(ri i=1;i<n;++i){
        scanf("%d%d",&x,&y);
        g[x].push_back(y);
        g[y].push_back(x);
    }k=0;dfs(1,0);k=1;dfs(n,0);
    for(ri i=1;i<=n;++i)
    if(f[0][i]<=f[1][i])++fen;
	if(fen>n/2)puts("Fennec");
    else puts("Snuke");
    return 0;
}

Measured memory_bytes: 11264
import math
#=input()
#=int(input())
a,b,h,m=map(int,input().split())
#=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

d = (60 * h + m) * 5.5 % 360
if d <= 180:
    s = d
else:
    s = 360 - d
ans = math.sqrt((a ** 2) + (b ** 2) - 2 * a * b * math.cos(math.radians(s)))
print(ans)

Measured memory_bytes: 9568
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
typedef long long ll; 
using namespace std;
/*
time:
wa:
反省:
考察・解説:
*/
int main() {
    string s; cin >> s;
    //文字の長さ
    int n = s.size();
    //バケット法
    int m[3] = {0};
    for(int i = 0; i < n; i++){
        if(s[i] == 'a') m[0]++;
        else if(s[i] == 'b') m[1]++;
        else m[2]++;
    }
    sort(m, m+3, greater<int>());

    for(int i = 0; i < 2; i++){
        for(int j = i+1; j < 3; j++){
            if(m[i]-m[j] > 1){
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 3724
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ld pi=acos(-1);
const ll inf=(ll)1e9;
const int mod=1000000007;
//const int mod=998244353;

int n,m,k;
const int N=1e6+10;



int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int q,t,u,v,h;
    ll x,a,b,c,d,y,w,z;
    cin >> n;
    vi vv(n);
    for(int i=0; i<n; i++){
        cin >> vv[i];
    }
    sort(all(vv));
    u=0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(vv[i]==vv[j])continue;
            for(int k=j+1; k<n; k++){
                if(vv[j]==vv[k])continue;
                if(vv[i]+vv[j]>vv[k]){
                    u++;
                }
            }
        }
    }
    cout << u << el;
    return 0;
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define Pi 3.1415926535
#define MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}



int solve(){
    int x,y,a,b,c; cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    rep(i,c) cin >> r[i];
    sort(rall(p));
    sort(rall(q));
    
    rep(i,x) r.pb(p[i]);
    rep(i,y) r.pb(q[i]);
    sort(rall(r));

    cout << accumulate(r.begin(),r.begin()+x+y,0ll) << endl;
     

    return 0;
}

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


Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  ll ret = 1e18;
  REP(p,1,101){
    ll sum = 0;
    rep(i,N){
      sum += (v[i]-p)*(ll)(v[i]-p);
    }
    ret = min(ret, sum);
  }
  
  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int parent(int i) {return (i-1) / 2;}
int left(int i) {return (i*2+1);}
int right(int i) {return (i*2+2);}

void update(vector<int>& tree, int s, int i, int v) {
    if(chmin(tree.at(s-1+i),v)){
        int p = parent(s-1+i);
        while(p != 0) {
            tree.at(p) = min(tree.at(left(p)), tree.at(right(p)));
            p = parent(p);
        }
    }
    
}

int seg_find(vector<int>& tree, int s, int x, int y, int p=-1, int l=0, int r=0) {
    if(p == -1) {
        p = 0;
        l = 0;
        r = s;
    }
    // printf("l = %d, r = %d, p = %d\n", l, r, p);
    if(y <= l or r <= x) return INT_MAX;
    else if(x <= l and r <= y) return tree.at(p);
    else {
        int res_l = seg_find(tree, s, x, y, left(p), l, (l+r)/2);
        int res_r = seg_find(tree, s, x, y, right(p), (l+r)/2, r);
        return min(res_l, res_r);
    }
}

vector<int> up(800010, INT_MAX);
vector<int> le(800010, INT_MAX);

int main() {
    int n, q; cin >> n >> q;
    int s = 1;
    while(n > s) s*=2;
    rp(i, 0, n-1) {
        update(up, s, i, n-2);
        update(le, s, i ,n-2);
    }
    ll res = n-2; res *= n-2;
    while(q--) {
        int type, x; cin >> type >> x;
        x-=2;
        if(type == 1) {
            int y = seg_find(up, s, x, n-1);
            // cout << y << endl;
            res -= y;
            update(le, s, y, x);
        } else {
            int y = seg_find(le, s, x, n-1);
            // cout << y << endl;
            res -= y;
            update(up, s, y, x);
        }
    }
    cout << res << endl;
    return 0;
}


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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("fibsubseq.in","r",stdin)
#define write()         freopen("fibsubseq.out","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long int
#define endll           printf("\n")
#define pf              printf
#define pi              acos(-1.0)
#define eps             1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())

bool Check(unsigned int  N,int pos){return (bool)(N & (1LL<<pos));}
ll  Set(unsigned int N,int pos){    return N=N | (1LL<<pos);}
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod  1000000007
#define mod1 1000000009
#define var    int ii,i,j,k,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};

bool chk(ll x,ll pos){return (bool)(x&(1<<pos));}
ll Set(ll x,ll pos){return x=x|(1<<pos);}
ll clr(ll x,ll pos){return x=x&~(1<<pos);}

ll n,m,a[405],dp[405][405];

ll fn(ll l,ll r)
{
    if(l==r)return 0;
    ll &z=dp[l][r];
    if(z!=-1)return z;
    z=LONG_LONG_MAX;
    for(ll i=l;i<r;i++)
    {
        z=min(z,fn(l,i)+fn(i+1,r)+a[r]-a[l-1]);
    }
    return z;
}

int main()
{
    ll var;
    sfl(n);
    mem(dp,-1);
    for(i=1;i<=n;i++)
    {
        sfl(a[i]);
        a[i]+=a[i-1];
    }
    z=fn(1,n);
    cout<<z<<endl;
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

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

  int ans = 1;
  vector<int> ansList;
  while (ans <= A && ans <= B) {
    if (A%ans == 0 && B%ans == 0) {
      ansList.pb(ans);
    }
    ans++;
  }

  ans = ansList[ansList.size()-K];

  cout << ans << endl;

  return 0;
}


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

set<string> S;


int main() {
  int m;
  cin >> m;
  while(m--) {
    S.clear();
    string s;
    cin >> s;
    int N = s.size();
    for(int i = 1; i < N; ++i) {
      string a = s.substr(0,i);
      string b = s.substr(i);
      for(int j = 0; j < 2; ++j, swap(a,b)) {
	for(int k = 0; k < 4; ++k) {
	  string c, d;
	  c = a;
	  d = b;
	  if(k & 1) reverse(c.begin(), c.end());
	  if(k & 2) reverse(d.begin(), d.end());
	  S.insert(c+d);
	  S.insert(d+c);
	}
      }
    }
    cout << S.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 1000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
#define f first
#define s second
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

ll n, m, a, b, c, dp[305][305][305], mm = 1e9+7, ans;
vector<pi> v[305];
bool ok[305][305][305];

void add(ll &a, ll b) {
	b %= mm;
	a += b;
	a %= mm;
}

int main() {
	fastio;
	cin >> n >> m;
	FOR(i, 1, m) {
		cin >> a >> b >> c;
		v[b].pb(pi(a, c));
	}
	memset(ok, true, sizeof ok);
	FOR(i, 0, n) {
		FOR(j, 0, n) {
			FOR(k, 0, n) {
				if ((i == j and i) or (i == k and i) or (j == k and j)) {
					ok[i][j][k] = false;
					continue;
				}
				for(auto it:v[max({i, j, k})]) {
					int cnt = 0;
					if (i >= it.f) cnt++;
					if (j >= it.f) cnt++;
					if (k >= it.f) cnt++;
					if (cnt != it.s) {
						ok[i][j][k] = false;
						break;
					}
				}
			}
		}
	}
	dp[0][0][0]  = 1;
	FOR(i, 0, n) {
		FOR(j, 0, n) {
			FOR(k, 0, n) {
				if (!ok[i][j][k]) continue;
				int ma = max({i, j, k});
				if (ma == n) add(ans, dp[i][j][k]);
				add(dp[ma+1][j][k], dp[i][j][k]);
				add(dp[i][ma+1][k], dp[i][j][k]);
				add(dp[i][j][ma+1], dp[i][j][k]);
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 248064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define tii tuple<int,int,int>
signed main(){
  int N,M;
  cin>>N>>M;
  vector<tii> A(M),ans(M);
  rep(i,0,M){
    int P,Y;
    cin>>P>>Y;
    A[i]=make_tuple(P,Y,i);
    }
  sort(ALL(A));
  int Point,count=1,P,Y,I;
  tie(Point,Y,I)=A[0];
  ans[0]=make_tuple(I,Point,count);
  rep(i,1,M){
    tie(P,Y,I)=A[i];
    if(P==Point){
      count++;
      }
    else{
      Point=P;
      count=1;
      }
    ans[i]=make_tuple(I,P,count);
    }
  sort(ALL(ans));
  rep(i,0,M){
    tie(I,P,Y)=ans[i];
    printf("%06d%06d\n",P,Y);
    }
}


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

typedef long long ll;

const ll MAX = 200005;
const ll MOD = 1000000007;

ll mul(ll a, ll b) { return a%MOD * (b%MOD) % MOD; }
ll modpow(ll b, ll p) { return !p? 1:mul(modpow(b*b%MOD, p/2), p&1? b:1); }
ll inv(ll a) { return modpow(a, MOD-2); }

ll fa[MAX], fi[MAX];

void init() {
    fa[0] = fi[0] = 1;
    for(ll i = 1; i < MAX; i++) {
        fa[i] = fa[i-1]*i % MOD;
        fi[i] = inv(fa[i]);
    } 
}

ll comb(ll n, ll k) { return fa[n] * fi[k] % MOD * fi[n-k] % MOD; }
ll solve(ll r, ll c) { return comb(r+c-2, r-1); }

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    init();
    ll r,c,x,y;
    while(cin >> r >> c >> x >> y) {
        ll ans = 0;
        for(ll j = y+1; j <= c; j++)
            ans = (ans + solve(r-x, j)*solve(x, c-j+1)%MOD) % MOD;
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 3328
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int r,g,b,n;
  cin >> r>>g>>b>>n;
 
  int ans=0;
  rep(i,n/r+1){
    rep(j,(n-r*i)/g+1){
      if((n-r*i-g*j)%b==0) ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (ll i = (ll)(start); i < (ll)(n); ++i)
static const ll INFTY = 1L << 62L;
struct UnionFind
{
    vector<int> r;
    UnionFind(int N)
    {
        r = vector<int>(N, -1); //全員の友達の数を1とする
    }
    int root(int x)
    {
        if (r[x] < 0)
            return x;
        return r[x] = root(r[x]);
    }
    bool unite(int x, int y)
    {
        x = root(x), y = root(y);
        if (x == y)
            return false;
        // if (r[x] > r[y])
        //     swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
    int size(int x)
    {
        return -r[root(x)];
    }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    UnionFind UF(n);
    rep(i, 0, m)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        UF.unite(a, b);
    }
    int ans = 0;
    rep(i, 0, n)
    {
        ans = max(ans, UF.size(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4688
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, L;
	cin >> N >> L;

	Int temp1 = INF;
	Int temp2;
	Int ans = 0;

	Int a;
	for (Int i = 1; i <= N; i++) {
		a = L + i - 1;
		ans += a;
		if (abs(L + i - 1) < temp1) {
			temp1 = abs(L + i - 1);
			temp2 = L + i - 1;
		}
	}

	cout << ans - temp2 << "\n";
}


Measured memory_bytes: 764
import sys
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
input = sys.stdin.buffer.readline
INF = 10**12

N, M, L = map(int, input().split())
G = np.zeros((N, N), dtype=np.int64)
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G[a][b] = c
    G[b][a] = c
Q = int(input())
ST = [list(map(int, input().split())) for _ in range(Q)]

fw = floyd_warshall(G)
path = np.full((N, N), INF, dtype=np.int64)
path[fw <= L] = 1
path_fw = (floyd_warshall(path) + 0.5).astype(np.int64)

ans = []
for s, t in ST:
    s -= 1
    t -= 1
    if path_fw[s][t] >= INF:
        ans.append(-1)
        continue
    ans.append(path_fw[s][t]-1)

print(*ans, sep="\n")


Measured memory_bytes: 36584
#include <iostream>
using namespace std;
int main(){
  string s;cin>>s;
  int a = 0;
  for(int i = 0; s.size() > i; i++){
    if(a==0 && s[i] == 'C'){
      a=1;
    }else if(a==1 && s[i] == 'F'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}
    

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#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)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int ceil(int bunsi, int bunbo) {
	return (bunsi + bunbo - 1) / bunbo;
}

int main() {
	
	int a, b; cin >> a >> b;

	cout << ceil(b - 1, a - 1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

#dist[i][j] = iからjまでの最短距離を求める
def floyd_warshall(dist):
    v = len(dist)
    for k in range(v):
        for i in range(v):
            for j in range(v):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
floyd_warshall(c)
A = [list(map(int, input().split())) for _ in range(H)]
ans = 0

#全ての座標について、-1以外の時はコスト足していく（1⇒1も0なのでOK）
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            ans += c[A[i][j]][1]

print(ans)

Measured memory_bytes: 40284
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define why 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  string s; cin>>s;
  map<char,bool> ma;
  rep(i,3) ma[s[i]]=true; 
  ll cnt=0;
  for(auto j:ma) if(j.S) cnt++;
  if(cnt==2) cout<<"Yes";
  else cout<<"No";
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;


int main(void) {
    Int n, h, w;
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1) << endl;
    return 0;
}


Measured memory_bytes: 3544
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
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;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
  int A,B,M;cin>>A>>B>>M;
  int er=10000000;
  int er1=10000000;
  vector<int> a(A),b(B);
  vector<int> x(M),y(M),c(M);
  REP(i,A){
    cin>>a[i];
    if(a[i]<er){
      er=a[i];
    }
  }
  REP(i,B){
    cin>>b[i];
    if(b[i]<er1){
      er1=b[i];
    }
  }
  REP(i,M){
    cin>>x[i]>>y[i]>>c[i];
  }
  ll cost=10000000;
  ll tmp=0;
  for(int i=0;i<M;i++){
    tmp=a[x[i]-1]+b[y[i]-1]-c[i];
    if(cost>tmp){
      cost=tmp;
    }
  }
  if(er1+er<cost){
    cout<<er1+er<<endl;
  }
  else{
    cout<<cost<<endl;
  }


}


Measured memory_bytes: 2176
#include<stdio.h>
int main()
{
    int a,b,s,h,m;
    scanf("%d%d",&a,&b);
    s=a+b;
    h=a-b;
    m=a*b;
    if(s>h&&s>m)
    {

        printf("%d",s);
    }


    else if(h>s&&h>m)
    {

        printf("%d",h);
    }
    else if(m>h&&m>s)
    {


        printf("%d",m);
    }
    else 
    {
        printf("%d",s);
    }
    return 0;








}


Measured memory_bytes: 256
import Data.Functor( (<$>))
main = do
    inputs <- takeWhile ("0"/=) . words <$> getContents
    let
	almost_answer = zip [1..] inputs
	putStrLn4itp0103b (ix,n)
	  =
	    putStrLn $ "Case "++(show ix)++": "++n

    putStrLn4itp0103b `mapM_` almost_answer



Measured memory_bytes: 5036
#include<cstdio>

int main(){
	int m, t;
	while(scanf("%d", &m) + 1){
		t = 1;
		bool f = 0;
		while(1024 - t){
			if(m & t){
				if(f){
					printf(" ");
				}
				printf("%d", t);
				f = 1;
			}
			t *= 2;
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1028
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
 
public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		String  	stdin = null;
		boolean		first = true;
		char[][]	map   = new char[8][5];

		Arrays.fill(map[2], '=');

		while ((stdin = parseStdin()) != null) {
			int	l = stdin.length();
			int	d = 5-l;

			Arrays.fill(map[0], '*');
			Arrays.fill(map[1], '*');
			Arrays.fill(map[3], '*');
			Arrays.fill(map[4], '*');
			Arrays.fill(map[5], '*');
			Arrays.fill(map[6], '*');
			Arrays.fill(map[7], '*');

			for (int i = 0; i < 5; i++) {
				int	cn = (i-d>=0) ? stdin.codePointAt(i-d)-'0' : 0;
				map[1-cn/5][i] = ' ';
				map[3+cn%5][i] = ' ';
			}

			if (!first) {
				System.out.println("");
			} else {
				first = false;
			}

			for (int i = 0; i < map.length; i++) {
				System.out.println(map[i]);
			}
		}
	}

	private static String parseStdin() {
		String  stdin = null;

		try {
			String  tmp = br.readLine();
			if (tmp != null) {
				if (!tmp.isEmpty()) stdin = tmp;
			}
		}
		catch (IOException e) {}

		return stdin;
	}
}

Measured memory_bytes: 22624
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
p=1
k=0
s=0
for i in range(h):
    c=""
    for j in range(w*(i%2)-i%2,w*(1-i%2)-i%2,(1 if i%2==0 else -1)):
        if i%2==1:
            c=str(p)+" "+c
        else:
            c+=str(p)+" "
        k+=1
        if a[p-1]==k:
            p+=1
            k=0
    else:
        print(c[:-1])

Measured memory_bytes: 3188
A = list(reversed(input()))
B = list(reversed(input()))
C = list(reversed(input()))
 
cards = {'a': A, 'b': B, 'c': C}
 
s = A.pop()
 
while(1):
    try:
        s = cards[s].pop()
    except IndexError:
        print(s.upper())
        exit()

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            int sum = m + f;
            char grade; 
            if(m == -1 && f == -1) break;
            else if(m == -1 || f == -1) grade = 'F';
            else if(sum >= 80) grade = 'A';
            else if(sum < 80 && sum >= 65) grade = 'B';
            else if(sum < 65 && sum >= 50) grade = 'C';
            else if(sum < 50 && sum >= 30) {
                if(r >= 50) grade = 'C';
                else grade = 'D';
            }
            else grade = 'F';
            System.out.println(grade);
        }
    }
}


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

bool isIn(int arr[], int n, int len){
    int flag = 0;
    for(int i = 0; i < len; i++){
        if(arr[i] == n){
            flag = 1;
            break;
        }
    }

    if(flag == 1){
        return true;
    }
    else{
        return false;
    }
}


int main(){

    int x, y, flag = 0, group1[7] = {1, 3, 5, 7, 8, 10, 12}, group2[4] = {4, 6, 9, 11}, group3[1] = {2};

    cin >> x >> y;

    if(isIn(group1, x, 7) && isIn(group1, y, 7)){
        flag = 1;
    }
    else if(isIn(group2, x, 4) && isIn(group2, y, 4)){
        flag = 1;
    }
    if(isIn(group3, x, 1) && isIn(group3, y, 1)){
        flag = 1;
    }

    if(flag == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;

}






Measured memory_bytes: 3668
#include<stdio.h>
int main() {
  int M[1000][1000];
  int i, j, n, m, l, p; 


  scanf("%d", &n);

  for ( i = 0; i <n; i++ ){
    for ( j = 0; j <n; j++ ) {
    	M[i][j] = 0;
    }
  }
  
  
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &m, &l);
    m--;
    for ( j = 0; j < l; j++ ){
      scanf("%d", &p);
      p--;
      M[m][p] = 1;
    }
  }
  
  
  
  for ( i = 0; i < n; i++ ){
    for ( j = 0; j < n; j++ ){
      if ( j >= 1) {
      	printf(" ");
      }
      printf("%d", M[i][j]) ;
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 2080
#include<cstdio>
const long long mod = 998244353;
int a[301][301];
int b[301][301];
int c[301];

long long power(long long a,long long b){
    long long res = 1;
    while(b){
        if(b&1) res = res*a%mod;
        a = a*a%mod;
        b /= 2;
    }
    return res;
}

void swapRow(int i,int j,int m){
    int t = c[i];
    c[i] = c[j];
    c[j] = t;
    for(int k = 1; k <= m; k++){
        int t = b[i][k];
        b[i][k] = b[j][k];
        b[j][k] = t;
    }
}

long long gauss(int n,int m){
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        int find = -1, findBit = -1;
        for(int j = i; j <= n; j++){
            int bit = -1;
            for(int k = m; k >= 1; k--) if(b[j][k]) bit = k;
            if(bit!=-1 && (find==-1 || bit<findBit)){
                find = j;
                findBit = bit;
            }
        }
        //printf("i = %d, find = %d, findBit = %d\n",i,find,findBit);
        if(find==-1){
            //printf("i = %d\n",i);
            int ok = 1;
            for(int j = i; j <= n; j++) if(c[j]==1) ok = 0;
            if(ok) ans = power(2,m-(i-1)); 
            else ans = 0;
            break; 
        }
        else{
            swapRow(i,find,m);
            for(int j = 1; j <= n; j++){
                if(j!=i && b[j][findBit]!=0){
                    for(int k = 1; k <= m; k++) b[j][k] ^= b[i][k];
                    c[j] ^= c[i]; 
                }
            }
        }
        if(i==n) ans = power(2,m-n);
    }
    return ans;
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            scanf("%d",&a[i][j]);
            b[j][i] = a[i][j];
        }
    }
    long long count0 = gauss(m,n);
    //printf("count0 = %lld\n",count0);
    long long count1 = power(2,n)-count0;
    if(count1<0) count1 += mod;
    long long ans = count1*power(2,m-1)%mod;
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

int main(void) {
    int N;
    cin >> N;

    int count = 0;
    for (int i = 1; i <= N; i++) {
        string s = to_string(i);
        if (s.length() % 2 == 1) {
            count++;
        }
    }

    cout << count << endl;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll INF = (ll)1e18;

struct edge {
  ll to, cost;

  edge(ll t, ll c) {
    to = t;
    cost = c;
  }
};

struct graph {
  ll V;
  vector<vector<edge>> G;
  vector<ll> d;

  graph(ll n) { init(n); }

  void init(ll n) {
    V = n;
    G.resize(V);
    d.resize(V);
  }

  void add_edge(ll s, ll t, ll cost) { G[s].push_back(edge(t, cost)); }

  bool Bellman_Ford(ll s) {
    for (int i = 0; i < V; i++) {
      d[i] = INF;
    }
    d[s] = 0;

    for (int i = 0; i < V; i++) {
      for (int v = 0; v < V; v++) {
        for (int k = 0; k < (int)G[v].size(); k++) {
          edge e = G[v][k];
          if (d[v] != INF && d[e.to] > d[v] + e.cost) {
            d[e.to] = d[v] + e.cost;
            if (i == V - 1 && e.to == V - 1) {
              return true;
            }
          }
        }
      }
    }
    return false;
  }
};

ll N, M;
graph G = graph(N);

void solve() {
  bool neg = G.Bellman_Ford(0);
  if (neg) {
    cout << "inf\n";
    return;
  } else {
    cout << -G.d[N - 1] << "\n";
    return;
  }
}

int main() {
  cin >> N >> M;
  G.init(N);
  for (int i = 0; i < M; ++i) {
    ll a, b, c;
    cin >> a >> b >> c;
    G.add_edge(a - 1, b - 1, -c);
  }

  solve();

  return 0;
}


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

int n,z,w;
int a[2020];
int x[2020];
int y[2020];
int main(){
    scanf("%d%d%d",&n,&z,&w);
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
    }

    a[0] = w;
    for(int i=n;i>=1;i--){
        x[i] = y[i] = abs(a[i-1]-a[n]);
        for(int j=i+1;j<=n;j++){
            x[i] = max(x[i], y[j]);
            y[i] = min(y[i], x[j]);
        }
    }
    printf("%d\n", x[1]);
}


Measured memory_bytes: 128