akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 INT;
struct cww{cww(){
    ios::sync_with_stdio(false);cin.tie(0);
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
template <typename T>inline void chmin(T &l,T r){l=min(l,r);}
template <typename T>inline void chmax(T &l,T r){l=max(l,r);}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef vector<INT> V;
typedef vector<V> VV;

INT comb[1145140][11];
const INT INF=1e15;
struct latte{
    latte(){
        for(int i=0;i<1145140;i++)comb[i][0]=1;
        for(int i=1;i<1145140;i++)
            for(int j=1;j<=min(i,10);j++)
                comb[i][j]=min(INF,comb[i-1][j]+comb[i-1][j-1]);
    }
}malta;

LL f(V a,V b,bool eq){
    int m=b.size();
    LL cnt=0;
    int ub=114514;
    while(a>b){
        cnt++;
        FOR(i,1,m){
            b[i]+=b[i-1];
            chmin(b[i],INF);
            if(b[i]==INF)chmin(ub,i);
        }
        if(ub<10)break;
    }
    if(eq){
        if(a==b)return cnt+1;
        if(a<b)return cnt;
    }
    else{
        if(a==b)return -cnt+1;
        if(a<b)return -cnt+1;
    }
    LL k=(a[1]-b[1]+b[0]-1)/b[0];
    //if(k<0)return 0;
    if(b[0]*k+b[1]>a[1]){
        if(eq)
            return cnt+k;
        else{
            return -cnt-k+1;
        }
    }
    if(k==0){
        if(eq){
            return cnt+k+1;
        }
        else{
            return -cnt-k;
        }
    }
   
    
    if(k>=1000000){
        if(eq)
            return cnt+k;
        else return -cnt-k+1;
    }
    for(int id=2;id<b.size();id++){
        INT sum=b[id];
        if(sum>a[id]){
            if(eq)
                return cnt+k;
            else
                return -cnt-k+1;
        }
        REP(i,id){
            sum+=min(INF,b[i]*comb[k+id-1][id-i]);
        }
        if(sum>a[id]){
            if(eq)
                return cnt+k;
            else
                return -cnt-k+1;
        }
        if(sum<a[id]){
            if(eq)return cnt+k+1;
            else return -cnt-k;
        }
    }
    if(eq){
        return cnt+k+1;
    }
    else{
        return -cnt-k+1;
    }
}


int main(){
    int N,M;
    cin>>N>>M;
    VV A(N,V(M));
    REP(i,N)REP(j,M){
        int a;
        cin>>a;
        A[i][j]=a;
    }
    if(M==1){
        int ans=0;
        REP(i,N-1)if(A[i]>=A[i+1])ans=-1;
        cout<<ans<<endl;
        return 0;
    }
    vector<LL> B(N-1,0);
    REP(i,N-1){
        if(A[i]==A[i+1])B[i]=1;
        else if(A[i]>A[i+1]){
            if(A[i][0]>A[i+1][0]){
                cout<<-1<<endl;
                return 0;
            }
            B[i]=f(A[i],A[i+1],true);
        }
        else {
            if(A[i][0]<A[i+1][0])B[i]=-INF;
            else 
                B[i]=f(A[i+1],A[i],false);
        }
        //cout<<i<<" "<<B[i]<<endl;
    }
    LL res=0,now=0;
    REP(i,N-1){
        now=max(0ll,now+B[i]);
        res+=now;
    }
    cout<<res<<endl;
    return 0;
}


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

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

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

string s;
i64 k, ans = 0;

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif

