akhauriyash/Code-Regression huggingface dataset:
R=[0,3,6]
N=range(9)
Z=[0]*9

n=input()
while n:
  F=[[" " for _ in Z] for _ in Z]
  M=[map(int,raw_input().split()) for _ in Z]
  M1=[[M[y][x] for y in N] for x in N]
  M2=[M[y][x:x+3]+M[y+1][x:x+3]+M[y+2][x:x+3] for y in R for x in R]
  for y in N:
    A=M[y]
    p0=y/3*3
    for x in N:
      p=p0+x/3
      a=A[x]
      if A.count(a)>1 or M1[x].count(a)>1 or M2[p].count(a)>1: F[y][x]="*"
  for i in N:
    s=zip(F[i],map(str,M[i]))
    print "".join([a+b for a,b in s])
  if n>1: print
  n-=1

Measured memory_bytes: 4296
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,a[100001];
mpii mp;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n){
		cin>>a[i];
		mp[a[i]]++;
		mp[a[i]-1]++;
		mp[a[i]+1]++;
	}
	int ans=0;
	rep(i,200001)
	ans=max(ans,mp[i]);
	cout<<ans;
	re 0;
}


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

#define N 200000
#define M 200000

int n, m, a[N], b[M];
__int64_t k;

int main(void)
{
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int j = 0; j < m; j++){
        cin >> b[j];
    }
    
    int cntMax, cntA=0, cntB=0, judge=0;
    __int64_t time=0;
    for (int i = 0; i < n; i++){
        time+=a[i];
        if(time>k){
            time -= a[i];
            break;
        }
        else{
            cntA = i+1;
        }
    }
    for (int j = 0; j < m; j++){
        time+=b[j];
        if(time>k){
            time -= b[j];
            break;
        }
        else{
            cntB = j+1;
        }
    }

    cntMax=cntA+cntB;
    if(cntA+cntB==n+m){
        cout << cntMax << endl;
        return 0;
    }

    for (int i = cntA-1; i >= 0; i--){
        cntA=i;
        time -= a[i];
        for (int j = cntB; j < m; j++){
            time+=b[j];
            if(time>k){
                time -= b[j];
                break;
            }
            else{
                cntB = j+1;
            }
        }
        cntMax = max(cntMax, cntA+cntB);
        if(cntB==m){
            break;
        }
    }
    
    cout << cntMax << endl;
    return 0;
}