	cin >> s;
    i64 len = i64(s.size());
    i64 n1 = -1, n2 = -1, n3 = -1, p2 = -1, p3 = -1;
    n1 = s[0] - '0';
    for (int i = 1; i < len; ++i) {
        if (s[i] != '0') {
            n2 = s[i] - '0';
            p2 = i + 1;
            break;
        }
    }
    if (p2 != -1) {
        for (int i = p2; i < len; ++i) {
            if (s[i] != '0') {
                n3 = s[i] - '0';
                p3 = i + 1;
                break;
            }
        }
    }
	cin >> k;
	if (k > len) {
        cout << 0 << '\n';
        return 0;
	}
	i64 tot = 0;
	i64 no = 0;
	if (k == 1) tot = len * 9;
	if (k == 2) {
        tot = len * (len - 1) / 2 * 9 * 9;
	}
	if (k == 3) {
       tot = len * (len - 1) * (len - 2) / 6 * 9 * 9 * 9;
	}
	if (k == 1) {
        no += (9 - n1);
	}
	if (k == 2) {
        no += (9 - n1) * (len - 1) * 9;
        if (n2 == -1) {
            no += (len - 1) * 9; // ok
        } else {
            no += (p2 - 2) * 9;//ok
            no += (9 - n2); // ok
        }
	}
	if (k == 3) {
        no += (9 - n1) * (len - 1) * (len - 2) / 2 * 9 * 9;
        if (n3 == -1) {
            if (n2 == -1) no += (len - 1) * (len - 2) / 2 * 9 * 9; // !!!!!fuck!!!
            else {
                no += ((p2 - 2) * 9 + (9 - n2 + 1)) * (len - p2) * 9;
                if (p2 - 2 > 0) {
                    no += (p2 - 2) * (p2 - 3) / 2 * 9 * 9;
                    no += (9 - n2 + 1) * (p2 - 2) * 9;
                }
            }
        } else {
            no += ((p2 - 2) * 9 + (9 - n2)) * ((len - p2) * 9) + ((p3 - p2 - 1) * 9 + (9 - n3));
        }
	}
	cout << (tot - no) << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = []
for i in a:
  if int(i/2) == i/2:
    b.append(i)
for i in b:
  if (i%3 != 0) and (i%5 != 0):
    print('DENIED')
    exit()
print('APPROVED')

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
	int S,h,m,s,ans1,ans2,ans3;
	cin>>S;
	ans1=S/3600;
	ans2=S%3600/60;
	ans3=S%3600%60;
	cout<<ans1<<":"<<ans2<<":"<<ans3<<endl;


return 0;
}

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

int main()
{
  int ans = 700;
  string S;
  cin >> S;
  
  if (S.at(0) == 'o') ans += 100;
  if (S.at(1) == 'o') ans += 100;
  if (S.at(2) == 'o') ans += 100;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 100

int main(void)
{
	int cs = 0, cp = 0, c;
	int i, j, k;
	int chars[(SIZE + 1) * 2] = {0}, charp[SIZE + 1] = {0};

	for (i = 0; ; i++){
		scanf("%c", &chars[i]);
		if (chars[i] == '\n') break;
		cs++;
	}
	for (i = 0; i < cs; i++) 
		chars[i + cs] = chars[i];

	for (i = 0; ; i++) {
		scanf("%c", &charp[i]);
		if (charp[i] == '\n') break;
		cp++;
	}

	for (i = 0; i < cp; i++) {
		for (j = 0; j < cs; j++) {
			c = 0;
			if (chars[j] == charp[i])
				for (k = 0; k < cp; k++) 
					if (chars[j + k] == charp[i + k]) {
						c++;
						if (c == cp) {
							puts("Yes");
							return 0;
						}
					}
		}
	}
	puts("No");
	return 0;
}

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back
#define div azazaz

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 200111, mod = 998244353;

string s;
int n;
vector<int> div[max_n];
ll p2[max_n];

void init() {
    for (int i = 1; i < max_n; ++i) {
        for (int j = i; j < max_n; j += i) {
            div[j].PB(i);
        }
    }
    p2[0] = 1;
    for (int i = 1; i < max_n; ++i) {
        p2[i] = (p2[i - 1] * 2) % mod;
    }
}

vector<int> alen;

ll dp[max_n];

int cntless(string s) {
    reverse(s.begin(), s.end());
    if (s[0] == '0') {
        dp[0] = 0;
    } else {
        dp[0] = 1;
    }
    for (int i = 1; i < s.size(); ++i) {
        if (s[i] == '0') {
            dp[i] = dp[i - 1];
        } else {
            dp[i] = (dp[i - 1] + p2[i]) % mod;
        }
    }
    return dp[s.size() - 1];
}
bool check(string ss) {
    string sr;
    for (int i = 0; i < ss.size(); ++i) {
        if (ss[i] == '0') {
            sr += '1';
        } else {
            sr += '0';
        }
    }
    string need = "";
    bool norm = 1;
    while (need.size() < s.size()) {
        if (norm) {
            need += ss;
        } else {
            need += sr;
        }
        norm = !norm;
    }
    return need <= s;
}

ll d[max_n];

int main()
{
    //freopen("input.txt", "r", stdin);
    init();
    cin >> n;
    cin >> s;
    for (int d : div[n]) {
        if (d % 2 == 0) {
            continue;
        }
        alen.PB(n / d);
    }
    sort(alen.begin(), alen.end());
    for (int len : alen) {
        int cnl = cntless(s.substr(0, len));
        if (check(s.substr(0, len))) {
            ++cnl;
        }
        d[len] = cnl;
        for (int dd : div[len]) {
            if (dd == len) {
                continue;
            }
            if ((len / dd) % 2 == 0) {
                continue;
            }
            d[len] = (d[len] - d[dd] + mod) % mod;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += (2LL * d[i] * i);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 25692
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
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; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline void LB(vector<T>& v, T& a) { return *lower_bound(ALL(v),a); }
template <typename T> inline void LBP(vector<T>& v, T& a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline void UB(vector<T>& v, T& a) { return *upper_bound(ALL(v),a); }
template <typename T> inline void UBP(vector<T>& v, T& a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

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

  int N,M;
  cin >> N >> M;
  auto A = make_v<int>(N,M);
  cin >> A;
  REP(i,N) REP(j,M) A[i][j]--;
  auto check = [&](int x) {
    vector<int> p(N,0), cnt(M,0);
    vector<bool> used(M,false);
    bool ok = true;
    while (ok) {
      cnt.assign(M,0);
      REP(i,N) cnt[A[i][p[i]]]++;
      int max_pos = max_element(ALL(cnt)) - cnt.begin();
      if (cnt[max_pos] <= x) return true;
      ok = true;
      REP(i,N) if (A[i][p[i]] == max_pos) {
        used[A[i][p[i]]] = true;
        while (p[i] < M && used[A[i][p[i]]]) p[i]++;
        if (p[i] == M) ok = false;
      }
    }
    return false;
  };
  int ng = 0, ok = N;
  while (ok - ng > 1) {
    int mid = (ok + ng) / 2;
    if (check(mid)) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3096
dists = []

N, D = input().split()
N = int(N)
D = int(D)

for i in range (0, N):
  X, Y = input().split()
  dist = int(X)**2 + int(Y)**2
  dists.append(dist)
  
compare = D**2
count = 0
ans = 0

while count < N:
  if dists[count] <= compare:
    ans += 1
  count += 1
print(ans)

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

inline int calc(int x){
	string s = to_string(x);
	int ret = 0;
	for(auto &c:s) ret += (c - '0');
	return ret;
}

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

	int ans = 1 << 20;

	rep(a,1,n){
		const int b = n - a;
		chmin(ans,calc(a) + calc(b));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i32 = read();
    let h: i32 = a / 3600;
    let m: i32 = (a % 3600) / 60;
    let s: i32 = (a % 3600) % 60;

    println!("{}:{}:{}", h, m, s);
}



Measured memory_bytes: 5032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}


int main() {
    int h,w,ans = 0,ans2 = 0;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            vector<vector<int>> dist(h,vector<int>(w,-1));
            if(s[i][j] == '#') continue;
            dist[i][j] = 0;
            queue<pair<int,int>> q;
            q.push({i,j});
            while(!q.empty()){
                int x = q.front().first;
                int y = q.front().second;
                q.pop();
                ans = max(ans,dist[x][y]);
                for (int k = 0; k < 4; ++k) {
                    int nx = x+dx[k];
                    int ny = y+dy[k];
                    if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
                    if(s[nx][ny] == '#') continue;
                    if(dist[nx][ny] != -1) continue;
                    dist[nx][ny] = dist[x][y]+1;
                    q.push({nx,ny});
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define ll unsigned long long

int n;
int a[100000+5], b[100000+5], c[100000+5];
int dp[100000+5][5];

int rec(int i, int prev)
{
    if(i >= n)
        return 0;
    if(dp[i][prev] != -1)
        return dp[i][prev];

    int ret = 0;
    if(prev == 0)
        ret = max(rec(i+1, 1)+b[i], rec(i+1, 2)+c[i]);
    else if(prev == 1)
        ret = max(rec(i+1, 0)+a[i], rec(i+1, 2)+c[i]);
    else if(prev == 2)
        ret = max(rec(i+1, 0)+a[i], rec(i+1, 1)+b[i]);

    return dp[i][prev] = ret;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin >> n;
    for (int i=0; i<n; i++)
        cin >> a[i] >> b[i] >> c[i];
    cout << max({rec(1,0)+a[0], rec(1,1)+b[0], rec(1,2)+c[0]}) << endl;
}



Measured memory_bytes: 11380
#include <stdio.h>

#define MAX 250
int H[MAX];

int main() {
  int n, i, j;
  scanf("%d\n", &n);

  for (i = 0; i < n; i++) {
    scanf("%d", &H[i]);
  }

  for (i = 0; i < n; i++) {
    j = i + 1;
    printf("node %d: key = %d, ", j, H[i]);

    if (j / 2 > 0) {
      printf("parent key = %d, ", H[j/2-1]);
    }

    if (j * 2 <= n) {
      printf("left key = %d, ", H[j*2-1]);
    }
    if ((j * 2 + 1) <= n) {
      printf("right key = %d, ", H[j*2]);
    }

    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#define MAX 105

int queue[100000],g[MAX][MAX],head=0,tail=0,cost[MAX];
void enqueue(int);
int dequeue(void);
void bfs();

int main(){
  int n,i,j,u,k;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    cost[i]=-1;
    scanf("%d%d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&g[u][j]);
    }
    g[u][j]=-1;
  }
  bfs();
  for(i=1;i<=n;i++) printf("%d %d\n",i,cost[i]);
  return 0;
}
void enqueue(int id){
  queue[tail]=id;
  tail++;
}
int dequeue(){
  if(head==tail) return -1;
  return queue[head++]; 
}
void bfs(){
  int id,i;
  enqueue(1); cost[1]=0;
  while((id=dequeue())!=-1){
    for(i=1;g[id][i]!=-1;i++){
	if(cost[g[id][i]]==-1){
	  cost[g[id][i]]=cost[id]+1;
	  enqueue(g[id][i]);
	}
    }
  }
}



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

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

    if (d == 0) {
        printf("%.10f\n", (1.0/n) * (m-1));
    }
    else {
        printf("%.10f\n", 2 * (n - d) / (n * n) * (m - 1));
    }
}


Measured memory_bytes: 256
X1, Y1, X2, Y2 = gets.chomp.split(" ").map(&:to_i)

X3 = X2 + (Y1 - Y2)
Y3 = Y2 - (X1 - X2)
X4 = X3 + (Y2 - Y3)
Y4 = Y3 - (X2 - X3)

puts "#{X3} #{Y3} #{X4} #{Y4}"


Measured memory_bytes: 1788
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = 26;

		int D = sc.nextInt();
		int[] c = new int[N];
		for(int i=0; i<N; i++)
			c[i] = sc.nextInt();
		
		int[][] s = new int[D][N];
		for(int i=0; i<D; i++)
			for(int j=0; j<N; j++)
				s[i][j] = sc.nextInt();
		
		int[] t = new int[D];
		for(int i=0; i<D; i++)
			t[i] = sc.nextInt()-1;
		
		int score = 0;
		int[] last = new int[N];
		for(int i=0; i<D; i++) {
			score += s[i][t[i]];
			last[t[i]]=i+1;
			for(int j=0; j<N; j++)
				score -= c[j]*(i+1-last[j]);
			System.out.println(score);
		}

		sc.close();
	}
}


Measured memory_bytes: 38320
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)
	top, _ := strconv.Atoi(s[0:2])
	bottom, _ := strconv.Atoi(s[2:4])
	if top > 0 && top <= 12 {
		if bottom > 0 && bottom <= 12 {
			fmt.Println("AMBIGUOUS")
		} else {
			fmt.Println("MMYY")
		}
	} else {
		if bottom > 0 && bottom <= 12 {
			fmt.Println("YYMM")
		} else {
			fmt.Println("NA")
		}
	}
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) throws Exception {

		MyScanner sc = new MyScanner();
		PrintWriter pr = new PrintWriter(System.out);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int t = sc.nextInt();
		long count = 0;
		int total = 0;
		
		while(total < n) {
			
			total += x;
			count++;
		}
		
		pr.print(count * t);
		pr.close();
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int rate = Integer.parseInt( br.readLine());

		if(rate < 1200) {
			System.out.println("ABC");
		}else if(rate < 2800) {
			System.out.println("ARC");
		}else {
			System.out.println("AGC");
		}
	}

}


Measured memory_bytes: 22868
#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 priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
signed main(){
  int N; cin>>N;
  int flag=0;
  int ans=1;
  int memo; cin>>memo;
  rep(i,1,N){
    int X; cin>>X;
    if(flag==0){
      if(X<memo)
        flag=1;
      else if(X>memo)
        flag=2;
    }
    else if(flag==1){
      if(memo<X){
        ans++;
        flag=0;
      }
    }
    else{
      if(memo>X){
        ans++;
        flag=0;
      }
    }
    memo=X;
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdbool.h>

#define limit_char_count (100)

//#define DEBUG_BUILD

#ifdef DEBUG_BUILD
# define DEBUG_PRINT(fmt, ...)  printf(fmt, ## __VA_ARGS__)
# define DEBUG_F_PRINT(fp,fmt, ...)  fprintf(fp,fmt, ## __VA_ARGS__)
#else
# define DEBUG_PRINT(fmt, ...)
# define DEBUG_F_PRINT(fmt, ...)
#endif

#ifdef DEBUG_BUILD
FILE *fp;
#endif

typedef struct {
	int taro;
	int hanako;
}Result;

Result Battle(char taro[],char hanako[]);

int main(void) {
	Result score={0};
#ifdef DEBUG_BUILD
	fp=fopen("output.txt","w");
#endif
	int n=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		char taro[limit_char_count]={0};
		char hanako[limit_char_count]={0};
		memset(taro,0,sizeof(taro));
		memset(hanako,0,sizeof(hanako));
		scanf("\n%s",taro);
		scanf("\n%s",hanako);
		Result result =Battle(taro,hanako);
		score.taro+=result.taro;
		score.hanako+=result.hanako;
	}
	printf("%d %d\n",score.taro,score.hanako);

#ifdef DEBUG_BUILD
	fclose(fp);
#endif
	return 0;
}

Result Battle(char taro[],char hanako[]){
	Result result={0};
	DEBUG_PRINT("taro  =%s\n",taro);
	DEBUG_PRINT("hanako=%s\n",hanako);

	int score = strcmp(taro,hanako);
	if(score==0){
		result.taro=1;
		result.hanako=1;
	}
	else if(score>0){
		result.taro=3;
	}
	else{
		result.hanako=3;
	}

	return result;
}




Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <iterator>
#include <vector>
#include <unordered_map>
#include <algorithm>

struct pair_hash {
	template <class T1, class T2>
	std::size_t operator() (const std::pair<T1, T2> &pair) const {
		return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
	}
};

int main()
{
  char s[100001];
  std::cin >> s;
  int try0 = 0, try1 = 0;

  for (int i=0; s[i]!='\0'; i++) {
    if (i%2) {
      if (s[i]=='1') try0++;
    }
    else if (s[i]=='0') try0++;
  }

  for (int i=0; s[i]!='\0'; i++) {
    if (i%2) {
      if (s[i]=='0') try1++;
    }
    else if (s[i]=='1') try1++;
  }

  //std::cout << (try0 > try1)? try1: try0;
  if (try0 > try1) std::cout << try1;
  else std::cout << try0;

  return 0;
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;
#define ll long long int

vector<ll> lunlun;

void findLunlun(ll cur) {

	// deb(cur);

	if (cur < 0)
		return;

	if (cur >= 10000000000)
		return;

	lunlun.push_back(cur);

	int unit_digit = cur % 10;

	findLunlun(cur*10 + unit_digit);

	if (unit_digit > 0)
		findLunlun(cur*10 + unit_digit-1);

	if (unit_digit < 9)
		findLunlun(cur*10 + unit_digit+1);
}

void init() {
	for (int i = 1; i <= 9; i++)
		findLunlun(i);

	sort(lunlun.begin(), lunlun.end());

	// for (auto x: lunlun)
	// 	cout << x << " ";
	// cout << endl;
}

int main() {

	IOS

	init();

	int k;
	cin >> k;
	cout << lunlun[k-1] << endl;

	return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[100005];
int dp[100005];
bool vis[100005];
void dfs(int u)
{
    vis[u]=true;
    for(auto v:adj[u])
    {
        if(vis[v]==false)
            dfs(v);
        dp[u]=max(dp[u],dp[v]+1);
    }


}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
    }
    for(int i=1; i<=n; i++)
    {
        if(vis[i]==false)
            dfs(i);
    }
    int ans=0;
    for(int i=1; i<=n; i++) ans=max(ans,dp[i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 8192
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

long long MOD = 1000000007;

int main(void)
{
    int n, m;
    cin >> n >> m;
    long long a[n + 10], dp[n + 10];
    REP(i, n + 1)
    {
        a[i] = 0;
        dp[i] = 0;
    }

    REP(i, m)
    {
        int t;
        cin >> t;
        a[t] = 1;
    }

    dp[0] = 1;
    for (int i = 0; i <= n; i++)
    {
        if (a[i] == 1)
        {
            continue;
        }
        if (i >= 2)
        {
            if (a[i - 1] == 0)
            {
                dp[i] = dp[i - 1];
            }
            if (a[i - 2] == 0)
            {
                dp[i] = (dp[i] + dp[i - 2]) % MOD;
            }
        }
        else if (i == 1)
        {
            if (a[i] == 0)
            {
                dp[1] = 1;
            }
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 1792
#include<iostream>

using namespace std;

#define ll long long int

ll dp[3001][3001];

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

	string s,t; cin >> s >> t;	

	for(int i = 0; i < s.size(); i++) {
		for(int j = 0; j < t.size(); j++) {
			
			dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
			
			if(s[i] == t[j]) {
				dp[i+1][j+1] = max(dp[i][j]+1,dp[i+1][j+1]); 
			}
		}
	}

	string ans = "";

	int i = s.size();
	int j = t.size();

	while(i > 0 && j > 0) {

		if(dp[i][j] == dp[i-1][j]) i--;
		else if(dp[i][j] == dp[i][j-1])j--;
		else {
			ans = s.substr(i-1,1) + ans;
			i--,j--;
		}
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 70656
#include <cstdio>

using namespace std;

#define FOR(i, a, b) for(i=a; i<b; ++i)

#define MAXN 101

long int k;
char s[MAXN]={0};

void solver() {
  long int len = 0;
  long int i;

  for (i=0; s[i]=='1'; ++i) {
    len++;

    if (k==len) {
      printf("%c\n", s[i]);
      return;
    }   
  }

  printf("%c\n", s[i]);

  return;
}

int main() {
  scanf("%s", s);
  scanf("%d", &k);
  solver();
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<cstring>
using namespace std;
inline int read(){
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
	if(a>=10)write(a/10);
	putchar('0'+a%10);
}
inline void writeln(int a){
	write(a); puts("");
}
const int N=305;
int n,m,a[N][N],tong[N],t[N],sum;
inline bool check(int x){
	int zs=0;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(tong[a[i][j]]){t[a[i][j]]++; break;}
	for(int i=1;i<=m;i++){if(t[i]>x){tong[i]=0;sum--;zs=1;} t[i]=0;}
	if(!zs)return 1; else if(!sum)return 0;
	return check(x);
}
int main(){
	n=read(); m=read();
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)a[i][j]=read();
	int l=1,r=n;
	while(l<r){
		int mid=(l+r)>>1; for(int i=1;i<=m;i++)tong[i]=1; sum=m;
		if(check(mid))r=mid; else l=mid+1;
	}
	writeln(l);
}

Measured memory_bytes: 640
import sys
bbn=1000000007
	
#+++++
		
def main():
	rets=[1,2,3]
	a = int(input())
	b = int(input())
	rets.pop(rets.index(a))
	rets.pop(rets.index(b))

	print(rets[0])
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 38384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct Pr{
	ll x,y;
}l_r[210000],r_l[210000];

struct Te{
	int ls,rs,lv,rv;
}t[210000];

int n;
ll mid;
vector<Pr>V[210000];

void insert(int x,Pr y){
	int i=V[x].size()-1;
	if(V[x].empty())V[x].push_back(y);
	else if(V[x][i].y>y.y){
		if(V[x][i].x==y.x)V[x].pop_back();
		V[x].push_back(y);
	}
}

int dfs(int u){
	V[u].clear();
	int i,j,ltor=0,rtol=0,dt=t[u].lv+t[u].rv;
	int ls=t[u].ls,rs=t[u].rs,lv=t[u].lv,rv=t[u].rv;
	if(t[u].ls==0){
		insert(u,(Pr){0,0});
		return 1;
	}int jud=dfs(t[u].ls)|dfs(t[u].rs);
	if(jud==0)return 0;
	for(i=V[ls].size()-1,j=V[rs].size()-1;i>=0;i--){while(j>=0&&V[ls][i].y+V[rs][j].x+dt>mid)j--;if(j>=0)l_r[++ltor]=(Pr){V[ls][i].x+lv,V[rs][j].y+rv};}
	for(i=V[ls].size()-1,j=V[rs].size()-1;j>=0;j--){while(i>=0&&V[ls][i].x+V[rs][j].y+dt>mid)i--;if(i>=0)r_l[++rtol]=(Pr){V[rs][j].x+rv,V[ls][i].y+lv};}
	reverse(l_r+1,l_r+ltor+1);
	reverse(r_l+1,r_l+rtol+1);
	i=1;j=1;
	while(i<=ltor&&j<=rtol){
		if(l_r[i].x<r_l[j].x){insert(u,l_r[i]);i++;}
		else {insert(u,r_l[j]);j++;}
	}while(i<=ltor){insert(u,l_r[i]);i++;}
	while(j<=rtol){insert(u,r_l[j]);j++;}
//	printf("%d:",u);
//	for(int i=0;i<V[u].size();i++){
//		printf("(%lld %lld),",V[u][i].x,V[u][i].y);
//	}printf("\n");
	return !V[u].empty();
}

int main(){
	int x,y;
	scanf("%d",&n);
	ll L=-1,R=17179869184ll;
	for(int i=2;i<=n;i++){
		scanf("%d %d",&x,&y);
		if(t[x].ls==0)t[x].ls=i,t[x].lv=y;
		else t[x].rs=i,t[x].rv=y;
	}while(L+1<R){
		mid=(L+R)>>1;
		if(dfs(1)){
			R=mid;
		}else L=mid;
	}printf("%lld\n",R);
	return 0;
}

Measured memory_bytes: 35368
X,Y,Z,K=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
B=sorted(list(map(int,input().split())),reverse=True)
C=sorted(list(map(int,input().split())),reverse=True)
ans=[]
for i in range(X):
  if i+1>K:
    break
  for j in range(Y):
    if (i+1)*(j+1)>K:
      break
    for k in range(Z):
      if (i+1)*(j+1)*(k+1)>K:
        break
      ans.append(A[i]+B[j]+C[k])
ans=sorted(ans,reverse=True)
for a in ans[:K]:
  print(a)

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

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector <char> > a(h,vector<char> (w));
    vector<bool> H(h,false);
    vector<bool> W(w,false);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            //cout << i <<j<< endl;
            cin >> a[i][j];
            if(a[i][j] == '#'){
                H[i] = true;
                W[j] = true;
            }
        }
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(H[i]&&W[j]){
                cout << a[i][j];
            }
        }
        if(H[i]){
            cout << endl;
        }
    }
    
    return 0;
}

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

int main() {
    string S, T;
    cin >> S >> T;
    map<char, char> smap;
    map<char, char> tmap;

    rep(i, S.size()) {
        char s = S[i];
        char t = T[i];
        if (smap.count(s) == 0) {
            smap[s] = t;
        } else if (smap[s] != t) {
            cout << "No" << endl;
            return 0;
        }
        
        if (tmap.count(t) == 0) {
            tmap[t] = s;
        } else if (tmap[t] != s) {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
}

Measured memory_bytes: 776
#include <stdio.h>
#include <vector>
using namespace std;

const long long mod = 1000000007;

vector<long long> mul(vector<long long> &a, vector<long long> &b)
{
	vector<long long> r(13);
  for (int i=0;i<13;i++) for (int j=0;j<13;j++){
r[(i+j)%13] = (r[(i+j)%13] + a[i]*b[j]) % mod;
  }
  return r;
}

char S[100100];
int main()
{
  scanf ("%s",S);
  int n = 0;
  while (S[n]) n++;
  long long u = 1;
  vector<long long> a(13); a[0] = 1;
  for (int i=n-1;i>=0;i--){
    vector<long long> b(13);
    if (S[i] == '?'){
for (int i=0;i<10;i++) b[(i*u)%13] = 1;
    }
    else{
b[(S[i]-'0')*u%13] = 1;
    }
    a = mul(a,b);
u = u * 10; u %= 13;
  }
  printf ("%lld\n",a[5]);
return 0;
}

Measured memory_bytes: 3288
#include <iostream>

using namespace std;

int main(void)
{
    long long num;

    cin >> num;

    if(num == 1){
        cout << 0 << endl;
        return 0;
    }

    long long current_num = num;

    int prime_index;
    int manip_sum = 0;

    prime_index = 0;
    while(current_num % 2 == 0){
        current_num /= 2;
        prime_index += 1;
    }

    int cnt = 0;
    while(prime_index > cnt){
        prime_index -= cnt;
        if(prime_index > cnt){
            cnt += 1;
        }
    }
    manip_sum += cnt;

    for(long long i = 3; i * i < num; i += 2){
        prime_index = 0;
        while(current_num % i == 0){
            current_num /= i;
            prime_index += 1;
        }

        int cnt = 0;
        while(prime_index > cnt){
            prime_index -= cnt;
            if(prime_index > cnt){
                cnt += 1;
            }
        }
        manip_sum += cnt;
    }

    if(current_num != 1){
        manip_sum += 1;
    }
    cout << manip_sum << endl;

    return 0;
}

Measured memory_bytes: 3636
n, m, X = map(int, input().split())
 
ans = 10**9
 
price = []
a = []
for _ in range(n):
    c = [int(x) for x in input().split()]
    price.append(c[0])
    a.append(c[1:])
 
for i in range(1 << n):
    l = [0]*m
    tmp = 0
    for j in range(n):
        if (i >> j) & 1:
            tmp += price[j]
            for x in range(m):
                l[x] += a[j][x]
    if all(x >= X for x in l):
        ans = min(ans, tmp)
 
print(-1 if ans == 10**9 else ans)

Measured memory_bytes: 69100
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scanf("%d %d", &h, &w)

	var tx []int
	var ty []int

	for i := 0; i < h; i++ {
		var s string
		fmt.Scanf("%s", &s)
		for k, v := range s {
			if v == 35 {
				tx = append(tx, i)
				ty = append(ty, k)
			}
		}
	}

	d := [][]int{
		[]int{-1, 0},
		[]int{0, 1},
		[]int{0, -1},
		[]int{1, 0},
	}

	for i := 0; i < len(tx); i++ {
		x, y := tx[i], ty[i]

		cnt := 0
		for _, dd := range d {
			xdash, ydash := x+dd[0], y+dd[1]
			if xdash < 0 || ydash < 0 {
				continue
			}
			for j := 0; j < len(tx); j++ {
				if xdash == tx[j] && ydash == ty[j] {
					cnt = cnt + 1
					break
				}
			}
		}
		if cnt == 0 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 1968
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Long[][] ab = new Long[n][3]; // 0:cost 1:limit 2:cumulative sum

		for ( int i = 0; i < n; i++ ) {
			ab[i][0] = in.nextLong();
			ab[i][1] = in.nextLong();
		}
		in.close();

		Arrays.sort(ab, new Comparator<Long[]>() {
			@Override
			public int compare(Long[] p1, Long[] p2) {
				return Long.compare(p1[1], p2[1]);
			}
		});

		ab[0][2] = ab[0][0];
		if ( ab[0][2] > ab[0][1] ) {
			System.out.println("No");
			return;
		}
		for ( int i = 1; i < n; i++ ) {
			ab[i][2] = ab[i][0] + ab[i - 1][2];

			if ( ab[i][2] > ab[i][1] ) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");

	}
}

Measured memory_bytes: 126608
import std.algorithm;
import std.range;
import std.stdio;
import std.typecons;

bool solve (int r, int c, int n)
{
	auto x1 = new int [n];
	auto y1 = new int [n];
	auto x2 = new int [n];
	auto y2 = new int [n];

	bool isBorder (int x, int y)
	{
		return x == 0 || x == r || y == 0 || y == c;
	}

	alias Point = Tuple !(int, q{coord}, int, q{kind});

	auto coord (int x, int y)
	{
		int res = 0;
		if (x == 0)
		{
			debug {writeln ("x == 0");}
			return res + y;
		}
		res += c;
		if (y == c)
		{
			debug {writeln ("y == c");}
			return res + x;
		}
		res += r;
		if (x == r)
		{
			debug {writeln ("x == r");}
			return res + (c - y);
		}
		res += c;
		if (y == 0)
		{
			debug {writeln ("y == 0");}
			return res + (r - x);
		}
		assert (false);
	}

	Point [] points;
	foreach (i; 0..n)
	{
		readf (" %s %s %s %s", &x1[i], &y1[i], &x2[i], &y2[i]);
		if (isBorder (x1[i], y1[i]) && isBorder (x2[i], y2[i]))
		{
			points ~= Point (coord (x1[i], y1[i]), i);
			points ~= Point (coord (x2[i], y2[i]), i);
		}
	}
	debug {writeln (points.map !(point => point.coord));}
	sort (points);

	int [] kinds;
	foreach (ref point; points)
	{
		if (!kinds.empty && kinds[$ - 1] == point.kind)
		{
			kinds.length--;
		}
		else
		{
			kinds.assumeSafeAppend ();
			kinds ~= point.kind;
		}
	}
	return kinds.empty;
}

void main ()
{
	int r, c, n;
	while (readf (" %s %s %s", &r, &c, &n) > 0)
	{
		writeln (solve (r, c, n) ? "YES" : "NO");
	}
}


Measured memory_bytes: 4220
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include <cmath>
//#include <iomanip>
//#include <map>
//#include <unordered_map>
//#include <cstring>
#include <queue>

using namespace std;
using ll = long long;
using pint = pair<int, int>;
// ll INF = 1LL << 60;

int dh[4] = { 1, 0, -1, 0 };
int dw[4] = { 0, 1, 0, -1 };

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<int>> dist(H, vector<int>(W, -1));
	vector<string> field(H);
	int white = 0;
	for (int h = 0; h < H; h++) cin >> field[h];
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			if (field[h][w] == '.') white++;
		}
	}
	queue<pint> q;
	q.push(make_pair(0, 0));
	dist[0][0] = 1;

	while (!q.empty()) {
		pint hw = q.front();
		int h = hw.first;
		int w = hw.second;
		q.pop();
		for (int dir = 0; dir < 4; dir++) {
			int nh = h + dh[dir];
			int nw = w + dw[dir];
			if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
			if (dist[nh][nw] != -1) continue;
			if (field[nh][nw] == '#') continue;
			q.push(make_pair(nh, nw));
			dist[nh][nw] = dist[h][w] + 1;
		}
	}
	if (dist[H - 1][W - 1] == -1) cout << -1 << endl;
	else cout << white - dist[H - 1][W - 1] << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
const ll mod = 1e9 + 7;
 
int main() {
    long double a, b, c;
  	cin >> a >> b >> c;
    if (sqrt(a) + sqrt(b) + 4e-15 < sqrt(c))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int main() {
   int c[5][5];
   rep (i, 3) {
      rep (j, 3) {
         cin >> c[i][j];
      }
   }

   int b2 = c[1][0] - c[0][0];
   int b3 = c[2][0] - c[0][0];
   int b[] = {c[1][0] - c[0][0], c[2][0] - c[0][0]};

   repp (i, 1, 3) {
      rep (j, 3) {
         if (b[i-1] + c[0][j] != c[i][j]) {
            puts("No");
            return 0;
         }
      }
   }

   puts("Yes");

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int partition(vector<int>& vec, int left, int right);

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

    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    int pivot = partition(a, 0, n - 1);
    cout << a[0];
    for (int i = 1; i < n; ++i) {
        if (i == pivot)
            cout << ' ' << "[" << a[i] << "]";
        else
            cout << ' ' << a[i];
    }
    cout << '\n';
}

int partition(vector<int>& vec, int left, int right)
{
    int pivot = vec[right];
    int boundary = left - 1;

    for (int i = left; i < right; ++i) {
        if (vec[i] <= pivot) {
            ++boundary;
            swap(vec[i], vec[boundary]);
        }
    }

    ++boundary;
    swap(vec[boundary], vec[right]);

    return boundary;
}



Measured memory_bytes: 3096
n=int(input())
a=[10**10]+[int(j) for j in input().split()]
b=[int(j) for j in input().split()]
c=[10**10]+[int(j) for j in input().split()]

a.sort()
b.sort()
c.sort()

ans=0
pa=0
pc=0
for j in range(n):
    while a[pa]<b[j]:
        pa+=1
    while c[pc]<=b[j]:
        pc+=1
    ans+=pa*(n-pc)
    
print(ans)

Measured memory_bytes: 105572
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int a[N],n,max1,kk;
int main(){
	scanf("%d",&n);int min1=1e9;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),max1=max(max1,a[i]);
	for (int i=1;i<=n;i++){
		if (a[i]==max1) continue;
		if (abs(a[i]-(max1/2))<min1){
			min1=abs(a[i]-(max1/2));
			kk=a[i];
		}
	}
	printf("%d %d\n",max1,kk);
	return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	int cnt,time,nowTime=0;
	cin >> cnt >> time;
	string name[cnt];
	int data[cnt];
	queue<int> que;
	for(int i=0; i<cnt; i++){
		cin >> name[i] >> data[i];
		que.push(i);
	}

	while(!que.empty()){
		int i = que.front();

		if( data[i] - time <= 0 ){
			nowTime += data[i];
			cout << name[i] << " " << nowTime << endl;
			que.pop();
		}else{
			data[i] -= time;
			nowTime += time;
			que.pop();
			que.push(i);
		}
	}
	return 0;
}

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

double eps = 1e-10;

class Point {
public:
	double x, y;
	
	Point(double x = 0, double y = 0) : x(x), y(y) {}
	
	Point operator + (const Point& p) {
		return Point(x + p.x, y + p.y);
	}
	Point operator - (const Point& p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator * (const double& a) {
		return Point(x * a, y * a);
	}
	Point operator / (const double& a) {
		return Point(x / a, y / a);
	}
	
	bool operator < (const Point& p) const {
		return x != p.x ? x < p.x : y < p.y;
	}
	bool operator == (const Point& p) const {
		return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
	}
	
	double abs() {
		return sqrt(norm());
	}
	double norm() {
		return x * x + y * y;
	}
	
};

class Circle {
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
};

int main() {
	int d[16] = {0}, sum[16] = {0}, v1, v2;
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7], &d[8], &d[9], &v1, &v2) != EOF){
		for(int i = 1; i <= 10; ++i)
			sum[i] = sum[i - 1] + d[i - 1];
		
		double t = (double)sum[10] / (double)(v1 + v2);
		double dv = t * v1;
		for(int i = 1; i <= 10; ++i){
			if(sum[i] >= dv){
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1200
<?php
while($input = fgets(STDIN)){
    if(trim($input)){
        $tmp_array = explode(' ', trim($input));
        $array[] = $tmp_array[0];
        $array[] = $tmp_array[1];
        $array[] = $tmp_array[2];
    }
}

for ($i = 0; $i <count($array); $i++) {
    echo strtoupper(substr($array[$i], 0, 1));
}

Measured memory_bytes: 3828
from collections import defaultdict
def factorization(n):
    arr = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt

    if temp != 1:
        arr[temp] = 1
    if len(arr.keys()) == 0:
        arr[n] = 1
    return arr


def prepare(n, MOD):

    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs

import math
from itertools import combinations
from collections import Counter
MOD = 1000000007

def solve():
    N, M = map(int, input().split())
    temp = factorization(M)
    #print(temp)
    max_num = max(temp.values())
    factorials, invs = prepare(N+max_num-1, MOD)
    #print(factorials, invs)
    ans = 1
    for i, j in temp.items():
        if i == 1:
            break
        ans *= factorials[N+j-1]
        ans %= MOD
        ans *= invs[N-1]
        ans %= MOD
        ans *= invs[j]
        ans %= MOD
        #print(ans)
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 11508