Measured memory_bytes: 5188
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
	//happy coding


	int a,b,c;
	cin>>a>>b>>c;
	cout<<max(0,c - (a-b))<<endl;

	
	return 0;
}
int main(){
	int test = 1;
  	//scanf("%d", &test);
  	while (test--)solve();return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, L;
  cin >> N >> L;
  int sum = 0;
  int dif = L;
  for (int i = 1; i <= N; i++){
  //  cout << L + i - 1 <<" ";
    sum += L + i - 1;
    if( L + i - 1 == 0) dif = 0;
    if( L + N - 1 < 0) dif = L + N - 1;
  }
  //cout << endl << " sum before "<<sum<<endl;

  cout << sum - dif << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>

int main()
{
  int N, K;
  std::cin >> N >> K;

  std::vector<std::vector<int>> ok;
  std::vector<std::vector<int>> ng;
  for (int i=0; i<K*2; ++i) {
    ok.push_back(std::vector<int>(K*2,0));
    ng.push_back(std::vector<int>(K*2,0));
  }
  const int K2 = K*2;
  for (int i=0; i<N; ++i) {
    int x, y;
    std::string s;
    std::cin >> x >> y >> s;
    y %= K2;
    x %= K2;
    int c = (s == "B") ? 0 : 1;
    int bw = (x / K + y / K) % 2;
//    std::cout << "s:" <<s<<" c:"<<c<<" bw:" << bw << std::endl;
    if (c == bw) {
      ok[y][x] += 1;
//      std::cout << "ok("<<y<<","<<x<<")" << std::endl;
    } else {
      ng[y][x] += 1;
//      std::cout << "ng("<<y<<","<<x<<")" << std::endl;
    }
  }
  int m = 0;
  std::vector<int> hoksum(K2,0);
  std::vector<int> hngsum(K2,0);
  for (int y=0; y<K2; ++y) {
    for (int x=0; x<K2; ++x) {
      hoksum[y] += ok[y][x];
      hngsum[y] += ng[y][x];
    }
    m += hoksum[y];
  }
//  std::cout << "hoksum " << std::accumulate(hoksum.begin(), hoksum.end(),0) << std::endl;
//  std::cout << "hngsum " << std::accumulate(hngsum.begin(), hngsum.end(),0) << std::endl;
//  std::cout << "initial m = " << m << std::endl;
  for (int x=0; x<K2; ++x) {
    int tm = std::accumulate(hoksum.begin(), hoksum.end(),0);
    // 縦に一周
    for (int y=0; y<K2; ++y) {
      {
        int diff = hngsum[y] - hoksum[y];
        std::swap(hoksum[y], hngsum[y]);
        tm += diff;
      }
      {
        int yyy = (y + K) % K2;
        int diff = hngsum[yyy] - hoksum[yyy];
        std::swap(hoksum[yyy], hngsum[yyy]);
        tm += diff;
      }
      if (m < tm) {
        m = tm;
      }
//      std::cout << " y:" << y << " tm:" << tm << " m:" << m << std::endl;
    }
//    std::cout << "x:" << x << " m:" << m << std::endl;
    // 横に１ずらす
    for (int y=0; y<K2; ++y) {
      {
        int diff = ng[y][x] - ok[y][x];
        std::swap(ng[y][x], ok[y][x]);
        hoksum[y] += diff;
        hngsum[y] -= diff;
      }
      {
        int xx = (x + K) % K2;
        int diff = ng[y][xx] - ok[y][xx];
        std::swap(ng[y][xx], ok[y][xx]);
        hoksum[y] += diff;
        hngsum[y] -= diff;
      }
    }
  }
  std::cout << m << std::endl;      
}

Measured memory_bytes: 33792
use std::io;

fn main() {
    let mut x = String::new();
    io::stdin().read_line(&mut x).expect("");
    let v: Vec<_> = x.trim().split(' ').collect();
    let a: u32 = v[0].trim().parse().expect("");
    let b: u32 = v[1].trim().parse().expect("");
    println!("{} {}", a * b, 2 * (a + b));
}



Measured memory_bytes: 5024
#include<bits/stdc++.h>
#define     fast                    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define     ll                      long long
#define     pb                      push_back
#define     M                       1000000007
using namespace std;
int main()
{
    ll p,q,x,y,sum=0;
    cin>>p>>q;
    vector<string> v;
    map<int,int>mp,mpt;
    int n = p;
    while(n--)
    {
        string s;
        cin>>s;
        v.pb(s);
    }


    for(ll i=0; i<p; i++)
    {
        int pos =1;
        for(ll j=0; j<q; j++)
        {
            if(v[i][j] == '#') pos = 0;
        }
        if(pos) mp[i]++;
    }


    for(ll i=0; i<q; i++)
    {
        int pos =1;
        for(ll j=0; j<p; j++)
        {
            if(v[j][i]=='#') pos = 0;
        }
        if(pos) mpt[i]++;
    }


    for(ll i=0; i<p; i++)
    {
        int pos=0;
        for(ll j=0; j<q; j++)
        {
            if(mp[i]==0 and mpt[j]==0)
            {
                cout<<v[i][j];
                pos = 1;
            }

        }
        if(pos) cout<<endl;
    }
}


Measured memory_bytes: 3620
use std::io::Read;

const MOD: u64 = 1_000_000_007;

fn mod_pow(r: u64, mut n: u64) -> u64 {
    let mut t = 1;
    let mut s = r;
    while n > 0 {
        if n & 1 == 1 {
            t = t * s % MOD;
        }
        s = s * s % MOD;
        n >>= 1;
    }
    t
}

fn comb(n: u64, k: u64) -> u64 {
    if n < k {
        return 0;
    }
    let k = std::cmp::min(k, n - k);
    let n = n % MOD;
    let mut nu = 1;
    let mut de = 1;
    for i in 0..k {
        nu = nu * (n - i + MOD) % MOD;
        de = de * (i + 1) % MOD;
    }
    nu * mod_pow(de, MOD - 2) % MOD
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    loop {
        let n: u64 = it.next().unwrap().parse().unwrap();
        let d: u64 = it.next().unwrap().parse().unwrap();
        let x: u64 = it.next().unwrap().parse().unwrap();
        if n == 0 {
            break;
        }
        let mut ans = 0;
        let mut sign = 1;
        let mut s = 0;
        let mut k = 0;
        while s <= n {
            ans += sign * comb(d - 1 + n - s, n - s) % MOD * comb(d, k) % MOD;
            sign = sign * (MOD - 1) % MOD;
            s += x;
            k += 1;
        }
        ans %= MOD;
        println!("{}", ans);
    }
}

fn main() {
    run();
}



Measured memory_bytes: 5032
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int n,k,x,y;

//上下左右みる
void rlud(int px,int py,int val,vector<vector<int>> &data,vector<vector<int>> &h){
  //val=h[px][py]
  if (h[px+1][py]>val+data[px][py]){
    h[px+1][py]=val+data[px][py];
    rlud(px+1,py,h[px+1][py],data,h);
  }

  if (h[px-1][py]>val+data[px][py]){
    h[px-1][py]=val+data[px][py];
    rlud(px-1,py,h[px-1][py],data,h);
  }
  
  if (h[px][py+1]>val+data[px][py]){
    h[px][py+1]=val+data[px][py];
    rlud(px,py+1,h[px][py+1],data,h);
  }
  
  if (h[px][py-1]>val+data[px][py]){
    h[px][py-1]=val+data[px][py];
    rlud(px,py-1,h[px][py-1],data,h);
  }

}

int main(){
  ll ans=0;
  cin >> n ;
  int nn=n*n;
  vi p(nn);
  
  
  REP(i,nn){
    cin>>p[i];
    p[i]--;
  }
  
  
  


  vector<vector<int>> h(n+2, vector<int>(n+2,0));//高さ
  vector<vector<int>> data(n+2, vector<int>(n+2,1));//true 壁

  for(int i=0;i<n+2;i++){
    data[0][i]=0;
    data[i][0]=0;
    data[n+1][i]=0;
    data[i][n+1]=0;
  }


  for(int i=0;i<=n/2;i++){
    for(int j=i;j<n-i;j++){
      //縦
      h[i+1][j+1]=i;
      h[n-i][j+1]=i;
      //横
      h[j+1][i+1]=i;
      h[j+1][n-i]=i;
    }
  }

/*
    REP(i,n+2){
      REP(j,n+2){
        cout<<h[i][j];
      }
      cout<<endl;

    }
    return 0;
*/




  for(int i=0;i<nn;i++){
    int px=p[i]%n+1;
    int py=p[i]/n+1;
    //cout<<px<<" "<<py<<" "<<h[px][py]<<endl;
    
    ans+=(ll)(h[px][py]);

  /*
    if (i==0){

      REP(i,6){
        REP(j,6){
          cout<<h[j][i];
        }
        cout<<endl;

      }
    }
    */

    data[px][py]=0;//空に
    int tmp0=min(h[px+1][py]+data[px+1][py],h[px-1][py]+data[px-1][py]);
    int tmp1=min(h[px][py+1]+data[px][py+1],h[px][py-1]+data[px][py-1]);
    h[px][py]=min(tmp0,tmp1);
    //cout<<"!"<<h[px][py]<<endl;
    rlud(px,py,h[px][py],data,h);
    
    /*
    if (i==0){

      REP(i,6){
        REP(j,6){
          cout<<h[j][i];
        }
        cout<<endl;

      }
      return 0;
    }
    */


  }

  cout<<ans<<endl;


  return 0;
}

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

using namespace std;

class Dice {
public:
  int label[6];
  void E(int label[]) {
    int rotate = label[0];
    label[0] = label[3];
    label[3] = label[5];
    label[5] = label[2];
    label[2] = rotate;
  }
  void N(int label[]) {
    int rotate = label[0];
    label[0] = label[1];
    label[1] = label[5];
    label[5] = label[4];
    label[4] = rotate;
  }
  void S(int label[]) {
    int rotate = label[0];
    label[0] = label[4];
    label[4] = label[5];
    label[5] = label[1];
    label[1] = rotate;
  }
  void W(int label[]) {
    int rotate = label[0];
    label[0] = label[2];
    label[2] = label[5];
    label[5] = label[3];
    label[3] = rotate;
  }
};

int main() {
  Dice dice;
  for (int i = 0; i < 6; i++) {
    cin >> dice.label[i];
  }
  string c;
  cin >> c;
  for (int i = 0; i < c.size(); i++) {
    if (c[i] == 'E') {
      dice.E(dice.label);
    } else if (c[i] == 'N') {
      dice.N(dice.label);
    } else if (c[i] == 'S') {
      dice.S(dice.label);
    } else if (c[i] == 'W') {
      dice.W(dice.label);
    }
  }
  cout << dice.label[0] << endl;
  return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }

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

  // vector<int> test;
  // test.push_back(1);
  // test.push_back(2);
  // auto it = upper_bound(test.begin(), test.end(), 1);
  // if(it == test.end()) {
  //   cout << "end" << endl;
  // } else {
  //   cout << test.end() - it << endl;
  // }
  // return 0;

  int N; cin >> N;
  string S; cin >> S;

  vector<int> R;
  vector<int> G;
  vector<int> B;
  rep(i, N) {
    if(S[i] == 'R') {
      R.push_back(i);
    } else if(S[i] == 'G') {
      G.push_back(i);
    } else {
      B.push_back(i);
    }
  }
  int RN = R.size();
  int GN = G.size();
  int BN = B.size();

  if(RN == 0 || GN == 0 || BN == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;

  const char n1[6] = { 'R', 'R', 'G', 'G', 'B', 'B' };
  const char n2[6] = { 'B', 'G', 'B', 'R', 'R', 'G' };
  const char n3[6] = { 'G', 'B', 'R', 'B', 'G', 'R' };

  rep(a, 6) {
    int rn = n1[a] == 'R' ? RN : n1[a] == 'G' ? GN : BN;
    int gn = n2[a] == 'R' ? RN : n2[a] == 'G' ? GN : BN;
    int bn = n3[a] == 'R' ? RN : n3[a] == 'G' ? GN : BN;
    vector<int>& r = n1[a] == 'R' ? R : n1[a] == 'G' ? G : B;
    vector<int>& g = n2[a] == 'R' ? R : n2[a] == 'G' ? G : B;
    vector<int>& b = n3[a] == 'R' ? R : n3[a] == 'G' ? G : B;

    rep(i, rn) {
      rep(j, gn) {
        if(r[i] > g[j]) continue;
        auto it = upper_bound(b.begin(), b.end(), g[j]);
        if(it == b.end()) continue;
        ans += b.end() - it;
        if(binary_search(it, b.end(), g[j] + g[j] - r[i])) --ans;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3648
N, T = map(int, input().split())
c = []
t = []

for i in range(N):
    box = [0,0]
    box[0], box[1] = map(int, input().split())
    c.append(box[0])
    t.append(box[1])

cost = 1000
check = -1
for i in range(N):
    if t[i] <=T and c[i] <= cost:
        check = i
        cost = c[i]
        #print(i)
        #print(cost)

if check == -1:
    print('TLE')
else:
    print(cost)

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

int main()
{
	ll x = 100, br = 0;
	ll n;
	cin >> n;
	while(1){
		x += x*0.01;
		br++;
		if(x >= n){
			cout << br;
			return 0;
		}
	}

    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl

u64 f(u64 n, u64 s) {
  u64 a = n / 1000;
  u64 b = (n / 100) % 10;
  u64 c = (n / 10) % 10;
  u64 d = n % 10;
  if(s & 4 != 0) b = -b;
  if(s & 2 != 0) c = -c;
  if(s & 1 != 0) d = -d;
  return a + b + c + d;
}

void g(u64 n, u64 s) {
  u64 a = n / 1000;
  u64 b = (n / 100) % 10;
  u64 c = (n / 10) % 10;
  u64 d = n % 10;
  
  string op1 = "+";
  string op2 = "+";
  string op3 = "+";
  if(s & 4 != 0) op1 = "-";
  if(s & 2 != 0) op2 = "-";
  if(s & 1 != 0) op3 = "-";
  cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
}

int main(int argc, const char* argv[]) {
  i64 s;
  cin >> s;
  
  i64 ss[4] = { s / 1000, 
                (s / 100) % 10,
                (s / 10) % 10,
                s % 10
              };
  
  rep(i, 8) {
    bool op1 = ((i & 4) != 0);
    bool op2 = ((i & 2) != 0);
    bool op3 = ((i & 1) != 0);
    
    i64 a = ss[0];
    i64 b = op1 ? ss[1] : -ss[1];
    i64 c = op2 ? ss[2] : -ss[2];
    i64 d = op3 ? ss[3] : -ss[3];
    
    if(a+b+c+d==7) {
      cout << a << (op1 ? "+" : "-") << ss[1] << (op2 ? "+" : "-") << ss[2] << (op3 ? "+" : "-") << ss[3] << "=7" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        long[] a = sc.nextLongArray(n);
        long[] la = new long[n];
        la[0] = a[0];
        long[] ra = new long[n];
        ra[n-1] = a[n-1];
        for(int i = 1; i < n; i++){
            la[i] = gcd(la[i-1],a[i]);
        }
        for(int i = n-2; i >= 0; i--){
            ra[i] = gcd(ra[i+1],a[i]);
        }
        long ans = 0;
        for(int i = 0; i < n; i++){
            if(i == 0){
                ans = Math.max(ans,ra[i+1]);
            }else if(i == n-1){
                ans = Math.max(ans,la[i-1]);
            }else{
                ans = Math.max(ans,gcd(la[i-1],ra[i+1]));
            }
        }
        System.out.println(ans);
    }
    private static long gcd(long a, long b){
        while (b > 0){
            long temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


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


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

    int N,D;
    cin >> N >> D;
    int X[N][D];
    rep(i,N){
        rep(j,D){
            cin >> X[i][j];
        }
    }
    int ans=0;
    rep(i,N-1){
        for(int j=i+1;j<N;j++){
            int sum=0;
            rep(k,D){
                sum += pow((X[i][k]-X[j][k]),2);
            }
            int p=pow(sum,0.5);
            if(sum == p*p) ans++;
        }
        
    }
    cout << ans << endl;

}


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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n, m;
queue<int> b[300];
int cnt[300];

int main() {
    cin >> n >> m;
    rep(i,n) {
        int tmp;
        rep(j,m) {
            cin >> tmp;
            b[i].push(tmp-1);
        }
        cnt[b[i].front()]++;
    } 
    int ans = n;
    rep(i,m-1) {
        int max_ind = 0, max_v = -1;
        rep(j,m) {
            if (cnt[j] > max_v) {
                max_v = cnt[j];
                max_ind = j;
            }
        }
        cnt[max_ind] = -1;
        ans = min(ans, max_v);
        rep(j,n) {
            if (cnt[b[j].front()] < 0) {
                while (cnt[b[j].front()] < 0) b[j].pop();
                cnt[b[j].front()]++;
            }
        }
    }
    cout << ans << endl;
}
































Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1e18;

int main() {
  ll a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a>k) {
    cout << ":(" << endl;
  }
  else {
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


int main() {
	ll a, b;
	cin >> a >> b;
	if (a <= 9 and b <= 9)cout << a * b << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 1000000005
#define MOD 1000000007 
#define N 150005
#define M 1000003
#define LOG 20
#define KOK 250
#define EPS 0.0000001
using namespace std;

int n,m,cur,lst;
int last[1<<18];
ii a[1<<18];
vector<int> has[1<<18];

int msb(int val,int& req) {

	for(int i=n-1;i>=0;i--) {

		if((val>>i)&1) return i;

		req|=(1<<i);

	}

}

void dfs(int mask) {

	if(sz(has[mask])==2 || last[mask]==lst) return ;

	has[mask].pb(cur);
	last[mask]=lst;

	for(int i=0;i<n;i++) {

		if((mask>>i)&1) {

			dfs(mask^(1<<i));

		}

	}

}

int main() {

	scanf("%d",&n);

	m=1<<n;

	for(int i=0;i<m;i++) {
	
		scanf("%d",&a[i].st);

		a[i].nd=i^(m-1);
	
	}

	sort(a,a+m,greater<ii>());

	for(int i=0;i<m;i++) {

		cur=a[i].st;
		lst=i+1;

		dfs(a[i].nd);

	}

	for(int i=1;i<m;i++) {

		int req=0;
		int ans=0;

		for(int big=msb(i,req);big>=0;big--) {

			req^=(1<<big);

			if((i>>big)&1) {

				if(sz(has[req])==2) umax(ans,has[req][0]+has[req][1]);

				req^=(1<<big);

			}

		}

		if(sz(has[req])==2) umax(ans,has[req][0]+has[req][1]);

		printf("%d\n",ans);

	}

}

Measured memory_bytes: 20480
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>

int main(){
  string s;
  cin >> s;
  
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '1')
      cout << '9';
    else
      cout << '1';
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	int a[5];

	rep(i, 5) {
		cin >> a[i];
	
	}
	rep(i, 5) {
		if (a[i] == 0)
			cout << i+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int n,d,x,A[200],B[200];
  cin >> n >> d >> x;
  for(int i = 0; i < n; i++) {
    cin >> A[i];
    B[i] = 1;
  }
  
  int sum = x;
  for(int i = 0; i < n; i++) {
    while(B[i] <= d) {
      B[i] += A[i];
      sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;

int main()
{
    pair<int, int> A, B;
    cin >> A.first >> A.second >> B.first >> B.second;
    if (A.first == B.first)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 1 << endl;
    }

    return 0;
}

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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<long long> H(N);
  long long total = 0;
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  sort(H.begin(), H.end(),greater<int>());
  
  for (int i = 0; i < N; i++) {
    if (i >= K) {
      total += H[i];
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 1792
import itertools
def MI(): return map(int, input().split())
H,W,K=MI()
Map=[input() for _ in range(H)]
ans=0
for gyou in itertools.product([0,1],repeat=H):
  for retsu in itertools.product([0,1],repeat=W):
    count=0
    for i in range(H):
      for j in range(W):
        if gyou[i] and retsu[j]:
          if Map[i][j]=='#':
            count+=1
    if count==K:
      ans+=1
print(ans)

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

#define S (n * m)
#define T (n * m + 1)
#define E(i, j) ((i) * m + (j))
#define P(e) {(e) / m, (e) % m}

typedef mf_graph<int> G;

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

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

  G g(n * m + 2); // graph-size + S + T
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] != '#') {
        if ((i + j) % 2 == 0) {
          g.add_edge(S, E(i, j), 1);
          if ((i     > 0) && (s[i - 1][j] != '#')) { g.add_edge(E(i, j), E(i - 1, j), 1); }
          if ((i + 1 < n) && (s[i + 1][j] != '#')) { g.add_edge(E(i, j), E(i + 1, j), 1); }
          if ((j     > 0) && (s[i][j - 1] != '#')) { g.add_edge(E(i, j), E(i, j - 1), 1); }
          if ((j + 1 < m) && (s[i][j + 1] != '#')) { g.add_edge(E(i, j), E(i, j + 1), 1); }
        } else {
          g.add_edge(E(i, j), T, 1);
        }
      }
    }
  }
  cout << g.flow(S, T) << endl;

  vector<G::edge> e = g.edges();
  for (unsigned long i = 0UL; i < e.size(); ++i) {
    if ((e[i].flow > 0) && (e[i].from != S) && (e[i].to != T)) {
      pair<int, int> f = P(e[i].from), t = P(e[i].to);
      if (f > t) { swap(f, t); }
      if (f.first + 1 == t.first) {
        s[f.first][f.second] = 'v';
        s[t.first][t.second] = '^';
      } else {
        s[f.first][f.second] = '>';
        s[t.first][t.second] = '<';
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    cout << s[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 5436
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define ll long long



void solve(){
    
}

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

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

struct dice
{
    int x[6];
    void roll(char c)
    {
        int a;
        if (c == 'N')
        {
            a = x[0];
            x[0] = x[1];
            x[1] = x[5];
            x[5] = x[4];
            x[4] = a;
        }
        if (c == 'S')
        {
            a = x[0];
            x[0] = x[4];
            x[4] = x[5];
            x[5] = x[1];
            x[1] = a;
        }
        if (c == 'E')
        {
            a = x[0];
            x[0] = x[3];
            x[3] = x[5];
            x[5] = x[2];
            x[2] = a;
        }
        if (c == 'W')
        {
            a = x[0];
            x[0] = x[2];
            x[2] = x[5];
            x[5] = x[3];
            x[3] = a;
        }
    }
    int top(void)
    {
        return x[0];
    }
};

int main()
{
    int n;
    cin >> n;
    vector<dice> d(n);
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < 6; ++j)
        {
            cin >> d[i].x[j];
        }
    }
    bool ok = true;
    for (int k = 0; k < n - 1; ++k)
    {
        for (int l = k + 1; l < n; ++l)
        {
            string s = "ENESNESNESNESENESNESNESNESENESNESNESNESENESNESNESNESNNESNESNESNESNNESNESNESNESNNESNESNESNESNNESNESNESNES";
            int sl = s.size();
            bool dif = true;
            for (int i = 0; i < sl; ++i)
            {
                d[k].roll(s[i]);
                bool ng = false;
                for (int j = 0; j < 6; ++j)
                {
                    if (d[k].x[j] != d[l].x[j])
                        ng = true;
                }
                if (!ng)
                    dif = false;
            }
            if (!dif)
                ok = false;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3184
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def isOk(x):
    prev = x%10
    x = x//10
    while x > 0:
        y = x%10
        if abs(y - prev) > 1:
            return False
    
    return True


k = int(input())

# if k <= 10:
#     print(k)
#     exit()

count = 0

def dfs(X,n):
    global count

    # log(X, n)

    if n == 0:
        count += 1
        if count == k:
            print("".join(map(str,X)))
            exit()
        # else:
            # log(count, "".join(map(str,X)))
        return
    
    if len(X) == 0:
        for y in range(1,10):
            dfs([y], n-1)
        return

    last = X[-1]
    for y in range(max(0,last-1), min(9,last+1)+1):
        dfs(X + [y], n-1)


dfs([], 1)
dfs([], 2)
dfs([], 3)
dfs([], 4)
dfs([], 5)
dfs([], 6)
dfs([], 7)
dfs([], 8)
dfs([], 9)
dfs([], 10)


Measured memory_bytes: 58712
#include<iostream>
int main(){
    int a,b,c,d,e,f,h,i;
    h=0;
    std::cin >> a >> b >> c >> d >> e >> f;
    i=a+b*5+c*10+d*50+e*100+f*500;
    if(i>=1000){
        h=1;
    }
    std::cout << h << std::endl;
    return 0;
}

Measured memory_bytes: 1160
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    D_arr = []
    for i in range(N):
        _ = list(map(int, _in[i+1].split(' ')))  # type:list(int)
        D_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = 0
    cnt = 0
    for a, b in D_arr:
        if a == b:
            cnt += 1
        else:
            cnt = 0
        if cnt == 3:
            ans = 'Yes'
            break
    else:
        ans = 'No'
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62088
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;

int main()
{
	int i=0,j;
	char inch[1200];

while(1){

	scanf("%c",&inch[i]);
	
if( inch[i] == '\n' ) break;

	if( isupper(inch[i]) ) inch[i] = tolower(inch[i]);
	else if( islower(inch[i]) ) inch[i] = toupper(inch[i]);
	else ; 	
	i++;	
		}

for(j=0;j < i; j++){
		
	cout <<inch[j];
	}
cout <<"\n";
return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int X, Y;
	cin >> X >> Y;
	int ans = 0;
	if (X <= 3) ans += 4 - X;
	if (Y <= 3) ans += 4 - Y;
	if (X == 1 && Y == 1) ans += 4;
	
	cout << ans * 100000 << endl;
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    string t("CF");
    int j = 0;
    rep(i, s.size()) {
        if (s.at(i) == t.at(j)) {
            j++;
            if (j < t.size())
                continue;
            puts("Yes");
            return 0;
        }
    }
    puts("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    cin, n;
    ll ans = 0;
    ans += n / 500 * 1000;
    n %= 500;
    ans += n / 5 * 5;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(void) {
    string b, c;
    cin >> b;
    if (b == "A") {
        c = "T";
    } else if (b == "T") {
        c = "A";
    } else if (b == "C") {
        c = "G";
    } else if (b == "G") {
        c = "C";
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

//_____________________________________________________________
const int MAX_NODE=101;

vvi G = vv(MAX_NODE, 0, 0, int);
void dfs(int from, int now){
  //std::cout << now << '\n';
  for(int i=0;i<G[now].size();i++) {
    if(from == G[now][i]) continue;
    dfs(now, G[now][i]);
  }
}
void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex) {
    if (dist > maxDist) maxDist = dist, maxVertex = current;
    for (auto to : G[current]) {
        if (to == from) continue;
        treeDFS(current, to, dist + 1, maxDist, maxVertex);
    }
}
vll getTreeDiameter(int s) {
    int start = s, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
    start = end, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
    //printf("start: %d, end: %d, diameter: %d\n", start, end, maxDist);
    return vll{maxDist, start, end};
}
vll pre(100001, -1);
void calc(ll now, ll from){
  pre[now] = from;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    calc(G[now][i], now);
  }
}
//_____________________________________________________________

vll max_child(101, 1);
void DFS(ll now, ll from, ll d){
  max_child[d] = max(max_child[d], (ll)G[now].size() - 1);
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==from) continue;
    DFS(G[now][i], now, d+1);
  }
}
int main(int argc, char const *argv[]) {
  ll a, b, n;std::cin >> n;
  re(i, n-1){
    std::cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vll t = getTreeDiameter(1);
  calc(t[1], -1);
  ll c = t[2];
  for(int i=0;i<t[0]/2;i++) c = pre[c];
  if(t[0]%2==0){
    ll ans = 1000000000000000000;
    //case c
    DFS(c, -1, 0);
    ll tmp = 1;
    for(int i=1;i<101;i++) tmp*=max_child[i];
    tmp*=max_child[0]+1;
    ans = min(ans, tmp);

    //case c-x
    for(int i=0;i<G[c].size();i++){
      for(int j=0;j<101;j++) max_child[j] = 1;
      ll p = G[c][i];
      DFS(c, p, 0);
      DFS(p, c, 0);
      tmp = 1;
      for(int j=0;j<101;j++) tmp*=max_child[j];
      ans = min(ans, tmp*2);
    }
    std::cout << t[0]/2+1 << " " << ans << '\n';
  }else{
    ll d = pre[c];
    DFS(c, d, 0);
    DFS(d, c, 0);
    ll ans = 1;
    for(int i=0;i<101;i++) ans *= max_child[i];
    std::cout << t[0]/2+1 << " " << ans*2 << '\n';
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, w;
    cin >> n >> w;
    vector<ll> best(w+1,-1);
    best[0] =0;
    rep(i,0,n) {
        int ww, v;
        cin >> ww >> v;
        for(int j=w; j>=ww;--j) {
            if(best[j-ww]!=-1) best[j] =max(best[j],best[j-ww]+v);
        }
    }
    ll b=0;
    rep(i,0,w+1) b=max(b,best[i]);
    cout<<b<<"\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b);
#define chmin(a, b) a = min(a, b);
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

const int MX = 200000;
vector<tuple<char, int, int, int>> ANS;

struct A {
    static int nxt;
    int r;
    A(int i):r(i){}
    A(): r(nxt++){}
    tuple<char, int, int> operator+(A z) {
        return {'+', r, z.r};
    }
    tuple<char, int, int> operator+(int z) {
        return {'+', r, z};
    }
    tuple<char, int, int> operator<(A z) {
        return {'<', r, z.r};
    }
    tuple<char, int, int> operator<(int z) {
        return {'<', r, z};
    }

    void operator=(int z) {ANS.emplace_back('+', z, 0, r);}
    void operator=(A z) {ANS.emplace_back('+', z.r, 0, r);}
    void operator+=(int z) {ANS.emplace_back('+', r, z, r);}
    void operator+=(A z) {ANS.emplace_back('+', r, z.r, r);}

    void operator=(tuple<char, int, int> t) {
        char c;
        int x, y;
        tie(c, x, y) = t;
        ANS.emplace_back(c, x, y, r);
    }
};
int A::nxt = 0;
tuple<char, int, int> operator+(int a, A b) {
	return {'+', a, b.r};
}
tuple<char, int, int> operator<(int a, A b) {
	return {'<', a, b.r};
}

vector<A> d(3);
vector<A> p(30);
A a, b, t, rv;
void select(A& x, A& b) {
    rv = 0;
    for(int i = 29; i >= 0; i--) {
        t = rv + p[i];
        t = t < x;
        t = t + b;
        t = 1 < t;
        rep(_, i) t += t;
        rv += t;
    }
    t = rv < x;
    t = t + b;
    t = 1 < t;
    rv += t;
}

int main() {
    a = d[0] + d[2];
    b = d[1] + d[2];
    d[0] = a < a;
    t = a + b;
    d[1] = 0 < t;
    p[0] = 1;
    rep(i, 29) p[i+1] = p[i] + p[i];
    A t2, acc, ans;
    for(int i = 29; i >= 0; i--) {
        t2 = acc + p[i];
        t2 = t2 < a;
        select(p[i], t2);
        acc += rv;
        select(b, t2);
        rep(_, i) rv += rv;
        ans += rv;
    }
    t2 = acc < a;
    select(b, t2);
    ans += rv;
    d[2] = ans;
    cout << ANS.size() << endl;
    for(auto t: ANS) {
        char c;
        int x, y, z;
        tie(c, x, y, z) = t;
        printf("%c %d %d %d\n", c, x, y, z);
    }
}

Measured memory_bytes: 4104
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x)      x.begin(), x.end()
#define rep(i,n)    for (i64 i = 0; i < (n); ++i)
#define reps(i,s,t) for (i64 i = (s); i <= (t); ++i)
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? (a=b,1) : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? (a=b,1) : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

constexpr double EPS = 1e-10;
signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    A *= 100;
    B *= 100;

    long double noudo = 0;
    int ansM = A;
    int ansSugar = 0;

    rep(a, 31) {
        rep(b, 31) {
            if (A * a + B * b > F) break;
            rep(c, 3001) {
                if (A*a + B*b + c*C > F) break;
                rep(d, 3001) {
                    const int water = A * a + B * b;
                    const int limit = (water / 100) * E;
                    const int sugar = c*C + d*D;
                    const int sum = water + sugar;

                    if (sum > F) continue;
                    if (water <= 0) continue;
                    if (sugar > limit) continue;

                    const long double tmp = (long double)(100.0 * sugar) / (long double)(sum);

                    if (tmp - EPS > noudo) {
                        noudo = tmp;
                        ansM = sum;
                        ansSugar = sugar;
                    }

                }
            }
        }
    }

    cout << ansM << ' ' << ansSugar << endl;

    return 0;
}



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

ll mod = 998244353;

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

    ll n;
    cin>>n;
    array<ll,2> a[n];
    ll d[n+1];
    for(int i=0;i<n;i++){
        ll x,f;
        cin>>x>>f;
        a[i] = {x,f};
        d[i]=x;
    }
    ll INF = 1e15;
    d[n] = INF;
    sort(a,a+n);
    sort(d,d+n+1);
    ll ma[n+1]={},cnt[n+1]={};
    ma[n]=n, cnt[n]=1;
    stack<ll> st;
    for(int i=n-1;i>=0;i--){
        ll r = lower_bound(d,d+n,a[i][0]+a[i][1]) - d;
        if(r == i+1){
            st.push(i+1);
            cnt[i] = cnt[i+1]*2;
        }
        else{
            while(!st.empty() && st.top() < r)st.pop();
            r = st.top();
            cnt[i] = cnt[r]+cnt[i+1];
        }
        cnt[i] %= mod;
        ma[i] = r;
    }
    cout << cnt[0] << endl;
}

Measured memory_bytes: 8960
# -*- coding: utf-8 -*-
 
N, A, B = map(int, input().split(" "))
s = 0

for i in range(1, N + 1):
  i = str(i)
  p = 0
  for j in i:
    p = p + int(j)
  if A <= p <= B:
    s = s + int(i)
    
print(s)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct BiMatch{
  int L,R;
  vector<vector<int> > G;
  vector<int> match,level;
  
  BiMatch(){}
  BiMatch(int L,int R):L(L),R(R),G(L+R),match(L+R,-1),level(L){}
  
  void add_edge(int u,int v){
    G[u].push_back(v+L);
    G[v+L].push_back(u);
  }
  
  bool bfs(){
    queue<int> q;
    for(int i=0;i<L;i++){
      level[i]=-1;
      if(match[i]<0){
	level[i]=0;
	q.emplace(i);
      }
    }
    while(!q.empty()){
      int v=q.front();q.pop();
      for(int u:G[v]){
	int w=match[u];
	if(w<0) return true;
	if(level[w]<0){
	  level[w]=level[v]+1;
	  q.emplace(w);
	}
      }
    }
    return false;
  }

  bool dfs(int v){
    for(int u:G[v]){
      int w=match[u];
      if(w<0||(level[w]>level[v]&&dfs(w))){
	match[v]=u;
	match[u]=v;
	return true;
      }
    }
    return false;
  }
  
  int build(){
    int res=0;
    while(bfs())
      for(int i=0;i<L;i++)
	if(match[i]<0&&dfs(i))
	  res++;
    return res;
  }
  
};
//END CUT HERE

signed main(){
  int X,Y,E;
  cin>>X>>Y>>E;
  BiMatch bm(X,Y);
  for(int i=0;i<E;i++){
    int x,y;
    cin>>x>>y;
    bm.add_edge(x,y);
  }
  cout<<bm.build()<<endl;
  return 0;
}
/*
  verified on 2017/10/29
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_7_A&lang=jp
*/



Measured memory_bytes: 3304
# input
N = int(input())
Ps = list(map(float, input().split()))

# probs[i][k] : コインiまでを投げて表がk枚出る確率
probs = [[0 for _ in range(N+1)] for _ in range(N)]

probs[0][1] = Ps[0]
probs[0][0] = 1 - Ps[0]
# for i in range(2, N+1):
#   probs[0][i] = 0

for i in range(1, N):
  for k in range(0, N+1):
    if k == 0:
      probs[i][k] = probs[i-1][k]*(1-Ps[i])
    else:
      probs[i][k] = probs[i-1][k-1]*Ps[i] + probs[i-1][k]*(1-Ps[i])

# print(probs)

sum_all = sum(probs[N-1])
sum_ok = 0

start = int(N/2) + 1
for i in range(start, N+1):
  sum_ok += probs[N-1][i]

print(sum_ok / sum_all)

Measured memory_bytes: 259848
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<int64_t> A(N);
    rep(n,0,N) cin>>A.at(n);

    vector<int64_t> Sum(N+1,0);
    rep(n,1,N+1) Sum.at(n)=Sum.at(n-1)+A.at(n-1);

    int64_t ans=INT64_MAX;
    rep(n,1,N){
        int64_t x,y;
        x=Sum.at(n);
        y=Sum.at(N)-Sum.at(n);
        ans=min(ans,abs(x-y));
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  int A, B;
  cin >> A >> B;
  if (A > 9 || B > 9) {
    cout << -1 << endl;
  } else {
    cout << A * B << endl;
  }
  return 0;
}

Measured memory_bytes: 3600